Changeset 4067 for devel-tools/trunk


Ignore:
Timestamp:
Feb 5, 2009, 3:49:17 PM (12 years ago)
Author:
yura
Message:
Location:
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/BracketMatcher.java

    r3508 r4067  
    1 /**
    2  *
    3  */
    41package org.refal.rfpdt.editor;
    52
     
    129public class BracketMatcher implements ICharacterPairMatcher {
    1310    private int fAnchor = -1;
     11   
     12    public static boolean isBracket (IDocument doc, int offset) {
     13        if (doc == null || offset < 0 || offset > doc.getLength())
     14            return false;
     15        try {
     16            offset = Math.max(offset - 1, 0);
     17            char prevChar = doc.getChar(offset);
     18            return Document.isOpen(prevChar) || Document.isClose(prevChar);
     19        } catch (BadLocationException ble) {
     20            return false;
     21        }
     22    }
    1423
    1524    public IRegion match (IDocument doc, int offset) {
     
    4352        fAnchor = -1;
    4453    }
    45 
    4654}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditorMessages.java

    r3861 r4067  
    2222    }
    2323
    24     public static String GotoMatchingBracket_error_invalidSelection;
    25     public static String GotoMatchingBracket_error_noMatchingBracket;
     24    public static String GotoMatchingBracketAction_error_invalidSelection;
     25    public static String GotoMatchingBracketAction_error_noMatchingBracket;
    2626
    27     public static String OpenDeclaration_error_invalidSelection;
     27    public static String OpenDeclarationAction_error_invalidSelection;
    2828}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditorMessages.properties

    r3861 r4067  
    1 GotoMatchingBracket_error_invalidSelection = No bracket selected
    2 GotoMatchingBracket_error_noMatchingBracket = No matching bracket found
     1GotoMatchingBracketAction_error_invalidSelection = No bracket selected
     2GotoMatchingBracketAction_error_noMatchingBracket = No matching bracket found
    33
    4 OpenDeclaration_error_invalidSelection = Current selection doesn't resolve to Refal element
     4OpenDeclarationAction_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

    r3861 r4067  
    66import org.eclipse.jface.text.source.ISourceViewer;
    77import org.eclipse.swt.custom.StyledText;
     8import org.refal.rfpdt.editor.BracketMatcher;
    89import org.refal.rfpdt.editor.RfpEditorMessages;
    910
    1011public class GotoMatchingBracketAction extends RfpEditorActionDelegate {
    1112    public void run () {
    12         /*
    13          * TODO: Keep (extend and shrink as necessary) current selection while jumping to matching bracket.
    14          */
     13        // TODO: Keep (extend and shrink as necessary) current selection while jumping to matching bracket.
    1514        ISourceViewer sourceViewer = editor.sourceViewer();
    1615        IDocument document = sourceViewer.getDocument();
     
    1817            return;
    1918        StyledText text = sourceViewer.getTextWidget();
    20         IRegion region = editor.getBracketMatcher().match(document, editor.widgetOffset2ModelOffset(text.getCaretOffset()));
    21         if (region == null) { // FIXME: sometimes another error is needed (GotoMatchingBracket_error_invalidSelection)
    22             editor.statusLineErrorMessage(RfpEditorMessages.GotoMatchingBracket_error_noMatchingBracket);
     19        int modelOffset = editor.widgetOffset2ModelOffset(text.getCaretOffset());
     20        if (!BracketMatcher.isBracket(document, modelOffset)) {
     21            editor.statusLineErrorMessage(RfpEditorMessages.GotoMatchingBracketAction_error_invalidSelection);
     22            text.getDisplay().beep();
     23            return;
     24        }
     25        IRegion region = editor.getBracketMatcher().match(document, modelOffset);
     26        if (region == null) {
     27            editor.statusLineErrorMessage(RfpEditorMessages.GotoMatchingBracketAction_error_noMatchingBracket);
    2328            text.getDisplay().beep();
    2429            return;
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/OpenDeclarationAction.java

    r3863 r4067  
    1717        AstNode astNode = editor.astInfo.getDeclaration(getSelection().getOffset());
    1818        if (astNode == null) {
    19             editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection);
     19            editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclarationAction_error_invalidSelection);
    2020            sourceViewer.getTextWidget().getDisplay().beep();
    2121            return;
Note: See TracChangeset for help on using the changeset viewer.