Author: timotei
Date: Tue Jul 26 17:29:22 2011
New Revision: 50418

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50418&view=rev
Log:
eclipse plugin: Re-implement the start-end tag
matching since the previous one made the CPU to
stay on 100% and keep spawning threads for the
modified xtext resource model

Added:
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLHighlightingHelper.java
Modified:
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLSyntaxColoringAdapter.java
    trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java
    trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLSemanticHighlightingCalculator.java

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLSyntaxColoringAdapter.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLSyntaxColoringAdapter.java?rev=50418&r1=50417&r2=50418&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLSyntaxColoringAdapter.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLSyntaxColoringAdapter.java
 Tue Jul 26 17:29:22 2011
@@ -9,10 +9,11 @@
 package org.wesnoth.ui;
 
 import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
 import org.wesnoth.ui.syntax.WMLHighlightingConfiguration;
 
 /**
- * A simple WML adapter that holds a coloring id
+ * A simple WML adapter that holds a coloring id on the specified resource
  */
 public class WMLSyntaxColoringAdapter extends AdapterImpl
 {
@@ -22,14 +23,13 @@
     public String ColorId;
 
     /**
-     * True whether this coloring applies to the start
-     * of the tag or to the end tag
+     * The object to color
      */
-    public boolean PaintStart;
+    public EObject TargetEObject;
 
-    public WMLSyntaxColoringAdapter( String id, boolean paintStart)
+    public WMLSyntaxColoringAdapter( String id, EObject target)
     {
         ColorId = id;
-        PaintStart = paintStart;
+        TargetEObject = target;
     }
 }

Modified: trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java?rev=50418&r1=50417&r2=50418&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java Tue 
Jul 26 17:29:22 2011
@@ -23,12 +23,14 @@
 import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper;
 import 
org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;
 import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingHelper;
 import 
org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
 import org.wesnoth.ui.autoedit.WMLAutoEditStrategy;
 import org.wesnoth.ui.contentassist.WMLContentAssistContext;
 import org.wesnoth.ui.contentassist.WMLProposalComparator;
 import org.wesnoth.ui.editor.WMLAbstractDirtyEditorCallback;
 import org.wesnoth.ui.editor.WMLEditor;
+import org.wesnoth.ui.editor.WMLHighlightingHelper;
 import org.wesnoth.ui.folding.WMLFoldingRegionProvider;
 import org.wesnoth.ui.labeling.WMLLabelProvider;
 import org.wesnoth.ui.navigation.WMLHyperlinkHelper;
@@ -57,6 +59,12 @@
        public void configure(Binder binder)
        {
                super.configure(binder);
+       }
+
+       @Override
+       public Class<? extends IHighlightingHelper> bindIHighlightingHelper()
+       {
+           return WMLHighlightingHelper.class;
        }
 
        public Class<? extends IHighlightingConfiguration> 
bindIHighlightingConfiguration()

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java?rev=50418&r1=50417&r2=50418&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java 
Tue Jul 26 17:29:22 2011
@@ -33,10 +33,8 @@
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;
@@ -50,6 +48,7 @@
 import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.ui.texteditor.IDocumentProvider;
 import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingHelper;
 import org.eclipse.xtext.ui.editor.utils.EditorUtils;
 import org.wesnoth.Logger;
 import org.wesnoth.WesnothPlugin;
@@ -65,6 +64,8 @@
 
        @Inject
        private IExtXtextEditorCustomizer editorCustomizer;
+
+       protected HighlightingHelper highlightingHelper_;
 
        public WMLEditor()
        {
@@ -81,15 +82,10 @@
                super.createPartControl(parent);
        }
 
-       public StyledText getTextWidget()
-       {
-               return getSourceViewer().getTextWidget();
-       }
-
-       public ISourceViewer getSourceViewer_()
-       {
-               return getSourceViewer();
-       }
+       public HighlightingHelper getHighlightingHelper()
+    {
+        return highlightingHelper_;
+    }
 
        @Override
        public boolean equals(Object obj)

Added: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLHighlightingHelper.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLHighlightingHelper.java?rev=50418&view=auto
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLHighlightingHelper.java
 (added)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLHighlightingHelper.java
 Tue Jul 26 17:29:22 2011
@@ -1,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2011 by Timotei Dolean <[email protected]>
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ 
*******************************************************************************/
+package org.wesnoth.ui.editor;
+
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.XtextSourceViewer;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingHelper;
+
+public class WMLHighlightingHelper extends HighlightingHelper
+{
+    @Override
+    public void install( XtextEditor editor, XtextSourceViewer sourceViewer )
+    {
+        super.install( editor, sourceViewer );
+
+        // set the highlighting helper in our editor
+        // so we can access the highlightingReconcilier in order
+        // to be able to refresh the semantic highlighting
+        if ( editor instanceof WMLEditor ) {
+            ( ( WMLEditor ) editor ).highlightingHelper_ = this;
+        }
+    }
+}

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java?rev=50418&r1=50417&r2=50418&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
 Tue Jul 26 17:29:22 2011
@@ -17,14 +17,15 @@
 import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
 import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.ui.editor.model.XtextDocument;
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
 import org.eclipse.xtext.util.concurrent.IUnitOfWork;
 import org.wesnoth.ui.WMLSyntaxColoringAdapter;
+import org.wesnoth.ui.editor.WMLEditor;
 import org.wesnoth.utils.WMLUtils;
 import org.wesnoth.wml.WMLTag;
 
 public class WMLCharacterPairMatcher extends DefaultCharacterPairMatcher
 {
-    private WMLSyntaxColoringAdapter currentAdapter_;
     private WMLTag currentTag_;
 
     private int matchCnt = 0;
@@ -32,7 +33,6 @@
     public WMLCharacterPairMatcher( char[] chars )
     {
         super( chars );
-        currentAdapter_ = null;
         currentTag_ = null;
     }
 
@@ -42,57 +42,66 @@
         ++ matchCnt;
         IRegion region = super.match( doc, offset );
 
-        if ( region == null && doc instanceof XtextDocument ) {
+        if ( region == null && doc instanceof XtextDocument &&
+             doc.getLength( ) > 0 ) {
             if ( matchCnt == 2 ) {
                 matchCnt = 0;
             } else {
-                ( ( XtextDocument ) doc ).modify( new IUnitOfWork<IRegion, 
XtextResource>(){
+                ( ( XtextDocument ) doc ).readOnly( new IUnitOfWork<Boolean, 
XtextResource>(){
 
                     @Override
-                    public IRegion exec( XtextResource state ) throws Exception
+                    public Boolean exec( XtextResource state ) throws Exception
                     {
-                        return computeMatchingRegion( state, offset );
+                        computeMatchingRegion( state, offset );
+                        return true;
                     }
+                });
 
-                });
+                // refresh the highlighting
+                WMLEditor currentEditor = ( WMLEditor ) 
EditorUtils.getActiveXtextEditor( );
+                if ( currentEditor != null &&
+                     currentEditor.getHighlightingHelper( ) != null &&
+                     currentEditor.getHighlightingHelper( ).getReconciler( ) 
!= null )
+                currentEditor.getHighlightingHelper( ).getReconciler( 
).refresh( );
             }
         }
 
         return region;
     }
 
-    public IRegion computeMatchingRegion(XtextResource state, int offset)
+    public synchronized void computeMatchingRegion(XtextResource state, int 
offset)
     {
         EObject object = WMLUtils.EObjectUtils( ).resolveElementAt( state, 
offset );
 
         // do nothing if we clicked the same tag
         if ( currentTag_ == object )
-            return null;
-
-        // remove current colored tag ( if any )
-        if ( currentTag_ != null ) {
-            synchronized ( currentTag_ ) {
-
-                Iterator<Adapter> itor = currentTag_.eAdapters( ).iterator( );
-                while ( itor.hasNext( ) ) {
-                    if ( itor.next( ) instanceof WMLSyntaxColoringAdapter ) {
-                        itor.remove( );
-                    }
-                }
-
-                currentAdapter_ = null;
-                currentTag_ = null;
-            }
-        }
+            return;
 
         if ( object instanceof WMLTag ) {
             WMLTag tag = ( WMLTag ) object;
 
-            currentAdapter_ = new WMLSyntaxColoringAdapter( 
WMLHighlightingConfiguration.RULE_MATCH_TAG, true );
             currentTag_ = tag;
-            tag.eAdapters( ).add( currentAdapter_ );
+            for ( Adapter adapter : state.eAdapters( ) ) {
+                if ( adapter instanceof WMLSyntaxColoringAdapter ){
+
+                    ( ( WMLSyntaxColoringAdapter ) adapter ).TargetEObject = 
object;
+                    return; // done here
+                }
+            }
+
+            state.eAdapters( ).add( new WMLSyntaxColoringAdapter(
+                    WMLHighlightingConfiguration.RULE_MATCH_TAG, object ) );
+        } else {
+            // nothing new selected, just remove current adapter
+            Iterator<Adapter> itor = state.eAdapters( ).iterator( );
+            while ( itor.hasNext( ) ) {
+                if ( itor.next( ) instanceof WMLSyntaxColoringAdapter ) {
+                    itor.remove( );
+                    break;
+                }
+            }
+
+            currentTag_ = null;
         }
-
-        return null;
     }
 }

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLSemanticHighlightingCalculator.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLSemanticHighlightingCalculator.java?rev=50418&r1=50417&r2=50418&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLSemanticHighlightingCalculator.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLSemanticHighlightingCalculator.java
 Tue Jul 26 17:29:22 2011
@@ -90,12 +90,16 @@
             }
 
             // check if we have any information specific information for 
highlighting
-            for ( Adapter adapter : current.eAdapters( ) ) {
+            for ( Adapter adapter : resource.eAdapters( ) ) {
                 if ( adapter instanceof WMLSyntaxColoringAdapter ) {
                     WMLSyntaxColoringAdapter wmlAdapter = ( 
WMLSyntaxColoringAdapter ) adapter;
 
-                    for ( Pair<INode, String> pair : toColor ) {
-                        pair.Second = wmlAdapter.ColorId;
+                    if ( wmlAdapter.TargetEObject == current ) {
+
+                        for ( Pair<INode, String> pair : toColor ) {
+                            pair.Second = wmlAdapter.ColorId;
+                        }
+
                     }
 
                     break;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to