# HG changeset patch # User Yuya Nishihara # Date 1659685743 -32400 # Fri Aug 05 16:49:03 2022 +0900 # Node ID 59a3afe1e2ccf5d363d3c187260ce65d1d301f90 # Parent ba2fd341ff57f0d535a6fc64a7c37d401794be3c mainwindow: add action to close (or unsplit) current text panel diff --git a/app/hgtextpanel.cpp b/app/hgtextpanel.cpp --- a/app/hgtextpanel.cpp +++ b/app/hgtextpanel.cpp @@ -292,6 +292,7 @@ menu->setAttribute(Qt::WA_DeleteOnClose); menu->addAction(actions_->toggleLogDock); menu->addAction(&actions_->selectOtherPanel); + menu->addAction(&actions_->closePanel); menu->addAction(&actions_->execSettingsDialog); menu->popup(ui_->textEdit->viewport()->mapToGlobal(pos)); } diff --git a/app/mainactions.h b/app/mainactions.h --- a/app/mainactions.h +++ b/app/mainactions.h @@ -12,6 +12,7 @@ QAction closeRepository; QAction selectOtherPanel; QAction splitRevisionPanel; + QAction closePanel; QPointer toggleLogDock; QAction reload; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -118,6 +118,11 @@ connect(&actions_->splitRevisionPanel, &QAction::triggered, this, &MainWindow::splitRevisionPanel); + actions_->closePanel.setText(tr("&Close Panel")); + actions_->closePanel.setShortcut(QKeySequence("Ctrl+X, 0")); + addAction(&actions_->closePanel); + connect(&actions_->closePanel, &QAction::triggered, this, &MainWindow::closeCurrentPanel); + actions_->toggleLogDock = logDock_->toggleViewAction(); actions_->toggleLogDock->setShortcut(QKeySequence("F12")); addAction(actions_->toggleLogDock); @@ -291,6 +296,28 @@ textPanel_->displayRevision(changesetPanel_->currentRevision()); } +void MainWindow::closeCurrentPanel() +{ + auto *panel = findAncestorSplitterChild(focusWidget(), mainSplitter_); + if (!panel || panel == changesetPanel_) + return; + // TODO: redesign routing between changeset panel and text panel + if (panel == textPanel_) { + std::vector textPanels; + collectSplitterChildren(textPanels, mainSplitter_); + textPanel_ = + textPanels.size() > 1 ? nextInCircularList(textPanels, textPanel_.data()) : nullptr; + if (textPanel_) { + connect(changesetPanel_, &HgChangesetPanel::currentRepositoryChanged, textPanel_, + &HgTextPanel::setCurrentRepository); + connect(changesetPanel_, &HgChangesetPanel::revisionActivated, textPanel_, + &HgTextPanel::displayRevision); + } + } + selectOtherPanel(); // move focus out of the panel to be deleted + delete panel; +} + void MainWindow::popupContextMenu(const QPoint &pos) { auto *menu = new QMenu(this); diff --git a/app/mainwindow.h b/app/mainwindow.h --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -45,6 +45,7 @@ void onCurrentRepositoryChanged(); void selectOtherPanel(); void splitRevisionPanel(); + void closeCurrentPanel(); void popupContextMenu(const QPoint &pos); void onLastRepositoryClosed();