summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-01-19 12:54:19 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-01-19 12:54:19 +0200
commit64a8403832c69a7ce754f707c41b78a3df17b2f3 (patch)
tree2b531e9f59d6197fd49e1e647f108210c8a3b5af /src
parent538aa4e5f226551d6a529b6d4e85c0cef4d862f7 (diff)
Closing tabs with the middle mouse button
IssueID #115
Diffstat (limited to 'src')
-rw-r--r--src/app.c14
-rw-r--r--src/ui/window.c16
2 files changed, 21 insertions, 9 deletions
diff --git a/src/app.c b/src/app.c
index a46a6976..5d27618b 100644
--- a/src/app.c
+++ b/src/app.c
@@ -1245,9 +1245,13 @@ iBool handleCommand_App(const char *cmd) {
1245 return iTrue; 1245 return iTrue;
1246 } 1246 }
1247 else if (equal_Command(cmd, "tabs.close")) { 1247 else if (equal_Command(cmd, "tabs.close")) {
1248 iWidget *tabs = findWidget_App("doctabs"); 1248 iWidget * tabs = findWidget_App("doctabs");
1249 size_t index = tabPageIndex_Widget(tabs, document_App()); 1249 const iRangecc tabId = range_Command(cmd, "id");
1250 iBool wasClosed = iFalse; 1250 iWidget * doc = !isEmpty_Range(&tabId) ? findWidget_App(cstr_Rangecc(tabId))
1251 : document_App();
1252 iBool wasCurrent = (doc == (iWidget *) document_App());
1253 size_t index = tabPageIndex_Widget(tabs, doc);
1254 iBool wasClosed = iFalse;
1251 if (argLabel_Command(cmd, "toright")) { 1255 if (argLabel_Command(cmd, "toright")) {
1252 while (tabCount_Widget(tabs) > index + 1) { 1256 while (tabCount_Widget(tabs) > index + 1) {
1253 destroy_Widget(removeTabPage_Widget(tabs, index + 1)); 1257 destroy_Widget(removeTabPage_Widget(tabs, index + 1));
@@ -1272,7 +1276,9 @@ iBool handleCommand_App(const char *cmd) {
1272 index--; 1276 index--;
1273 } 1277 }
1274 arrange_Widget(tabs); 1278 arrange_Widget(tabs);
1275 postCommandf_App("tabs.switch page:%p", tabPage_Widget(tabs, index)); 1279 if (wasCurrent) {
1280 postCommandf_App("tabs.switch page:%p", tabPage_Widget(tabs, index));
1281 }
1276 } 1282 }
1277 else { 1283 else {
1278 postCommand_App("quit"); 1284 postCommand_App("quit");
diff --git a/src/ui/window.c b/src/ui/window.c
index 8cab100d..2e38512b 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -437,11 +437,17 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
437 else if (equal_Command(cmd, "mouse.clicked") && arg_Command(cmd)) { 437 else if (equal_Command(cmd, "mouse.clicked") && arg_Command(cmd)) {
438 iWidget *widget = pointer_Command(cmd); 438 iWidget *widget = pointer_Command(cmd);
439 iWidget *menu = findWidget_App("doctabs.menu"); 439 iWidget *menu = findWidget_App("doctabs.menu");
440 if (isTabButton_Widget(widget) && !isVisible_Widget(menu)) { 440 if (isTabButton_Widget(widget)) {
441 iWidget *tabs = findWidget_App("doctabs"); 441 if (!isVisible_Widget(menu)) {
442 showTabPage_Widget(tabs, 442 iWidget *tabs = findWidget_App("doctabs");
443 tabPage_Widget(tabs, childIndex_Widget(widget->parent, widget))); 443 iWidget *page = tabPage_Widget(tabs, childIndex_Widget(widget->parent, widget));
444 openMenu_Widget(menu, coord_Command(cmd)); 444 if (argLabel_Command(cmd, "button") == SDL_BUTTON_MIDDLE) {
445 postCommandf_App("tabs.close id:%s", cstr_String(id_Widget(page)));
446 return iTrue;
447 }
448 showTabPage_Widget(tabs, page);
449 openMenu_Widget(menu, coord_Command(cmd));
450 }
445 } 451 }
446 } 452 }
447 else if (equal_Command(cmd, "navigate.reload")) { 453 else if (equal_Command(cmd, "navigate.reload")) {