Mercurial > octave-nkf
comparison libgui/src/m-editor/file-editor-tab.cc @ 16018:e0df71fbe39b
gui: clearer message box with cancel button when closing an unsaved editor file
* file-editor-tab.cc (check_file_modified): buttons in message box are save,
discard and cancel, save is default; removed unused parameters
* file-editor-tab.cc (handle_file_modified_answer): adjust button names
* file-editor-tab.h: removed unused parameters from check_file_modified
author | Torsten <ttl@justmail.de> |
---|---|
date | Fri, 08 Feb 2013 16:05:04 +0100 |
parents | 06187a0b7a62 |
children | f482302d81c9 |
comparison
equal
deleted
inserted
replaced
16017:06187a0b7a62 | 16018:e0df71fbe39b |
---|---|
140 void | 140 void |
141 file_editor_tab::closeEvent (QCloseEvent *e) | 141 file_editor_tab::closeEvent (QCloseEvent *e) |
142 { | 142 { |
143 // ignore close event if file is not saved and user cancels | 143 // ignore close event if file is not saved and user cancels |
144 // closing this window | 144 // closing this window |
145 if (check_file_modified ("Close File", | 145 if (check_file_modified () == QMessageBox::Cancel) |
146 QMessageBox::Cancel) == QMessageBox::Cancel) | |
147 { | 146 { |
148 e->ignore (); | 147 e->ignore (); |
149 } | 148 } |
150 else | 149 else |
151 { | 150 { |
689 _copy_available = enableCopy; | 688 _copy_available = enableCopy; |
690 emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name)); | 689 emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name)); |
691 } | 690 } |
692 | 691 |
693 int | 692 int |
694 file_editor_tab::check_file_modified (const QString&, int) | 693 file_editor_tab::check_file_modified () |
695 { | 694 { |
696 int decision = QMessageBox::Yes; | 695 int decision = QMessageBox::Yes; |
697 if (_edit_area->isModified ()) | 696 if (_edit_area->isModified ()) |
698 { | 697 { |
699 // File is modified but not saved, ask user what to do. The file | 698 // File is modified but not saved, ask user what to do. The file |
700 // editor tab can't be made parent because it may be deleted depending | 699 // editor tab can't be made parent because it may be deleted depending |
701 // upon the response. Instead, change the _edit_area to read only. | 700 // upon the response. Instead, change the _edit_area to read only. |
702 QMessageBox* msgBox = new QMessageBox ( | 701 QMessageBox* msgBox = new QMessageBox ( |
703 QMessageBox::Warning, tr ("Octave Editor"), | 702 QMessageBox::Warning, tr ("Octave Editor"), |
704 tr ("The file \'%1\' has been modified. Do you want to save the changes?"). | 703 tr ("The file\n" |
705 arg (_file_name), QMessageBox::Yes | QMessageBox::No, 0); | 704 "%1\n" |
705 "is about to be closed but has been modified.\n" | |
706 "Do you want to cancel closing, save or discard the changes?"). | |
707 arg (_file_name), | |
708 QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard, 0); | |
709 msgBox->setDefaultButton (QMessageBox::Save); | |
706 _edit_area->setReadOnly (true); | 710 _edit_area->setReadOnly (true); |
707 connect (msgBox, SIGNAL (finished (int)), | 711 connect (msgBox, SIGNAL (finished (int)), |
708 this, SLOT (handle_file_modified_answer (int))); | 712 this, SLOT (handle_file_modified_answer (int))); |
709 msgBox->setWindowModality (Qt::NonModal); | 713 msgBox->setWindowModality (Qt::NonModal); |
710 msgBox->setAttribute (Qt::WA_DeleteOnClose); | 714 msgBox->setAttribute (Qt::WA_DeleteOnClose); |
721 } | 725 } |
722 | 726 |
723 void | 727 void |
724 file_editor_tab::handle_file_modified_answer (int decision) | 728 file_editor_tab::handle_file_modified_answer (int decision) |
725 { | 729 { |
726 if (decision == QMessageBox::Yes) | 730 if (decision == QMessageBox::Save) |
727 { | 731 { |
728 // Save file, then remove from editor. | 732 // Save file, then remove from editor. |
729 save_file (_file_name, true); | 733 save_file (_file_name, true); |
730 } | 734 } |
731 else if (decision == QMessageBox::No) | 735 else if (decision == QMessageBox::Discard) |
732 { | 736 { |
733 // User doesn't want to save, just remove from editor. | 737 // User doesn't want to save, just remove from editor. |
734 emit tab_remove_request (); | 738 emit tab_remove_request (); |
735 } | 739 } |
736 else | 740 else |