Skip to content

Commit a3f1266

Browse files
committed
feat: only show the buttons available in the quick access panel
1 parent 295dac6 commit a3f1266

1 file changed

Lines changed: 70 additions & 3 deletions

File tree

src/view/DefaultPanelView.js

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ define(function (require, exports, module) {
7272
/** @type {Panel} The default panel instance */
7373
let _panel;
7474

75+
/** @type {jQueryObject} The panel DOM element */
76+
let _$panel;
77+
7578
/**
7679
* Build the panel DOM.
7780
* @return {jQueryObject}
@@ -89,6 +92,7 @@ define(function (require, exports, module) {
8992
_panelButtons.forEach(function (btn) {
9093
let $button = $('<button class="default-panel-btn"></button>')
9194
.attr("data-command", btn.commandID)
95+
.attr("data-btn-id", btn.id)
9296
.attr("title", btn.label);
9397
let $icon = $('<i></i>').addClass(btn.icon);
9498
let $label = $('<span class="default-panel-btn-label"></span>').text(btn.label);
@@ -102,22 +106,78 @@ define(function (require, exports, module) {
102106
return $panel;
103107
}
104108

109+
/**
110+
* Check whether Git is available for the current project.
111+
* The Git extension hides its toolbar icon with the "forced-hidden" class
112+
* when Git is not available (no binary, not a repo, extension disabled, etc.).
113+
* @return {boolean}
114+
* @private
115+
*/
116+
function _isGitAvailable() {
117+
const $gitIcon = $("#git-toolbar-icon");
118+
return $gitIcon.length > 0 && !$gitIcon.hasClass("forced-hidden");
119+
}
120+
121+
/**
122+
* Check whether there are currently lint errors/warnings.
123+
* The status bar indicator gets the "inspection-errors" class when problems exist.
124+
* @return {boolean}
125+
* @private
126+
*/
127+
function _hasProblems() {
128+
const $indicator = $("#status-inspection");
129+
return $indicator.length > 0 && $indicator.hasClass("inspection-errors");
130+
}
131+
132+
/**
133+
* Show or hide the Git and Problems buttons based on current state.
134+
* @private
135+
*/
136+
function _updateButtonVisibility() {
137+
if (!_$panel) {
138+
return;
139+
}
140+
_$panel.find('.default-panel-btn[data-btn-id="git"]').toggle(_isGitAvailable());
141+
_$panel.find('.default-panel-btn[data-btn-id="problems"]').toggle(_hasProblems());
142+
}
143+
144+
/**
145+
* Set up MutationObservers on the Git toolbar icon and status-inspection
146+
* indicator so that button visibility updates live.
147+
* @private
148+
*/
149+
function _observeStateChanges() {
150+
// Watch Git toolbar icon for class changes (forced-hidden added/removed)
151+
const gitIcon = document.getElementById("git-toolbar-icon");
152+
if (gitIcon) {
153+
const gitObserver = new MutationObserver(_updateButtonVisibility);
154+
gitObserver.observe(gitIcon, {attributes: true, attributeFilter: ["class"]});
155+
}
156+
157+
// Watch status-inspection indicator for class changes (inspection-errors)
158+
const statusInspection = document.getElementById("status-inspection");
159+
if (statusInspection) {
160+
const inspectionObserver = new MutationObserver(_updateButtonVisibility);
161+
inspectionObserver.observe(statusInspection, {attributes: true, attributeFilter: ["class"]});
162+
}
163+
}
164+
105165
/**
106166
* Initialise the default panel. Called once at appReady.
107167
* @private
108168
*/
109169
function _init() {
110-
let $panel = _buildPanelHTML();
170+
_$panel = _buildPanelHTML();
111171
_panel = WorkspaceManager.createBottomPanel(
112172
WorkspaceManager.DEFAULT_PANEL_ID,
113-
$panel,
173+
_$panel,
114174
undefined,
115175
Strings.BOTTOM_PANEL_DEFAULT_TITLE
116176
);
117177

118178
// Button click handler: execute the command to open the target panel.
119179
// The auto-hide listener (EVENT_PANEL_SHOWN) will close the default panel.
120-
$panel.on("click", ".default-panel-btn", function () {
180+
_$panel.on("click", ".default-panel-btn", function () {
121181
let commandID = $(this).attr("data-command");
122182
if (commandID) {
123183
CommandManager.execute(commandID);
@@ -130,7 +190,14 @@ define(function (require, exports, module) {
130190
if (panelID !== WorkspaceManager.DEFAULT_PANEL_ID) {
131191
_panel.hide();
132192
}
193+
if (panelID === WorkspaceManager.DEFAULT_PANEL_ID) {
194+
_updateButtonVisibility();
195+
}
133196
});
197+
198+
// Initial visibility update and set up live observers
199+
_updateButtonVisibility();
200+
_observeStateChanges();
134201
}
135202

136203
AppInit.appReady(_init);

0 commit comments

Comments
 (0)