Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 379e15e56e63be769ca7b2f6e23083aa0d3fb7dc (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
/*******************************************************************************
 * Copyright (c) 2009 Avaloq Evolution AG, 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:
 *     Tom Eicher (Avaloq Evolution AG) - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.texteditor;

import java.util.ResourceBundle;

import org.eclipse.jface.action.IAction;


/**
 * This action toggles the block (aka column) selection mode.
 *
 * @since 3.5
 */
final class BlockSelectionModeToggleAction 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
	 */
	public BlockSelectionModeToggleAction(ResourceBundle resourceBundle, String prefix, ITextEditor editor) {
		super(resourceBundle, prefix, editor, IAction.AS_CHECK_BOX);
	}

	@Override
	public void run() {
		ITextEditor editor= getTextEditor();
		if (editor instanceof ITextEditorExtension5) {
			ITextEditorExtension5 ext5= (ITextEditorExtension5) editor;
			ext5.setBlockSelectionMode(!ext5.isBlockSelectionModeEnabled());
		}
		update(); // update in case anyone else has directly accessed the widget
	}

	@Override
	public void update() {
		ITextEditor editor= getTextEditor();
		if (editor instanceof ITextEditorExtension5) {
			ITextEditorExtension5 ext5= (ITextEditorExtension5) editor;
			setEnabled(true);
			setChecked(ext5.isBlockSelectionModeEnabled());
			return;
		}
		setEnabled(false);
		setChecked(false);
	}
}

Back to the top