You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/04/11 07:04:40 UTC

[GitHub] JaroslavTulach closed pull request #482: Better consistency between SaveCookie presence and modified status

JaroslavTulach closed pull request #482: Better consistency between SaveCookie presence and modified status
URL: https://github.com/apache/incubator-netbeans/pull/482
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java b/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java
index fdc19ec00..0f1ebf2ae 100644
--- a/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java
+++ b/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java
@@ -96,7 +96,7 @@ protected int associateLookup() {
     @Override
     public void setModified(boolean modif) {
         super.setModified(modif);
-        if (!modif) {
+        if (!isModified()) {
             GenericEditorSupport ges = getLookup().lookup(GenericEditorSupport.class);
             // defect #203688, probably file deletion in parallel with DO's creation - not completed, so cookie not registered yet.
             if (ges != null) {
diff --git a/csl.api/test/unit/src/org/netbeans/modules/csl/core/GsfDataObjectTest.java b/csl.api/test/unit/src/org/netbeans/modules/csl/core/GsfDataObjectTest.java
index 5f8de5b7d..9c91a7eb2 100644
--- a/csl.api/test/unit/src/org/netbeans/modules/csl/core/GsfDataObjectTest.java
+++ b/csl.api/test/unit/src/org/netbeans/modules/csl/core/GsfDataObjectTest.java
@@ -18,6 +18,8 @@
  */
 package org.netbeans.modules.csl.core;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import org.netbeans.junit.NbTestCase;
 import org.openide.cookies.EditorCookie;
 import org.openide.cookies.SaveCookie;
@@ -49,4 +51,27 @@ public void testSetModifiedRemovesSaveCookie() throws Exception {
         assertNull("Should not have SaveCookie.",
                 dob.getLookup().lookup(SaveCookie.class));
     }
+    
+    public void testSetModifiedNestedChange() throws Exception {
+        FileSystem fs = FileUtil.createMemoryFileSystem();
+        FileObject f = fs.getRoot().createData("index.test");
+        DataObject dob = DataObject.find(f);
+        assertEquals("The right object", GsfDataObject.class, dob.getClass());
+        dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
+                "modified", null);
+        assertTrue("Should be modified.", dob.isModified());
+        dob.addPropertyChangeListener(new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                String s = evt.getPropertyName();
+                if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) {
+                    dob.setModified(true);
+                }
+            }
+        });
+        dob.setModified(false);
+        assertTrue("Should be still modified.", dob.isModified());
+        assertNotNull("Still should have save cookie.",
+                dob.getLookup().lookup(SaveCookie.class));
+    }
 }
diff --git a/html/src/org/netbeans/modules/html/HtmlDataObject.java b/html/src/org/netbeans/modules/html/HtmlDataObject.java
index 74c698e8d..8d9311464 100644
--- a/html/src/org/netbeans/modules/html/HtmlDataObject.java
+++ b/html/src/org/netbeans/modules/html/HtmlDataObject.java
@@ -160,7 +160,7 @@ protected int associateLookup() {
     @Override
     public void setModified(boolean modif) {
         super.setModified(modif);
-        if(!modif) {
+        if(!isModified()) {
             HtmlEditorSupport support = getLookup().lookup(HtmlEditorSupport.class);
             support.removeSaveCookie();
         }
diff --git a/html/test/unit/src/org/netbeans/modules/html/HtmlDataObjectTest.java b/html/test/unit/src/org/netbeans/modules/html/HtmlDataObjectTest.java
index 136e3b285..70cb37488 100644
--- a/html/test/unit/src/org/netbeans/modules/html/HtmlDataObjectTest.java
+++ b/html/test/unit/src/org/netbeans/modules/html/HtmlDataObjectTest.java
@@ -18,17 +18,16 @@
  */
 package org.netbeans.modules.html;
 
-import java.awt.EventQueue;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.IOException;
 import java.util.Collection;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.StyledDocument;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.assertTrue;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.junit.MockServices;
 import org.netbeans.modules.csl.api.test.CslTestBase;
@@ -36,6 +35,7 @@
 import org.openide.cookies.EditorCookie;
 import org.openide.cookies.SaveCookie;
 import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileSystem;
 import org.openide.filesystems.FileUtil;
 import org.openide.loaders.DataObject;
 import org.openide.nodes.Children;
@@ -199,6 +199,29 @@ public void run() {
         assertNull(obj.getLookup().lookup(SaveCookie.class));
     }
 
+    public void testSetModifiedNestedChange() throws Exception {
+        FileSystem fs = FileUtil.createMemoryFileSystem();
+        FileObject f = fs.getRoot().createData("modify.html");
+        final DataObject dob = DataObject.find(f);
+        assertEquals("The right object", HtmlDataObject.class, dob.getClass());
+        dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
+                "modified", null);
+        assertTrue("Should be modified.", dob.isModified());
+        dob.addPropertyChangeListener(new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                String s = evt.getPropertyName();
+                if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) {
+                    dob.setModified(true);
+                }
+            }
+        });
+        dob.setModified(false);
+        assertTrue("Should be still modified.", dob.isModified());
+        assertNotNull("Still should have save cookie.",
+                dob.getLookup().lookup(SaveCookie.class));
+    }
+
     public void testFindEncoding() {
         assertEquals("UTF-8",
                 HtmlDataObject.findEncoding(
diff --git a/xml.multiview/src/org/netbeans/modules/xml/multiview/XmlMultiViewDataObject.java b/xml.multiview/src/org/netbeans/modules/xml/multiview/XmlMultiViewDataObject.java
index 2263ac084..de13e1975 100644
--- a/xml.multiview/src/org/netbeans/modules/xml/multiview/XmlMultiViewDataObject.java
+++ b/xml.multiview/src/org/netbeans/modules/xml/multiview/XmlMultiViewDataObject.java
@@ -185,7 +185,7 @@ public Lookup getLookup() {
     public void setModified(boolean modif) {
         super.setModified(modif);
         //getEditorSupport().updateDisplayName();
-        if (modif) {
+        if (isModified()) {
             // Add save cookie
             if (getCookie(SaveCookie.class) == null) {
                 getCookieSet().add(saveCookie);
diff --git a/xml.multiview/test/unit/src/org/netbeans/modules/xml/multiview/test/XmlMultiViewEditorTest.java b/xml.multiview/test/unit/src/org/netbeans/modules/xml/multiview/test/XmlMultiViewEditorTest.java
index 5b5fa0a63..530d7ff1b 100644
--- a/xml.multiview/test/unit/src/org/netbeans/modules/xml/multiview/test/XmlMultiViewEditorTest.java
+++ b/xml.multiview/test/unit/src/org/netbeans/modules/xml/multiview/test/XmlMultiViewEditorTest.java
@@ -19,18 +19,17 @@
 
 package org.netbeans.modules.xml.multiview.test;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.FileInputStream;
 import java.io.OutputStream;
-import java.io.StringWriter;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import junit.textui.TestRunner;
 import org.netbeans.junit.NbTestCase;
-import org.netbeans.junit.NbTestSuite;
 import org.netbeans.junit.AssertionFailedErrorException;
 
 import org.openide.cookies.EditorCookie;
@@ -47,6 +46,7 @@
 import javax.swing.*;
 import javax.swing.text.Document;
 import javax.swing.text.BadLocationException;
+import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
 
 /**
  *
@@ -227,4 +227,34 @@ private BookDataObject initDataObject() throws IOException {
 //    public static void main(String[] args) {
 //        TestRunner.run(new NbTestSuite(XmlMultiViewEditorTest.class));
 //    }
+    
+
+    public void testSetModifiedNestedChange() throws Exception {
+        File f = Helper.getBookFile(getDataDir(), getWorkDir());
+        FileObject fo = FileUtil.toFileObject(f);
+        assertNotNull(fo);
+
+        doSetPreferredLoader(fo, loader);
+        final DataObject dob = DataObject.find(fo);
+
+        assertTrue("The right object", dob instanceof XmlMultiViewDataObject);
+        dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
+                "modified", null);
+        assertTrue("Should be modified.", dob.isModified());
+        dob.addPropertyChangeListener(new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                String s = evt.getPropertyName();
+                if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) {
+                    dob.setModified(true);
+                }
+            }
+        });
+        dob.setModified(false);
+        assertTrue("Should be still modified.", dob.isModified());
+        assertNotNull("Still should have save cookie.",
+                dob.getLookup().lookup(SaveCookie.class));
+    }
+
+    
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists