# HG changeset patch # User John Donoghue # Date 1396891893 14400 # Node ID 7cb98e81ecd132899f705034c4d12a696ec83ef9 # Parent 5b6901b061065a54e690285bdcfb856f445bec0c GUI: Prompt to exit Octave option (Bug #41080) * libgui/src/settings-dialog.ui: Add prompt to exit checkbox. * libgui/src/main-window.cc, libgui/src/main-window.h: (main_window::confirm_exit_octave): New function. (main_window::closeEvent): call prompt/check function before exit. * libgui/src/settings-dialog.cc: (settings_dialog::settings_dialog): Load prompt_on_exit setting. (settings_dialog::write_changed_settings): Save prompt on exit settings. diff -r 5b6901b06106 -r 7cb98e81ecd1 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sun Apr 06 13:37:23 2014 -0700 +++ b/libgui/src/main-window.cc Mon Apr 07 13:31:33 2014 -0400 @@ -894,7 +894,8 @@ main_window::closeEvent (QCloseEvent *e) { e->ignore (); - octave_link::post_event (this, &main_window::exit_callback); + if (confirm_exit_octave()) + octave_link::post_event (this, &main_window::exit_callback); } void @@ -2365,3 +2366,25 @@ { _clipboard->clear (QClipboard::Clipboard); } + +bool +main_window::confirm_exit_octave () +{ + bool closenow = true; + + QSettings *settings = resource_manager::get_settings (); + + if (settings->value ("prompt_to_exit", false ).toBool()) + { + int ans = QMessageBox::question (this, tr ("Octave"), + tr ("Are you sure you want to exit Octave?"), + QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok); + + if (ans != QMessageBox::Ok) + closenow = false; + + } + return closenow; +} + + diff -r 5b6901b06106 -r 7cb98e81ecd1 libgui/src/main-window.h --- a/libgui/src/main-window.h Sun Apr 06 13:37:23 2014 -0700 +++ b/libgui/src/main-window.h Mon Apr 07 13:31:33 2014 -0400 @@ -271,6 +271,8 @@ void execute_debug_callback (); + bool confirm_exit_octave (); + workspace_model *_workspace_model; // Toolbars. diff -r 5b6901b06106 -r 7cb98e81ecd1 libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Sun Apr 06 13:37:23 2014 -0700 +++ b/libgui/src/settings-dialog.cc Mon Apr 07 13:31:33 2014 -0400 @@ -118,6 +118,10 @@ ui->cb_widget_custom_style->setChecked ( settings->value ("DockWidgets/widget_title_custom_style",false).toBool ()); + // prompt on exit + ui->cb_prompt_to_exit->setChecked ( + settings->value ("prompt_to_exit",false).toBool ()); + // Octave startup ui->cb_restore_octave_dir->setChecked ( settings->value ("restore_octave_dir",false).toBool ()); @@ -538,6 +542,9 @@ // icon size settings->setValue ("toolbar_icon_size", ui->toolbar_icon_size->value ()); + // promp to exit + settings->setValue ( "prompt_to_exit", ui->cb_prompt_to_exit->isChecked ()); + // Octave startup settings->setValue ("restore_octave_dir", ui->cb_restore_octave_dir->isChecked ()); diff -r 5b6901b06106 -r 7cb98e81ecd1 libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Sun Apr 06 13:37:23 2014 -0700 +++ b/libgui/src/settings-dialog.ui Mon Apr 07 13:31:33 2014 -0400 @@ -103,6 +103,13 @@ + + + + Confirm before exiting + + +