1
0
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:
Randy Edmunds 2013-03-19 15:07:11 -07:00
commit 05930926db
13 changed files with 113 additions and 85 deletions

View File

@ -50,8 +50,8 @@ module.exports = function (grunt) {
/* specs that can run in phantom.js */ /* specs that can run in phantom.js */
specs : [ specs : [
'test/spec/CommandManager-test.js', 'test/spec/CommandManager-test.js',
'test/spec/LanguageManager-test.js', //'test/spec/LanguageManager-test.js',
'test/spec/PreferencesManager-test.js', //'test/spec/PreferencesManager-test.js',
'test/spec/ViewUtils-test.js' 'test/spec/ViewUtils-test.js'
] ]
}, },

View File

@ -49,7 +49,6 @@ define(function main(require, exports, module) {
UrlParams = require("utils/UrlParams").UrlParams, UrlParams = require("utils/UrlParams").UrlParams,
Strings = require("strings"); Strings = require("strings");
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
var prefs; var prefs;
var params = new UrlParams(); var params = new UrlParams();
var config = { var config = {
@ -220,9 +219,9 @@ define(function main(require, exports, module) {
}); });
// init prefs // init prefs
prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, {highlight: true}); prefs = PreferencesManager.getPreferenceStorage(module, {highlight: true});
//TODO: Remove preferences migration code //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"); config.highlight = prefs.getValue("highlight");

View File

@ -109,8 +109,7 @@ define(function (require, exports, module) {
PerfUtils.addMeasurement("brackets module dependencies resolved"); PerfUtils.addMeasurement("brackets module dependencies resolved");
// Local variables // Local variables
var params = new UrlParams(), var params = new UrlParams();
PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
// read URL params // read URL params
params.parse(); 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 // 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 // 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.) // 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(); deferred = new $.Deferred();
//TODO: Remove preferences migration code //TODO: Remove preferences migration code
PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.startup"); PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.startup");

View File

@ -95,11 +95,6 @@ define(function (require, exports, module) {
Commands = require("command/Commands"), Commands = require("command/Commands"),
LanguageManager = require("language/LanguageManager"); LanguageManager = require("language/LanguageManager");
/**
* Unique PreferencesManager clientID
*/
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
/** /**
* @private * @private
* @see DocumentManager.getCurrentDocument() * @see DocumentManager.getCurrentDocument()
@ -1261,7 +1256,7 @@ define(function (require, exports, module) {
exports.notifyPathNameChanged = notifyPathNameChanged; exports.notifyPathNameChanged = notifyPathNameChanged;
// Setup preferences // Setup preferences
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); _prefs = PreferencesManager.getPreferenceStorage(module);
//TODO: Remove preferences migration code //TODO: Remove preferences migration code
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.DocumentManager"); PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.DocumentManager");

View File

@ -72,13 +72,12 @@ define(function (require, exports, module) {
TokenUtils = require("utils/TokenUtils"), TokenUtils = require("utils/TokenUtils"),
ViewUtils = require("utils/ViewUtils"); ViewUtils = require("utils/ViewUtils");
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id), var defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false };
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false };
/** Editor preferences */ /** Editor preferences */
var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); var _prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
//TODO: Remove preferences migration code //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) */ /** @type {boolean} Global setting: When inserting new text, use tab characters? (instead of spaces) */
var _useTabChar = _prefs.getValue("useTabChar"); var _useTabChar = _prefs.getValue("useTabChar");

View File

@ -42,13 +42,12 @@ define(function (require, exports, module) {
FileUtils = brackets.getModule("file/FileUtils"), FileUtils = brackets.getModule("file/FileUtils"),
NativeFileSystem = brackets.getModule("file/NativeFileSystem").NativeFileSystem; NativeFileSystem = brackets.getModule("file/NativeFileSystem").NativeFileSystem;
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
var $dropdownToggle, var $dropdownToggle,
$dropdown, $dropdown,
$settings; $settings;
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); var prefs = PreferencesManager.getPreferenceStorage(module);
//TODO: Remove preferences migration code //TODO: Remove preferences migration code
PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.brackets-recent-projects"); PreferencesManager.handleClientIdChange(prefs, "com.adobe.brackets.brackets-recent-projects");

View File

@ -49,8 +49,7 @@ define(function (require, exports, module) {
AppInit = require("utils/AppInit"), AppInit = require("utils/AppInit"),
StatusBar = require("widgets/StatusBar"); StatusBar = require("widgets/StatusBar");
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id), var defaultPrefs = { enabled: !!brackets.config.enable_jslint };
defaultPrefs = { enabled: !!brackets.config.enable_jslint };
/** /**
* @private * @private
@ -265,9 +264,9 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_JSLINT_FIRST_ERROR, Commands.NAVIGATE_GOTO_JSLINT_ERROR, _handleGotoJSLintError); CommandManager.register(Strings.CMD_JSLINT_FIRST_ERROR, Commands.NAVIGATE_GOTO_JSLINT_ERROR, _handleGotoJSLintError);
// Init PreferenceStorage // Init PreferenceStorage
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); _prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
//TODO: Remove preferences migration code //TODO: Remove preferences migration code
PreferencesManager.handleClientIdChange(_prefs, module.id, defaultPrefs); PreferencesManager.handleClientIdChange(_prefs, module.id);
// Initialize items dependent on HTML DOM // Initialize items dependent on HTML DOM
AppInit.htmlReady(function () { AppInit.htmlReady(function () {

View File

@ -33,28 +33,91 @@ define(function (require, exports, module) {
"use strict"; "use strict";
var PreferenceStorage = require("preferences/PreferenceStorage").PreferenceStorage, 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"; 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 // Private Properties
var preferencesKey, var preferencesKey,
prefStorage, prefStorage,
persistentStorage, persistentStorage,
extensionPaths,
doLoadPreferences = false; doLoadPreferences = false;
/** /**
* Retreive preferences data for the given clientID. * @private
* * Returns an array with the extension paths used in Brackets. The result is stored on a
* @param {string} clientID Unique identifier * private variable on the first call and used to return the value on the next calls.
* @param {string} defaults Default preferences stored as JSON * @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} * @return {PreferenceStorage}
*/ */
function getPreferenceStorage(clientID, defaults) { function getPreferenceStorage(clientID, defaults) {
if ((clientID === undefined) || (clientID === null)) { if (!clientID || (typeof clientID === "object" && (!clientID.id || !clientID.uri))) {
console.error("Invalid clientID"); console.error("Invalid clientID");
return; return;
} }
if (typeof clientID === "object") {
clientID = getClientID(clientID);
}
var prefs = prefStorage[clientID]; var prefs = prefStorage[clientID];
@ -117,34 +180,21 @@ define(function (require, exports, module) {
* *
* @param {!PreferenceStorage} newPrefs The new PreferenceStorage * @param {!PreferenceStorage} newPrefs The new PreferenceStorage
* @param {!string} oldID The id of the old PreferenceStorage * @param {!string} oldID The id of the old PreferenceStorage
* @param {?obj} defaults The defaults to add
*/ */
function handleClientIdChange(newPrefs, oldID, defaults) { function handleClientIdChange(newPrefs, oldID) {
var oldPrefs = getPreferenceStorage(oldID); if (prefStorage[oldID]) {
var oldPrefs = getPreferenceStorage(oldID);
defaults = defaults || {};
if (!newPrefs.getValue("newClientID")) {
var data = oldPrefs.getAllValues();
if ($.isEmptyObject(data)) {
data = defaults;
}
newPrefs.setAllValues(data, false); if (!newPrefs.getValue("newClientID")) {
newPrefs.setValue("newClientID", true); 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 // Check localStorage for a preferencesKey. Production and unit test keys
@ -167,7 +217,7 @@ define(function (require, exports, module) {
exports.getPreferenceStorage = getPreferenceStorage; exports.getPreferenceStorage = getPreferenceStorage;
exports.savePreferences = savePreferences; exports.savePreferences = savePreferences;
exports.handleClientIdChange = handleClientIdChange; exports.handleClientIdChange = handleClientIdChange;
exports.getClientId = getClientId; exports.getClientID = getClientID;
// Unit test use only // Unit test use only
exports._reset = _reset; exports._reset = _reset;

View File

@ -126,11 +126,6 @@ define(function (require, exports, module) {
*/ */
var _projectBaseUrl = ""; var _projectBaseUrl = "";
/**
* Unique PreferencesManager clientID
*/
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id);
/** /**
* @private * @private
* @type {PreferenceStorage} * @type {PreferenceStorage}
@ -1348,9 +1343,9 @@ define(function (require, exports, module) {
var defaults = { var defaults = {
projectPath: _getWelcomeProjectPath() /* initialize to welcome project */ projectPath: _getWelcomeProjectPath() /* initialize to welcome project */
}; };
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); _prefs = PreferencesManager.getPreferenceStorage(module, defaults);
//TODO: Remove preferences migration code //TODO: Remove preferences migration code
PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.ProjectManager", defaults); PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.ProjectManager");
if (!_prefs.getValue("welcomeProjectsFixed")) { if (!_prefs.getValue("welcomeProjectsFixed")) {
// One-time cleanup of duplicates in the welcome projects list--there used to be a bug where // One-time cleanup of duplicates in the welcome projects list--there used to be a bug where

View File

@ -38,8 +38,7 @@ define(function (require, exports, module) {
AppInit = require("utils/AppInit"), AppInit = require("utils/AppInit"),
Strings = require("strings"); Strings = require("strings");
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id), var defaultPrefs = {
defaultPrefs = {
currentSort: Commands.SORT_WORKINGSET_BY_ADDED, currentSort: Commands.SORT_WORKINGSET_BY_ADDED,
automaticSort: false automaticSort: false
}; };
@ -349,9 +348,9 @@ define(function (require, exports, module) {
// Initialize PreferenceStorage // Initialize PreferenceStorage
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); _prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs);
//TODO: Remove preferences migration code //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 // Initialize items dependent on extensions/workingSet
AppInit.appReady(function () { AppInit.appReady(function () {

View File

@ -63,9 +63,6 @@ define(function (require, exports, module) {
PreferencesManager = require("preferences/PreferencesManager"), PreferencesManager = require("preferences/PreferencesManager"),
EditorManager = require("editor/EditorManager"); EditorManager = require("editor/EditorManager");
var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id),
defaultPrefs = { };
/** /**
* @private * @private
* @type {PreferenceStorage} * @type {PreferenceStorage}
@ -389,9 +386,9 @@ define(function (require, exports, module) {
} }
// Init PreferenceStorage // Init PreferenceStorage
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); _prefs = PreferencesManager.getPreferenceStorage(module);
//TODO: Remove preferences migration code //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 // Scan DOM for horz-resizable and vert-resizable classes and make them resizable
AppInit.htmlReady(function () { AppInit.htmlReady(function () {

View File

@ -40,12 +40,17 @@ define(function (require, exports, module) {
UpdateDialogTemplate = require("text!htmlContent/update-dialog.html"), UpdateDialogTemplate = require("text!htmlContent/update-dialog.html"),
UpdateListTemplate = require("text!htmlContent/update-list.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 // Extract current build number from package.json version field 0.0.0-0
var _buildNumber = Number(/-([0-9]+)/.exec(brackets.metadata.version)[1]); var _buildNumber = Number(/-([0-9]+)/.exec(brackets.metadata.version)[1]);
// PreferenceStorage // 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() // 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 called with "false", only show the update notification dialog if there
// is an update newer than this one. This value is saved in preferences. // is an update newer than this one. This value is saved in preferences.

View File

@ -43,14 +43,6 @@ define(function (require, exports, module) {
*/ */
var DYNAMIC_FONT_STYLE_ID = "codemirror-dynamic-fonts"; 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 * @const
* @private * @private
@ -335,7 +327,7 @@ define(function (require, exports, module) {
KeyBindingManager.addBinding(Commands.VIEW_SCROLL_LINE_DOWN); KeyBindingManager.addBinding(Commands.VIEW_SCROLL_LINE_DOWN);
// Init PreferenceStorage // Init PreferenceStorage
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, _defaultPrefs); _prefs = PreferencesManager.getPreferenceStorage(module, _defaultPrefs);
// Update UI when opening or closing a document // Update UI when opening or closing a document
$(DocumentManager).on("currentDocumentChange", _updateUI); $(DocumentManager).on("currentDocumentChange", _updateUI);