* 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.
This commit is contained in:
Pavel Roskin 2003-07-21 03:54:47 +00:00
parent 7a5c9a3834
commit dadbdd25e9
5 changed files with 46 additions and 22 deletions

View File

@ -1,5 +1,13 @@
2003-07-20 Pavel Roskin <proski@gnu.org> 2003-07-20 Pavel Roskin <proski@gnu.org>
* 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 * 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 stack. Don't force any refresh. Don't delete unsaved files, do
it ... it ...

View File

@ -2520,7 +2520,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion)
break; break;
case CK_Exit: case CK_Exit:
edit_quit_cmd (edit); dlg_stop (edit->widget.parent);
break; break;
case CK_New: case CK_New:
edit_new_cmd (edit); edit_new_cmd (edit);

View File

@ -198,6 +198,7 @@ int edit_save_as_cmd (WEdit * edit);
WEdit *edit_init (WEdit *edit, int lines, int columns, WEdit *edit_init (WEdit *edit, int lines, int columns,
const char *filename, long line); const char *filename, long line);
int edit_clean (WEdit * edit); int edit_clean (WEdit * edit);
int edit_ok_to_exit (WEdit *edit);
int edit_renew (WEdit * edit); int edit_renew (WEdit * edit);
int edit_new_cmd (WEdit * edit); int edit_new_cmd (WEdit * edit);
int edit_reload (WEdit *edit, const char *filename); 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_mark_cmd (WEdit * edit, int unmark);
void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2); void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
void edit_push_markers (WEdit * edit); void edit_push_markers (WEdit * edit);
void edit_quit_cmd (WEdit * edit);
void edit_replace_cmd (WEdit * edit, int again); void edit_replace_cmd (WEdit * edit, int again);
void edit_search_cmd (WEdit * edit, int again); void edit_search_cmd (WEdit * edit, int again);
void edit_complete_word_cmd (WEdit * edit); void edit_complete_word_cmd (WEdit * edit);

View File

@ -2049,16 +2049,24 @@ 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) { if (!edit->modified)
switch (edit_query_dialog3 (_ ("Quit"), _ (" File was modified, Save with exit? "), _ ("Cancel quit"), _ ("&Yes"), _ ("&No"))) { return 1;
switch (edit_query_dialog3
(_("Quit"), _(" File was modified, Save with exit? "),
_("Cancel quit"), _("&Yes"), _("&No"))) {
case 1: case 1:
edit_push_markers (edit); edit_push_markers (edit);
edit_set_markers (edit, 0, 0, 0, 0); edit_set_markers (edit, 0, 0, 0, 0);
if (!edit_save_cmd (edit)) if (!edit_save_cmd (edit))
return; return 0;
break; break;
case 2: case 2:
if (edit->locked) if (edit->locked)
@ -2066,12 +2074,13 @@ void edit_quit_cmd (WEdit * edit)
break; break;
case 0: case 0:
case -1: case -1:
return; return 0;
} }
}
dlg_stop (edit->widget.parent); return 1;
} }
#define TEMP_BUF_LEN 1024 #define TEMP_BUF_LEN 1024
/* Return a null terminated length of text. Result must be g_free'd */ /* Return a null terminated length of text. Result must be g_free'd */

View File

@ -141,12 +141,19 @@ edit_adjust_size (Dlg_head *h)
/* Callback for the edit dialog */ /* Callback for the edit dialog */
static int 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) { switch (msg) {
case DLG_RESIZE: case DLG_RESIZE:
edit_adjust_size (h); edit_adjust_size (h);
return MSG_HANDLED; 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); return default_dlg_callback (h, id, msg);
} }