From: Jochen L. <lue...@us...> - 2004-10-01 04:58:03
|
Update of /cvsroot/e-p-i-c/org.epic.perleditor/src/org/epic/perleditor/editors In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14586/src/org/epic/perleditor/editors Modified Files: PerlEditor.java PerlFoldingThread.java PerlActionContributor.java Log Message: Changes by LeO Index: PerlActionContributor.java =================================================================== RCS file: /cvsroot/e-p-i-c/org.epic.perleditor/src/org/epic/perleditor/editors/PerlActionContributor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- PerlActionContributor.java 29 Sep 2004 14:22:17 -0000 1.9 +++ PerlActionContributor.java 1 Oct 2004 04:57:53 -0000 1.10 @@ -7,6 +7,7 @@ import org.epic.perleditor.actions.ExportHtmlSourceAction; import org.epic.perleditor.actions.FormatSourceAction; +import org.epic.perleditor.actions.Jump2BracketAction; import org.epic.perleditor.actions.ToggleCommentAction; import org.epic.perleditor.actions.ValidateSourceAction; import org.epic.perleditor.popupmenus.OpenDeclaration; @@ -22,6 +23,7 @@ protected ValidateSourceAction validateSourceAction; protected OpenDeclaration openDeclarationAction; protected ToggleCommentAction toggleCommentAction; + protected Jump2BracketAction jump2BracketAction; /** * Default constructor. @@ -33,6 +35,7 @@ validateSourceAction = new ValidateSourceAction(); openDeclarationAction = new OpenDeclaration(); toggleCommentAction = new ToggleCommentAction(); + jump2BracketAction = new Jump2BracketAction(); //formatSourceAction.setActionDefinitionId("org.epic.perledior.formatsource"); } @@ -72,6 +75,7 @@ bars.setGlobalActionHandler("org.epic.perleditor.HtmlExport", htmExportAction); bars.setGlobalActionHandler("org.epic.perleditor.ValidateSyntax", validateSourceAction); bars.setGlobalActionHandler("org.epic.perleditor.popupmenus.OpenSubAction", openDeclarationAction); + bars.setGlobalActionHandler("org.epic.perleditor.Jump2Bracket", jump2BracketAction); } else { bars.setGlobalActionHandler("org.epic.perleditor.FormatSource", null); @@ -79,6 +83,7 @@ bars.setGlobalActionHandler("org.epic.perleditor.ValidateSyntax", null); bars.setGlobalActionHandler("org.epic.perleditor.popupmenus.OpenSubAction", null); bars.setGlobalActionHandler("org.epic.perleditor.ToggleComment", null); + bars.setGlobalActionHandler("org.epic.perleditor.Jump2Bracket", null); } } Index: PerlEditor.java =================================================================== RCS file: /cvsroot/e-p-i-c/org.epic.perleditor/src/org/epic/perleditor/editors/PerlEditor.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- PerlEditor.java 29 Sep 2004 14:22:17 -0000 1.38 +++ PerlEditor.java 1 Oct 2004 04:57:52 -0000 1.39 @@ -109,10 +109,10 @@ private final String matchBrakets = "{([<>])}"; private ITextViewerExtension5 viewer; + +// private SourceViewer fSourceViewer; - private SourceViewer fSourceViewer; - - private IDocumentProvider fDocumentProvider; +// private IDocumentProvider fDocumentProvider; private IdleTimer idleTimer; @@ -158,12 +158,14 @@ setAction("org.epic.perleditor.ContentAssist", action); + + IDocumentProvider provider = getDocumentProvider(); IDocument document = provider.getDocument(getEditorInput()); getSourceViewer().setDocument(document); - fDocumentProvider = provider; - fSourceViewer = (SourceViewer) getSourceViewer(); +// fDocumentProvider = provider; +// fSourceViewer = (SourceViewer) getSourceViewer(); if (fValidationThread == null && isPerlMode()) { fValidationThread = new PerlSyntaxValidationThread(this, @@ -176,16 +178,18 @@ } if (fValidationThread != null) { - try { - // Give the validation thread time for initialization - // TODO Find better solution - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } +// Any reason why this is required at all? + // try { +// // Give the validation thread time for initialization +// // TODO Find better solution +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } // Always check syntax when editor is opened //fValidationThread.setText(getSourceViewer().getTextWidget().getText()); - fValidationThread.setText(getSourceViewer().getDocument().get()); +// fValidationThread.setText(getSourceViewer().getDocument().get()); + fValidationThread.setText(document.get()); } calculateIgnoreTypeHash(); // to get the current HashCodes of Strings we should ignore @@ -275,6 +279,15 @@ super.doRevertToSaved(); + if (page != null) { + page.update(page.getSubList(), page.getModList()); + } + + if (fValidationThread != null) { + //fValidationThread.setText(getSourceViewer().getTextWidget().getText()); + fValidationThread.setText(getSourceViewer().getDocument().get()); + } + } /** @@ -468,7 +481,14 @@ } } - + + /** + * To provide an access to a changed position + * Colouring of the Brackets will be adjusted. + */ + public final void newCurosorPos() { + handleCursorPositionChanged(); + } protected void handleCursorPositionChanged() { super.handleCursorPositionChanged(); @@ -776,8 +796,9 @@ } public void createPartControl(Composite parent) { - super.createPartControl(parent); + super.createPartControl(parent); ProjectionViewer viewer = (ProjectionViewer) getSourceViewer(); + projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors()); projectionSupport @@ -841,6 +862,23 @@ } /** + * to access the method via Command-Stroke + * + * @param StartPosition from the widget + * @return the position for the widget + */ + public int findNextOccurance(int StartPosition){ + StyledText myText = getSourceViewer().getTextWidget(); + IDocument myDocument=getSourceViewer().getDocument(); + + int cursorPosition = myText.getCaretOffset(); + char sourceChar = myText.getTextRange(cursorPosition - 1, 1).charAt(0); + return viewer.modelOffset2WidgetOffset(findNextOccurance(myDocument, + sourceChar, + cursorPosition + )); + } + /** * Finds the next matching Bracket <p> * If the current Bracket is under quotes/comments => consider the next * matching bracket also under (same) quotes/comment. If the next found @@ -855,8 +893,7 @@ * @return absolute Positon in the Document * @since Sep. 2004 */ - public final int findNextOccurance(final IDocument myDocument, char findNextChar, int StartPosition) { - + public int findNextOccurance(final IDocument myDocument, char findNextChar, int StartPosition) { char nextStringPair = ' '; int StackCounter = 0; int findFirst; Index: PerlFoldingThread.java =================================================================== RCS file: /cvsroot/e-p-i-c/org.epic.perleditor/src/org/epic/perleditor/editors/PerlFoldingThread.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- PerlFoldingThread.java 29 Sep 2004 14:22:17 -0000 1.2 +++ PerlFoldingThread.java 1 Oct 2004 04:57:53 -0000 1.3 @@ -7,9 +7,7 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.FindReplaceDocumentAdapter; import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.ISourceViewer; @@ -73,168 +71,107 @@ } public void updateFoldingAnnotations() { - IAnnotationModel model = (IAnnotationModel) fTextEditor - .getAdapter(ProjectionAnnotationModel.class); - - String lineSep = null; - try { - lineSep = fSourceViewer.getDocument().getLineDelimiter(0); - HashMap positionHash = new HashMap(); - - if (model != null) { - // Remove all annotations - // for (Iterator i = model.getAnnotationIterator(); i.hasNext();) { - // ProjectionAnnotation annotation = (ProjectionAnnotation) i - // .next(); - // model.removeAnnotation(annotation); - // } - - IPreferenceStore store = PerlEditorPlugin.getDefault() - .getPreferenceStore(); - - boolean foldingEnabled = store - .getBoolean(PreferenceConstants.SOURCE_FOLDING); - - List podList = new ArrayList(); - List subList = new ArrayList(); - - if (foldingEnabled) { + IAnnotationModel model = (IAnnotationModel) fTextEditor.getAdapter(ProjectionAnnotationModel.class); - // Get all pod comments - String podExpr = "^(=head.*(" + lineSep + ".*)+?" + lineSep - + "=cut)$"; - podList = SourceParser.getElements(text, podExpr, "", "", - SourceParser.DO_NOT_DELETE_COMMENT_POD); - - // Get all subroutines - //String subExpr = "^\\s*sub\\s+(.*{.*(" + lineSep + - // ".*)+?.*\\n})"; - String subExpr = "^[\\s]*(sub\\s+[^\\n\\r{]+)"; - List subListTmp = SourceParser.getElements(text, subExpr, "", - "", SourceParser.DELETE_COMMENT - | SourceParser.DELETE_POD); - subList = new ArrayList(); - - // Find closing brackets for subs manually - for (int i = 0; i < subListTmp.size(); i++) { - try { - Model sub = (Model) subListTmp.get(i); -// int pos = searchForClosingBracket(sub.getStart() -// + sub.getLength() + 1, '{', '}', fSourceViewer -// .getDocument()); + String lineSep = null; + try { + lineSep = fSourceViewer.getDocument().getLineDelimiter(0); + + if (model != null) { + HashMap positionHash = new HashMap(); + // Remove all annotations + // for (Iterator i = model.getAnnotationIterator(); i.hasNext();) { + // ProjectionAnnotation annotation = (ProjectionAnnotation) i + // .next(); + // model.removeAnnotation(annotation); + // } - // Make sure to get the starting bracket - FindReplaceDocumentAdapter finder = new FindReplaceDocumentAdapter(fSourceViewer.getDocument()); - IRegion region =finder.find(sub.getStart(), "{", true, false, false, false); - int pos = ((PerlEditor)fTextEditor).findNextOccurance(fSourceViewer.getDocument(), '{', region.getOffset() +1); + IPreferenceStore store = PerlEditorPlugin.getDefault().getPreferenceStore(); - if (pos != -1) { - subList.add(new Model(sub.getName(), - sub.getStart(), pos - sub.getStart() + 1)); - } - - } catch (BadLocationException e) { - - } - - } - } - - List completeList = new ArrayList(); - completeList.add(podList); - completeList.add(subList); - - for (int i = 0; i < completeList.size(); i++) { - if (!(completeList.get(i) instanceof List)) { - continue; - } - List list = (List) completeList.get(i); - - for (int j = 0; j < list.size(); j++) { - if (!(list.get(j) instanceof Model)) { - continue; - } - int start = ((Model) list.get(j)).getStart(); - int length = ((Model) list.get(j)).getLength(); - - Position position = new Position(start, length); - //model.addAnnotation(new ProjectionAnnotation(), - // position); - positionHash.put(position, ANNOTATION_NEW); - } - - } - - } /* LeO: macht das Ende hier einen Sinn? model kann ja auch null sein! (zumindest theoretisch und - * praktisch wenn man was falsch ausprogrammiert hat! - */ - - // Delete unnecessary annotations and mark existig annotations - for (Iterator i = model.getAnnotationIterator(); i.hasNext();) { - ProjectionAnnotation annotation = (ProjectionAnnotation) i.next(); - - Position pos = model.getPosition(annotation); - - if (positionHash.get(pos) == null) { - model.removeAnnotation(annotation); - } else { - positionHash.put(pos, ANNOTATION_EXISTS); - } - } - - // Add new annotations - for (Iterator it = positionHash.keySet().iterator(); it.hasNext();) { - Position pos = (Position) it.next(); - Integer val = (Integer) positionHash.get(pos); - if (val != ANNOTATION_EXISTS) { - model.addAnnotation(new ProjectionAnnotation(), pos); - } - } - - } catch (BadLocationException e1) { - /* nothing to do, cause LineDel for 0 should be always present - * and if there is an exception, then we are in a new file, first line with no LineDel - */ - } - } + boolean foldingEnabled = store.getBoolean(PreferenceConstants.SOURCE_FOLDING); - /** - * Returns the position of the closing bracket after startPosition. - * - * @returns the location of the closing bracket. - * @param startPosition - - * the beginning position - * @param openBracket - - * the character that represents the open bracket - * @param closeBracket - - * the character that represents the close bracket - * @param document - - * the document being searched - */ - protected int searchForClosingBracket(int startPosition, char openBracket, - char closeBracket, IDocument document) throws BadLocationException { - int stack = 1; - int closePosition = startPosition + 1; - int length = document.getLength(); - char nextChar; + List podList = new ArrayList(); + List subList = new ArrayList(); - while (closePosition < length && stack > 0) { - nextChar = document.getChar(closePosition); - if (nextChar == openBracket && nextChar != closeBracket) - stack++; - else if (nextChar == closeBracket) - stack--; - closePosition++; - } + if (foldingEnabled) { - if (stack == 0) - return closePosition; - else - return -1; + // Get all pod comments + String podExpr = "^(=head.*(" + lineSep + ".*)+?" + lineSep + "=cut)$"; + podList = SourceParser.getElements(text, podExpr, "", "", SourceParser.DO_NOT_DELETE_COMMENT_POD); - } - + // Get all subroutines + //String subExpr = "^\\s*sub\\s+(.*{.*(" + lineSep + + // ".*)+?.*\\n})"; + String subExpr = "^[\\s]*(sub\\s+[^\\n\\r{]+)"; + List subListTmp = SourceParser.getElements(text, subExpr, "", "", SourceParser.DELETE_COMMENT | SourceParser.DELETE_POD); + subList = new ArrayList(); + + // Find closing brackets for subs manually + for (int i = 0; i < subListTmp.size(); i++) { + Model sub = (Model) subListTmp.get(i); + int bracketPos = text.indexOf("{", sub.getStart()) + 1; + int pos = ((PerlEditor) fTextEditor).findNextOccurance(fSourceViewer.getDocument(), '{', bracketPos); + if (pos >= 0) { + subList.add(new Model(sub.getName(), sub.getStart(), pos - sub.getStart() + 1)); + } + } + } + + List completeList = new ArrayList(); + completeList.add(podList); + completeList.add(subList); + + for (int i = 0; i < completeList.size(); i++) { + if (!(completeList.get(i) instanceof List)) { + continue; + } + List list = (List) completeList.get(i); + + for (int j = 0; j < list.size(); j++) { + if (!(list.get(j) instanceof Model)) { + continue; + } + int start = ((Model) list.get(j)).getStart(); + int length = ((Model) list.get(j)).getLength(); + + Position position = new Position(start, length); + //model.addAnnotation(new ProjectionAnnotation(), + // position); + positionHash.put(position, ANNOTATION_NEW); + } + + } + + // Delete unnecessary annotations and mark existig annotations + for (Iterator i = model.getAnnotationIterator(); i.hasNext();) { + ProjectionAnnotation annotation = (ProjectionAnnotation) i.next(); + + Position pos = model.getPosition(annotation); + + if (positionHash.get(pos) == null) { + model.removeAnnotation(annotation); + } else { + positionHash.put(pos, ANNOTATION_EXISTS); + } + } + // Add new annotations + for (Iterator it = positionHash.keySet().iterator(); it.hasNext();) { + Position pos = (Position) it.next(); + Integer val = (Integer) positionHash.get(pos); + if (val != ANNOTATION_EXISTS) { + model.addAnnotation(new ProjectionAnnotation(), pos); + } + } + } + } catch (BadLocationException e1) { + /* + * nothing to do, cause LineDel for 0 should be always present and if there is an exception, then we are in a new file, first line + * with no LineDel + */ + } + } + public void dispose() throws InterruptedException { this.interrupt(); this.join(); |