added confirmation dialog when closing a tab

This commit is contained in:
fourtf 2018-05-23 20:02:12 +02:00
parent 4cb666b75a
commit fb750d6d85

View file

@ -324,15 +324,25 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
{ {
this->mouseDown = false; this->mouseDown = false;
auto removeThisPage = [this] {
auto reply = QMessageBox::question(this, "Remove this tab",
"Are you sure that you want to remove this tab?",
QMessageBox::Yes | QMessageBox::Cancel);
if (reply == QMessageBox::Yes) {
this->notebook->removePage(this->page);
}
};
if (event->button() == Qt::MiddleButton) { if (event->button() == Qt::MiddleButton) {
if (this->rect().contains(event->pos())) { if (this->rect().contains(event->pos())) {
this->notebook->removePage(this->page); removeThisPage();
} }
} else { } else {
if (this->hasXButton() && this->mouseDownX && this->getXRect().contains(event->pos())) { if (this->hasXButton() && this->mouseDownX && this->getXRect().contains(event->pos())) {
this->mouseDownX = false; this->mouseDownX = false;
this->notebook->removePage(this->page); removeThisPage();
} else { } else {
this->update(); this->update();
} }