blob: 6f683866f3e2269076cddc2f2c4dbbd169a5f8ee (
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
|
/*******************************************************************************
* Copyright (c) 2015 Andrey Loskutov and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrey Loskutov <loskutov@gmx.de> - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.texteditor;
import java.util.ResourceBundle;
import org.eclipse.jface.action.IAction;
/**
* This action toggles the word wrap in the editor.
*
* @since 3.10
*/
final class WordWrapToggleAction extends TextEditorAction {
/**
* Construct the action and initialize its state.
*
* @param resourceBundle the resource bundle to construct label and tooltip from
* @param prefix the prefix to use for constructing resource bundle keys
* @param editor the editor this action is associated with
* @param checked initial toggle state
*/
public WordWrapToggleAction(ResourceBundle resourceBundle, String prefix, ITextEditor editor, boolean checked) {
super(resourceBundle, prefix, editor, IAction.AS_CHECK_BOX);
update(checked);
}
@Override
public void run() {
boolean newState = false;
if (isWordWrapPossible()) {
ITextEditorExtension6 ext6= (ITextEditorExtension6) getTextEditor();
newState= !ext6.isWordWrapEnabled();
ext6.setWordWrap(newState);
}
update(newState);
}
private void update(boolean checked) {
setEnabled(isWordWrapPossible());
setChecked(checked);
}
@Override
public void update() {
setEnabled(isWordWrapPossible());
setChecked(isWordWrapEnabled());
}
private boolean isWordWrapPossible(){
return getTextEditor() instanceof ITextEditorExtension6;
}
private boolean isWordWrapEnabled(){
if (isWordWrapPossible()) {
return ((ITextEditorExtension6)getTextEditor()).isWordWrapEnabled();
}
return false;
}
}
|