Changeset 3859
- Timestamp:
- Jul 21, 2008, 7:27:20 PM (12 years ago)
- Location:
- devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/FormatAction.java
r3508 r3859 5 5 6 6 public class FormatAction extends IndentAction { 7 protected ITextSelection getSelection() {8 9 10 11 12 7 protected ITextSelection getSelection () { 8 ITextSelection selection = super.getSelection(); 9 if (selection.getLength() == 0) 10 selection = new TextSelection(0, getDocument().getLength()); 11 return selection; 12 } 13 13 } -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/IndentAction.java
r3520 r3859 1 1 package org.refal.rfpdt.ui.actions; 2 2 3 import org.eclipse.jface.action.IAction;4 3 import org.eclipse.jface.text.BadLocationException; 5 4 import org.eclipse.jface.text.IDocument; … … 8 7 import org.eclipse.jface.text.ITextSelection; 9 8 import org.eclipse.jface.text.Position; 10 import org.eclipse.jface.text.TextSelection;11 import org.eclipse.jface.viewers.ISelection;12 import org.eclipse.jface.viewers.ISelectionProvider;13 9 import org.eclipse.swt.custom.BusyIndicator; 14 10 import org.eclipse.swt.widgets.Display; 15 import org.eclipse.ui.IEditorActionDelegate;16 import org.eclipse.ui.IEditorInput;17 import org.eclipse.ui.IEditorPart;18 import org.eclipse.ui.texteditor.IDocumentProvider;19 11 import org.refal.rfpdt.editor.Document; 20 12 import org.refal.rfpdt.editor.RfpAutoIndentStrategy; 21 import org.refal.rfpdt.editor.RfpEditor;22 13 import org.refal.rfpdt.ui.RfpUI; 23 14 24 public class IndentAction implements IEditorActionDelegate { 25 26 private RfpEditor editor; 27 28 public IndentAction () {} 29 30 public void run (IAction action) { 31 this.run(); 32 } 33 15 public class IndentAction extends RfpEditorActionDelegate { 34 16 public void run () { 35 36 if (editor == null) 17 if (editor == null || !editor.validateEditorInputState()) 37 18 return; 38 39 if (!editor.validateEditorInputState())40 return;41 42 19 ITextSelection selection = getSelection(); 43 20 final IDocument document = getDocument(); 44 45 21 if (document != null) { 46 47 22 final int offset = selection.getOffset(); 48 23 final int length = selection.getLength(); 49 24 final Position end = new Position(offset + length); 50 25 final int firstLine, nLines; 51 52 26 try { 53 27 document.addPosition(end); … … 61 35 return; 62 36 } 63 64 37 Runnable runnable = new Runnable() { 65 38 public void run () { … … 97 70 } 98 71 }; 99 100 72 if (nLines > 57) { 101 73 Display display = editor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(); … … 105 77 } 106 78 } 107 108 /**109 * Returns the document currently displayed in the editor, or <code>null</code> if none can be obtained.110 *111 * @return the current document or <code>null</code>112 */113 protected IDocument getDocument () {114 if (editor != null) {115 116 IDocumentProvider provider = editor.getDocumentProvider();117 IEditorInput input = editor.getEditorInput();118 if (provider != null && input != null)119 return provider.getDocument(input);120 121 }122 return null;123 }124 125 /**126 * Returns the editor's selection provider.127 *128 * @return the editor's selection provider or <code>null</code>129 */130 protected ISelectionProvider getSelectionProvider () {131 if (editor != null) {132 return editor.getSelectionProvider();133 }134 return null;135 }136 137 /**138 * Returns the selection on the editor or an invalid selection if none can be obtained. Returns never139 * <code>null</code>.140 *141 * @return the current selection, never <code>null</code>142 */143 protected ITextSelection getSelection () {144 ISelectionProvider provider = getSelectionProvider();145 if (provider != null) {146 147 ISelection selection = provider.getSelection();148 if (selection instanceof ITextSelection)149 return (ITextSelection) selection;150 }151 152 // null object153 return TextSelection.emptySelection();154 }155 156 public void setActiveEditor (IAction action, IEditorPart editor) {157 if (editor instanceof RfpEditor)158 this.editor = (RfpEditor) editor;159 else160 this.editor = null;161 }162 163 public void selectionChanged (IAction action, ISelection selection) {}164 79 } -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/OpenDeclarationAction.java
r3858 r3859 3 3 import java.util.List; 4 4 5 import org.eclipse.jface.text.IDocument;6 5 import org.eclipse.jface.text.source.ISourceViewer; 7 import org.eclipse.swt.custom.StyledText;8 6 import org.refal.rfpdt.ast.AstCall; 9 7 import org.refal.rfpdt.ast.AstCut; … … 17 15 import org.refal.rfpdt.editor.RfpEditorMessages; 18 16 19 public class OpenDeclarationAction extends Rfp Action{17 public class OpenDeclarationAction extends RfpEditorActionDelegate { 20 18 public static final String OPEN_DECLARATION = "openDeclaration"; //$NON-NLS-1$ 21 19 22 20 public void run () { 21 if (editor == null) 22 return; 23 23 ISourceViewer sourceViewer = editor.sourceViewer(); 24 IDocument document = sourceViewer.getDocument(); 25 if (document == null) 26 return; 27 StyledText text = sourceViewer.getTextWidget(); 28 List<AstNode> nodeList = editor.getNodes(editor.widgetOffset2ModelOffset(text.getCaretOffset())); 24 List<AstNode> nodeList = editor.getNodes(getSelection().getOffset()); 29 25 if (nodeList == null) { 30 26 editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection); 31 text.getDisplay().beep();27 sourceViewer.getTextWidget().getDisplay().beep(); 32 28 return; 33 29 } … … 35 31 if (astNode == null) { 36 32 editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection); 37 text.getDisplay().beep();33 sourceViewer.getTextWidget().getDisplay().beep(); 38 34 return; 39 35 } -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/RfpEditorActionDelegate.java
r3858 r3859 13 13 import org.refal.rfpdt.editor.RfpEditor; 14 14 15 public abstract class RfpAction implements IEditorActionDelegate { 16 protected RfpEditor editor; 15 public abstract class RfpEditorActionDelegate implements IEditorActionDelegate { 16 /** May be <code>null</code>! */ 17 protected RfpEditor editor = null; 17 18 18 19 public void run (IAction action) { … … 43 44 */ 44 45 protected ISelectionProvider getSelectionProvider () { 45 if (editor != null) {46 if (editor != null) 46 47 return editor.getSelectionProvider(); 47 }48 48 return null; 49 49 } … … 58 58 ISelectionProvider provider = getSelectionProvider(); 59 59 if (provider != null) { 60 61 60 ISelection selection = provider.getSelection(); 62 61 if (selection instanceof ITextSelection) 63 62 return (ITextSelection) selection; 64 63 } 65 66 // null object67 64 return TextSelection.emptySelection(); 68 65 }
Note: See TracChangeset
for help on using the changeset viewer.