static inline void edit_quit (WDialog * h) { GList *l; WEdit *e = NULL; h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ for (l = h->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (WIDGET (l->data))) { e = (WEdit *) l->data; if (e->drag_state != MCEDIT_DRAG_NORMAL) { edit_restore_size (e); return; } if (e->modified) { dlg_select_widget (e); if (!edit_ok_to_exit (e)) return; } } /* no editors in dialog at all or no any file required to be saved */ if (e == NULL || l == NULL) h->state = DLG_CLOSED; }
static cb_ret_t edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { WEdit *edit; WMenuBar *menubar; WButtonBar *buttonbar; edit = (WEdit *) find_widget_type (h, edit_callback); menubar = find_menubar (h); buttonbar = find_buttonbar (h); switch (msg) { case DLG_INIT: edit_set_buttonbar (edit, buttonbar); return MSG_HANDLED; case DLG_DRAW: /* don't use common_dialog_repaint() -- we don't need a frame */ tty_setcolor (EDITOR_NORMAL_COLOR); dlg_erase (h); return MSG_HANDLED; case DLG_RESIZE: /* dlg_set_size() is surplus for this case */ h->lines = LINES; h->cols = COLS; widget_set_size (&buttonbar->widget, h->lines - 1, h->x, 1, h->cols); widget_set_size (&menubar->widget, h->y, h->x, 1, h->cols); menubar_arrange (menubar); widget_set_size (&edit->widget, h->y + 1, h->x, h->lines - 2, h->cols); return MSG_HANDLED; case DLG_ACTION: if (sender == (Widget *) menubar) return send_message ((Widget *) edit, WIDGET_COMMAND, parm); if (sender == (Widget *) buttonbar) return send_message ((Widget *) edit, WIDGET_COMMAND, parm); return MSG_HANDLED; case DLG_VALIDATE: h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ if (edit_ok_to_exit (edit)) h->state = DLG_CLOSED; return MSG_HANDLED; default: return default_dlg_callback (h, sender, msg, parm, data); } }
static inline void edit_quit (WDialog * h) { GList *l; WEdit *e = NULL; GSList *m = NULL; GSList *me; /* don't stop the dialog before final decision */ widget_set_state (WIDGET (h), WST_ACTIVE, TRUE); /* check window state and get modified files */ for (l = h->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (CONST_WIDGET (l->data))) { e = (WEdit *) l->data; if (e->drag_state != MCEDIT_DRAG_NONE) { edit_restore_size (e); g_slist_free (m); return; } /* create separate list because widget_select() changes the window position in Z order */ if (e->modified) m = g_slist_prepend (m, l->data); } for (me = m; me != NULL; me = g_slist_next (me)) { e = (WEdit *) me->data; widget_select (WIDGET (e)); if (!edit_ok_to_exit (e)) break; } /* if all files were checked, quit editor */ if (me == NULL) dlg_stop (h); g_slist_free (m); }