Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 36946515c36f3eeb1a14df1234a228e9ad3b9ff5 (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
/*******************************************************************************
 * Copyright (c) 2000, 2005 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.texteditor;


import java.util.ResourceBundle;

import org.eclipse.jface.text.IMarkRegionTarget;

/**
 * An action to handle emacs-like marked regions.
 *
 * @since 2.0
 */
public class MarkAction extends TextEditorAction {

	/** Sets the mark. */
	public static final int SET_MARK= 0;
	/** Clears the mark. */
	public static final int CLEAR_MARK= 1;
	/** Swaps the mark and the cursor position. */
	public static final int SWAP_MARK= 2;

	/** The mark action type. */
	private final int fType;

	/**
	 * Constructor for MarkAction.
	 *
	 * @param bundle the resource bundle
	 * @param prefix a prefix to be prepended to the various resource keys
	 *   (described in <code>ResourceAction</code> constructor), or
	 *   <code>null</code> if none
	 * @param editor the text editor
	 * @param type the mark action type, must be one of
	 * <code>SET_MARK</code>, <code>CLEAR_MARK</code> or <code>SWAP_MARK</code>.
	 */
	public MarkAction(ResourceBundle bundle, String prefix, ITextEditor editor, int type) {
		super(bundle, prefix, editor);
		fType= type;
	}

	@Override
	public void run() {

		ITextEditor editor= getTextEditor();
		if (editor == null)
			return;

		IMarkRegionTarget target= editor.getAdapter(IMarkRegionTarget.class);
		if (target == null)
			return;

		switch (fType) {
		case SET_MARK:
			target.setMarkAtCursor(true);
			break;

		case CLEAR_MARK:
			target.setMarkAtCursor(false);
			break;

		case SWAP_MARK:
			target.swapMarkAndCursor();
			break;
		}
	}
}

Back to the top