This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
/
preferences.js
72 lines (56 loc) · 1.85 KB
/
preferences.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
define(function (require, exports, module) {
"use strict";
var Dialogs = brackets.getModule("widgets/Dialogs"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
ProjectManager = brackets.getModule("project/ProjectManager"),
Strings = brackets.getModule("strings"),
PrefsTemplate = require("text!ui/preferences.html");
var preferenceKeyId = 'io.emmet.preferences';
var defaultPreferences = {
tab: true,
extPath: ''
};
function getStorage() {
var userData = localStorage.getItem(preferenceKeyId);
return userData ? JSON.parse(userData) : $.extend({}, defaultPreferences);
}
function saveStorage(storage) {
localStorage.setItem(preferenceKeyId, JSON.stringify(storage));
}
function setPreference(name, value) {
var storage = getStorage();
if (typeof name == 'object') {
for (var p in name) if (name.hasOwnProperty(p)) {
storage[p] = name[p];
}
} else {
storage[name] = value;
}
saveStorage(storage);
}
function getPreference(name) {
return getStorage()[name];
}
function showEmmetPreferencesDialog(baseUrl, errorMessage) {
var dlg, tabFld, extPathFld;
var promise = Dialogs.showModalDialogUsingTemplate(Mustache.render(PrefsTemplate, Strings))
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK) {
setPreference({
tab: !!tabFld[0].checked,
extPath: extPathFld.val()
});
}
});
dlg = $(".emmet-settings-dialog.instance");
tabFld = dlg.find('#emmet-tab-fld');
extPathFld = dlg.find('#emmet-ext-path-fld');
tabFld[0].checked = !!getPreference('tab');
extPathFld.val(getPreference('extPath'));
tabFld.focus();
return promise;
}
exports.showPreferencesDialog = showEmmetPreferencesDialog;
exports.getPreference = getPreference;
exports.setPreference = setPreference;
});