-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add confirmation dialogue on exit with unsaved changes. #74
Changes from all commits
9899099
8ba43a5
bf26bde
5038982
b06bf68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
#include <rviz/visualization_manager.h> | ||
|
||
#include <QFileDialog> | ||
#include <QMessageBox> | ||
|
||
#include <qteditorfactory.h> | ||
#include <qtpropertymanager.h> | ||
|
@@ -43,9 +44,38 @@ void URDFEditor::on_action_Open_triggered() | |
} | ||
} | ||
|
||
bool URDFEditor::unsaved_changes() | ||
{ | ||
QMessageBox::StandardButton reply; | ||
reply = QMessageBox::question(this, "Save changes?", "Save your changes before exiting?", QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); | ||
|
||
if (reply == QMessageBox::Yes) | ||
{ | ||
on_actionSave_As_triggered(); | ||
return true; | ||
} | ||
if (reply == QMessageBox::Cancel) | ||
return false; | ||
if (reply == QMessageBox::No) | ||
return true; | ||
} | ||
|
||
void URDFEditor::on_action_Save_triggered() | ||
{ | ||
urdf_tree_->saveURDF(file_path_); | ||
QMessageBox msgBox; | ||
if (urdf_tree_->saveURDF(file_path_)) | ||
{ | ||
urdf_tree_->unsavedChanges = false; | ||
msgBox.setWindowTitle("Success"); | ||
msgBox.setText("The file was saved."); | ||
msgBox.exec(); | ||
} | ||
else | ||
{ | ||
msgBox.setWindowTitle("FAILURE"); | ||
msgBox.setText("An error occurred during saving."); | ||
msgBox.exec(); | ||
} | ||
} | ||
|
||
void URDFEditor::on_actionSave_As_triggered() | ||
|
@@ -54,19 +84,51 @@ void URDFEditor::on_actionSave_As_triggered() | |
if (!file_path.isEmpty()) | ||
{ | ||
file_path_ = file_path; | ||
urdf_tree_->saveURDF(file_path); | ||
ui->action_Save->setDisabled(false); | ||
|
||
QMessageBox msgBox; | ||
if (!urdf_tree_->saveURDF(file_path)) | ||
{ | ||
msgBox.setWindowTitle("FAILURE"); | ||
msgBox.setText("An error occurred during saving."); | ||
msgBox.exec(); | ||
} | ||
else | ||
{ | ||
urdf_tree_->unsavedChanges = false; | ||
ui->action_Save->setDisabled(false); | ||
} | ||
} | ||
} | ||
|
||
void URDFEditor::on_action_New_triggered() | ||
{ | ||
file_path_.clear(); | ||
urdf_tree_->clear(); | ||
ui->action_Save->setDisabled(true); | ||
file_path_.clear(); | ||
urdf_tree_->clear(); | ||
ui->action_Save->setDisabled(true); | ||
} | ||
|
||
void URDFEditor::on_action_Exit_triggered() | ||
{ | ||
QCloseEvent closing; | ||
closeEvent( &closing ); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may have misunderstood the |
||
|
||
void URDFEditor::on_actionE_xit_triggered() | ||
void URDFEditor::closeEvent( QCloseEvent *event ) | ||
{ | ||
if ( urdf_tree_->unsavedChanges == true ) // If there were unsaved changes | ||
{ | ||
if ( !unsaved_changes() ) // User canceled the quit | ||
event->ignore(); | ||
else | ||
{ | ||
event->accept(); | ||
QMainWindow::closeEvent(event); | ||
QApplication::quit(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here: from the example I got the idea that just ignoring or accepting the event would be enough to have Qt continue the application close sequence. From the code here it seems that is not the case, and an explicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gavanderhoorn quit() is needed when the user tries to quit by File->Exit. Otherwise the window remains open. Clicking the X to exit works perfectly without quit(). I'm not sure why the X and File->Exit are set up differently. It seems like they should have the same behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After more testing, I found that closeEvent() can be skipped and quit() suffices for both cases (X and File->Exit). However, closeEvent() "looks nicer" because it closes the windows rapidly. I suggest keeping it the way it will be on this upcoming commit. Sorry that I don't have a better explanation. |
||
} | ||
else | ||
{ | ||
event->accept(); | ||
QApplication::quit(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation, and did you have a particular reason to still show the dialogue for the case saving completes successfully? From your earlier comments I figured you wanted to remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the confirmation useful after "Save" but annoying after "Save As," because there are 3 other boxes to click through on "Save As."