-
-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathDefaultPanelView.js
More file actions
230 lines (207 loc) · 8.09 KB
/
Copy pathDefaultPanelView.js
File metadata and controls
230 lines (207 loc) · 8.09 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
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/**
* DefaultPanelView - A launcher panel shown in the bottom panel area when no
* other panels are open. Provides quick-access buttons for common panels
* (Problems, Find in Files, Git, Custom Snippets, Keyboard Shortcuts) and a
* link to the documentation.
*
* @module view/DefaultPanelView
*/
define(function (require, exports, module) {
const AppInit = require("utils/AppInit"),
Commands = require("command/Commands"),
CommandManager = require("command/CommandManager"),
Strings = require("strings"),
WorkspaceManager = require("view/WorkspaceManager"),
PanelView = require("view/PanelView");
/**
* Descriptors for each launcher button.
*/
const _panelButtons = [
{
id: "problems",
icon: "fa-solid fa-triangle-exclamation",
label: Strings.CMD_VIEW_TOGGLE_PROBLEMS || "Problems",
commandID: Commands.VIEW_TOGGLE_PROBLEMS
},
{
id: "search",
icon: "fa-solid fa-magnifying-glass",
label: Strings.CMD_FIND_IN_FILES || "Find in Files",
commandID: Commands.CMD_FIND_IN_FILES
},
{
id: "git",
icon: "fa-solid fa-code-branch",
label: Strings.GIT_PANEL_TITLE || "Git",
commandID: Commands.CMD_GIT_TOGGLE_PANEL
},
{
id: "snippets",
icon: "fa-solid fa-code",
label: Strings.CUSTOM_SNIPPETS_PANEL_TITLE || "Custom Snippets",
commandID: Commands.CMD_CUSTOM_SNIPPETS_PANEL
},
{
id: "shortcuts",
icon: "fa-solid fa-keyboard",
label: Strings.KEYBOARD_SHORTCUT_PANEL_TITLE || "Keyboard Shortcuts",
commandID: Commands.HELP_TOGGLE_SHORTCUTS_PANEL
},
{
id: "terminal",
icon: "fa-solid fa-terminal",
label: "Terminal",
commandID: Commands.VIEW_TERMINAL,
nativeOnly: true
}
];
/** @type {Panel} The default panel instance */
let _panel;
/** @type {jQueryObject} The panel DOM element */
let _$panel;
/**
* Build the panel DOM.
* @return {jQueryObject}
* @private
*/
function _buildPanelHTML() {
let $panel = $('<div id="default-panel" class="bottom-panel"></div>');
let $content = $('<div class="default-panel-content"></div>');
let $heading = $('<div class="default-panel-heading"></div>')
.text(Strings.BOTTOM_PANEL_DEFAULT_HEADING);
$content.append($heading);
let $buttonsRow = $('<div class="default-panel-buttons"></div>');
_panelButtons.forEach(function (btn) {
if (btn.nativeOnly && !Phoenix.isNativeApp) {
return;
}
let $button = $('<button class="default-panel-btn"></button>')
.attr("data-command", btn.commandID)
.attr("data-btn-id", btn.id)
.attr("title", btn.label);
let $icon = $('<i></i>').addClass(btn.icon);
let $label = $('<span class="default-panel-btn-label"></span>').text(btn.label);
$button.append($icon).append($label);
$buttonsRow.append($button);
});
$content.append($buttonsRow);
$panel.append($content);
return $panel;
}
/**
* Check whether Git is available for the current project.
* The Git extension hides its toolbar icon with the "forced-hidden" class
* when Git is not available (no binary, not a repo, extension disabled, etc.).
* @return {boolean}
* @private
*/
function _isGitAvailable() {
const $gitIcon = $("#git-toolbar-icon");
return $gitIcon.length > 0 && !$gitIcon.hasClass("forced-hidden");
}
/**
* Show or hide buttons based on current state.
* The Problems button is always shown since the panel now displays
* meaningful content regardless of error state.
* @private
*/
function _updateButtonVisibility() {
if (!_$panel) {
return;
}
_$panel.find('.default-panel-btn[data-btn-id="git"]').toggle(_isGitAvailable());
}
/**
* Set up MutationObservers on the Git toolbar icon so that
* button visibility updates live.
* @private
*/
function _observeStateChanges() {
// Watch Git toolbar icon for class changes (forced-hidden added/removed)
const gitIcon = document.getElementById("git-toolbar-icon");
if (gitIcon) {
const gitObserver = new MutationObserver(_updateButtonVisibility);
gitObserver.observe(gitIcon, {attributes: true, attributeFilter: ["class"]});
}
}
/**
* Initialise the default panel. Called once at appReady.
* @private
*/
function _init() {
_$panel = _buildPanelHTML();
_panel = WorkspaceManager.createBottomPanel(
WorkspaceManager.DEFAULT_PANEL_ID,
_$panel,
undefined,
Strings.BOTTOM_PANEL_DEFAULT_TITLE
);
// Button click handler: execute the command to open the target panel.
// The auto-hide listener (EVENT_PANEL_SHOWN) will close the default panel.
_$panel.on("click", ".default-panel-btn", function () {
let commandID = $(this).attr("data-command");
if (commandID) {
CommandManager.execute(commandID);
}
});
const iconHTML = '<img class="app-drawer-tab-icon" src="styles/images/app-drawer.svg"'
+ ' style="width:12px;height:12px;vertical-align:middle;margin-right:4px">';
/**
* Inject the app-drawer icon into the Quick Access tab title.
* Called each time the panel is shown because the tab DOM is rebuilt.
*/
function _addTabIcon() {
const $tabTitle = $('#bottom-panel-tab-bar .bottom-panel-tab[data-panel-id="'
+ WorkspaceManager.DEFAULT_PANEL_ID + '"] .bottom-panel-tab-title');
if ($tabTitle.length && !$tabTitle.find(".app-drawer-tab-icon").length) {
$tabTitle.prepend(iconHTML);
}
}
// The app-drawer button is defined in index.html; set its title here.
const $drawerBtn = $("#app-drawer-button")
.attr("title", Strings.BOTTOM_PANEL_DEFAULT_TITLE);
$drawerBtn.on("click", function () {
if (_panel.isVisible()) {
_panel.hide();
} else {
_panel.show();
}
});
// Auto-hide when any other panel is shown; update drawer button state.
PanelView.on(PanelView.EVENT_PANEL_SHOWN, function (event, panelID) {
if (panelID !== WorkspaceManager.DEFAULT_PANEL_ID) {
_panel.hide();
} else {
_updateButtonVisibility();
_addTabIcon();
}
$drawerBtn.toggleClass("selected-button", panelID === WorkspaceManager.DEFAULT_PANEL_ID);
});
PanelView.on(PanelView.EVENT_PANEL_HIDDEN, function (event, panelID) {
if (panelID === WorkspaceManager.DEFAULT_PANEL_ID) {
$drawerBtn.removeClass("selected-button");
}
});
// Initial visibility update and set up live observers
_updateButtonVisibility();
_observeStateChanges();
}
AppInit.appReady(_init);
});