blob: 06581432d1f36a0f0227cfacf3631a329d3d26f1 (
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
|
/*******************************************************************************
* Copyright (c) 2000, 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.ui.console.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.ui.texteditor.IUpdate;
/**
* Common function for actions that operate on a text viewer.
* <p>
* Clients may subclass this class.
* </p>
* @since 3.0
*/
public class TextViewerAction extends Action implements IUpdate {
private int fOperationCode= -1;
private ITextOperationTarget fOperationTarget;
/**
* Constructs a new action in the given text viewer with the specified operation
* code.
*
* @param viewer The viewer containing the action.
* @param operationCode The operation code of the action.
*/
public TextViewerAction(ITextViewer viewer, int operationCode) {
fOperationCode= operationCode;
fOperationTarget= viewer.getTextOperationTarget();
update();
}
/* (non-Javadoc)
* @see org.eclipse.ui.texteditor.IUpdate#update()
*
* Updates the enabled state of the action.
* Fires a property change if the enabled state changes.
*
* @see org.eclipse.jface.action.Action#firePropertyChange(String, Object, Object)
*/
@Override
public void update() {
boolean wasEnabled= isEnabled();
boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode));
setEnabled(isEnabled);
if (wasEnabled != isEnabled) {
firePropertyChange(ENABLED, wasEnabled ? Boolean.TRUE : Boolean.FALSE, isEnabled ? Boolean.TRUE : Boolean.FALSE);
}
}
@Override
public void run() {
if (fOperationCode != -1 && fOperationTarget != null) {
fOperationTarget.doOperation(fOperationCode);
}
}
/**
* Configures this action with a label, tool tip, and description.
*
* @param text action label
* @param toolTipText action tool tip
* @param description action description
*/
public void configureAction(String text, String toolTipText, String description) {
setText(text);
setToolTipText(toolTipText);
setDescription(description);
}
}
|