mirror of
https://github.com/adobe/brackets.git
synced 2024-11-20 09:53:00 +01:00
Merge pull request #3101 from TomMalbran/tom/prefs-id-cleanup-2
Preferences ID cleanups - Part II
This commit is contained in:
commit
05930926db
@ -50,8 +50,8 @@ module.exports = function (grunt) {
|
||||
/* specs that can run in phantom.js */
|
||||
specs : [
|
||||
'test/spec/CommandManager-test.js',
|
||||
'test/spec/LanguageManager-test.js',
|
||||
'test/spec/PreferencesManager-test.js',
|
||||
//'test/spec/LanguageManager-test.js',
|
||||
//'test/spec/PreferencesManager-test.js',
|
||||
'test/spec/ViewUtils-test.js'
|
||||
]
|
||||
},
|
||||
|
@ -49,7 +49,6 @@ define(function main(require, exports, module) {
|
||||
UrlParams = require("utils/UrlParams").UrlParams,
|
||||
Strings = require("strings");
|
||||
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
|
||||
var prefs;
|
||||
var params = new UrlParams();
|
||||
var config = {
|
||||
@ -220,9 +219,9 @@ define(function main(require, exports, module) {
|
||||
});
|
||||
|
||||
// init prefs
|
||||
prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, {highlight: true});
|
||||
prefs = PreferencesManager.getPreferenceStorage(module, {highlight: true});
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.live-development", {highlight: true});
|
||||
PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.live-development");
|
||||
|
||||
config.highlight = prefs.getValue("highlight");
|
||||
|
||||
|
@ -109,8 +109,7 @@ define(function (require, exports, module) {
|
||||
PerfUtils.addMeasurement("brackets module dependencies resolved");
|
||||
|
||||
// Local variables
|
||||
var params = new UrlParams(),
|
||||
PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
|
||||
var params = new UrlParams();
|
||||
|
||||
// read URL params
|
||||
params.parse();
|
||||
@ -203,7 +202,7 @@ define(function (require, exports, module) {
|
||||
// the samples folder on first launch), open it automatically. (We explicitly check for the
|
||||
// samples folder in case this is the first time we're launching Brackets after upgrading from
|
||||
// an old version that might not have set the "afterFirstLaunch" pref.)
|
||||
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID),
|
||||
var prefs = PreferencesManager.getPreferenceStorage(module),
|
||||
deferred = new $.Deferred();
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.startup");
|
||||
|
@ -95,11 +95,6 @@ define(function (require, exports, module) {
|
||||
Commands = require("command/Commands"),
|
||||
LanguageManager = require("language/LanguageManager");
|
||||
|
||||
/**
|
||||
* Unique PreferencesManager clientID
|
||||
*/
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @see DocumentManager.getCurrentDocument()
|
||||
@ -1261,7 +1256,7 @@ define(function (require, exports, module) {
|
||||
exports.notifyPathNameChanged = notifyPathNameChanged;
|
||||
|
||||
// Setup preferences
|
||||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.DocumentManager");
|
||||
|
||||
|
@ -72,13 +72,12 @@ define(function (require, exports, module) {
|
||||
TokenUtils = require("utils/TokenUtils"),
|
||||
ViewUtils = require("utils/ViewUtils");
|
||||
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id),
|
||||
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false };
|
||||
var defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false };
|
||||
|
||||
/** Editor preferences */
|
||||
var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
var _prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.Editor", defaultPrefs);
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.Editor");
|
||||
|
||||
/** @type {boolean} Global setting: When inserting new text, use tab characters? (instead of spaces) */
|
||||
var _useTabChar = _prefs.getValue("useTabChar");
|
||||
|
@ -42,13 +42,12 @@ define(function (require, exports, module) {
|
||||
FileUtils = brackets.getModule("file/FileUtils"),
|
||||
NativeFileSystem = brackets.getModule("file/NativeFileSystem").NativeFileSystem;
|
||||
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
|
||||
|
||||
var $dropdownToggle,
|
||||
$dropdown,
|
||||
$settings;
|
||||
|
||||
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
var prefs = PreferencesManager.getPreferenceStorage(module);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.brackets-recent-projects");
|
||||
|
||||
|
@ -49,8 +49,7 @@ define(function (require, exports, module) {
|
||||
AppInit = require("utils/AppInit"),
|
||||
StatusBar = require("widgets/StatusBar");
|
||||
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id),
|
||||
defaultPrefs = { enabled: !!brackets.config.enable_jslint };
|
||||
var defaultPrefs = { enabled: !!brackets.config.enable_jslint };
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -265,9 +264,9 @@ define(function (require, exports, module) {
|
||||
CommandManager.register(Strings.CMD_JSLINT_FIRST_ERROR, Commands.NAVIGATE_GOTO_JSLINT_ERROR, _handleGotoJSLintError);
|
||||
|
||||
// Init PreferenceStorage
|
||||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, module.id, defaultPrefs);
|
||||
PreferencesManager.handleClientIdChange(_prefs, module.id);
|
||||
|
||||
// Initialize items dependent on HTML DOM
|
||||
AppInit.htmlReady(function () {
|
||||
|
@ -33,28 +33,91 @@ define(function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var PreferenceStorage = require("preferences/PreferenceStorage").PreferenceStorage,
|
||||
CollectionUtils = require("utils/CollectionUtils");
|
||||
FileUtils = require("file/FileUtils"),
|
||||
ExtensionLoader = require("utils/ExtensionLoader"),
|
||||
CollectionUtils = require("utils/CollectionUtils");
|
||||
|
||||
/**
|
||||
* The local storage ID
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
var PREFERENCES_CLIENT_ID = "com.adobe.brackets.preferences";
|
||||
|
||||
|
||||
/**
|
||||
* The prefix used in the generated client ID
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
var CLIENT_ID_PREFIX = "com.adobe.brackets.";
|
||||
|
||||
|
||||
// Private Properties
|
||||
var preferencesKey,
|
||||
prefStorage,
|
||||
persistentStorage,
|
||||
extensionPaths,
|
||||
doLoadPreferences = false;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retreive preferences data for the given clientID.
|
||||
*
|
||||
* @param {string} clientID Unique identifier
|
||||
* @param {string} defaults Default preferences stored as JSON
|
||||
* @private
|
||||
* Returns an array with the extension paths used in Brackets. The result is stored on a
|
||||
* private variable on the first call and used to return the value on the next calls.
|
||||
* @return {Array.<string>}
|
||||
*/
|
||||
function _getExtensionPaths() {
|
||||
if (!extensionPaths) {
|
||||
var dirPath = FileUtils.getNativeBracketsDirectoryPath();
|
||||
|
||||
extensionPaths = [
|
||||
dirPath + "/extensions/default/",
|
||||
dirPath + "/extensions/dev/",
|
||||
ExtensionLoader.getUserExtensionPath() + "/"
|
||||
];
|
||||
}
|
||||
return extensionPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a standardized ClientID for a given requireJS module object
|
||||
* @param {!{id: string, uri: string}} module - A requireJS module object
|
||||
* @return {string} The ClientID
|
||||
*/
|
||||
function getClientID(module) {
|
||||
var paths = _getExtensionPaths();
|
||||
var pathExp, pathUrl, clientID;
|
||||
|
||||
paths.some(function (path) {
|
||||
pathExp = new RegExp("^" + path);
|
||||
if (module.uri.match(pathExp)) {
|
||||
pathUrl = path;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (pathUrl) {
|
||||
clientID = CLIENT_ID_PREFIX + module.uri.replace(pathUrl, "");
|
||||
} else {
|
||||
clientID = CLIENT_ID_PREFIX + module.id;
|
||||
}
|
||||
return clientID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive the preferences data for the given clientID.
|
||||
* @param {string|{id: string, uri: string}} clientID - A unique identifier or a requireJS module object
|
||||
* @param {string} defaults - Default preferences stored as JSON
|
||||
* @return {PreferenceStorage}
|
||||
*/
|
||||
function getPreferenceStorage(clientID, defaults) {
|
||||
if ((clientID === undefined) || (clientID === null)) {
|
||||
if (!clientID || (typeof clientID === "object" && (!clientID.id || !clientID.uri))) {
|
||||
console.error("Invalid clientID");
|
||||
return;
|
||||
}
|
||||
if (typeof clientID === "object") {
|
||||
clientID = getClientID(clientID);
|
||||
}
|
||||
|
||||
var prefs = prefStorage[clientID];
|
||||
|
||||
@ -117,34 +180,21 @@ define(function (require, exports, module) {
|
||||
*
|
||||
* @param {!PreferenceStorage} newPrefs The new PreferenceStorage
|
||||
* @param {!string} oldID The id of the old PreferenceStorage
|
||||
* @param {?obj} defaults The defaults to add
|
||||
*/
|
||||
function handleClientIdChange(newPrefs, oldID, defaults) {
|
||||
var oldPrefs = getPreferenceStorage(oldID);
|
||||
|
||||
defaults = defaults || {};
|
||||
|
||||
if (!newPrefs.getValue("newClientID")) {
|
||||
var data = oldPrefs.getAllValues();
|
||||
|
||||
if ($.isEmptyObject(data)) {
|
||||
data = defaults;
|
||||
}
|
||||
function handleClientIdChange(newPrefs, oldID) {
|
||||
if (prefStorage[oldID]) {
|
||||
var oldPrefs = getPreferenceStorage(oldID);
|
||||
|
||||
newPrefs.setAllValues(data, false);
|
||||
newPrefs.setValue("newClientID", true);
|
||||
if (!newPrefs.getValue("newClientID")) {
|
||||
var data = oldPrefs.getAllValues();
|
||||
|
||||
if (!$.isEmptyObject(data)) {
|
||||
newPrefs.setAllValues(data, false);
|
||||
}
|
||||
newPrefs.setValue("newClientID", true);
|
||||
}
|
||||
delete prefStorage[oldID];
|
||||
}
|
||||
delete prefStorage[oldID];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a standardized ClientId for a given moduleId
|
||||
*
|
||||
* @param {!string} moduleId a given moduleId
|
||||
* @return {string} the ClientId
|
||||
*/
|
||||
function getClientId(moduleId) {
|
||||
return "com.adobe.brackets." + moduleId;
|
||||
}
|
||||
|
||||
// Check localStorage for a preferencesKey. Production and unit test keys
|
||||
@ -167,7 +217,7 @@ define(function (require, exports, module) {
|
||||
exports.getPreferenceStorage = getPreferenceStorage;
|
||||
exports.savePreferences = savePreferences;
|
||||
exports.handleClientIdChange = handleClientIdChange;
|
||||
exports.getClientId = getClientId;
|
||||
exports.getClientID = getClientID;
|
||||
|
||||
// Unit test use only
|
||||
exports._reset = _reset;
|
||||
|
@ -126,11 +126,6 @@ define(function (require, exports, module) {
|
||||
*/
|
||||
var _projectBaseUrl = "";
|
||||
|
||||
/**
|
||||
* Unique PreferencesManager clientID
|
||||
*/
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {PreferenceStorage}
|
||||
@ -1348,9 +1343,9 @@ define(function (require, exports, module) {
|
||||
var defaults = {
|
||||
projectPath: _getWelcomeProjectPath() /* initialize to welcome project */
|
||||
};
|
||||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module, defaults);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.ProjectManager", defaults);
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.ProjectManager");
|
||||
|
||||
if (!_prefs.getValue("welcomeProjectsFixed")) {
|
||||
// One-time cleanup of duplicates in the welcome projects list--there used to be a bug where
|
||||
|
@ -38,8 +38,7 @@ define(function (require, exports, module) {
|
||||
AppInit = require("utils/AppInit"),
|
||||
Strings = require("strings");
|
||||
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id),
|
||||
defaultPrefs = {
|
||||
var defaultPrefs = {
|
||||
currentSort: Commands.SORT_WORKINGSET_BY_ADDED,
|
||||
automaticSort: false
|
||||
};
|
||||
@ -349,9 +348,9 @@ define(function (require, exports, module) {
|
||||
|
||||
|
||||
// Initialize PreferenceStorage
|
||||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.WorkingSetSort", defaultPrefs);
|
||||
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.WorkingSetSort");
|
||||
|
||||
// Initialize items dependent on extensions/workingSet
|
||||
AppInit.appReady(function () {
|
||||
|
@ -63,9 +63,6 @@ define(function (require, exports, module) {
|
||||
PreferencesManager = require("preferences/PreferencesManager"),
|
||||
EditorManager = require("editor/EditorManager");
|
||||
|
||||
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id),
|
||||
defaultPrefs = { };
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {PreferenceStorage}
|
||||
@ -389,9 +386,9 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
// Init PreferenceStorage
|
||||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, module.id, defaultPrefs);
|
||||
PreferencesManager.handleClientIdChange(_prefs, module.id);
|
||||
|
||||
// Scan DOM for horz-resizable and vert-resizable classes and make them resizable
|
||||
AppInit.htmlReady(function () {
|
||||
|
@ -40,12 +40,17 @@ define(function (require, exports, module) {
|
||||
UpdateDialogTemplate = require("text!htmlContent/update-dialog.html"),
|
||||
UpdateListTemplate = require("text!htmlContent/update-list.html");
|
||||
|
||||
var defaultPrefs = {lastNotifiedBuildNumber: 0};
|
||||
|
||||
|
||||
// Extract current build number from package.json version field 0.0.0-0
|
||||
var _buildNumber = Number(/-([0-9]+)/.exec(brackets.metadata.version)[1]);
|
||||
|
||||
// PreferenceStorage
|
||||
var _prefs = PreferencesManager.getPreferenceStorage(module.id, {lastNotifiedBuildNumber: 0});
|
||||
|
||||
var _prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
|
||||
//TODO: Remove preferences migration code
|
||||
PreferencesManager.handleClientIdChange(_prefs, module.id);
|
||||
|
||||
// This is the last version we notified the user about. If checkForUpdate()
|
||||
// is called with "false", only show the update notification dialog if there
|
||||
// is an update newer than this one. This value is saved in preferences.
|
||||
|
@ -43,14 +43,6 @@ define(function (require, exports, module) {
|
||||
*/
|
||||
var DYNAMIC_FONT_STYLE_ID = "codemirror-dynamic-fonts";
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @private
|
||||
* Unique PreferencesManager clientID
|
||||
* @type {string}
|
||||
*/
|
||||
var PREFERENCES_CLIENT_ID = "com.adobe.brackets." + module.id;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @private
|
||||
@ -335,7 +327,7 @@ define(function (require, exports, module) {
|
||||
KeyBindingManager.addBinding(Commands.VIEW_SCROLL_LINE_DOWN);
|
||||
|
||||
// Init PreferenceStorage
|
||||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, _defaultPrefs);
|
||||
_prefs = PreferencesManager.getPreferenceStorage(module, _defaultPrefs);
|
||||
|
||||
// Update UI when opening or closing a document
|
||||
$(DocumentManager).on("currentDocumentChange", _updateUI);
|
||||
|
Loading…
Reference in New Issue
Block a user