From 66014d07a0869f3251272e521de3a966ab68efd8 Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 16 Jan 2018 18:55:30 +0100 Subject: [PATCH] minor changes to the close tab confirm dialog --- src/widgets/notebook.cpp | 9 +++++---- src/widgets/splitcontainer.cpp | 19 ++++++++++++------- src/widgets/splitcontainer.hpp | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index ba62041c9..09a815443 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -49,10 +49,10 @@ Notebook::Notebook(Window *parent, bool _showButtons, const std::string &setting this->loadTabs(); - closeConfirmDialog.setText("Are you sure to close this tab?"); + closeConfirmDialog.setText("Are you sure you want to close this tab?"); closeConfirmDialog.setIcon(QMessageBox::Icon::Question); - closeConfirmDialog.setStandardButtons(QMessageBox::Close | QMessageBox::Abort); - closeConfirmDialog.setDefaultButton(QMessageBox::Close); + closeConfirmDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); + closeConfirmDialog.setDefaultButton(QMessageBox::Yes); } SplitContainer *Notebook::addNewPage() @@ -80,8 +80,9 @@ SplitContainer *Notebook::addPage(const std::string &uuid, bool select) void Notebook::removePage(SplitContainer *page) { - if (closeConfirmDialog.exec() != QMessageBox::Close) + if (page->splitCount() > 0 && closeConfirmDialog.exec() != QMessageBox::Yes) { return; + } int index = this->pages.indexOf(page); diff --git a/src/widgets/splitcontainer.cpp b/src/widgets/splitcontainer.cpp index cfac0b7fd..590cd7342 100644 --- a/src/widgets/splitcontainer.cpp +++ b/src/widgets/splitcontainer.cpp @@ -32,7 +32,7 @@ SplitContainer::SplitContainer(Notebook *parent, NotebookTab *_tab, const std::s , chats(fS("{}/chats", this->settingRoot)) , tab(_tab) , dropPreview(this) - , chatWidgets() + , splits() { this->tab->page = this; @@ -64,12 +64,17 @@ void SplitContainer::updateFlexValues() } } +int SplitContainer::splitCount() const +{ + return this->splits.size(); +} + std::pair SplitContainer::removeFromLayout(Split *widget) { // remove reference to chat widget from chatWidgets vector - auto it = std::find(std::begin(this->chatWidgets), std::end(this->chatWidgets), widget); - if (it != std::end(this->chatWidgets)) { - this->chatWidgets.erase(it); + auto it = std::find(std::begin(this->splits), std::end(this->splits), widget); + if (it != std::end(this->splits)) { + this->splits.erase(it); this->refreshTitle(); } @@ -102,7 +107,7 @@ std::pair SplitContainer::removeFromLayout(Split *widget) void SplitContainer::addToLayout(Split *widget, std::pair position) { - this->chatWidgets.push_back(widget); + this->splits.push_back(widget); this->refreshTitle(); @@ -139,7 +144,7 @@ void SplitContainer::addToLayout(Split *widget, std::pair position) const std::vector &SplitContainer::getChatWidgets() const { - return this->chatWidgets; + return this->splits; } NotebookTab *SplitContainer::getTab() const @@ -448,7 +453,7 @@ void SplitContainer::refreshTitle() QString newTitle = ""; bool first = true; - for (const auto &chatWidget : this->chatWidgets) { + for (const auto &chatWidget : this->splits) { auto channelName = QString::fromStdString(chatWidget->channelName.getValue()); if (channelName.isEmpty()) { diff --git a/src/widgets/splitcontainer.hpp b/src/widgets/splitcontainer.hpp index 5d0c2deb5..601eb95a2 100644 --- a/src/widgets/splitcontainer.hpp +++ b/src/widgets/splitcontainer.hpp @@ -50,6 +50,7 @@ public: void requestFocus(int x, int y); void updateFlexValues(); + int splitCount() const; protected: virtual bool eventFilter(QObject *object, QEvent *event) override; @@ -86,7 +87,7 @@ private: QHBoxLayout hbox; } ui; - std::vector chatWidgets; + std::vector splits; std::vector dropRegions; pajlada::Settings::Setting>> chats;