01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.texteditor;
11:
12: import java.util.ResourceBundle;
13:
14: import org.eclipse.jface.text.IMarkRegionTarget;
15:
16: /**
17: * An action to handle emacs-like marked regions.
18: *
19: * @since 2.0
20: */
21: public class MarkAction extends TextEditorAction {
22:
23: /** Sets the mark. */
24: public static final int SET_MARK = 0;
25: /** Clears the mark. */
26: public static final int CLEAR_MARK = 1;
27: /** Swaps the mark and the cursor position. */
28: public static final int SWAP_MARK = 2;
29:
30: /** The mark action type. */
31: private final int fType;
32:
33: /**
34: * Constructor for MarkAction.
35: *
36: * @param bundle the resource bundle
37: * @param prefix a prefix to be prepended to the various resource keys
38: * (described in <code>ResourceAction</code> constructor), or
39: * <code>null</code> if none
40: * @param editor the text editor
41: * @param type the mark action type, must be one of
42: * <code>SET_MARK</code>, <code>CLEAR_MARK</code> or <code>SWAP_MARK</code>.
43: */
44: public MarkAction(ResourceBundle bundle, String prefix,
45: ITextEditor editor, int type) {
46: super (bundle, prefix, editor);
47: fType = type;
48: }
49:
50: /*
51: * @see IAction#run()
52: */
53: public void run() {
54:
55: ITextEditor editor = getTextEditor();
56: if (editor == null)
57: return;
58:
59: IMarkRegionTarget target = (IMarkRegionTarget) editor
60: .getAdapter(IMarkRegionTarget.class);
61: if (target == null)
62: return;
63:
64: switch (fType) {
65: case SET_MARK:
66: target.setMarkAtCursor(true);
67: break;
68:
69: case CLEAR_MARK:
70: target.setMarkAtCursor(false);
71: break;
72:
73: case SWAP_MARK:
74: target.swapMarkAndCursor();
75: break;
76: }
77: }
78: }
|