removing UI freezing by change of default Smarty delimiters release70_base
authorMartin Fousek <marfous@netbeans.org>
Thu, 03 Mar 2011 00:03:37 +0100
changeset 1730960f4cc6038b3
parent 17308 bca6b070e8d1
child 17310 77235f099ff6
child 17313 b3e5a823b7b2
child 17315 99dc5d12b306
child 17321 2218699a0dc5
child 17323 a45c85f47e03
child 17339 eb8bbca948b9
removing UI freezing by change of default Smarty delimiters
php.smarty/src/org/netbeans/modules/php/smarty/editor/TplKit.java
php.smarty/src/org/netbeans/modules/php/smarty/editor/lexer/TplTopLexer.java
php.smarty/src/org/netbeans/modules/php/smarty/editor/utlis/LexerUtils.java
     1.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/TplKit.java	Wed Mar 02 22:05:53 2011 +0100
     1.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/TplKit.java	Thu Mar 03 00:03:37 2011 +0100
     1.3 @@ -45,6 +45,7 @@
     1.4  import org.netbeans.editor.ext.ExtKit;
     1.5  import org.netbeans.modules.editor.NbEditorKit;
     1.6  import javax.swing.Action;
     1.7 +import javax.swing.SwingUtilities;
     1.8  import javax.swing.text.*;
     1.9  import org.netbeans.modules.editor.NbEditorUtilities;
    1.10  import org.openide.filesystems.FileObject;
    1.11 @@ -53,10 +54,10 @@
    1.12  import org.netbeans.modules.csl.api.InstantRenameAction;
    1.13  import org.netbeans.modules.csl.api.SelectCodeElementAction;
    1.14  import org.netbeans.modules.csl.api.ToggleBlockCommentAction;
    1.15 +import org.netbeans.modules.editor.NbEditorDocument;
    1.16  import org.netbeans.modules.php.smarty.editor.lexer.TplTopTokenId;
    1.17  import org.netbeans.modules.php.smarty.editor.utlis.TplUtils;
    1.18  import org.netbeans.spi.lexer.MutableTextInput;
    1.19 -import sun.rmi.runtime.Log;
    1.20  
    1.21  /**
    1.22   * Editor kit implementation for TPL content type
    1.23 @@ -115,7 +116,7 @@
    1.24          return TextAction.augmentList(super.createActions(), javaActions);
    1.25      }
    1.26  
    1.27 -    public void initLexerColoringListener(Document doc) {
    1.28 +    public void initLexerColoringListener(final Document doc) {
    1.29          DataObject dobj = NbEditorUtilities.getDataObject(doc);
    1.30          FileObject fobj = (dobj != null) ? dobj.getPrimaryFile() : null;
    1.31  
    1.32 @@ -127,10 +128,23 @@
    1.33          inputAttributes.setValue(TplTopTokenId.language(), TplMetaData.class, tplMetaData, false);
    1.34          doc.putProperty(InputAttributes.class, inputAttributes);
    1.35  
    1.36 -        MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
    1.37 -        if (mti != null) {
    1.38 -            mti.tokenHierarchyControl().rebuild();
    1.39 -        }
    1.40 +        SwingUtilities.invokeLater(new Runnable() {
    1.41 +
    1.42 +            @Override
    1.43 +            public void run() {
    1.44 +                NbEditorDocument nbdoc = (NbEditorDocument) doc;
    1.45 +                nbdoc.runAtomic(new Runnable() {
    1.46 +
    1.47 +                    @Override
    1.48 +                    public void run() {
    1.49 +                        MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
    1.50 +                        if (mti != null) {
    1.51 +                            mti.tokenHierarchyControl().rebuild();
    1.52 +                        }
    1.53 +                    }
    1.54 +                });
    1.55 +            }
    1.56 +        });
    1.57      }
    1.58  
    1.59      @Override
     2.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/lexer/TplTopLexer.java	Wed Mar 02 22:05:53 2011 +0100
     2.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/lexer/TplTopLexer.java	Thu Mar 03 00:03:37 2011 +0100
     2.3 @@ -194,7 +194,7 @@
     2.4                  char cc = (char) c;
     2.5                  text = input.readText();
     2.6                  textLength = text.length();
     2.7 -                switch (state) {
     2.8 +               switch (state) {
     2.9                  case INIT:
    2.10                  case OUTER:
    2.11                      if (isSmartyOpenDelimiter(text)) {
     3.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/utlis/LexerUtils.java	Wed Mar 02 22:05:53 2011 +0100
     3.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/utlis/LexerUtils.java	Thu Mar 03 00:03:37 2011 +0100
     3.3 @@ -39,6 +39,7 @@
     3.4  package org.netbeans.modules.php.smarty.editor.utlis;
     3.5  
     3.6  import javax.swing.text.Document;
     3.7 +import org.netbeans.modules.editor.NbEditorDocument;
     3.8  import org.netbeans.modules.php.smarty.editor.TplKit;
     3.9  import org.netbeans.spi.lexer.MutableTextInput;
    3.10  import org.openide.text.CloneableEditor;
    3.11 @@ -70,14 +71,21 @@
    3.12                  TopComponent[] topComponents = WindowManager.getDefault().getOpenedTopComponents(WindowManager.getDefault().findMode("editor"));
    3.13                  for (TopComponent topComponent : topComponents) {
    3.14                      if (topComponent instanceof CloneableEditor) {
    3.15 -                        Document doc = ((CloneableEditor) topComponent).getEditorPane().getDocument();
    3.16 +                        final Document doc = ((CloneableEditor) topComponent).getEditorPane().getDocument();
    3.17                          if (((CloneableEditor) topComponent).getEditorPane().getEditorKit() instanceof TplKit) {
    3.18                              ((TplKit) ((CloneableEditor) topComponent).getEditorPane().getEditorKit()).initLexerColoringListener(doc);
    3.19                          }
    3.20 -                        MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
    3.21 -                        if (mti != null) {
    3.22 -                            mti.tokenHierarchyControl().rebuild();
    3.23 -                        }
    3.24 +                        NbEditorDocument nbdoc = (NbEditorDocument) doc;
    3.25 +                        nbdoc.runAtomic(new Runnable() {
    3.26 +
    3.27 +                            @Override
    3.28 +                            public void run() {
    3.29 +                                MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
    3.30 +                                if (mti != null) {
    3.31 +                                    mti.tokenHierarchyControl().rebuild();
    3.32 +                                }
    3.33 +                            }
    3.34 +                        });
    3.35                      }
    3.36                  }
    3.37              }