Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bd69e71022d1786bd534a928fc6496cf97a2a7f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*******************************************************************************
 * Copyright (c) 2006, 2013 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.commands.actions;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.commands.IStepFiltersHandler;
import org.eclipse.debug.internal.core.StepFilterManager;
import org.eclipse.debug.internal.ui.DebugPluginImages;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.internal.ui.actions.ActionMessages;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.actions.DebugCommandAction;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;

/**
 * This class provides the action for toggling step filters on or off for the debug view
 */
public class ToggleStepFiltersAction extends DebugCommandAction implements IPreferenceChangeListener {

	private boolean fInitialized = !DebugUITools.isUseStepFilters();

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getDisabledImageDescriptor()
	 */
	@Override
	public ImageDescriptor getDisabledImageDescriptor() {
		return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TOGGLE_STEP_FILTERS);
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getHelpContextId()
	 */
	@Override
	public String getHelpContextId() {
		return "org.eclipse.debug.ui.step_with_filters_action_context"; //$NON-NLS-1$
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getHoverImageDescriptor()
	 */
	@Override
	public ImageDescriptor getHoverImageDescriptor() {
		return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TOGGLE_STEP_FILTERS);
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getId()
	 */
	@Override
	public String getId() {
		return "org.eclipse.debug.ui.actions.ToggleStepFilters"; //$NON-NLS-1$
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getImageDescriptor()
	 */
	@Override
	public ImageDescriptor getImageDescriptor() {
		return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TOGGLE_STEP_FILTERS);
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getText()
	 */
	@Override
	public String getText() {
		return ActionMessages.ToggleStepFiltersAction_1;
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getToolTipText()
	 */
	@Override
	public String getToolTipText() {
		return ActionMessages.ToggleStepFiltersAction_0;
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getInitialEnablement()
	 */
	@Override
	protected boolean getInitialEnablement() {
		return true;
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getCommandType()
	 */
	@Override
	protected Class<IStepFiltersHandler> getCommandType() {
		return IStepFiltersHandler.class;
	}

    /**
     * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#run()
     */
    @Override
	public void run() {
    	// ignore initial call to run from abstract debug view
    	// that runs the action to initialize it's state when
    	// the workbench persisted the action as "on"
    	if (fInitialized) {
    		DebugUITools.setUseStepFilters(!DebugUITools.isUseStepFilters());
    	} else {
    		fInitialized = true;
    	}
    }

    /**
     * @see org.eclipse.jface.action.Action#getStyle()
     */
    @Override
	public int getStyle() {
    	return AS_CHECK_BOX;
    }

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
	 */
	@Override
	public void debugContextChanged(DebugContextEvent event) {
		ISelection context = event.getContext();
		if (context.isEmpty()) {
			setEnabled(true);
		} else {
			super.debugContextChanged(event);
		}
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#init(org.eclipse.ui.IWorkbenchPart)
	 */
	@Override
	public void init(IWorkbenchPart part) {
		super.init(part);
		initState();
	}

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#init(org.eclipse.ui.IWorkbenchWindow)
	 */
	@Override
	public void init(IWorkbenchWindow window) {
		super.init(window);
		initState();
	}

    /**
     * Initializes the state, by adding this action as a property listener
     */
    protected void initState() {
		IEclipsePreferences node = InstanceScope.INSTANCE.getNode(DebugPlugin.getUniqueIdentifier());
		if (node != null) {
			node.addPreferenceChangeListener(this);
		}
    }

	/**
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#dispose()
	 */
	@Override
	public void dispose() {
		super.dispose();
		IEclipsePreferences node = InstanceScope.INSTANCE.getNode(DebugPlugin.getUniqueIdentifier());
		if (node != null) {
			node.removePreferenceChangeListener(this);
		}
	}

	@Override
	public void preferenceChange(PreferenceChangeEvent event) {
		if (event.getKey().equals(StepFilterManager.PREF_USE_STEP_FILTERS)) {
			boolean checked = DebugUITools.isUseStepFilters();
			setChecked(checked);
			IAction action = getActionProxy();
			if (action != null) {
				action.setChecked(checked);
			}
		}
	}
}

Back to the top