Bug 1033853 - Do not reload files that have changed in project editor. r=harth

This commit is contained in:
Brian Grinstead 2014-07-07 07:45:00 +02:00
parent 0db29c76bc
commit ce4d9f6dfb
5 changed files with 57 additions and 3 deletions

View File

@ -40,6 +40,11 @@ var ItchEditor = Class({
emit(this, name, ...args); emit(this, name, ...args);
}, },
/* Does the editor not have any unsaved changes? */
isClean: function() {
return true;
},
/** /**
* Initialize the editor with a single host. This should be called * Initialize the editor with a single host. This should be called
* by objects extending this object with: * by objects extending this object with:
@ -145,6 +150,13 @@ var TextEditor = Class({
return extraKeys; return extraKeys;
}, },
isClean: function() {
if (!this.editor.isAppended()) {
return true;
}
return this.editor.isClean();
},
initialize: function(document, mode=Editor.modes.text) { initialize: function(document, mode=Editor.modes.text) {
ItchEditor.prototype.initialize.apply(this, arguments); ItchEditor.prototype.initialize.apply(this, arguments);
this.label = mode.name; this.label = mode.name;

View File

@ -22,9 +22,8 @@ var DirtyPlugin = Class({
// Dont' force a refresh unless the dirty state has changed... // Dont' force a refresh unless the dirty state has changed...
let priv = this.priv(editor); let priv = this.priv(editor);
let clean = editor.editor.isClean(); let clean = editor.isClean()
if (priv.isClean !== clean) { if (priv.isClean !== clean) {
let resource = editor.shell.resource; let resource = editor.shell.resource;
emit(resource, "label-change", resource); emit(resource, "label-change", resource);
priv.isClean = clean; priv.isClean = clean;

View File

@ -192,7 +192,10 @@ var ShellDeck = Class({
this.deck.selectedPanel = shell.elt; this.deck.selectedPanel = shell.elt;
this._activeShell = shell; this._activeShell = shell;
shell.load(); // Only reload the shell if the editor doesn't have local changes.
if (shell.editor.isClean()) {
shell.load();
}
shell.editorLoaded.then(() => { shell.editorLoaded.then(() => {
// Handle case where another shell has been requested before this // Handle case where another shell has been requested before this
// one is finished loading. // one is finished loading.

View File

@ -22,9 +22,41 @@ let test = asyncTest(function*() {
let resource = resources.filter(r=>r.basename === data.basename)[0]; let resource = resources.filter(r=>r.basename === data.basename)[0];
yield selectFile(projecteditor, resource); yield selectFile(projecteditor, resource);
yield testChangeFileExternally(projecteditor, getTempFile(data.path).path, data.newContent); yield testChangeFileExternally(projecteditor, getTempFile(data.path).path, data.newContent);
yield testChangeUnsavedFileExternally(projecteditor, getTempFile(data.path).path, data.newContent + "[changed]");
} }
}); });
function testChangeUnsavedFileExternally(projecteditor, filePath, newData) {
info ("Testing file external changes for: " + filePath);
let editor = projecteditor.currentEditor;
let resource = projecteditor.resourceFor(editor);
let initialData = yield getFileData(filePath);
is (resource.path, filePath, "Resource path is set correctly");
is (editor.editor.getText(), initialData, "Editor is loaded with correct file contents");
info ("Editing but not saving file in project editor");
ok (editor.isClean(), "Editor is clean");
editor.editor.setText("foobar");
ok (!editor.isClean(), "Editor is dirty");
info ("Editor has been selected, writing to file externally");
yield writeToFile(resource.path, newData);
info ("Selecting another resource, then reselecting this one");
projecteditor.projectTree.selectResource(resource.store.root);
yield onceEditorActivated(projecteditor);
projecteditor.projectTree.selectResource(resource);
yield onceEditorActivated(projecteditor);
let editor = projecteditor.currentEditor;
info ("Checking to make sure the editor is now populated correctly");
is (editor.editor.getText(), "foobar", "Editor has not been updated with new file contents");
info ("Finished checking saving for " + filePath);
}
function testChangeFileExternally(projecteditor, filePath, newData) { function testChangeFileExternally(projecteditor, filePath, newData) {
info ("Testing file external changes for: " + filePath); info ("Testing file external changes for: " + filePath);

View File

@ -344,6 +344,14 @@ Editor.prototype = {
return def.promise; return def.promise;
}, },
/**
* Returns a boolean indicating whether the editor is ready to
* use. Use appendTo(el).then(() => {}) for most cases
*/
isAppended: function() {
return editors.has(this);
},
/** /**
* Returns the currently active highlighting mode. * Returns the currently active highlighting mode.
* See Editor.modes for the list of all suppoert modes. * See Editor.modes for the list of all suppoert modes.