diff --git a/edit/ChangeLog b/edit/ChangeLog index ff6056884..22c9fa740 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -1,5 +1,13 @@ 2003-07-20 Pavel Roskin + * editcmd.c (edit_quit_cmd): Rename to ... + (edit_ok_to_exit): ... this. Don't stop dialog - this function + is called by the dialog code. + * editwidget.c (edit_dialog_callback): Process DLG_VALIDATE + event. Don't exit it the user wants to continue editing. + * edit.c (edit_execute_cmd): Close the dialog - it will ask user + if necessary. + * editcmd.c (edit_quit_cmd): Don't save this command in the undo stack. Don't force any refresh. Don't delete unsaved files, do it ... diff --git a/edit/edit.c b/edit/edit.c index fd164f93b..5ae03e152 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -2520,7 +2520,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion) break; case CK_Exit: - edit_quit_cmd (edit); + dlg_stop (edit->widget.parent); break; case CK_New: edit_new_cmd (edit); diff --git a/edit/edit.h b/edit/edit.h index a70adec5a..06470eb9f 100644 --- a/edit/edit.h +++ b/edit/edit.h @@ -198,6 +198,7 @@ int edit_save_as_cmd (WEdit * edit); WEdit *edit_init (WEdit *edit, int lines, int columns, const char *filename, long line); int edit_clean (WEdit * edit); +int edit_ok_to_exit (WEdit *edit); int edit_renew (WEdit * edit); int edit_new_cmd (WEdit * edit); int edit_reload (WEdit *edit, const char *filename); @@ -205,7 +206,6 @@ int edit_load_cmd (WEdit * edit); void edit_mark_cmd (WEdit * edit, int unmark); void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2); void edit_push_markers (WEdit * edit); -void edit_quit_cmd (WEdit * edit); void edit_replace_cmd (WEdit * edit, int again); void edit_search_cmd (WEdit * edit, int again); void edit_complete_word_cmd (WEdit * edit); diff --git a/edit/editcmd.c b/edit/editcmd.c index 16c2d5073..80ecb369f 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -2049,29 +2049,38 @@ void edit_search_cmd (WEdit * edit, int again) } -/* Real edit only */ -void edit_quit_cmd (WEdit * edit) +/* + * Check if it's OK to close the editor. If there are unsaved changes, + * ask user. Return 1 if it's OK to exit, 0 to continue editing. + */ +int +edit_ok_to_exit (WEdit *edit) { - if (edit->modified) { - switch (edit_query_dialog3 (_ ("Quit"), _ (" File was modified, Save with exit? "), _ ("Cancel quit"), _ ("&Yes"), _ ("&No"))) { - case 1: - edit_push_markers (edit); - edit_set_markers (edit, 0, 0, 0, 0); - if (!edit_save_cmd (edit)) - return; - break; - case 2: - if (edit->locked) - edit->locked = edit_unlock_file (edit->filename); - break; - case 0: - case -1: - return; - } + if (!edit->modified) + return 1; + + switch (edit_query_dialog3 + (_("Quit"), _(" File was modified, Save with exit? "), + _("Cancel quit"), _("&Yes"), _("&No"))) { + case 1: + edit_push_markers (edit); + edit_set_markers (edit, 0, 0, 0, 0); + if (!edit_save_cmd (edit)) + return 0; + break; + case 2: + if (edit->locked) + edit->locked = edit_unlock_file (edit->filename); + break; + case 0: + case -1: + return 0; } - dlg_stop (edit->widget.parent); + + return 1; } + #define TEMP_BUF_LEN 1024 /* Return a null terminated length of text. Result must be g_free'd */ diff --git a/edit/editwidget.c b/edit/editwidget.c index 60dd987d0..eece55023 100644 --- a/edit/editwidget.c +++ b/edit/editwidget.c @@ -141,12 +141,19 @@ edit_adjust_size (Dlg_head *h) /* Callback for the edit dialog */ static int -edit_dialog_callback (Dlg_head * h, int id, int msg) +edit_dialog_callback (Dlg_head *h, int id, int msg) { + WEdit *edit; + switch (msg) { case DLG_RESIZE: edit_adjust_size (h); return MSG_HANDLED; + case DLG_VALIDATE: + edit = (WEdit *) find_widget_type (h, (callback_fn) edit_callback); + if (!edit_ok_to_exit (edit)) { + h->running = 1; + } } return default_dlg_callback (h, id, msg); }