Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 7d74ae9

Browse files
committed
- Fix bug #7300 (Prefs are never saved again after opening folder that
contains the user prefs JSON files in its subtree) - ensure that FileSystem always knows we've read the JSON file before we try to write to it. We don't want to enable the 'blind' flag since it will mean we virtually always overwrite external changes to the prefs file, and we don't want to start using file watchers to observe external changes on the fly since we haven't yet deeply tested having multiple watch roots active at once. - Rename confusing "filename" vars in PreferencesBase - Fix JSLint errors in ProjectManager from #7026
1 parent 8c6d382 commit 7d74ae9

4 files changed

Lines changed: 40 additions & 16 deletions

File tree

src/preferences/PreferenceStorage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
/**
2828
* PreferenceStorage defines an interface for persisting preference data as
2929
* name/value pairs for a module or plugin.
30+
*
31+
* @deprecated Use PreferencesManager APIs instead.
3032
*/
3133
define(function (require, exports, module) {
3234
"use strict";

src/preferences/PreferencesBase.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ define(function (require, exports, module) {
115115
/**
116116
* MemoryStorage is not stored in a file, so fileChanged is ignored.
117117
*
118-
* @param {string} filename File that has changed
118+
* @param {string} filePath File that has changed
119119
*/
120-
fileChanged: function (filename) {
120+
fileChanged: function (filePath) {
121121
}
122122
};
123123

@@ -241,10 +241,10 @@ define(function (require, exports, module) {
241241
/**
242242
* If the filename matches this Storage's path, a changed message is triggered.
243243
*
244-
* @param {string} filename File that has changed
244+
* @param {string} filePath File that has changed
245245
*/
246-
fileChanged: function (filename) {
247-
if (filename === this.path) {
246+
fileChanged: function (filePath) {
247+
if (filePath === this.path) {
248248
$(this).trigger("changed");
249249
}
250250
}
@@ -485,10 +485,10 @@ define(function (require, exports, module) {
485485
* Tells the Scope that the given file has been changed so that the
486486
* Storage can be reloaded if needed.
487487
*
488-
* @param {string} filename Name of the file that has changed
488+
* @param {string} filePath File that has changed
489489
*/
490-
fileChanged: function (filename) {
491-
this.storage.fileChanged(filename);
490+
fileChanged: function (filePath) {
491+
this.storage.fileChanged(filePath);
492492
},
493493

494494
/**
@@ -1693,11 +1693,11 @@ define(function (require, exports, module) {
16931693
* Tells the PreferencesSystem that the given file has been changed so that any
16941694
* related Scopes can be reloaded.
16951695
*
1696-
* @param {string} filename Name of the file that has changed
1696+
* @param {string} filePath File that has changed
16971697
*/
1698-
fileChanged: function (filename) {
1698+
fileChanged: function (filePath) {
16991699
_.forEach(this._scopes, function (scope) {
1700-
scope.fileChanged(filename);
1700+
scope.fileChanged(filePath);
17011701
});
17021702
},
17031703

src/preferences/PreferencesImpl.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ define(function (require, exports, module) {
3232
"use strict";
3333

3434
var PreferencesBase = require("./PreferencesBase"),
35+
ProjectManager = require("project/ProjectManager"),
3536
Async = require("utils/Async"),
3637

3738
// The SETTINGS_FILENAME is used with a preceding "." within user projects
@@ -103,6 +104,7 @@ define(function (require, exports, module) {
103104
});
104105
});
105106

107+
106108
// "State" is stored like preferences but it is not generally intended to be user-editable.
107109
// It's for more internal, implicit things like window size, working set, etc.
108110
var stateManager = new PreferencesBase.PreferencesSystem();
@@ -112,6 +114,18 @@ define(function (require, exports, module) {
112114
smUserScope.addLayer(stateProjectLayer);
113115
var smUserScopeLoading = stateManager.addScope("user", smUserScope);
114116

117+
118+
// Listen for times where we might be unwatching a root that contains one of the user-level prefs files,
119+
// and force a re-read of the file in order to ensure we can write to it later (see #7300).
120+
$(ProjectManager).on("projectClose", function (event, rootDir) {
121+
var prefsDir = brackets.app.getApplicationSupportDirectory() + "/";
122+
if (prefsDir.indexOf(rootDir.fullPath) === 0) {
123+
manager.fileChanged(userPrefFile);
124+
stateManager.fileChanged(userStateFile);
125+
}
126+
});
127+
128+
115129
// Semi-Public API. Use this at your own risk. The public API is in PreferencesManager.
116130
exports.manager = manager;
117131
exports.projectStorage = projectStorage;

src/project/ProjectManager.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
* the file tree.
3131
*
3232
* This module dispatches these events:
33-
* - beforeProjectClose -- before _projectRoot changes
33+
* - beforeProjectClose -- before _projectRoot changes, but working set files still open
34+
* - projectClose -- *just* before _projectRoot changes; working set already cleared & project root unwatched
3435
* - beforeAppClose -- before Brackets quits entirely
3536
* - projectOpen -- after _projectRoot changes and the tree is re-rendered
3637
* - projectRefresh -- when project tree is re-rendered for a reason other than
@@ -159,6 +160,7 @@ define(function (require, exports, module) {
159160
/**
160161
* @private
161162
* @see getProjectRoot()
163+
* @type {Directory}
162164
*/
163165
var _projectRoot = null;
164166

@@ -674,15 +676,15 @@ define(function (require, exports, module) {
674676
var events = $._data(_projectTree[0], "events"),
675677
eventsForType = events ? events[type] : null,
676678
event = eventsForType ? _.find(eventsForType, function (e) {
677-
return e.namespace === namespace && e.selector === selector;
678-
}) : null,
679+
return e.namespace === namespace && e.selector === selector;
680+
}) : null,
679681
eventHandler = event ? event.handler : null;
680682
if (!eventHandler) {
681683
console.error(type + "." + namespace + " " + selector + " handler not found!");
682684
}
683685
return eventHandler;
684686
};
685-
var createCustomHandler = function(originalHandler) {
687+
var createCustomHandler = function (originalHandler) {
686688
return function (event) {
687689
var $node = $(event.target).parent("li"),
688690
methodName;
@@ -1102,15 +1104,21 @@ define(function (require, exports, module) {
11021104
if (_projectRoot && _projectRoot.fullPath === rootPath) {
11031105
return (new $.Deferred()).resolve().promise();
11041106
}
1107+
1108+
// About to close current project (if any)
11051109
if (_projectRoot) {
1106-
// close current project
11071110
$(exports).triggerHandler("beforeProjectClose", _projectRoot);
11081111
}
11091112

11101113
// close all the old files
11111114
DocumentManager.closeAll();
11121115

11131116
_unwatchProjectRoot().always(function () {
1117+
// Done closing old project (if any)
1118+
if (_projectRoot) {
1119+
$(exports).triggerHandler("projectClose", _projectRoot);
1120+
}
1121+
11141122
startLoad.resolve();
11151123
});
11161124
}

0 commit comments

Comments
 (0)