minor changes to the close tab confirm dialog

This commit is contained in:
fourtf 2018-01-16 18:55:30 +01:00
parent 17f5fd0ff1
commit 66014d07a0
3 changed files with 19 additions and 12 deletions

View file

@ -49,10 +49,10 @@ Notebook::Notebook(Window *parent, bool _showButtons, const std::string &setting
this->loadTabs(); 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.setIcon(QMessageBox::Icon::Question);
closeConfirmDialog.setStandardButtons(QMessageBox::Close | QMessageBox::Abort); closeConfirmDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
closeConfirmDialog.setDefaultButton(QMessageBox::Close); closeConfirmDialog.setDefaultButton(QMessageBox::Yes);
} }
SplitContainer *Notebook::addNewPage() SplitContainer *Notebook::addNewPage()
@ -80,8 +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) if (page->splitCount() > 0 && closeConfirmDialog.exec() != QMessageBox::Yes) {
return; return;
}
int index = this->pages.indexOf(page); int index = this->pages.indexOf(page);

View file

@ -32,7 +32,7 @@ SplitContainer::SplitContainer(Notebook *parent, NotebookTab *_tab, const std::s
, chats(fS("{}/chats", this->settingRoot)) , chats(fS("{}/chats", this->settingRoot))
, tab(_tab) , tab(_tab)
, dropPreview(this) , dropPreview(this)
, chatWidgets() , splits()
{ {
this->tab->page = this; this->tab->page = this;
@ -64,12 +64,17 @@ void SplitContainer::updateFlexValues()
} }
} }
int SplitContainer::splitCount() const
{
return this->splits.size();
}
std::pair<int, int> SplitContainer::removeFromLayout(Split *widget) std::pair<int, int> SplitContainer::removeFromLayout(Split *widget)
{ {
// remove reference to chat widget from chatWidgets vector // remove reference to chat widget from chatWidgets vector
auto it = std::find(std::begin(this->chatWidgets), std::end(this->chatWidgets), widget); auto it = std::find(std::begin(this->splits), std::end(this->splits), widget);
if (it != std::end(this->chatWidgets)) { if (it != std::end(this->splits)) {
this->chatWidgets.erase(it); this->splits.erase(it);
this->refreshTitle(); this->refreshTitle();
} }
@ -102,7 +107,7 @@ std::pair<int, int> SplitContainer::removeFromLayout(Split *widget)
void SplitContainer::addToLayout(Split *widget, std::pair<int, int> position) void SplitContainer::addToLayout(Split *widget, std::pair<int, int> position)
{ {
this->chatWidgets.push_back(widget); this->splits.push_back(widget);
this->refreshTitle(); this->refreshTitle();
@ -139,7 +144,7 @@ void SplitContainer::addToLayout(Split *widget, std::pair<int, int> position)
const std::vector<Split *> &SplitContainer::getChatWidgets() const const std::vector<Split *> &SplitContainer::getChatWidgets() const
{ {
return this->chatWidgets; return this->splits;
} }
NotebookTab *SplitContainer::getTab() const NotebookTab *SplitContainer::getTab() const
@ -448,7 +453,7 @@ void SplitContainer::refreshTitle()
QString newTitle = ""; QString newTitle = "";
bool first = true; bool first = true;
for (const auto &chatWidget : this->chatWidgets) { for (const auto &chatWidget : this->splits) {
auto channelName = QString::fromStdString(chatWidget->channelName.getValue()); auto channelName = QString::fromStdString(chatWidget->channelName.getValue());
if (channelName.isEmpty()) { if (channelName.isEmpty()) {

View file

@ -50,6 +50,7 @@ public:
void requestFocus(int x, int y); void requestFocus(int x, int y);
void updateFlexValues(); void updateFlexValues();
int splitCount() const;
protected: protected:
virtual bool eventFilter(QObject *object, QEvent *event) override; virtual bool eventFilter(QObject *object, QEvent *event) override;
@ -86,7 +87,7 @@ private:
QHBoxLayout hbox; QHBoxLayout hbox;
} ui; } ui;
std::vector<Split *> chatWidgets; std::vector<Split *> splits;
std::vector<DropRegion> dropRegions; std::vector<DropRegion> dropRegions;
pajlada::Settings::Setting<std::vector<std::vector<std::string>>> chats; pajlada::Settings::Setting<std::vector<std::vector<std::string>>> chats;