Changeset 3861 for devel-tools


Ignore:
Timestamp:
Jul 21, 2008, 9:35:08 PM (12 years ago)
Author:
yura
Message:
Location:
devel-tools/trunk/eclipse/org.refal.rfpdt.ui
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/plugin.xml

    r3858 r3861  
    169169               path="edit">
    170170            <groupMarker name="content"/>
    171             <separator name="additions"/>
    172171         </menu>
    173172         <action
     
    189188               label="&amp;Format"
    190189               menubarPath="org.refal.rfpdt.editor.rfpEditorSourceMenu/content"/>
     190         <action
     191               class="org.refal.rfpdt.ui.actions.GotoMatchingBracketAction"
     192               definitionId="org.refal.rfpdt.editor.commands.gotoMatchingBracket"
     193               id="org.refal.rfpdt.editor.gotoMatchingBracket"
     194               label="Matching &amp;Bracket"
     195               menubarPath="navigate/goTo/additions2"/>
    191196         <action
    192197               class="org.refal.rfpdt.ui.actions.OpenDeclarationAction"
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditor.java

    r3860 r3861  
    77import org.eclipse.core.resources.IProject;
    88import org.eclipse.core.runtime.CoreException;
    9 import org.eclipse.jface.action.Action;
    109import org.eclipse.jface.preference.IPreferenceStore;
    1110import org.eclipse.jface.text.BadLocationException;
     
    5655import org.refal.rfpdt.editor.preferences.IPreferenceConstants;
    5756import org.refal.rfpdt.ui.RfpUI;
    58 import org.refal.rfpdt.ui.actions.GotoMatchingBracketAction;
    59 import org.refal.rfpdt.ui.actions.IRfpEditorActionDefinitionIds;
    6057
    6158public class RfpEditor extends TextEditor {
     
    300297    }
    301298
    302     protected void createActions () {
    303         super.createActions();
    304         Action action = new GotoMatchingBracketAction(this);
    305         action.setActionDefinitionId(IRfpEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
    306         setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
    307     }
    308 
    309299    public void createPartControl (Composite parent) {
    310300        super.createPartControl(parent);
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditorMessages.java

    r3858 r3861  
    2222    }
    2323
    24     public static String GotoMatchingBracket_label;
    2524    public static String GotoMatchingBracket_error_invalidSelection;
    2625    public static String GotoMatchingBracket_error_noMatchingBracket;
    27     public static String GotoMatchingBracket_error_bracketOutsideSelectedElement;
    28    
    29     public static String OpenDeclaration_label;
     26
    3027    public static String OpenDeclaration_error_invalidSelection;
    3128}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditorMessages.properties

    r3858 r3861  
    1 GotoMatchingBracket_label = Matching &Bracket
    21GotoMatchingBracket_error_invalidSelection = No bracket selected
    32GotoMatchingBracket_error_noMatchingBracket = No matching bracket found
    4 GotoMatchingBracket_error_bracketOutsideSelectedElement = Matching bracket is outside the selected element
    53
    6 OpenDeclaration_label = &Open Declaration
    74OpenDeclaration_error_invalidSelection = Current selection doesn't resolve to Refal element
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/GotoMatchingBracketAction.java

    r3508 r3861  
    11package org.refal.rfpdt.ui.actions;
    22
    3 import org.eclipse.core.runtime.Assert;
    4 import org.eclipse.jface.action.Action;
    53import org.eclipse.jface.text.IDocument;
    64import org.eclipse.jface.text.IRegion;
     
    86import org.eclipse.jface.text.source.ISourceViewer;
    97import org.eclipse.swt.custom.StyledText;
    10 import org.refal.rfpdt.editor.RfpEditor;
    118import org.refal.rfpdt.editor.RfpEditorMessages;
    129
    13 public class GotoMatchingBracketAction extends Action {
    14     public static final String GOTO_MATCHING_BRACKET = "gotoMatchingBracket"; //$NON-NLS-1$
    15 
    16     private final RfpEditor editor;
    17 
    18     public GotoMatchingBracketAction (RfpEditor editor) {
    19         super(RfpEditorMessages.GotoMatchingBracket_label);
    20         Assert.isNotNull(editor);
    21         this.editor = editor;
    22         setEnabled(true);
    23         // PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
    24         // IJavaHelpContextIds.GOTO_MATCHING_BRACKET_ACTION);
    25     }
    26 
     10public class GotoMatchingBracketAction extends RfpEditorActionDelegate {
    2711    public void run () {
    2812        /*
     
    3519        StyledText text = sourceViewer.getTextWidget();
    3620        IRegion region = editor.getBracketMatcher().match(document, editor.widgetOffset2ModelOffset(text.getCaretOffset()));
    37         if (region == null) {
     21        if (region == null) { // FIXME: sometimes another error is needed (GotoMatchingBracket_error_invalidSelection)
    3822            editor.statusLineErrorMessage(RfpEditorMessages.GotoMatchingBracket_error_noMatchingBracket);
    3923            text.getDisplay().beep();
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/RfpEditorActionContributor.java

    r3508 r3861  
    33import org.eclipse.jface.action.IMenuManager;
    44import org.eclipse.jface.action.Separator;
    5 import org.eclipse.ui.IEditorPart;
    65import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
    7 import org.eclipse.ui.texteditor.ITextEditor;
    8 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
    9 import org.refal.rfpdt.editor.RfpEditorMessages;
    106
    117public class RfpEditorActionContributor extends BasicTextEditorActionContributor {
    12 
    13     private RetargetTextEditorAction gotoMatchingBracket;
    14 
    15     public RfpEditorActionContributor () {
    16         super();
    17         gotoMatchingBracket = new RetargetTextEditorAction(RfpEditorMessages.getBundleForConstructedKeys(), "GotoMatchingBracket."); //$NON-NLS-1$
    18         gotoMatchingBracket.setActionDefinitionId(IRfpEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
    19     }
    20 
    21     /*
    22      * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
    23      */
    24     public void contributeToMenu(IMenuManager menu) {
    25 
    26         super.contributeToMenu(menu);
    27 
    28         IMenuManager gotoMenu= menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$
    29         if (gotoMenu != null) {
    30             gotoMenu.add(new Separator("additions2"));  //$NON-NLS-1$
    31 //            gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
    32 //            gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
    33             gotoMenu.appendToGroup("additions2", gotoMatchingBracket); //$NON-NLS-1$
    34         }
    35     }
    36 
    37     /*
    38      * @see EditorActionBarContributor#setActiveEditor(IEditorPart)
    39      */
    40     public void setActiveEditor(IEditorPart part) {
    41 
    42         super.setActiveEditor(part);
    43 
    44         ITextEditor textEditor = null;
    45         if (part instanceof ITextEditor)
    46             textEditor = (ITextEditor)part;
    47 
    48         gotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
     8    public void contributeToMenu (IMenuManager menu) {
     9        IMenuManager gotoMenu = menu.findMenuUsingPath("navigate/goTo"); //$NON-NLS-1$
     10        if (gotoMenu != null)
     11            gotoMenu.add(new Separator("additions2")); //$NON-NLS-1$
    4912    }
    5013}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/ToggleCommentAction.java

    r3520 r3861  
    66package org.refal.rfpdt.ui.actions;
    77
    8 import org.eclipse.jface.action.Action;
    9 import org.eclipse.jface.action.IAction;
    108import org.eclipse.jface.dialogs.MessageDialog;
    119import org.eclipse.jface.text.BadLocationException;
     
    1917import org.eclipse.swt.widgets.Display;
    2018import org.eclipse.swt.widgets.Shell;
    21 import org.eclipse.ui.IEditorActionDelegate;
    22 import org.eclipse.ui.IEditorPart;
    23 import org.refal.rfpdt.editor.RfpEditor;
    2419import org.refal.rfpdt.ui.RfpUI;
    2520
    26 public class ToggleCommentAction extends Action implements IEditorActionDelegate {
     21public class ToggleCommentAction extends RfpEditorActionDelegate {
     22    private static final String[] commentPrefixes = { "//" };
    2723
    28         private RfpEditor editor;
    29        
    30         private static final String[] commentPrefixes = { "//" };
    31        
    32         public ToggleCommentAction(RfpEditor editor) {
    33                 this.editor = editor;
    34         }
     24    /**
     25     * Checks if the selected lines are all commented or not and uncomments/comments them respectively.
     26     */
     27    public void run () {
     28        if (editor == null || !editor.validateEditorInputState())
     29            return;
     30        final int operationCode;
     31        if (isSelectionCommented(editor.getSelectionProvider().getSelection()))
     32            operationCode = ITextOperationTarget.STRIP_PREFIX;
     33        else
     34            operationCode = ITextOperationTarget.PREFIX;
     35        Shell shell = editor.getSite().getShell();
     36        final ITextOperationTarget operationTarget = (ITextOperationTarget) editor
     37                .getAdapter(ITextOperationTarget.class);
     38        if (!operationTarget.canDoOperation(operationCode)) {
     39            if (shell != null)
     40                MessageDialog.openError(shell, "Toggle Comment", "An error occurred while toggling comments.");
     41            return;
     42        }
     43        Display display = null;
     44        if (shell != null && !shell.isDisposed())
     45            display = shell.getDisplay();
    3546
    36         public ToggleCommentAction() {
    37         }
     47        BusyIndicator.showWhile(display, new Runnable() {
     48            public void run () {
     49                operationTarget.doOperation(operationCode);
     50            }
     51        });
     52    }
    3853
    39         public void run(IAction action) {
    40                 this.run();
    41         }
     54    /**
     55     * Is the given selection single-line commented?
     56     *
     57     * @param selection
     58     *            Selection to check
     59     * @return <code>true</code> iff all selected lines are commented
     60     */
     61    private boolean isSelectionCommented (ISelection selection) {
     62        if (!(selection instanceof ITextSelection))
     63            return false;
     64        ITextSelection textSelection = (ITextSelection) selection;
     65        if (textSelection.getStartLine() < 0 || textSelection.getEndLine() < 0)
     66            return false;
     67        IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
     68        if (!isBlockCommented(textSelection.getStartLine(), textSelection.getEndLine(), commentPrefixes, document))
     69            return false;
     70        return true;
     71    }
    4272
    43         /**
    44          * Implementation of the <code>IAction</code> prototype. Checks if the selected
    45          * lines are all commented or not and uncomments/comments them respectively.
    46          */
    47         public void run() {
    48 
    49                 if (editor == null)
    50                         return;
    51                
    52                 if (!editor.validateEditorInputState())
    53                         return;
    54 
    55                 final int operationCode;
    56                 if (isSelectionCommented(editor.getSelectionProvider().getSelection()))
    57                         operationCode = ITextOperationTarget.STRIP_PREFIX;
    58                 else
    59                         operationCode = ITextOperationTarget.PREFIX;
    60 
    61                 Shell shell= editor.getSite().getShell();
    62                 final ITextOperationTarget operationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
    63                 if (!operationTarget.canDoOperation(operationCode)) {
    64                         if (shell != null)
    65                                 MessageDialog.openError(shell, "Toggle Comment", "An error occurred while toggling comments.");
    66                         return;
    67                 }
    68 
    69                 Display display = null;
    70                 if (shell != null && !shell.isDisposed())
    71                         display = shell.getDisplay();
    72 
    73                 BusyIndicator.showWhile(display, new Runnable() {
    74                         public void run() {
    75                                 operationTarget.doOperation(operationCode);
    76                         }
    77                 });
    78         }
    79 
    80         /**
    81          * Is the given selection single-line commented?
    82          *
    83          * @param selection Selection to check
    84          * @return <code>true</code> iff all selected lines are commented
    85          */
    86         private boolean isSelectionCommented(ISelection selection) {
    87                 if (!(selection instanceof ITextSelection))
    88                         return false;
    89                 ITextSelection textSelection = (ITextSelection) selection;
    90                 if (textSelection.getStartLine() < 0 || textSelection.getEndLine() < 0)
    91                         return false;
    92                 IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    93                 if (!isBlockCommented(textSelection.getStartLine(), textSelection.getEndLine(), commentPrefixes, document))
    94                         return false;
    95                 return true;
    96         }
    97 
    98         /**
    99          * Determines whether each line is prefixed by one of the prefixes.
    100          *
    101          * @param startLine Start line in document
    102          * @param endLine End line in document
    103          * @param prefixes Possible comment prefixes
    104          * @param document The document
    105          * @return <code>true</code> iff each line from <code>startLine</code>
    106          *             to and including <code>endLine</code> is prepended by one
    107          *             of the <code>prefixes</code>, ignoring whitespace at the
    108          *             begin of line
    109          */
    110         private boolean isBlockCommented(int startLine, int endLine,
    111                         String[] prefixes, IDocument document) {
    112 
    113                 try {
    114 
    115                         // check for occurrences of prefixes in the given lines
    116                         for (int i = startLine; i <= endLine; i++) {
    117 
    118                                 IRegion line = document.getLineInformation(i);
    119                                 String text = document.get(line.getOffset(), line.getLength());
    120 
    121                                 int[] found = TextUtilities.indexOf(prefixes, text, 0);
    122 
    123                                 if (found[0] == -1)
    124                                         // found a line which is not commented
    125                                         return false;
    126 
    127                                 String s = document.get(line.getOffset(), found[0]);
    128                                 s = s.trim();
    129                                 if (s.length() != 0)
    130                                         // found a line which is not commented
    131                                         return false;
    132 
    133                         }
    134 
    135                         return true;
    136 
    137                 } catch (BadLocationException x) {
    138                         // should not happen
    139                     RfpUI.log(x);
    140                 }
    141 
    142                 return false;
    143         }
    144 
    145         public void setActiveEditor(IAction action, IEditorPart editor) {
    146                 if (editor instanceof RfpEditor)
    147                         this.editor = (RfpEditor) editor;
    148                 else
    149                         this.editor = null;
    150         }
    151 
    152         public void selectionChanged(IAction action, ISelection selection) {
    153         }
     73    /**
     74     * Determines whether each line is prefixed by one of the prefixes.
     75     *
     76     * @param startLine
     77     *            Start line in document
     78     * @param endLine
     79     *            End line in document
     80     * @param prefixes
     81     *            Possible comment prefixes
     82     * @param document
     83     *            The document
     84     * @return <code>true</code> iff each line from <code>startLine</code> to and including <code>endLine</code> is
     85     *         prepended by one of the <code>prefixes</code>, ignoring whitespace at the begin of line
     86     */
     87    private boolean isBlockCommented (int startLine, int endLine, String[] prefixes, IDocument document) {
     88        try {
     89            // check for occurrences of prefixes in the given lines
     90            for (int i = startLine; i <= endLine; i++) {
     91                IRegion line = document.getLineInformation(i);
     92                String text = document.get(line.getOffset(), line.getLength());
     93                int[] found = TextUtilities.indexOf(prefixes, text, 0);
     94                if (found[0] == -1)
     95                    // found a line which is not commented
     96                    return false;
     97                String s = document.get(line.getOffset(), found[0]);
     98                s = s.trim();
     99                if (s.length() != 0)
     100                    // found a line which is not commented
     101                    return false;
     102            }
     103            return true;
     104        } catch (BadLocationException x) {
     105            // should not happen
     106            RfpUI.log(x);
     107        }
     108        return false;
     109    }
    154110}
Note: See TracChangeset for help on using the changeset viewer.