Added a confirmation Dialog when trying to close a tab

This commit is contained in:
Bur0k 2018-01-10 01:59:55 +01:00 committed by fourtf
parent 0ca916717c
commit 17f5fd0ff1
2 changed files with 12 additions and 0 deletions

View file

@ -31,6 +31,7 @@ Notebook::Notebook(Window *parent, bool _showButtons, const std::string &setting
, userButton(this) , userButton(this)
, showButtons(_showButtons) , showButtons(_showButtons)
, tabs(fS("{}/tabs", this->settingRoot)) , tabs(fS("{}/tabs", this->settingRoot))
, closeConfirmDialog(this)
{ {
this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked())); this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked())); this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
@ -47,6 +48,11 @@ Notebook::Notebook(Window *parent, bool _showButtons, const std::string &setting
settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); }); settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); });
this->loadTabs(); this->loadTabs();
closeConfirmDialog.setText("Are you sure to close this tab?");
closeConfirmDialog.setIcon(QMessageBox::Icon::Question);
closeConfirmDialog.setStandardButtons(QMessageBox::Close | QMessageBox::Abort);
closeConfirmDialog.setDefaultButton(QMessageBox::Close);
} }
SplitContainer *Notebook::addNewPage() SplitContainer *Notebook::addNewPage()
@ -74,6 +80,9 @@ SplitContainer *Notebook::addPage(const std::string &uuid, bool select)
void Notebook::removePage(SplitContainer *page) void Notebook::removePage(SplitContainer *page)
{ {
if (closeConfirmDialog.exec() != QMessageBox::Close)
return;
int index = this->pages.indexOf(page); int index = this->pages.indexOf(page);
if (this->pages.size() == 1) { if (this->pages.size() == 1) {

View file

@ -6,6 +6,7 @@
#include "widgets/splitcontainer.hpp" #include "widgets/splitcontainer.hpp"
#include <QList> #include <QList>
#include <QMessageBox>
#include <QWidget> #include <QWidget>
namespace chatterino { namespace chatterino {
@ -73,6 +74,8 @@ private:
void loadTabs(); void loadTabs();
QMessageBox closeConfirmDialog;
public: public:
void save(); void save();
}; };