Index: openide-spec-vers.properties
===================================================================
RCS file: /cvs/openide/openide-spec-vers.properties,v
retrieving revision 1.163
diff -u -r1.163 openide-spec-vers.properties
--- openide-spec-vers.properties 6 Dec 2004 14:39:46 -0000 1.163
+++ openide-spec-vers.properties 6 Jan 2005 15:56:36 -0000
@@ -4,4 +4,4 @@
# Must always be numeric (numbers separated by '.', e.g. 4.11).
# See http://openide.netbeans.org/versioning-policy.html for more.
-openide.specification.version=5.2
+openide.specification.version=5.3
Index: arch/arch-openide-editor.xml
===================================================================
RCS file: /cvs/openide/arch/arch-openide-editor.xml,v
retrieving revision 1.18
diff -u -r1.18 arch-openide-editor.xml
--- arch/arch-openide-editor.xml 9 Sep 2004 18:09:52 -0000 1.18
+++ arch/arch-openide-editor.xml 6 Jan 2005 15:56:36 -0000
@@ -375,6 +375,21 @@
This property can be used by the modules and is part of the Editor API.
+DocumentListener
s are always notified under the lock, so a special contract has
+been established (since version 5.3) by registering an instance of VetoableListener
+by calling putProperty ("beforeModificationListener", listener)
. The
+NetBeans aware document are adviced to honor this property and call the listener
+outside of the document lock when a modification is made. The actual contract
+of the call can be seen in
+NbLikeEditorKit.java
+in methods
+insertString
and remove
.
+
+
- * Could be useful if we have to modify document, but do not want the
- * Save and Save All actions to be enabled/disabled automatically.
- * Initially modifications are listened to.
- * @param listenToModifs whether to listen to modifications
- *
- public void setModificationListening (final boolean listenToModifs) {
- if (this.listenToModifs == listenToModifs) return;
- this.listenToModifs = listenToModifs;
- if (doc == null) return;
- if (listenToModifs)
- doc.addi(getModifL());
- else
- doc.removeDocumentListener(getModifL());
- }
- */
-
-
-
/** Loads the document for this object.
* @param kit kit to use
* @param d original document to load data into
@@ -1617,6 +1592,7 @@
if (doc != null) {
doc.removeUndoableEditListener (getUndoRedo ());
doc.removeDocumentListener(getListener());
+ doc.putProperty ("beforeModificationListener", null);
}
if (positionManager != null) {
@@ -1949,9 +1925,10 @@
* document, environment and also temporarilly on undoredo.
*/
private final class Listener extends Object
- implements ChangeListener, DocumentListener, PropertyChangeListener, Runnable {
+ implements ChangeListener, DocumentListener, PropertyChangeListener,
+ Runnable, java.beans.VetoableChangeListener {
- Listener() {}
+ Listener() {}
/** Stores exception from loadDocument, can be set in run method */
private IOException loadExc;
@@ -1993,6 +1970,18 @@
//modified(); (bugfix #1492)
}
+ public void vetoableChange (PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
+ if ("modified".equals (evt.getPropertyName ())) { // NOI18N
+ if (Boolean.TRUE.equals (evt.getNewValue ())) {
+ if (!callNotifyModified ()) {
+ throw new java.beans.PropertyVetoException ("Not allowed", evt); // NOI18N
+ }
+ } else {
+ notifyUnmodified ();
+ }
+ }
+ }
+
/** Gives notification that there was an insert into the document.
* @param ev event describing the action
*/
@@ -2054,6 +2043,7 @@
* which can prevent dedloks that sometimes occured during file reload.
*/
doc.removeDocumentListener(getListener());
+ doc.putProperty ("beforeModificationListener", null); // NOI18N
try {
loadExc = null;
LOCAL_LOAD_TASK.set(Boolean.TRUE);
@@ -2079,7 +2069,9 @@
// Start listening on changes in document
doc.addDocumentListener(getListener());
+ doc.putProperty ("beforeModificationListener", getListener ()); // NOI18N // NOI18N
}
+
// }
}
@@ -2286,7 +2278,7 @@
public void undo() {
super.undo();
- if (saveTime == lastSaveTime) {
+ if (saveTime == lastSaveTime && alreadyModified) {
notifyUnmodified();
}
}
Index: test/unit/src/org/openide/text/NbLikeEditorKit.java
===================================================================
RCS file: /cvs/openide/test/unit/src/org/openide/text/NbLikeEditorKit.java,v
retrieving revision 1.1
diff -u -r1.1 NbLikeEditorKit.java
--- test/unit/src/org/openide/text/NbLikeEditorKit.java 28 Jul 2004 12:34:10 -0000 1.1
+++ test/unit/src/org/openide/text/NbLikeEditorKit.java 6 Jan 2005 15:56:37 -0000
@@ -14,6 +14,7 @@
package org.openide.text;
+import java.beans.VetoableChangeListener;
import javax.swing.text.*;
/**
@@ -88,5 +89,46 @@
public java.awt.Color getForeground(javax.swing.text.AttributeSet attr) {
return null;
}
+
+ public void insertString (int offs, String str, AttributeSet a) throws BadLocationException {
+ insOrRemove (offs, str, a, 0, true);
+ }
+
+ public void remove (int offs, int len) throws BadLocationException {
+ insOrRemove (offs, null, null, len, false);
+ }
+
+
+ private void insOrRemove (int offset, String str, AttributeSet set, int len, boolean insert)
+ throws BadLocationException {
+ Object o = getProperty ("beforeModificationListener");
+ if (o instanceof VetoableChangeListener) {
+ VetoableChangeListener l = (VetoableChangeListener)o;
+ try {
+ l.vetoableChange (new java.beans.PropertyChangeEvent (this, "modified", null, Boolean.TRUE));
+ } catch (java.beans.PropertyVetoException ex) {
+ return;
+ }
+ }
+
+ try {
+ if (insert) {
+ super.insertString (offset, str, set);
+ } else {
+ super.remove(offset, len);
+ }
+ } catch (BadLocationException ex) {
+ if (o instanceof VetoableChangeListener) {
+ VetoableChangeListener l = (VetoableChangeListener)o;
+ try {
+ l.vetoableChange (new java.beans.PropertyChangeEvent (this, "modified", null, Boolean.FALSE));
+ } catch (java.beans.PropertyVetoException ignore) {
+ // ignore this
+ }
+ }
+ throw ex;
+ }
+ }
+
} // end of Doc
}
Index: test/unit/src/org/openide/text/NotifyModifiedTest.java
===================================================================
RCS file: /cvs/openide/test/unit/src/org/openide/text/NotifyModifiedTest.java,v
retrieving revision 1.1
diff -u -r1.1 NotifyModifiedTest.java
--- test/unit/src/org/openide/text/NotifyModifiedTest.java 5 Jan 2005 17:05:25 -0000 1.1
+++ test/unit/src/org/openide/text/NotifyModifiedTest.java 6 Jan 2005 15:56:37 -0000
@@ -45,6 +45,8 @@
private java.util.List/*