Просмотр исходного кода

* 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.

Pavel Roskin 21 лет назад
Родитель
Сommit
dadbdd25e9
5 измененных файлов с 46 добавлено и 22 удалено
  1. 8 0
      edit/ChangeLog
  2. 1 1
      edit/edit.c
  3. 1 1
      edit/edit.h
  4. 28 19
      edit/editcmd.c
  5. 8 1
      edit/editwidget.c

+ 8 - 0
edit/ChangeLog

@@ -1,5 +1,13 @@
 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
 	stack.  Don't force any refresh.  Don't delete unsaved files, do
 	it ...

+ 1 - 1
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);

+ 1 - 1
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);

+ 28 - 19
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 */

+ 8 - 1
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);
 }