[hg] main-silver: #222935: action enablement updates more consis...

  • From: Svata Dedic < >
  • To: , ,
  • Subject: [hg] main-silver: #222935: action enablement updates more consis...
  • Date: Wed, 10 Jul 2013 23:36:02 -0700

changeset 3460f583449a in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/3460f583449a
description:
        #222935: action enablement updates more consistently; DES indicates 
that file became editable

diffstat:

 editor.lib/src/org/netbeans/editor/BaseDocument.java          |  17 ++++++++
 editor.lib/src/org/netbeans/editor/EditorUI.java              |  22 
++++++++++-
 editor.lib/src/org/netbeans/editor/GuardedDocument.java       |   4 ++
 openide.loaders/src/org/openide/text/DataEditorSupport.java   |   2 +-
 openide.text/src/org/openide/text/CloneableEditorSupport.java |   6 +++
 5 files changed, 48 insertions(+), 3 deletions(-)

diffs (145 lines):

diff --git a/editor.lib/src/org/netbeans/editor/BaseDocument.java 
b/editor.lib/src/org/netbeans/editor/BaseDocument.java
--- a/editor.lib/src/org/netbeans/editor/BaseDocument.java
+++ b/editor.lib/src/org/netbeans/editor/BaseDocument.java
@@ -204,6 +204,13 @@
      */
     public static final String LINE_LIMIT_PROP = "line-limit"; // NOI18N
 
+    /**
+     * If set, determines the document's editability. Note that even though 
the 
+     * editable property may be set to true, the document may be still 
uneditable for
+     * other reasons. The document should not permit any edits if the 
editable
+     * property is set to false.
+     */
+    /* public */ static final String EDITABLE_PROP = "editable"; // NOI18N
 
     /**
      * Size of the line batch. Line batch can be used at various places
@@ -1686,6 +1693,7 @@
     
     final void atomicLockImpl () {
         boolean alreadyAtomicLocker;
+        boolean modifiableChanged = false;
         synchronized (this) {
             if (runExclusiveDepth > 0) {
                 throw new IllegalStateException(
@@ -1713,6 +1721,12 @@
                 extWriteLock();
                 atomicDepth++;
                 if (atomicDepth == 1) { // lock really started
+                    Object o = getProperty(EDITABLE_PROP);
+                    if (o == null) {
+                        o = Boolean.TRUE;
+                    }
+                    modifiableChanged = modifiable != modifiableLocal || 
+                            o != modifiableLocal;                
                     modifiable = modifiableLocal;
                     fireAtomicLock(atomicLockEventInstance);
                     // Copy the listener list - will be used for firing undo
@@ -1720,6 +1734,9 @@
                 }
             }
         }
+        if (modifiableChanged) {
+            putProperty(EDITABLE_PROP, modifiable);
+        }
     }
 
     /** 
diff --git a/editor.lib/src/org/netbeans/editor/EditorUI.java 
b/editor.lib/src/org/netbeans/editor/EditorUI.java
--- a/editor.lib/src/org/netbeans/editor/EditorUI.java
+++ b/editor.lib/src/org/netbeans/editor/EditorUI.java
@@ -285,6 +285,14 @@
                             if (ui!=null) ui.refresh();
                          }
                      }
+
+                     @Override
+                     public void focusLost(FocusEvent e) {
+                         // see #222935, update actions before menu activates
+                         if (e.isTemporary()) {
+                             doStateChange(true);
+                         }
+                     }
                  };
 
         getToolTipSupport();
@@ -477,6 +485,10 @@
     }
     
     public @Override void stateChanged(ChangeEvent evt) {
+        doStateChange(false);
+    }
+    
+    private void doStateChange(final boolean b) {
         SwingUtilities.invokeLater(
             new Runnable() {
                 
@@ -503,9 +515,15 @@
                         } else {
                             int offset = c.getCaretPosition();
                             boolean guarded = gdoc.isPosGuarded(offset);
+                            boolean startGuarded = guarded;
+                            // only enable paste if on start of the 1st 
guarded line, not at each line start.
+                            if (offset > 0 && !gdoc.isPosGuarded(offset -1) 
&&
+                                
org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(bdoc).charAt(offset
 - 1) == '\n') { // NOI18N
+                                startGuarded = false;
+                            }
                             return new boolean [] {
                                 guarded,
-                                guarded && !(offset == 0 || 
org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(bdoc).charAt(offset
 - 1) == '\n') //NOI18N
+                                startGuarded
                             };
                         }
                     }
@@ -514,7 +532,7 @@
                 
                 public @Override void run() {
                     JTextComponent c = component;
-                    if (c != null && c.hasFocus()) { // do nothing if the 
component does not have focus, see #110715
+                    if (c != null && (b || c.hasFocus())) { // do nothing if 
the component does not have focus, see #110715
                         BaseKit kit = Utilities.getKit(c);
                         if (kit != null) {
                             boolean isEditable = c.isEditable();
diff --git a/editor.lib/src/org/netbeans/editor/GuardedDocument.java 
b/editor.lib/src/org/netbeans/editor/GuardedDocument.java
--- a/editor.lib/src/org/netbeans/editor/GuardedDocument.java
+++ b/editor.lib/src/org/netbeans/editor/GuardedDocument.java
@@ -187,6 +187,10 @@
     }
 
     public boolean isPosGuarded(int offset) {
+        Object o = getProperty(EDITABLE_PROP);
+        if (o != null) {
+            return !(Boolean)o;
+        }
         if (!modifiable) { // if whole doc is readonly due to CES 
modificationListener veto
             return true;
         }
diff --git a/openide.loaders/src/org/openide/text/DataEditorSupport.java 
b/openide.loaders/src/org/openide/text/DataEditorSupport.java
--- a/openide.loaders/src/org/openide/text/DataEditorSupport.java
+++ b/openide.loaders/src/org/openide/text/DataEditorSupport.java
@@ -1015,7 +1015,7 @@
                             NotifyDescriptor.WARNING_MESSAGE));
                 }
                 // event is consumed in CloneableEditorSupport
-                firePropertyChange("DataEditorSupport.read-only.changing", 
null, null);  //NOI18N
+                firePropertyChange("DataEditorSupport.read-only.changing", 
!canWrite, canWrite);  //NOI18N
             }
         }
 
diff --git a/openide.text/src/org/openide/text/CloneableEditorSupport.java 
b/openide.text/src/org/openide/text/CloneableEditorSupport.java
--- a/openide.text/src/org/openide/text/CloneableEditorSupport.java
+++ b/openide.text/src/org/openide/text/CloneableEditorSupport.java
@@ -3024,6 +3024,12 @@
 
             // #129178 - update title if read-only state is externally 
changed
             if 
("DataEditorSupport.read-only.changing".equals(ev.getPropertyName())) {  
//NOI18N
+                Object o = ev.getNewValue();
+                if (o == Boolean.TRUE) {
+                    Document d = getDoc();
+                    // see #222935, indicate the file has become editable to 
editor.lib
+                    d.putProperty("editable", Boolean.TRUE);
+                }
                 updateTitles();
             }
         }

[hg] main-silver: #222935: action enablement updates more consis...

Svata Dedic 07/11/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 348 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close