-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathDefaultPanelView.js
More file actions
227 lines (206 loc) · 8.43 KB
/
DefaultPanelView.js
File metadata and controls
227 lines (206 loc) · 8.43 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
/*
* 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",
iconSvg: "styles/images/panel-icon-problems.svg",
label: Strings.CMD_VIEW_TOGGLE_PROBLEMS || "Problems",
commandID: Commands.VIEW_TOGGLE_PROBLEMS
},
{
id: "git",
iconSvg: "styles/images/panel-icon-git.svg",
label: Strings.GIT_PANEL_TITLE || "Git",
commandID: Commands.CMD_GIT_TOGGLE_PANEL,
nativeOnly: true
},
{
id: "snippets",
iconSvg: "styles/images/panel-icon-snippets.svg",
label: Strings.CUSTOM_SNIPPETS_PANEL_TITLE || "Custom Snippets",
commandID: Commands.CMD_CUSTOM_SNIPPETS_PANEL
},
{
id: "shortcuts",
iconSvg: "styles/images/panel-icon-shortcuts.svg",
label: Strings.KEYBOARD_SHORTCUT_PANEL_TITLE || "Keyboard Shortcuts",
commandID: Commands.HELP_TOGGLE_SHORTCUTS_PANEL
},
{
id: "terminal",
iconSvg: "styles/images/panel-icon-terminal.svg",
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 = $('<span class="panel-titlebar-icon"></span>');
const maskUrl = "url('" + btn.iconSvg + "')";
$icon[0].style.maskImage = maskUrl;
$icon[0].style.webkitMaskImage = maskUrl;
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.
* On desktop, Git is always shown. On browser, it depends on availability.
* @private
*/
function _updateButtonVisibility() {
if (!_$panel) {
return;
}
if (!Phoenix.isNativeApp) {
_$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,
{iconSvg: "styles/images/app-drawer.svg"}
);
// 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);
}
});
// 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 () {
// Design mode collapses the editor and stretches live preview, which
// leaves no room for the bottom tools panel. Exit design mode first
// so the panel has somewhere to go.
// TODO: revisit once the tools panel can float / overlay the live
// preview without disrupting it, so users can peek at tools without
// leaving design mode.
if (WorkspaceManager.isInDesignMode()) {
CommandManager.execute(Commands.VIEW_TOGGLE_DESIGN_MODE);
}
if (_panel.isVisible()) {
_panel.hide();
} else {
_panel.show();
}
});
// Drawer button reflects whether the Quick Access (default) panel is
// the active visible panel. _switchToTab silently swaps active tabs
// without firing PANEL_HIDDEN for the previous one, so we have to gate
// the SHOWN handler on the panelID — relying on a HIDDEN event would
// miss the case where another tab takes over from Quick Access.
// The minimize-button "stuck selected" case is handled by PanelView
// firing PANEL_HIDDEN with the default panel id, picked up below.
PanelView.on(PanelView.EVENT_PANEL_SHOWN, function (event, panelID) {
if (panelID === WorkspaceManager.DEFAULT_PANEL_ID) {
_updateButtonVisibility();
}
$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);
});