X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=1821ad1e67a69276bd3e6b04c607df0e2c1f121f;hb=a2b9ac403cb540b5c6499d00d3d376384ec6c94f;hp=8aaa1635c737d376321b8ebcb9202572182cde98;hpb=f30eb549fe91dde6a56f69c24f2f8169039c12a2;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 8aaa163..1821ad1 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -213,6 +213,12 @@ shared_ptr MainWindow::add_view(const QString &title, this, SLOT(on_new_view(Session*))); main_bar->action_view_show_cursors()->setChecked(v->cursors_shown()); + + /* For the main view we need to prevent the dock widget from + * closing itself when its close button is clicked. This is + * so we can confirm with the user first. Regular views don't + * need this */ + close_btn->disconnect(SIGNAL(clicked()), dock, SLOT(close())); } else { /* Additional view, create a standard bar */ pv::views::trace::StandardBar *standard_bar = @@ -477,8 +483,20 @@ std::shared_ptr MainWindow::get_tab_session(int index) const void MainWindow::closeEvent(QCloseEvent *event) { - save_ui_settings(); - event->accept(); + bool data_saved = true; + + for (auto entry : session_windows_) + if (!entry.first->data_saved()) + data_saved = false; + + if (!data_saved && (QMessageBox::question(this, tr("Confirmation"), + tr("There is unsaved data. Close anyway?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) { + event->ignore(); + } else { + save_ui_settings(); + event->accept(); + } } QMenu* MainWindow::createPopupMenu() @@ -662,11 +680,16 @@ void MainWindow::on_view_close_clicked() if (!session->has_view(view)) continue; - // Also destroy the entire session if its main view is closing + // Also destroy the entire session if its main view is closing... if (view == session->main_view()) { - remove_session(session); + // ...but only if data is saved or the user confirms closing + if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"), + tr("This session contains unsaved data. Close it anyway?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)) + remove_session(session); break; } else + // All other views can be closed at any time as no data will be lost remove_view(view); } } @@ -681,11 +704,13 @@ void MainWindow::on_tab_changed(int index) void MainWindow::on_tab_close_requested(int index) { - // TODO Ask user if this is intended in case data is unsaved - shared_ptr session = get_tab_session(index); - if (session) + assert(session); + + if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"), + tr("This session contains unsaved data. Close it anyway?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)) remove_session(session); }