From 64a8403832c69a7ce754f707c41b78a3df17b2f3 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 19 Jan 2021 12:54:19 +0200 Subject: Closing tabs with the middle mouse button IssueID #115 --- src/app.c | 14 ++++++++++---- src/ui/window.c | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') 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) { return iTrue; } else if (equal_Command(cmd, "tabs.close")) { - iWidget *tabs = findWidget_App("doctabs"); - size_t index = tabPageIndex_Widget(tabs, document_App()); - iBool wasClosed = iFalse; + iWidget * tabs = findWidget_App("doctabs"); + const iRangecc tabId = range_Command(cmd, "id"); + iWidget * doc = !isEmpty_Range(&tabId) ? findWidget_App(cstr_Rangecc(tabId)) + : document_App(); + iBool wasCurrent = (doc == (iWidget *) document_App()); + size_t index = tabPageIndex_Widget(tabs, doc); + iBool wasClosed = iFalse; if (argLabel_Command(cmd, "toright")) { while (tabCount_Widget(tabs) > index + 1) { destroy_Widget(removeTabPage_Widget(tabs, index + 1)); @@ -1272,7 +1276,9 @@ iBool handleCommand_App(const char *cmd) { index--; } arrange_Widget(tabs); - postCommandf_App("tabs.switch page:%p", tabPage_Widget(tabs, index)); + if (wasCurrent) { + postCommandf_App("tabs.switch page:%p", tabPage_Widget(tabs, index)); + } } else { 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) { else if (equal_Command(cmd, "mouse.clicked") && arg_Command(cmd)) { iWidget *widget = pointer_Command(cmd); iWidget *menu = findWidget_App("doctabs.menu"); - if (isTabButton_Widget(widget) && !isVisible_Widget(menu)) { - iWidget *tabs = findWidget_App("doctabs"); - showTabPage_Widget(tabs, - tabPage_Widget(tabs, childIndex_Widget(widget->parent, widget))); - openMenu_Widget(menu, coord_Command(cmd)); + if (isTabButton_Widget(widget)) { + if (!isVisible_Widget(menu)) { + iWidget *tabs = findWidget_App("doctabs"); + iWidget *page = tabPage_Widget(tabs, childIndex_Widget(widget->parent, widget)); + if (argLabel_Command(cmd, "button") == SDL_BUTTON_MIDDLE) { + postCommandf_App("tabs.close id:%s", cstr_String(id_Widget(page))); + return iTrue; + } + showTabPage_Widget(tabs, page); + openMenu_Widget(menu, coord_Command(cmd)); + } } } else if (equal_Command(cmd, "navigate.reload")) { -- cgit v1.2.3