Changeset 3859 for devel-tools/trunk


Ignore:
Timestamp:
Jul 21, 2008, 7:27:20 PM (12 years ago)
Author:
yura
Message:
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  
    55
    66public class FormatAction extends IndentAction {
    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         }
     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    }
    1313}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/IndentAction.java

    r3520 r3859  
    11package org.refal.rfpdt.ui.actions;
    22
    3 import org.eclipse.jface.action.IAction;
    43import org.eclipse.jface.text.BadLocationException;
    54import org.eclipse.jface.text.IDocument;
     
    87import org.eclipse.jface.text.ITextSelection;
    98import 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;
    139import org.eclipse.swt.custom.BusyIndicator;
    1410import 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;
    1911import org.refal.rfpdt.editor.Document;
    2012import org.refal.rfpdt.editor.RfpAutoIndentStrategy;
    21 import org.refal.rfpdt.editor.RfpEditor;
    2213import org.refal.rfpdt.ui.RfpUI;
    2314
    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 
     15public class IndentAction extends RfpEditorActionDelegate {
    3416    public void run () {
    35 
    36         if (editor == null)
     17        if (editor == null || !editor.validateEditorInputState())
    3718            return;
    38 
    39         if (!editor.validateEditorInputState())
    40             return;
    41 
    4219        ITextSelection selection = getSelection();
    4320        final IDocument document = getDocument();
    44 
    4521        if (document != null) {
    46 
    4722            final int offset = selection.getOffset();
    4823            final int length = selection.getLength();
    4924            final Position end = new Position(offset + length);
    5025            final int firstLine, nLines;
    51 
    5226            try {
    5327                document.addPosition(end);
     
    6135                return;
    6236            }
    63 
    6437            Runnable runnable = new Runnable() {
    6538                public void run () {
     
    9770                }
    9871            };
    99 
    10072            if (nLines > 57) {
    10173                Display display = editor.getEditorSite().getWorkbenchWindow().getShell().getDisplay();
     
    10577        }
    10678    }
    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 never
    139      * <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 object
    153         return TextSelection.emptySelection();
    154     }
    155 
    156     public void setActiveEditor (IAction action, IEditorPart editor) {
    157         if (editor instanceof RfpEditor)
    158             this.editor = (RfpEditor) editor;
    159         else
    160             this.editor = null;
    161     }
    162 
    163     public void selectionChanged (IAction action, ISelection selection) {}
    16479}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/OpenDeclarationAction.java

    r3858 r3859  
    33import java.util.List;
    44
    5 import org.eclipse.jface.text.IDocument;
    65import org.eclipse.jface.text.source.ISourceViewer;
    7 import org.eclipse.swt.custom.StyledText;
    86import org.refal.rfpdt.ast.AstCall;
    97import org.refal.rfpdt.ast.AstCut;
     
    1715import org.refal.rfpdt.editor.RfpEditorMessages;
    1816
    19 public class OpenDeclarationAction extends RfpAction {
     17public class OpenDeclarationAction extends RfpEditorActionDelegate {
    2018    public static final String OPEN_DECLARATION = "openDeclaration"; //$NON-NLS-1$
    2119
    2220    public void run () {
     21        if (editor == null)
     22            return;
    2323        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());
    2925        if (nodeList == null) {
    3026            editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection);
    31             text.getDisplay().beep();
     27            sourceViewer.getTextWidget().getDisplay().beep();
    3228            return;
    3329        }
     
    3531        if (astNode == null) {
    3632            editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection);
    37             text.getDisplay().beep();
     33            sourceViewer.getTextWidget().getDisplay().beep();
    3834            return;
    3935        }
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/RfpEditorActionDelegate.java

    r3858 r3859  
    1313import org.refal.rfpdt.editor.RfpEditor;
    1414
    15 public abstract class RfpAction implements IEditorActionDelegate {
    16     protected RfpEditor editor;
     15public abstract class RfpEditorActionDelegate implements IEditorActionDelegate {
     16    /** May be <code>null</code>! */
     17    protected RfpEditor editor = null;
    1718
    1819    public void run (IAction action) {
     
    4344     */
    4445    protected ISelectionProvider getSelectionProvider () {
    45         if (editor != null) {
     46        if (editor != null)
    4647            return editor.getSelectionProvider();
    47         }
    4848        return null;
    4949    }
     
    5858        ISelectionProvider provider = getSelectionProvider();
    5959        if (provider != null) {
    60 
    6160            ISelection selection = provider.getSelection();
    6261            if (selection instanceof ITextSelection)
    6362                return (ITextSelection) selection;
    6463        }
    65 
    66         // null object
    6764        return TextSelection.emptySelection();
    6865    }
Note: See TracChangeset for help on using the changeset viewer.