Skip to content

Commit 3b7541f

Browse files
Added dialog box for closing a dirty file in the default plugin editor
1 parent daf6384 commit 3b7541f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

libEPLViz/src/pluginEditor/DefaultPluginEditor.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,31 @@ void DefaultPluginEditor::closeDocument(QString name) {
7373
if (!widget)
7474
return;
7575

76-
if (dirtyFiles.contains(name)) {
77-
// TODO Add notification to make sure the user keeps his changes
76+
// Check if file is dirty
77+
if (dirtyFiles.contains(name) || (name == current && widget->document()->isModified())) {
78+
// Ask user for further input
79+
QMessageBox msg(this);
7880

79-
dirtyFiles.removeOne(name);
81+
QPushButton *saveButton = msg.addButton("Save", QMessageBox::ActionRole);
82+
msg.addButton("Discard", QMessageBox::ActionRole);
83+
84+
85+
msg.setText("The file '" + name + "' has unsaved changes.");
86+
msg.setInformativeText("Would you like to save them?");
87+
msg.setDefaultButton(saveButton);
88+
89+
// Open message box
90+
msg.exec();
91+
92+
QPushButton *clicked = dynamic_cast<QPushButton *>(msg.clickedButton());
93+
94+
if (clicked == saveButton) {
95+
// Save the changes to this document
96+
save();
97+
} else {
98+
// Discard button was pressed, remove from dirty files
99+
dirtyFiles.removeOne(name);
100+
}
80101
}
81102

82103
files.remove(name);

0 commit comments

Comments
 (0)