Skip to content

Commit b9a8688

Browse files
committed
feat: better support for bottom panel tab bar title
1 parent 72db915 commit b9a8688

10 files changed

Lines changed: 28 additions & 41 deletions

File tree

src/extensions/default/DebugCommands/testBuilder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ define(function (require, exports, module) {
3838
function toggleTestBuilder() {
3939
if(!$panel){
4040
$panel = $(panelHTML);
41-
builderPanel = WorkspaceManager.createBottomPanel("phcode-test-builder-panel", $panel, 100);
41+
builderPanel = WorkspaceManager.createBottomPanel("phcode-test-builder-panel", $panel, 100, "Test Builder");
4242
builderPanel.hide();
4343
_setupPanel().then(()=>{
4444
builderPanel.setVisible(!builderPanel.isVisible());
@@ -177,7 +177,7 @@ define(function (require, exports, module) {
177177
return;
178178
}
179179
$panel = $(panelHTML);
180-
builderPanel = WorkspaceManager.createBottomPanel("phcode-test-builder-panel", $panel, 100);
180+
builderPanel = WorkspaceManager.createBottomPanel("phcode-test-builder-panel", $panel, 100, "Test Builder");
181181
builderPanel.hide();
182182
_setupPanel();
183183
});

src/extensions/default/Git/src/Panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ define(function (require, exports) {
12401240
var $panelHtml = $(panelHtml);
12411241
$panelHtml.find(".git-available, .git-not-available").hide();
12421242

1243-
gitPanel = WorkspaceManager.createBottomPanel("main-git.panel", $panelHtml, 100);
1243+
gitPanel = WorkspaceManager.createBottomPanel("main-git.panel", $panelHtml, 100, Strings.GIT_PANEL_TITLE);
12441244
$gitPanel = gitPanel.$panel;
12451245
const resizeObserver = new ResizeObserver(_panelResized);
12461246
resizeObserver.observe($gitPanel[0]);

src/extensionsIntegrated/CustomSnippets/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ define(function (require, exports, module) {
5858
* @private
5959
*/
6060
function _createPanel() {
61-
customSnippetsPanel = WorkspaceManager.createBottomPanel(PANEL_ID, $snippetsPanel, PANEL_MIN_SIZE);
61+
customSnippetsPanel = WorkspaceManager.createBottomPanel(PANEL_ID, $snippetsPanel, PANEL_MIN_SIZE,
62+
Strings.CUSTOM_SNIPPETS_PANEL_TITLE);
6263
customSnippetsPanel.show();
6364

6465
// also register the handlers

src/extensionsIntegrated/DisplayShortcuts/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ define(function (require, exports, module) {
478478

479479
// AppInit.htmlReady() has already executed before extensions are loaded
480480
// so, for now, we need to call this ourself
481-
panel = WorkspaceManager.createBottomPanel(TOGGLE_SHORTCUTS_ID, $(s), 300);
481+
panel = WorkspaceManager.createBottomPanel(TOGGLE_SHORTCUTS_ID, $(s), 300,
482+
Strings.KEYBOARD_SHORTCUT_PANEL_TITLE);
482483
panel.hide();
483484

484485
$shortcutsPanel = $("#shortcuts-panel");

src/features/FindReferencesManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ define(function (require, exports, module) {
194194
searchModel,
195195
"reference-in-files-results",
196196
"reference-in-files.results",
197-
"reference"
197+
"reference",
198+
Strings.REFERENCES_PANEL_TITLE
198199
);
199200
if(_resultsView) {
200201
_resultsView

src/language/CodeInspection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ define(function (require, exports, module) {
12631263
Editor.registerGutter(CODE_INSPECTION_GUTTER, CODE_INSPECTION_GUTTER_PRIORITY);
12641264
// Create bottom panel to list error details
12651265
var panelHtml = Mustache.render(PanelTemplate, Strings);
1266-
problemsPanel = WorkspaceManager.createBottomPanel("errors", $(panelHtml), 100);
1266+
problemsPanel = WorkspaceManager.createBottomPanel("errors", $(panelHtml), 100, Strings.CMD_VIEW_TOGGLE_PROBLEMS);
12671267
$problemsPanel = $("#problems-panel");
12681268
$fixAllBtn = $problemsPanel.find(".problems-fix-all-btn");
12691269
$fixAllBtn.click(()=>{

src/nls/root/strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,8 @@ define({
12491249
"REFERENCES_IN_FILES": "references",
12501250
"REFERENCE_IN_FILES": "reference",
12511251
"REFERENCES_NO_RESULTS": "No References available for current cursor position",
1252+
"REFERENCES_PANEL_TITLE": "References",
1253+
"SEARCH_RESULTS_PANEL_TITLE": "Search Results",
12521254

12531255
"CMD_FIND_DOCUMENT_SYMBOLS": "Find Document Symbols",
12541256
"CMD_FIND_PROJECT_SYMBOLS": "Find Project Symbols",
@@ -1396,6 +1398,7 @@ define({
13961398
"BUTTON_CANCEL": "Cancel",
13971399
"CHECKOUT_COMMIT": "Checkout",
13981400
"CHECKOUT_COMMIT_DETAIL": "<b>Commit Message:</b> {0} <br><b>Commit hash:</b> {1}",
1401+
"GIT_PANEL_TITLE": "Git",
13991402
"GIT_CLONE": "Clone",
14001403
"BUTTON_CLOSE": "Close",
14011404
"BUTTON_COMMIT": "Commit",

src/search/FindInFilesUI.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ define(function (require, exports, module) {
536536
// Initialize items dependent on HTML DOM
537537
AppInit.htmlReady(function () {
538538
var model = FindInFiles.searchModel;
539-
_resultsView = new SearchResultsView(model, "find-in-files-results", "find-in-files.results");
539+
_resultsView = new SearchResultsView(model, "find-in-files-results", "find-in-files.results",
540+
undefined, Strings.SEARCH_RESULTS_PANEL_TITLE);
540541
_resultsView
541542
.on("replaceBatch", function () {
542543
_finishReplaceBatch(model);

src/search/SearchResultsView.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ define(function (require, exports, module) {
7676
* @param {string} panelID The CSS ID to use for the panel.
7777
* @param {string} panelName The name to use for the panel, as passed to WorkspaceManager.createBottomPanel().
7878
* @param {string} type type to identify if it is reference search or string match serach
79+
* @param {string=} title Display title for the panel tab.
7980
*/
80-
function SearchResultsView(model, panelID, panelName, type) {
81+
function SearchResultsView(model, panelID, panelName, type, title) {
8182
const self = this;
8283
let panelHtml = Mustache.render(searchPanelTemplate, {panelID: panelID});
8384

84-
this._panel = WorkspaceManager.createBottomPanel(panelName, $(panelHtml), 100);
85+
this._panel = WorkspaceManager.createBottomPanel(panelName, $(panelHtml), 100, title);
8586
this._$summary = this._panel.$panel.find(".title");
8687
this._$table = this._panel.$panel.find(".table-container");
8788
this._$previewEditor = this._panel.$panel.find(".search-editor-preview");

src/view/WorkspaceManager.js

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,6 @@ define(function (require, exports, module) {
140140
/** @type {Object} Map of panelID -> minSize for bottom panels */
141141
let _panelMinSizes = {};
142142

143-
/** Fallback title map for panels that don't have a .toolbar .title element */
144-
const _KNOWN_PANEL_TITLES = {
145-
"errors": "Problems",
146-
"problems-panel": "Problems",
147-
"search-results": "Search Results",
148-
"find-in-files-results": "Search Results",
149-
"references-panel": "References",
150-
"git-panel": "Git",
151-
"keyboard-shortcuts-panel": "Keyboard Shortcuts",
152-
"custom-snippets-panel": "Custom Snippets",
153-
"test-builder-panel": "Test Builder"
154-
};
155143

156144

157145
/**
@@ -260,27 +248,17 @@ define(function (require, exports, module) {
260248

261249
/**
262250
* Resolve the display title for a bottom panel tab.
263-
* First looks for a .toolbar .title element within the panel DOM,
264-
* then falls back to the _KNOWN_PANEL_TITLES map using the panel's DOM id.
251+
* Uses the explicit title if provided, otherwise humanizes the panel id.
265252
* @param {string} id The panel registration ID
266-
* @param {jQueryObject} $panel The panel's jQuery element
253+
* @param {string=} title Explicit title passed to createBottomPanel
267254
* @return {string}
268255
* @private
269256
*/
270-
function _getPanelTitle(id, $panel) {
271-
let $titleEl = $panel.find(".toolbar .title");
272-
if ($titleEl.length && $.trim($titleEl.text())) {
273-
return $.trim($titleEl.text());
257+
function _getPanelTitle(id, title) {
258+
if (title) {
259+
return title;
274260
}
275-
let domId = $panel.attr("id") || "";
276-
if (_KNOWN_PANEL_TITLES[domId]) {
277-
return _KNOWN_PANEL_TITLES[domId];
278-
}
279-
if (_KNOWN_PANEL_TITLES[id]) {
280-
return _KNOWN_PANEL_TITLES[id];
281-
}
282-
// Last resort: humanize the id
283-
let label = (domId || id).replace(/[-_]/g, " ");
261+
let label = id.replace(new RegExp("[-_.]", "g"), " ").split(" ")[0];
284262
return label.charAt(0).toUpperCase() + label.slice(1);
285263
}
286264

@@ -301,7 +279,7 @@ define(function (require, exports, module) {
301279
if (!panel) {
302280
return;
303281
}
304-
let title = panel._tabTitle || _getPanelTitle(panelId, panel.$panel);
282+
let title = panel._tabTitle || _getPanelTitle(panelId);
305283
let isActive = (panelId === _activeBottomPanelId);
306284
let $tab = $('<div class="bottom-panel-tab' + (isActive ? ' active' : '') + '" data-panel-id="' + panelId + '">' +
307285
'<span class="bottom-panel-tab-title">' + $("<span>").text(title).html() + '</span>' +
@@ -368,9 +346,10 @@ define(function (require, exports, module) {
368346
* @param {!jQueryObject} $panel DOM content to use as the panel. Need not be in the document yet. Must have an id
369347
* attribute, for use as a preferences key.
370348
* @param {number=} minSize Minimum height of panel in px.
349+
* @param {string=} title Display title shown in the bottom panel tab bar.
371350
* @return {!Panel}
372351
*/
373-
function createBottomPanel(id, $panel, minSize) {
352+
function createBottomPanel(id, $panel, minSize, title) {
374353
// Insert panel into the tabbed container instead of before #status-bar
375354
$bottomPanelContainer.append($panel);
376355
$panel.hide();
@@ -383,7 +362,7 @@ define(function (require, exports, module) {
383362
panelIDMap[id] = bottomPanel;
384363

385364
// Cache the tab title at creation time
386-
bottomPanel._tabTitle = _getPanelTitle(id, $panel);
365+
bottomPanel._tabTitle = _getPanelTitle(id, title);
387366

388367
// Do NOT call Resizer.makeResizable on individual panels.
389368
// The container handles resizing.

0 commit comments

Comments
 (0)