Modified 'close all except/left/right' to be effective on the tab the mouse points at.

This commit is contained in:
Matthias Koefferlein 2022-10-05 22:27:13 +02:00
parent 42de46caf2
commit 95686ea630
4 changed files with 45 additions and 51 deletions

View File

@ -397,8 +397,8 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection
QAction *action = new QAction (tr ("Close All"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all ()));
tabWidget->addAction (action);
action = new QAction (tr ("Close All Except Current"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_but_current ()));
action = new QAction (tr ("Close All Except This"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_but_this ()));
tabWidget->addAction (action);
action = new QAction (tr ("Close All Left"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_left ()));
@ -474,6 +474,8 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection
connect (replaceAllButton, SIGNAL (clicked ()), this, SLOT (replace_all_button_clicked ()));
connect (allVariables, SIGNAL (clicked (bool)), variableList, SLOT (set_show_all (bool)));
tabWidget->installEventFilter (this);
splitter->setCollapsible (1, false);
replaceFrame->hide ();
@ -1541,7 +1543,13 @@ MacroEditorDialog::eventFilter (QObject *obj, QEvent *event)
}
}
} else if (obj == tabWidget->tabBar () && dynamic_cast<QMouseEvent *> (event) != 0) {
// just spy on the events, don't eat them
QMouseEvent *mouse_event = dynamic_cast<QMouseEvent *> (event);
m_mouse_pos = mouse_event->pos ();
}
return false;
}
@ -2269,7 +2277,7 @@ END_PROTECTED
}
void
MacroEditorDialog::close_all_but_current ()
MacroEditorDialog::close_all_but_this ()
{
close_many (0);
}
@ -2295,10 +2303,8 @@ MacroEditorDialog::close_many (int r2c)
BEGIN_PROTECTED
int ci = tabWidget->currentIndex ();
int ci = tabWidget->tabBar ()->tabAt (m_mouse_pos);
if (ci < 0) {
close_all ();
return;
}

View File

@ -213,7 +213,7 @@ private slots:
void search_finished ();
void tab_close_requested (int);
void close_all ();
void close_all_but_current ();
void close_all_but_this ();
void close_all_left ();
void close_all_right ();
void replace_mode_button_clicked ();
@ -306,6 +306,7 @@ private:
lay::Dispatcher *mp_plugin_root;
lym::MacroCollection *mp_root;
bool m_first_show;
QPoint m_mouse_pos;
bool m_debugging_on;
lym::Macro *mp_run_macro;
std::vector<lym::Macro *> m_macro_templates;

View File

@ -234,6 +234,7 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
EnhancedTabBar *enh_tab_widget = new EnhancedTabBar (mp_main_frame);
mp_tab_bar = enh_tab_widget;
mp_tab_bar->installEventFilter (this);
vbh_tab->addWidget (enh_tab_widget);
vbh_tab->addWidget (enh_tab_widget->menu_button ());
@ -248,8 +249,8 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
QAction *action = new QAction (tr ("Close All"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_views ()));
mp_tab_bar->addAction (action);
action = new QAction (tr ("Close All Except Current"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_except_current_view ()));
action = new QAction (tr ("Close All Except This"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_except_this ()));
mp_tab_bar->addAction (action);
action = new QAction (tr ("Close All Left"), this);
connect (action, SIGNAL (triggered ()), this, SLOT (close_all_views_left ()));
@ -2608,33 +2609,6 @@ MainWindow::cm_close_all ()
interactive_close_view (0, views (), false, false);
}
void
MainWindow::cm_close_all_except_current ()
{
int current_index = index_of (lay::LayoutView::current ());
if (current_index >= 0) {
interactive_close_view (current_index, current_index + 1, true, false);
}
}
void
MainWindow::cm_close_all_left ()
{
int current_index = index_of (lay::LayoutView::current ());
if (current_index >= 0) {
interactive_close_view (0, current_index, false, false);
}
}
void
MainWindow::cm_close_all_right ()
{
int current_index = index_of (lay::LayoutView::current ());
if (current_index >= 0) {
interactive_close_view (current_index + 1, views (), false, false);
}
}
void
MainWindow::cm_close ()
{
@ -2865,21 +2839,30 @@ MainWindow::close_all_views ()
}
void
MainWindow::close_all_except_current_view ()
MainWindow::close_all_except_this ()
{
cm_close_all_except_current ();
int index = mp_tab_bar->tabAt (m_mouse_pos);
if (index >= 0) {
interactive_close_view (index, index + 1, true, false);
}
}
void
MainWindow::close_all_views_left ()
{
cm_close_all_left ();
int index = mp_tab_bar->tabAt (m_mouse_pos);
if (index >= 0) {
interactive_close_view (0, index, false, false);
}
}
void
MainWindow::close_all_views_right ()
{
cm_close_all_right ();
int index = mp_tab_bar->tabAt (m_mouse_pos);
if (index >= 0) {
interactive_close_view (index + 1, views (), false, false);
}
}
void
@ -3986,12 +3969,6 @@ MainWindow::menu_activated (const std::string &symbol)
cm_clone ();
} else if (symbol == "cm_close_all") {
cm_close_all ();
} else if (symbol == "cm_close_all_left") {
cm_close_all_left ();
} else if (symbol == "cm_close_all_right") {
cm_close_all_right ();
} else if (symbol == "cm_close_all_except_current") {
cm_close_all_except_current ();
} else if (symbol == "cm_close") {
cm_close ();
} else if (symbol == "cm_packages") {
@ -4058,6 +4035,17 @@ MainWindow::dragEnterEvent(QDragEnterEvent *event)
}
}
bool
MainWindow::eventFilter (QObject *watched, QEvent *event)
{
// spy on the mouse events of the tab bar so we can tell which tab the menu was issued on
if (watched == mp_tab_bar && dynamic_cast<QMouseEvent *> (event) != 0) {
m_mouse_pos = dynamic_cast<QMouseEvent *> (event)->pos ();
}
return QMainWindow::eventFilter (watched, event);
}
void
MainWindow::dropEvent(QDropEvent *event)
{

View File

@ -633,7 +633,7 @@ public slots:
void close_current_view ();
void close_view (int index);
void close_all_views ();
void close_all_except_current_view ();
void close_all_except_this ();
void close_all_views_left ();
void close_all_views_right ();
void clone ();
@ -680,6 +680,7 @@ protected:
void update_content ();
void do_update_menu ();
void do_update_mru_menus ();
bool eventFilter (QObject *watched, QEvent *event);
private:
lay::Dispatcher m_dispatcher;
@ -688,6 +689,7 @@ private:
// Main menu
QTabBar *mp_tab_bar;
QPoint m_mouse_pos;
QToolBar *mp_tool_bar;
QDockWidget *mp_navigator_dock_widget;
lay::Navigator *mp_navigator;
@ -793,9 +795,6 @@ private:
void cm_new_layout ();
void cm_clone ();
void cm_close_all ();
void cm_close_all_except_current ();
void cm_close_all_left ();
void cm_close_all_right ();
void cm_close ();
void cm_packages ();
void cm_technologies ();