Change preferences filename to brackets.prefs (.brackets.prefs in projects).

Also preferencifies linting enabled and collapsed.
This commit is contained in:
Kevin Dangoor 2013-12-09 12:12:46 -08:00
Родитель 0edb621d86
Коммит 6521e957dc
7 изменённых файлов: 45 добавлений и 27 удалений

Просмотреть файл

@ -10,7 +10,8 @@
"defaultExtension": "js", "defaultExtension": "js",
"path": { "path": {
"src/thirdparty/CodeMirror2/**/*.js": { "src/thirdparty/CodeMirror2/**/*.js": {
"spaceUnits": 2 "spaceUnits": 2,
"linting.enabled": false
} }
}, },
"spaceUnits": 4 "spaceUnits": 4

Просмотреть файл

@ -39,7 +39,7 @@ define(function (require, exports, module) {
Strings = brackets.getModule("strings"); Strings = brackets.getModule("strings");
PreferencesManager.definePreference("jslintOptions", "object"); PreferencesManager.definePreference("jslint.options", "object");
/** /**
* Run JSLint on the current document. Reports results to the main UI. Displays * Run JSLint on the current document. Reports results to the main UI. Displays
@ -58,7 +58,7 @@ define(function (require, exports, module) {
} }
text = arr.join("\n"); text = arr.join("\n");
var options = PreferencesManager.get("jslintOptions"); var options = PreferencesManager.get("jslint.options");
var jslintResult = JSLINT(text, options); var jslintResult = JSLINT(text, options);
if (!jslintResult) { if (!jslintResult) {

Просмотреть файл

@ -57,12 +57,7 @@ define(function (require, exports, module) {
PanelTemplate = require("text!htmlContent/problems-panel.html"), PanelTemplate = require("text!htmlContent/problems-panel.html"),
ResultsTemplate = require("text!htmlContent/problems-panel-table.html"); ResultsTemplate = require("text!htmlContent/problems-panel-table.html");
var INDICATOR_ID = "status-inspection", var INDICATOR_ID = "status-inspection";
defaultPrefs = {
enabled: brackets.config["linting.enabled_by_default"],
collapsed: false
};
/** Values for problem's 'type' property */ /** Values for problem's 'type' property */
var Type = { var Type = {
/** Unambiguous error, such as a syntax error */ /** Unambiguous error, such as a syntax error */
@ -74,10 +69,13 @@ define(function (require, exports, module) {
}; };
/** /**
* @private * Constants for the preferences defined in this file.
* @type {PreferenceStorage}
*/ */
var _prefs = null; var PREF_ENABLED = "linting.enabled",
PREF_COLLAPSED = "linting.collapsed";
PreferencesManager.definePreference(PREF_ENABLED, "boolean", brackets.config["linting.enabled_by_default"]);
PreferencesManager.definePreference(PREF_COLLAPSED, "boolean", false);
/** /**
* When disabled, the errors panel is closed and the status bar icon is grayed out. * When disabled, the errors panel is closed and the status bar icon is grayed out.
@ -317,8 +315,9 @@ define(function (require, exports, module) {
/** /**
* Enable or disable all inspection. * Enable or disable all inspection.
* @param {?boolean} enabled Enabled state. If omitted, the state is toggled. * @param {?boolean} enabled Enabled state. If omitted, the state is toggled.
* @param {?boolean} doNotSave true if the preference should not be saved to user settings. This is generally for events triggered by project-level settings.
*/ */
function toggleEnabled(enabled) { function toggleEnabled(enabled, doNotSave) {
if (enabled === undefined) { if (enabled === undefined) {
enabled = !_enabled; enabled = !_enabled;
} }
@ -326,7 +325,9 @@ define(function (require, exports, module) {
CommandManager.get(Commands.VIEW_TOGGLE_INSPECTION).setChecked(_enabled); CommandManager.get(Commands.VIEW_TOGGLE_INSPECTION).setChecked(_enabled);
updateListeners(); updateListeners();
_prefs.setValue("enabled", _enabled); if (!doNotSave) {
PreferencesManager.set("user", PREF_ENABLED, _enabled);
}
// run immediately // run immediately
run(); run();
@ -339,14 +340,17 @@ define(function (require, exports, module) {
* collapsed, the panel will not reopen automatically on switch files or save. * collapsed, the panel will not reopen automatically on switch files or save.
* *
* @param {?boolean} collapsed Collapsed state. If omitted, the state is toggled. * @param {?boolean} collapsed Collapsed state. If omitted, the state is toggled.
* @param {?boolean} doNotSave true if the preference should not be saved to user settings. This is generally for events triggered by project-level settings.
*/ */
function toggleCollapsed(collapsed) { function toggleCollapsed(collapsed, doNotSave) {
if (collapsed === undefined) { if (collapsed === undefined) {
collapsed = !_collapsed; collapsed = !_collapsed;
} }
_collapsed = collapsed; _collapsed = collapsed;
_prefs.setValue("collapsed", _collapsed); if (doNotSave) {
PreferencesManager.setValue("user", PREF_COLLAPSED, _collapsed);
}
if (_collapsed) { if (_collapsed) {
Resizer.hide($problemsPanel); Resizer.hide($problemsPanel);
@ -370,8 +374,13 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_VIEW_TOGGLE_INSPECTION, Commands.VIEW_TOGGLE_INSPECTION, toggleEnabled); CommandManager.register(Strings.CMD_VIEW_TOGGLE_INSPECTION, Commands.VIEW_TOGGLE_INSPECTION, toggleEnabled);
CommandManager.register(Strings.CMD_GOTO_FIRST_PROBLEM, Commands.NAVIGATE_GOTO_FIRST_PROBLEM, handleGotoFirstProblem); CommandManager.register(Strings.CMD_GOTO_FIRST_PROBLEM, Commands.NAVIGATE_GOTO_FIRST_PROBLEM, handleGotoFirstProblem);
// Init PreferenceStorage $(PreferencesManager.getPreference(PREF_ENABLED)).on("change", function (e, data) {
_prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs); toggleEnabled(data.newValue, true);
});
$(PreferencesManager.getPreference(PREF_COLLAPSED)).on("change", function (e, data) {
toggleCollapsed(data.newValue, true);
});
// Initialize items dependent on HTML DOM // Initialize items dependent on HTML DOM
AppInit.htmlReady(function () { AppInit.htmlReady(function () {
@ -416,8 +425,8 @@ define(function (require, exports, module) {
// Set initial UI state // Set initial UI state
toggleEnabled(_prefs.getValue("enabled")); toggleEnabled(PreferencesManager.get(PREF_ENABLED), true);
toggleCollapsed(_prefs.getValue("collapsed")); toggleCollapsed(PreferencesManager.get(PREF_COLLAPSED), true);
}); });

Просмотреть файл

@ -203,7 +203,7 @@ define(function (require, exports, module) {
// New code follows. The code above (with the exception of the imports) is // New code follows. The code above (with the exception of the imports) is
// deprecated. // deprecated.
var SETTINGS_FILENAME = "brackets.settings.json", var SETTINGS_FILENAME = "brackets.prefs",
STATE_FILENAME = "state.json"; STATE_FILENAME = "state.json";
var preferencesManager = new PreferencesBase.PreferencesManager(); var preferencesManager = new PreferencesBase.PreferencesManager();
@ -245,6 +245,7 @@ define(function (require, exports, module) {
exports.get = preferencesManager.get.bind(preferencesManager); exports.get = preferencesManager.get.bind(preferencesManager);
exports.set = preferencesManager.set.bind(preferencesManager); exports.set = preferencesManager.set.bind(preferencesManager);
exports.save = preferencesManager.save.bind(preferencesManager); exports.save = preferencesManager.save.bind(preferencesManager);
exports.getPreference = preferencesManager.getPreference.bind(preferencesManager);
exports.setValueAndSave = setValueAndSave; exports.setValueAndSave = setValueAndSave;
exports.addScope = preferencesManager.addScope.bind(preferencesManager); exports.addScope = preferencesManager.addScope.bind(preferencesManager);
exports.stateManager = stateManager; exports.stateManager = stateManager;

Просмотреть файл

@ -98,6 +98,13 @@ define(function (require, exports, module) {
* @type {RegExp} * @type {RegExp}
*/ */
var _binaryExclusionListRegEx = /\.svgz$|\.jsz$|\.zip$|\.gz$|\.htmz$|\.htmlz$|\.rar$|\.tar$|\.exe$|\.bin$/; var _binaryExclusionListRegEx = /\.svgz$|\.jsz$|\.zip$|\.gz$|\.htmz$|\.htmlz$|\.rar$|\.tar$|\.exe$|\.bin$/;
/**
* @private
* Filename to use for project settings files.
* @type {string}
*/
var SETTINGS_FILENAME = "." + PreferencesManager.SETTINGS_FILENAME;
/** /**
* @private * @private
@ -1728,14 +1735,14 @@ define(function (require, exports, module) {
function _reloadProjectPreferencesScope() { function _reloadProjectPreferencesScope() {
var root = getProjectRoot(); var root = getProjectRoot();
if (root) { if (root) {
PreferencesManager._projectFileStorage.setPath(root.fullPath + PreferencesManager.SETTINGS_FILENAME); PreferencesManager._projectFileStorage.setPath(root.fullPath + SETTINGS_FILENAME);
} }
} }
$(exports).on("projectOpen", _reloadProjectPreferencesScope); $(exports).on("projectOpen", _reloadProjectPreferencesScope);
$(DocumentManager).on("documentSaved", function (e, document) { $(DocumentManager).on("documentSaved", function (e, document) {
if (document.file && FileUtils.getDirectoryPath(document.file.fullPath) === _projectRoot.fullPath && document.file.name === PreferencesManager.SETTINGS_FILENAME) { if (document.file && FileUtils.getDirectoryPath(document.file.fullPath) === _projectRoot.fullPath && document.file.name === SETTINGS_FILENAME) {
_reloadProjectPreferencesScope(); _reloadProjectPreferencesScope();
} }
}); });

Просмотреть файл

@ -769,8 +769,8 @@ define(function (require, exports, module) {
}); });
describe("File Storage", function () { describe("File Storage", function () {
var settingsFile = FileSystem.getFileForPath(testPath + "/brackets.settings.json"), var settingsFile = FileSystem.getFileForPath(testPath + "/brackets.prefs"),
newSettingsFile = FileSystem.getFileForPath(testPath + "/new.settings.json"), newSettingsFile = FileSystem.getFileForPath(testPath + "/new.prefs"),
filestorage, filestorage,
originalText; originalText;
@ -814,7 +814,7 @@ define(function (require, exports, module) {
}); });
it("can load preferences from disk", function () { it("can load preferences from disk", function () {
var filestorage = new PreferencesBase.FileStorage(testPath + "/brackets.settings.json"); var filestorage = new PreferencesBase.FileStorage(settingsFile.fullPath);
var pm = new PreferencesBase.PreferencesManager(); var pm = new PreferencesBase.PreferencesManager();
var projectScope = new PreferencesBase.Scope(filestorage); var projectScope = new PreferencesBase.Scope(filestorage);
waitsForDone(pm.addScope("project", projectScope)); waitsForDone(pm.addScope("project", projectScope));
@ -829,7 +829,7 @@ define(function (require, exports, module) {
}); });
it("can save preferences", function () { it("can save preferences", function () {
var filestorage = new PreferencesBase.FileStorage(testPath + "/brackets.settings.json"); var filestorage = new PreferencesBase.FileStorage(settingsFile.fullPath);
var pm = new PreferencesBase.PreferencesManager(); var pm = new PreferencesBase.PreferencesManager();
var projectScope = new PreferencesBase.Scope(filestorage); var projectScope = new PreferencesBase.Scope(filestorage);
waitsForDone(pm.addScope("project", projectScope)); waitsForDone(pm.addScope("project", projectScope));