-
Notifications
You must be signed in to change notification settings - Fork 4
/
SettingsDialog.js
65 lines (57 loc) · 2.68 KB
/
SettingsDialog.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
/**
* Dialog to change default settings for latex compilation
* @author Patrick Oladimeji
* @date 12/2/13 8:47:22 AM
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define,$, brackets*/
define(function (require, exports, module) {
"use strict";
var Dialogs = brackets.getModule("widgets/Dialogs"),
ProjectManager = brackets.getModule("project/ProjectManager"),
DefaultSettings = require("DefaultSettings"),
FileUtils = brackets.getModule("file/FileUtils"),
Strings = require("i18n!nls/strings"),
settingsDialogTemplate = require("text!htmlTemplates/settings-dialog.html"),
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
preferences = require("Preferences");
function setFormValues(prefs) {
$("#latex-settings-dialog #settings-texbin-directory").val(prefs.texBinDirectory);
$("#latex-settings-dialog #settings-output-directory").val(prefs.outputDirectory);
$("#latex-settings-dialog #settings-compiler #option-" + prefs.compiler).prop("selected", true);
$("#latex-settings-dialog #main-file" ).val(prefs.mainFile);
}
function restoreDefaults() {
setFormValues(DefaultSettings);
}
function bindListeners() {
$("button[data-button-id='defaults']").on("click", function (e) {
e.stopPropagation();
restoreDefaults();
});
}
function showDialog() {
var projectRoot = ProjectManager.getProjectRoot().fullPath;
ProjectManager.getAllFiles().then(function (res) {
var files = res.map(function (d) {
return d.fullPath.substring(projectRoot.length);
}).filter(function (f) {
return FileUtils.getFileExtension(f) === "tex";
});
var template = Mustache.render(settingsDialogTemplate, {strings: Strings, files: files});
var dialog = Dialogs.showModalDialogUsingTemplate(template);
setFormValues(preferences.getAllValues());
dialog.done(function (buttonId) {
if (buttonId === "ok") {
var $dialog = dialog.getElement();
preferences.set("texBinDirectory", $("#settings-texbin-directory", $dialog).val());
preferences.set("outputDirectory", $("#settings-output-directory", $dialog).val());
preferences.set("compiler", $("#settings-compiler", $dialog).val());
preferences.set("mainFile", $("#main-file", $dialog).val());
}
});
});
}
bindListeners();
exports.show = showDialog;
});