-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
129 lines (107 loc) · 3.96 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */
define(function (require, exports, module) {
"use strict";
// Brackets modules
var AppInit = brackets.getModule("utils/AppInit"),
NativeApp = brackets.getModule("utils/NativeApp"),
Dialogs = brackets.getModule("widgets/Dialogs"),
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
FileUtils = brackets.getModule("file/FileUtils"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
FileTreeView = brackets.getModule("project/FileTreeView"),
FileTreeViewModel = brackets.getModule("project/FileTreeViewModel"),
MainViewManager = brackets.getModule("view/MainViewManager"),
PopUpManager = brackets.getModule("widgets/PopUpManager"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
ProjectManager = brackets.getModule("project/ProjectManager"),
StringUtils = brackets.getModule("utils/StringUtils"),
WorkspaceManager = brackets.getModule("view/WorkspaceManager");
// Templates
var settingsTemplate = require("text!templates/settings.html");
// Local modules
// none yet
// jQuery objects
var $dialog,
$icon;
// Other vars
var dialog;
var JsFilesToHide = [];
// Prefs
var _prefs = PreferencesManager.getExtensionPrefs("better-coffee");
_prefs.definePreference("hideJsFiles", "boolean", true);
// Settings button click
var _showSettings = function() {
dialog = Dialogs.showModalDialogUsingTemplate(settingsTemplate);
$dialog = dialog.getElement();
$dialog.find("#hideJsFiles")
.prop("checked", _prefs.get("hideJsFiles") ? 1 : 0)
.change(function (e) {
_prefs.set("hideJsFiles", e.target.checked);
_updateJsFilesShowing();
});
};
// Update js files showing
var _updateJsFilesShowing = function() {
if(_prefs.get('hideJsFiles'))
_findJsFilesToHide();
else {
JsFilesToHide = [];
ProjectManager.rerenderTree();
}
}
// Find js files to hide & rerender filetreeview
var _findJsFilesToHide = function() {
var coffeeFiles = [];
ProjectManager.getAllFiles(function(elt) {
var ext = FileUtils.getSmartFileExtension(elt._path);
return ext === 'js' || ext === 'coffee';
}).done(function(fileList) {
// extract coffee filepaths
fileList.forEach(function(elt) {
if (FileUtils.getSmartFileExtension(elt._path) === 'coffee')
coffeeFiles.push(elt._path);
});
JsFilesToHide = [];
// for each js file, check if there is a coffee file matching
fileList.forEach(function(elt) {
if (FileUtils.getSmartFileExtension(elt._path) === 'js')
if (coffeeFiles.indexOf(FileUtils.getFilenameWithoutExtension(elt._path) + '.coffee') !== -1) {
JsFilesToHide.push(elt._path);
}
});
// now that JsFilesToHide is ready, rerender
ProjectManager.rerenderTree();
});
}
// Load custom CSS
ExtensionUtils.loadStyleSheet(module, "styles/BetterCoffee.css");
// Add toolbar icon
$icon = $("<a>")
.attr({
id: "better-coffee-icon",
href: "#"
})
.click(_showSettings)
.appendTo($("#main-toolbar .buttons"));
// The magic !
FileTreeView.addClassesProvider(function(item) {
if (JsFilesToHide.indexOf(item.fullPath) !== -1) {
return 'js-to-hide';
}
});
// Project change events
ProjectManager.on("projectOpen", function () {
_updateJsFilesShowing();
/*FileSystem.on("change", function() {
_updateJsFilesShowing();
});*/
});
ProjectManager.on("projectRefresh", function () {
_updateJsFilesShowing();
});
$(ProjectManager).on("projectClose", function () {
});
});