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).
Registers a new status indicator
function addIndicator(id, indicator, visible, style, tooltip, insertBefore) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
indicator = indicator || window.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);
}
}
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();
}
}
Hides all panels but not the status bar
function hideAllPanes() {
hideInformation();
hideIndicators();
}
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");
}
Hide the statusbar Indicators
function hideIndicators() {
$indicators.css("display", "none");
}
Hide the statusbar Information Panel
function hideInformation() {
$statusInfo.css("display", "none");
}
Show the statusbar
function show() {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (!$statusBar.is(":visible")) {
$statusBar.show();
WorkspaceManager.recomputeLayout();
}
}
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;
});
Shows all panels (will not show a hidden statusbar)
function showAllPanes() {
showInformation();
showIndicators();
}
Shows the 'busy' indicator
function showBusyIndicator(updateCursor) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (updateCursor) {
_busyCursor = true;
$("*").addClass("busyCursor");
}
$busyIndicator.addClass("spin");
}
Show the statusbar Indicators
function showIndicators() {
$indicators.css("display", "");
}
Show the statusbar Information Panel
function showInformation() {
$statusInfo.css("display", "");
}
Updates a status indicator
function updateIndicator(id, visible, style, tooltip) {
if (!_init && !!brackets.test) {
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);
}
}
}