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; }
WEdit * find_editor (const WDialog * h) { if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) return (WEdit *) h->current->data; return (WEdit *) find_widget_type (h, edit_callback); }
WEdit * find_editor (const Dlg_head * h) { if (edit_widget_is_editor ((Widget *) h->current->data)) return (WEdit *) h->current->data; return (WEdit *) find_widget_type (h, edit_callback); }
static void edit_reset_over_col (void *data, void *user_data) { (void) user_data; if (edit_widget_is_editor ((const Widget *) data)) ((WEdit *) data)->over_col = 0; }
/** * Handle mouse events of editor screen. * * @param w Widget object (the editor) * @param msg mouse event message * @param event mouse event data */ static void edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) { gboolean unhandled = TRUE; if (msg == MSG_MOUSE_DOWN && event->y == 0) { WDialog *h = DIALOG (w); WMenuBar *b; b = find_menubar (h); if (!widget_get_state (WIDGET (b), WST_FOCUSED)) { /* menubar */ GList *l; GList *top = NULL; int x; /* Try find top fullscreen window */ for (l = h->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (CONST_WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen) top = l; /* Handle fullscreen/close buttons in the top line */ x = w->cols - 6; if (top != NULL && event->x >= x) { WEdit *e = (WEdit *) top->data; if (top != h->current) { /* Window is not active. Activate it */ widget_select (WIDGET (e)); } /* Handle buttons */ if (event->x - x <= 2) edit_toggle_fullscreen (e); else send_message (h, NULL, MSG_ACTION, CK_Close, NULL); unhandled = FALSE; } if (unhandled) menubar_activate (b, drop_menus, -1); } } /* Continue handling of unhandled event in window or menu */ event->result.abort = unhandled; }
static int edit_dialog_event (Gpm_Event * event, void *data) { WDialog *h = DIALOG (data); Widget *w; Widget *wh = WIDGET (h); int ret = MOU_UNHANDLED; w = WIDGET (find_menubar (h)); if (event->y == wh->y + 1 && (event->type & GPM_DOWN) != 0 && !MENUBAR (w)->is_active) { /* menubar */ GList *l; GList *top = NULL; int x; /* Try find top fullscreen window */ for (l = h->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen) top = l; /* Handle fullscreen/close buttons in the top line */ x = wh->x + wh->cols + 1 - 6; if (top != NULL && event->x >= x) { WEdit *e; e = (WEdit *) top->data; x = event->x - x; if (top != h->current) { /* Window is not active. Activate it */ dlg_set_top_widget (e); } /* Handle buttons */ if (x <= 2) edit_toggle_fullscreen (e); else send_message (h, NULL, MSG_ACTION, CK_Close, NULL); ret = MOU_NORMAL; } if (ret == MOU_UNHANDLED) dlg_select_widget (w); } return ret; }
static void edit_reload_syntax (void *data, void *user_data) { (void) user_data; if (edit_widget_is_editor (WIDGET (data))) { WEdit *edit = (WEdit *) data; edit_load_syntax (edit, NULL, edit->syntax_type); } }
static int edit_dialog_event (Gpm_Event * event, void *data) { Dlg_head *h = (Dlg_head *) data; Widget *w; int ret = MOU_UNHANDLED; w = (Widget *) find_menubar (h); if (event->y == h->y + 1 && (event->type & GPM_DOWN) != 0 && !((WMenuBar *) w)->is_active) { /* menubar */ GList *l; GList *top = NULL; int x; /* Try find top fullscreen window */ for (l = h->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor ((Widget *) l->data) && ((WEdit *) l->data)->fullscreen) top = l; /* Handle fullscreen/close buttons in the top line */ x = h->x + h->cols + 1 - 6; if (top != NULL && event->x >= x) { WEdit *e; e = (WEdit *) top->data; x = event->x - x; if (top != h->current) { /* Window is not active. Activate it */ dlg_set_top_widget (e); } /* Handle buttons */ if (x <= 2) edit_toggle_fullscreen (e); else edit_dialog_callback (h, NULL, DLG_ACTION, CK_Close, NULL); ret = MOU_NORMAL; } if (ret == MOU_UNHANDLED) dlg_select_widget (w); } return ret; }
static void edit_dialog_resize_cb (void *data, void *user_data) { Widget *w = WIDGET (data); (void) user_data; if (edit_widget_is_editor (w) && ((WEdit *) w)->fullscreen) { Widget *wh = WIDGET (w->owner); w->lines = wh->lines - 2; w->cols = wh->cols; } }
static void edit_dialog_resize_cb (void *data, void *user_data) { Widget *w = (Widget *) data; (void) user_data; if (edit_widget_is_editor (w) && ((WEdit *) w)->fullscreen) { Dlg_head *h = w->owner; w->lines = h->lines - 2; w->cols = h->cols; } }
static void edit_window_list (const Dlg_head * h) { const size_t offset = 2; /* skip menu and buttonbar */ const size_t dlg_num = g_list_length (h->widgets) - offset; int lines, cols; Listbox *listbox; GList *w; int i = 0; int rv; lines = min ((size_t) (LINES * 2 / 3), dlg_num); cols = COLS * 2 / 3; listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); for (w = h->widgets; w != NULL; w = g_list_next (w)) if (edit_widget_is_editor ((Widget *) w->data)) { WEdit *e = (WEdit *) w->data; char *fname; if (e->filename_vpath == NULL) fname = g_strdup_printf ("%c [%s]", e->modified ? '*' : ' ', _("NoName")); else { char *fname2; fname2 = vfs_path_to_str (e->filename_vpath); fname = g_strdup_printf ("%c%s", e->modified ? '*' : ' ', fname2); g_free (fname2); } listbox_add_item (listbox->list, LISTBOX_APPEND_AT_END, get_hotkey (i++), str_term_trim (fname, listbox->list->widget.cols - 2), NULL); g_free (fname); } rv = g_list_position (h->widgets, h->current) - offset; listbox_select_entry (listbox->list, rv); rv = run_listbox (listbox); if (rv >= 0) { w = g_list_nth (h->widgets, rv + offset); dlg_set_top_widget (w->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); }
static void edit_window_list (const WDialog * h) { const size_t dlg_num = g_list_length (h->widgets) - 2; /* 2 = skip menu and buttonbar */ int lines, cols; Listbox *listbox; GList *w; WEdit *selected; int i = 0; lines = MIN ((size_t) (LINES * 2 / 3), dlg_num); cols = COLS * 2 / 3; listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); for (w = h->widgets; w != NULL; w = g_list_next (w)) if (edit_widget_is_editor (CONST_WIDGET (w->data))) { WEdit *e = (WEdit *) w->data; char *fname; if (e->filename_vpath == NULL) fname = g_strdup_printf ("%c [%s]", e->modified ? '*' : ' ', _("NoName")); else fname = g_strdup_printf ("%c%s", e->modified ? '*' : ' ', vfs_path_as_str (e->filename_vpath)); listbox_add_item (listbox->list, LISTBOX_APPEND_AT_END, get_hotkey (i++), str_term_trim (fname, WIDGET (listbox->list)->cols - 2), e, FALSE); g_free (fname); } selected = run_listbox_with_data (listbox, h->current->data); if (selected != NULL) widget_select (WIDGET (selected)); }
static cb_ret_t edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WMenuBar *menubar; WButtonBar *buttonbar; WDialog *h = DIALOG (w); switch (msg) { case MSG_INIT: edit_dlg_init (); return MSG_HANDLED; case MSG_DRAW: /* don't use dlg_default_repaint() -- we don't need a frame */ tty_setcolor (EDITOR_BACKGROUND); dlg_erase (h); return MSG_HANDLED; case MSG_RESIZE: menubar = find_menubar (h); buttonbar = find_buttonbar (h); /* dlg_set_size() is surplus for this case */ w->lines = LINES; w->cols = COLS; widget_set_size (WIDGET (buttonbar), w->lines - 1, w->x, 1, w->cols); widget_set_size (WIDGET (menubar), w->y, w->x, 1, w->cols); menubar_arrange (menubar); g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL); return MSG_HANDLED; case MSG_ACTION: { /* Handle shortcuts, menu, and buttonbar. */ cb_ret_t result; result = edit_dialog_command_execute (h, parm); /* We forward any commands coming from the menu, and which haven't been handled by the dialog, to the focused WEdit window. */ if (result == MSG_NOT_HANDLED && sender == WIDGET (find_menubar (h))) result = send_message (h->current->data, NULL, MSG_ACTION, parm, NULL); return result; } case MSG_KEY: { Widget *we = WIDGET (h->current->data); cb_ret_t ret = MSG_NOT_HANDLED; if (edit_widget_is_editor (we)) { WEdit *e = (WEdit *) we; long command; if (!e->extmod) command = keybind_lookup_keymap_command (editor_map, parm); else command = keybind_lookup_keymap_command (editor_x_map, parm); if (command == CK_IgnoreKey) e->extmod = FALSE; else { ret = edit_dialog_command_execute (h, command); /* if command was not handled, keep the extended mode for the further key processing */ if (ret == MSG_HANDLED) e->extmod = FALSE; } } /* * Due to the "end of bracket" escape the editor sees input with is_idle() == false * (expects more characters) and hence doesn't yet refresh the screen, but then * no further characters arrive (there's only an "end of bracket" which is swallowed * by tty_get_event()), so you end up with a screen that's not refreshed after pasting. * So let's trigger an IDLE signal. */ if (!is_idle ()) widget_idle (w, TRUE); return ret; } /* hardcoded menu hotkeys (see edit_drop_hotkey_menu) */ case MSG_UNHANDLED_KEY: return edit_drop_hotkey_menu (h, parm) ? MSG_HANDLED : MSG_NOT_HANDLED; case MSG_VALIDATE: edit_quit (h); return MSG_HANDLED; case MSG_END: edit_dlg_deinit (); return MSG_HANDLED; case MSG_IDLE: widget_idle (w, FALSE); return send_message (h->current->data, NULL, MSG_IDLE, 0, NULL); default: return dlg_default_callback (w, sender, msg, parm, data); } }
static cb_ret_t edit_dialog_command_execute (WDialog * h, long command) { Widget *wh = WIDGET (h); cb_ret_t ret = MSG_HANDLED; switch (command) { case CK_EditNew: edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0); break; case CK_EditFile: edit_load_cmd (h); break; case CK_EditSyntaxFile: edit_load_syntax_file (h); break; case CK_EditUserMenu: edit_load_menu_file (h); break; case CK_Close: /* if there are no opened files anymore, close MC editor */ if (edit_widget_is_editor (CONST_WIDGET (h->current->data)) && edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) dlg_stop (h); break; case CK_Help: edit_help (); /* edit->force |= REDRAW_COMPLETELY; */ break; case CK_Menu: edit_menu_cmd (h); break; case CK_Quit: case CK_Cancel: /* don't close editor due to SIGINT, but stop move/resize window */ { Widget *w = WIDGET (h->current->data); if (edit_widget_is_editor (w) && ((WEdit *) w)->drag_state != MCEDIT_DRAG_NONE) edit_restore_size ((WEdit *) w); else if (command == CK_Quit) dlg_stop (h); } break; case CK_About: edit_about (); break; case CK_SyntaxOnOff: edit_syntax_onoff_cmd (h); break; case CK_ShowTabTws: edit_show_tabs_tws_cmd (h); break; case CK_ShowMargin: edit_show_margin_cmd (h); break; case CK_ShowNumbers: edit_show_numbers_cmd (h); break; case CK_Refresh: edit_refresh_cmd (); break; case CK_Shell: view_other_cmd (); break; case CK_LearnKeys: learn_keys (); break; case CK_WindowMove: case CK_WindowResize: if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) edit_handle_move_resize ((WEdit *) h->current->data, command); break; case CK_WindowList: edit_window_list (h); break; case CK_WindowNext: dlg_select_next_widget (h); break; case CK_WindowPrev: dlg_select_prev_widget (h); break; case CK_Options: edit_options_dialog (h); break; case CK_OptionsSaveMode: edit_save_mode_cmd (); break; case CK_SaveSetup: save_setup_cmd (); break; default: ret = MSG_NOT_HANDLED; break; } return ret; }
static cb_ret_t edit_dialog_command_execute (Dlg_head * h, unsigned long command) { gboolean ret = MSG_HANDLED; switch (command) { case CK_EditNew: edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, NULL, 0); break; case CK_EditFile: edit_load_cmd (h); break; case CK_EditSyntaxFile: edit_load_syntax_file (h); break; case CK_EditUserMenu: edit_load_menu_file (h); break; case CK_Close: /* if there are no opened files anymore, close MC editor */ if (edit_widget_is_editor ((Widget *) h->current->data) && edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) dlg_stop (h); break; case CK_Help: edit_help (); /* edit->force |= REDRAW_COMPLETELY; */ break; case CK_Menu: edit_menu_cmd (h); break; case CK_Quit: case CK_Cancel: { Widget *w = (Widget *) h->current->data; if (!edit_widget_is_editor (w) || ((WEdit *) w)->drag_state == MCEDIT_DRAG_NORMAL) dlg_stop (h); else edit_restore_size ((WEdit *) w); } break; case CK_About: edit_about (); break; case CK_SyntaxOnOff: edit_syntax_onoff_cmd (h); break; case CK_ShowTabTws: edit_show_tabs_tws_cmd (h); break; case CK_ShowMargin: edit_show_margin_cmd (h); break; case CK_ShowNumbers: edit_show_numbers_cmd (h); break; case CK_Refresh: edit_refresh_cmd (); break; case CK_Shell: view_other_cmd (); break; case CK_LearnKeys: learn_keys (); break; case CK_WindowMove: case CK_WindowResize: if (edit_widget_is_editor ((Widget *) h->current->data)) edit_handle_move_resize ((WEdit *) h->current->data, command); break; case CK_WindowList: edit_window_list (h); break; case CK_WindowNext: dlg_one_down (h); dlg_set_top_widget (h->current->data); break; case CK_WindowPrev: dlg_one_up (h); dlg_set_top_widget (h->current->data); break; case CK_Options: edit_options_dialog (h); break; case CK_OptionsSaveMode: edit_save_mode_cmd (); break; case CK_SaveSetup: save_setup_cmd (); break; default: ret = MSG_NOT_HANDLED; break; } return ret; }
static cb_ret_t edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { WMenuBar *menubar; WButtonBar *buttonbar; switch (msg) { case DLG_INIT: edit_dlg_init (); return MSG_HANDLED; case DLG_DRAW: /* don't use common_dialog_repaint() -- we don't need a frame */ tty_setcolor (EDITOR_BACKGROUND); dlg_erase (h); return MSG_HANDLED; case DLG_RESIZE: menubar = find_menubar (h); buttonbar = find_buttonbar (h); /* 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); g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL); return MSG_HANDLED; case DLG_ACTION: /* shortcut */ if (sender == NULL) return edit_dialog_command_execute (h, parm); /* message from menu */ menubar = find_menubar (h); if (sender == (Widget *) menubar) { if (edit_dialog_command_execute (h, parm) == MSG_HANDLED) return MSG_HANDLED; /* try send command to the current window */ return send_message ((Widget *) h->current->data, WIDGET_COMMAND, parm); } /* message from buttonbar */ buttonbar = find_buttonbar (h); if (sender == (Widget *) buttonbar) { if (data != NULL) return send_message ((Widget *) data, WIDGET_COMMAND, parm); return edit_dialog_command_execute (h, parm); } return MSG_NOT_HANDLED; case DLG_KEY: { Widget *w = h->current->data; cb_ret_t ret = MSG_NOT_HANDLED; if (edit_widget_is_editor (w)) { WEdit *e = (WEdit *) w; unsigned long command; if (!e->extmod) command = keybind_lookup_keymap_command (editor_map, parm); else { e->extmod = FALSE; command = keybind_lookup_keymap_command (editor_x_map, parm); } if (command != CK_IgnoreKey) ret = edit_dialog_command_execute (h, command); } return ret; } /* hardcoded menu hotkeys (see edit_drop_hotkey_menu) */ case DLG_UNHANDLED_KEY: return edit_drop_hotkey_menu (h, parm) ? MSG_HANDLED : MSG_NOT_HANDLED; case DLG_VALIDATE: edit_quit (h); return MSG_HANDLED; case DLG_END: edit_dlg_deinit (); return MSG_HANDLED; default: return default_dlg_callback (h, sender, msg, parm, data); } }