forked from humphd/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusBar.js
More file actions
307 lines (260 loc) · 9.68 KB
/
Copy pathStatusBar.js
File metadata and controls
307 lines (260 loc) · 9.68 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, document, Mustache */
/**
* A status bar with support for file information and busy and status indicators. This is a semi-generic
* container; for the code that decides what content appears in the status bar, see client modules like
* EditorStatusBar. (Although in practice StatusBar's HTML structure and initialization
* assume it's only used for this one purpose, and all the APIs are on a singleton).
*/
define(function (require, exports, module) {
'use strict';
var AppInit = require("utils/AppInit"),
StatusBarHTML = require("text!widgets/StatusBar.html"),
Strings = require("strings"),
WorkspaceManager = require("view/WorkspaceManager");
var _init = false;
// Indicates if the busy cursor is active to avoid unnecesary operations
var _busyCursor = false;
// A simple regexp to sanitize indicator ids
var _indicatorIDRegexp = new RegExp("[^a-zA-Z 0-9]+", "g");
// These vars are initialized by the AppInit.htmlReady handler
// below since they refer to DOM elements
var $statusInfo,
$statusBar,
$indicators,
$busyIndicator;
// XXXBramble: whether the status bar is enabled or disabled
var _enabled = false;
/**
* Shows the 'busy' indicator
* @param {boolean} updateCursor Sets the cursor to "wait"
*/
function showBusyIndicator(updateCursor) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (updateCursor) {
_busyCursor = true;
$("*").addClass("busyCursor");
}
$busyIndicator.addClass("spin");
}
/**
* Hides the 'busy' indicator
*/
function hideBusyIndicator() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
// Check if we are using the busyCursor class to avoid
// unnecesary calls to $('*').removeClass()
if (_busyCursor) {
_busyCursor = false;
$("*").removeClass("busyCursor");
}
$busyIndicator.removeClass("spin");
}
/**
* Registers a new status indicator
* @param {string} id Registration id of the indicator to be updated.
* @param {(DOMNode|jQueryObject)=} indicator Optional DOMNode for the indicator
* @param {boolean=} visible Shows or hides the indicator over the statusbar.
* @param {string=} style Sets the attribute "class" of the indicator.
* @param {string=} tooltip Sets the attribute "title" of the indicator.
* @param {string=} insertBefore An id of an existing status bar indicator.
* The new indicator will be inserted before (i.e. to the left of)
* the indicator specified by this parameter.
*/
function addIndicator(id, indicator, visible, style, tooltip, insertBefore) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
indicator = indicator || document.createElement("div");
tooltip = tooltip || "";
style = style || "";
id = id.replace(_indicatorIDRegexp, "-") || "";
var $indicator = $(indicator);
$indicator.attr("id", id);
$indicator.attr("title", tooltip);
$indicator.addClass("indicator");
$indicator.addClass(style);
if (!visible) {
$indicator.hide();
}
// This code looks backwards because the DOM model is ordered
// top-to-bottom but the UI view is ordered right-to-left. The concept
// of "before" in the model is "after" in the view, and vice versa.
if (insertBefore && $("#" + insertBefore).length > 0) {
$indicator.insertAfter("#" + insertBefore);
} else {
// No positioning is provided, put on left end of indicators, but
// to right of "busy" indicator (which is usually hidden).
var $busyIndicator = $("#status-bar .spinner");
$indicator.insertBefore($busyIndicator);
}
}
/**
* Updates a status indicator
* @param {string} id Registration id of the indicator to be updated.
* @param {boolean} visible Shows or hides the indicator over the statusbar.
* @param {string=} style Sets the attribute "class" of the indicator.
* @param {string=} tooltip Sets the attribute "title" of the indicator.
*/
function updateIndicator(id, visible, style, tooltip) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
var $indicator = $("#" + id.replace(_indicatorIDRegexp, "-"));
if ($indicator) {
if (visible) {
$indicator.show();
} else {
$indicator.hide();
}
if (style) {
$indicator.removeClass();
$indicator.addClass(style);
} else {
$indicator.removeClass();
$indicator.addClass("indicator");
}
if (tooltip) {
$indicator.attr("title", tooltip);
}
}
}
/**
* Hide the statusbar Information Panel
*/
function hideInformation() {
$statusInfo.css("display", "none");
}
/**
* Show the statusbar Information Panel
*/
function showInformation() {
$statusInfo.css("display", "");
}
/**
* Hide the statusbar Indicators
*/
function hideIndicators() {
$indicators.css("display", "none");
}
/**
* Show the statusbar Indicators
*/
function showIndicators() {
$indicators.css("display", "");
}
/**
* Hides all panels but not the status bar
*/
function hideAllPanes() {
hideInformation();
hideIndicators();
}
/**
* Shows all panels (will not show a hidden statusbar)
*/
function showAllPanes() {
showInformation();
showIndicators();
}
/**
* Hide the statusbar
*/
function hide() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if ($statusBar.is(":visible")) {
$statusBar.hide();
WorkspaceManager.recomputeLayout();
}
}
/**
* Show the statusbar
*/
function show() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
// XXXBramble: ignore requests to show the status bar if not enabled
if (!_enabled) {
return;
}
if (!$statusBar.is(":visible")) {
$statusBar.show();
WorkspaceManager.recomputeLayout();
}
}
/**
* XXXBramble: Disables the status bar completely, such that calls to show() do nothing
*/
function enable() {
_enabled = true;
show();
}
/**
* XXXBramble: Enables the status bar, such that calls to show() do something
*/
function disable() {
_enabled = false;
hide();
}
AppInit.htmlReady(function () {
var $parent = $(".main-view .content");
$parent.append(Mustache.render(StatusBarHTML, Strings));
// Initialize items dependent on HTML DOM
$statusBar = $("#status-bar");
$indicators = $("#status-indicators");
$busyIndicator = $("#status-bar .spinner");
$statusInfo = $("#status-info");
_init = true;
// hide on init
hide();
});
exports.hideInformation = hideInformation;
exports.showInformation = showInformation;
exports.showBusyIndicator = showBusyIndicator;
exports.hideBusyIndicator = hideBusyIndicator;
exports.hideIndicators = hideIndicators;
exports.showIndicators = showIndicators;
exports.hideAllPanes = hideAllPanes;
exports.showAllPanes = showAllPanes;
exports.addIndicator = addIndicator;
exports.updateIndicator = updateIndicator;
exports.hide = hide;
exports.show = show;
exports.enable = enable;
exports.disable = disable;
});