Skip to content

Commit dcd0a33

Browse files
committed
feat: handle close all tabs from more-options button
1 parent 95d55ea commit dcd0a33

File tree

6 files changed

+84
-30
lines changed

6 files changed

+84
-30
lines changed

src/extensionsIntegrated/TabBar/helper.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ define(function (require, exports, module) {
1010
/**
1111
* Shows the tab bar, when its hidden.
1212
* Its only shown when tab bar is enabled and there is atleast one working file
13+
* We need to show both the tab bar and the more options
1314
*
1415
* @param {$.Element} $tabBar - The tab bar element
16+
* @param {$.Element} $moreOptions - The more options element
1517
*/
16-
function _showTabBar($tabBar) {
18+
function _showTabBar($tabBar, $moreOptions) {
1719
if ($tabBar) {
1820
$tabBar.show();
21+
if($moreOptions) {
22+
$moreOptions.show();
23+
}
1924
// when we add/remove something from the editor, the editor shifts up/down which leads to blank space
2025
// so we need to recompute the layout to make sure things are in the right place
2126
WorkspaceManager.recomputeLayout(true);
@@ -25,12 +30,17 @@ define(function (require, exports, module) {
2530
/**
2631
* Hides the tab bar.
2732
* Its hidden when tab bar feature is disabled or there are no working files
33+
* Both the tab bar and the more options should be hidden to hide the tab bar container
2834
*
2935
* @param {$.Element} $tabBar - The tab bar element
36+
* @param {$.Element} $moreOptions - The more options element
3037
*/
31-
function _hideTabBar($tabBar) {
38+
function _hideTabBar($tabBar, $moreOptions) {
3239
if ($tabBar) {
3340
$tabBar.hide();
41+
if($moreOptions) {
42+
$moreOptions.hide();
43+
}
3444
WorkspaceManager.recomputeLayout(true);
3545
}
3646
}

src/extensionsIntegrated/TabBar/html/tabbar-second-pane.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="phoenix-tab-bar-2" class="phoenix-tab-bar">
33

44
</div>
5-
<div id="tab-bar-more-options" class="tab-bar-more-options">
5+
<div id="tab-bar-more-options-2" class="tab-bar-more-options-2">
66
<i class="fa-solid fa-ellipsis-vertical"></i>
77
</div>
88
</div>

src/extensionsIntegrated/TabBar/main.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ define(function (require, exports, module) {
147147
const $secondTabBar = $('#phoenix-tab-bar-2');
148148

149149
if (firstPaneWorkingSet.length === 0 && ($('#phoenix-tab-bar'))) {
150-
Helper._hideTabBar($('#phoenix-tab-bar'));
150+
Helper._hideTabBar($('#phoenix-tab-bar'), $('#tab-bar-more-options'));
151151
}
152152

153153
if (secondPaneWorkingSet.length === 0 && ($('#phoenix-tab-bar-2'))) {
154-
Helper._hideTabBar($('#phoenix-tab-bar-2'));
154+
Helper._hideTabBar($('#phoenix-tab-bar-2'), $('#tab-bar-more-options-2'));
155155
}
156156

157157
// get the count of tabs that we want to display in the tab bar (from preference settings)
@@ -371,6 +371,16 @@ define(function (require, exports, module) {
371371
const $tab = $tabBar.find(`.tab[data-path="${filePath}"]`);
372372
$tab.toggleClass('dirty', doc.isDirty);
373373
});
374+
375+
// handle click events on the tab bar more options button
376+
$(document).on("click", ".tab-bar-more-options", function (event) {
377+
event.stopPropagation();
378+
MoreOptions.showMoreOptionsContextMenu("first-pane");
379+
});
380+
$(document).on("click", ".tab-bar-more-options-2", function (event) {
381+
event.stopPropagation();
382+
MoreOptions.showMoreOptionsContextMenu("second-pane");
383+
});
374384
}
375385

376386

@@ -404,7 +414,5 @@ define(function (require, exports, module) {
404414

405415
// handle when a single tab gets clicked
406416
handleTabClick();
407-
408-
MoreOptions.handleMoreOptionsClick();
409417
});
410418
});
Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
1+
/*
2+
* This file manages the more options context menu.
3+
* The more option button is present at the right side of the tab bar.
4+
* When clicked, it will show the more options context menu.
5+
* which will have various options related to the tab bar
6+
*/
17
define(function (require, exports, module) {
2-
const DropdownButton = brackets.getModule("widgets/DropdownButton");
8+
const DropdownButton = require("widgets/DropdownButton");
9+
const Strings = require("strings");
10+
const MainViewManager = require("view/MainViewManager");
11+
const CommandManager = require("command/CommandManager");
12+
const Commands = require("command/Commands");
313

4-
function showMoreOptionsContextMenu(x, y) {
5-
const items = [
6-
"close all tabs",
7-
"close unmodified tabs"
8-
];
14+
// List of items to show in the context menu
15+
// Strings defined in `src/nls/root/strings.js`
16+
const items = [
17+
Strings.CLOSE_ALL_TABS,
18+
Strings.CLOSE_UNMODIFIED_TABS
19+
];
20+
21+
22+
/**
23+
* This function is called when the close all tabs option is selected from the context menu
24+
* This will close all tabs no matter whether they are in first pane or second pane
25+
*/
26+
function handleCloseAllTabs() {
27+
CommandManager.execute(Commands.FILE_CLOSE_ALL);
28+
}
29+
30+
31+
/**
32+
* This function is called when the more options button is clicked
33+
* This will show the more options context menu
34+
* @param {String} paneId - the id of the pane ["first-pane", "second-pane"]
35+
*/
36+
function showMoreOptionsContextMenu(paneId) {
937

1038
const dropdown = new DropdownButton.DropdownButton("", items);
1139

12-
$(".tab-bar-more-options").append(dropdown.$button);
40+
// we need to determine which pane the tab belongs to show the context menu at the right place
41+
if (paneId === "first-pane") {
42+
$("#tab-bar-more-options").append(dropdown.$button);
43+
} else {
44+
$("#tab-bar-more-options-2").append(dropdown.$button);
45+
}
46+
1347
dropdown.showDropdown();
1448

15-
dropdown.$button.on(DropdownButton.EVENT_SELECTED, function (e, item, index) {
16-
console.log("Selected item:", item);
17-
// TODO: Add the logic here
18-
// check for index and then call the items
49+
// handle the option selection
50+
dropdown.on("select", function (e, item, index) {
51+
if (index === 0) {
52+
handleCloseAllTabs(paneId);
53+
}
1954
});
2055

21-
$(document).one("click", function () {
22-
dropdown.closeDropdown();
56+
dropdown.$button.css({
57+
display: "none"
2358
});
24-
}
2559

26-
function handleMoreOptionsClick() {
27-
$(document).on("click", ".tab-bar-more-options", function (event) {
28-
event.stopPropagation();
29-
showMoreOptionsContextMenu(event.pageX, event.pageY);
30-
});
3160
}
3261

3362
module.exports = {
34-
handleMoreOptionsClick
63+
showMoreOptionsContextMenu
3564
};
3665
});

src/nls/root/strings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ define({
426426
"STATUSBAR_TASKS_STOP": "Stop",
427427
"STATUSBAR_TASKS_RESTART": "Restart",
428428

429+
// Tab bar Strings
430+
"CLOSE_ALL_TABS": "Close All Tabs",
431+
"CLOSE_UNMODIFIED_TABS": "Close Unmodified Tabs",
432+
429433
// CodeInspection: errors/warnings
430434
"ERRORS_NO_FILE": "No File Open",
431435
"ERRORS_PANEL_TITLE_MULTIPLE": "{0} Problems - {1}",

src/styles/Extn-TabBar.less

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
}
2727

2828

29-
.tab-bar-more-options {
29+
.tab-bar-more-options,
30+
.tab-bar-more-options-2 {
3031
display: flex;
3132
align-items: center;
3233
height: 2rem;
@@ -38,12 +39,14 @@
3839
}
3940

4041

41-
.tab-bar-more-options:hover {
42+
.tab-bar-more-options:hover,
43+
.tab-bar-more-options-2:hover {
4244
background-color: #333;
4345
}
4446

4547

46-
.tab-bar-more-options::before {
48+
.tab-bar-more-options::before,
49+
.tab-bar-more-options-2::before {
4750
content: "";
4851
position: absolute;
4952
top: 0;

0 commit comments

Comments
 (0)