Bug 935176 - saving a style sheet doesn't remove the star, r=harth
authorGirish Sharma <scrapmachines@gmail.com>
Fri, 06 Dec 2013 23:51:16 +0530
changeset 159231 9408665d53845f3038f904d15fe2255afb6d44e4
parent 159230 b86d25a3c04889e8ef3ce707af6323810cca46ba
child 159232 83bce9e1d37fc70461f87c8e9610fdbc48aa5464
push id25777
push userryanvm@gmail.com
push dateFri, 06 Dec 2013 21:03:53 +0000
treeherdermozilla-central@b3806ae5399d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersharth
bugs935176
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 935176 - saving a style sheet doesn't remove the star, r=harth
browser/devtools/sourceeditor/editor.js
browser/devtools/styleeditor/StyleSheetEditor.jsm
browser/devtools/styleeditor/test/browser_styleeditor_filesave.js
--- a/browser/devtools/sourceeditor/editor.js
+++ b/browser/devtools/sourceeditor/editor.js
@@ -231,17 +231,23 @@ Editor.prototype = {
       cm = win.CodeMirror(win.document.body, this.config);
       cm.getWrapperElement().addEventListener("contextmenu", (ev) => {
         ev.preventDefault();
         this.showContextMenu(el.ownerDocument, ev.screenX, ev.screenY);
       }, false);
 
       cm.on("focus", () => this.emit("focus"));
       cm.on("scroll", () => this.emit("scroll"));
-      cm.on("change", () => this.emit("change"));
+      cm.on("change", () => {
+        this.emit("change");
+        if (!this._lastDirty) {
+          this._lastDirty = true;
+          this.emit("dirty-change");
+        }
+      });
       cm.on("cursorActivity", (cm) => this.emit("cursorActivity"));
 
       cm.on("gutterClick", (cm, line, gutter, ev) => {
         let head = { line: line, ch: 0 };
         let tail = { line: line, ch: this.getText(line).length };
 
         // Shift-click on a gutter selects the whole line.
         if (ev.shiftKey)
@@ -609,16 +615,18 @@ Editor.prototype = {
 
   /**
    * Marks the contents as clean and returns the current
    * version number.
    */
   setClean: function () {
     let cm = editors.get(this);
     this.version = cm.changeGeneration();
+    this._lastDirty = false;
+    this.emit("dirty-change");
     return this.version;
   },
 
   /**
    * Returns true if contents of the text area are
    * clean i.e. no changes were made since the last version.
    */
   isClean: function () {
--- a/browser/devtools/styleeditor/StyleSheetEditor.jsm
+++ b/browser/devtools/styleeditor/StyleSheetEditor.jsm
@@ -229,17 +229,17 @@ StyleSheetEditor.prototype = {
 
       sourceEditor.setFirstVisibleLine(this._state.topIndex);
       sourceEditor.setSelection(this._state.selection.start,
                                 this._state.selection.end);
 
       this.emit("source-editor-load");
     });
 
-    sourceEditor.on("change", this._onPropertyChange);
+    sourceEditor.on("dirty-change", this._onPropertyChange);
   },
 
   /**
    * Get the source editor for this editor.
    *
    * @return {Promise}
    *         Promise that will resolve with the editor.
    */
--- a/browser/devtools/styleeditor/test/browser_styleeditor_filesave.js
+++ b/browser/devtools/styleeditor/test/browser_styleeditor_filesave.js
@@ -9,17 +9,16 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 let tempScope = {};
 Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope);
 Components.utils.import("resource://gre/modules/NetUtil.jsm", tempScope);
 let FileUtils = tempScope.FileUtils;
 let NetUtil = tempScope.NetUtil;
 
-
 function test()
 {
   waitForExplicitFinish();
 
   copy(TESTCASE_URI_HTML, "simple.html", function(htmlFile) {
     copy(TESTCASE_URI_CSS, "simple.css", function(cssFile) {
       addTabAndOpenStyleEditor(function(panel) {
         let UI = panel.UI;
@@ -36,19 +35,32 @@ function test()
       let filePath = uri.resolve("");
       content.location = filePath;
     });
   });
 }
 
 function runTests(editor)
 {
+  editor.sourceEditor.once("dirty-change", () => {
+    is(editor.sourceEditor.isClean(), false, "Editor is dirty.");
+    ok(editor.summary.classList.contains("unsaved"),
+       "Star icon is present in the corresponding summary.");
+  });
+  let beginCursor = {line: 0, ch: 0};
+  editor.sourceEditor.replaceText("DIRTY TEXT", beginCursor, beginCursor);
+
+  editor.sourceEditor.once("dirty-change", () => {
+    is(editor.sourceEditor.isClean(), true, "Editor is clean.");
+    ok(!editor.summary.classList.contains("unsaved"),
+       "Star icon is not present in the corresponding summary.");
+    finish();
+  });
   editor.saveToFile(null, function (file) {
     ok(file, "file should get saved directly when using a file:// URI");
-    finish();
   });
 }
 
 function copy(aSrcChromeURL, aDestFileName, aCallback)
 {
   let destFile = FileUtils.getFile("ProfD", [aDestFileName]);
   write(read(aSrcChromeURL), destFile, aCallback);
 }