Editor: optimization of menu handling.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
a2fdf8997f
Коммит
d9bb50b013
@ -178,12 +178,12 @@ extern gboolean search_create_bookmark;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int edit_drop_hotkey_menu (WEdit * e, int key);
|
||||
void edit_menu_cmd (WEdit * e);
|
||||
gboolean edit_drop_hotkey_menu (Dlg_head * h, int key);
|
||||
void edit_menu_cmd (Dlg_head * h);
|
||||
void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
|
||||
void edit_init_menu (struct WMenuBar *menubar);
|
||||
void menu_save_mode_cmd (void);
|
||||
int edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
|
||||
gboolean edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
|
||||
int edit_get_byte (WEdit * edit, long byte_index);
|
||||
int edit_get_utf (WEdit * edit, long byte_index, int *char_width);
|
||||
long edit_count_lines (WEdit * edit, long current, long upto);
|
||||
|
@ -2,11 +2,12 @@
|
||||
Editor key translation.
|
||||
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2011
|
||||
2005, 2006, 2007, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Paul Sheer, 1996, 1997
|
||||
Andrew Borodin <aborodin@vmail.ru> 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -73,7 +74,7 @@
|
||||
* Translate the keycode into either 'command' or 'char_for_insertion'.
|
||||
* 'command' is one of the editor commands from cmddef.h.
|
||||
*/
|
||||
int
|
||||
gboolean
|
||||
edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch)
|
||||
{
|
||||
unsigned long command = (unsigned long) CK_InsertChar;
|
||||
@ -198,7 +199,7 @@ edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch)
|
||||
*cmd = (int) command; /* FIXME */
|
||||
*ch = char_for_insertion;
|
||||
|
||||
return (command == (unsigned long) CK_InsertChar && char_for_insertion == -1) ? 0 : 1;
|
||||
return !(command == (unsigned long) CK_InsertChar && char_for_insertion == -1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -226,11 +226,11 @@ create_options_menu (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_drop_menu_cmd (WEdit * e, int which)
|
||||
edit_drop_menu_cmd (Dlg_head * h, int which)
|
||||
{
|
||||
WMenuBar *menubar;
|
||||
|
||||
menubar = find_menubar (e->widget.owner);
|
||||
menubar = find_menubar (h);
|
||||
|
||||
if (!menubar->is_active)
|
||||
{
|
||||
@ -239,7 +239,7 @@ edit_drop_menu_cmd (WEdit * e, int which)
|
||||
if (which >= 0)
|
||||
menubar->selected = which;
|
||||
|
||||
menubar->previous_widget = dlg_get_current_widget_id (e->widget.owner);
|
||||
menubar->previous_widget = dlg_get_current_widget_id (h);
|
||||
dlg_select_widget (menubar);
|
||||
}
|
||||
}
|
||||
@ -271,15 +271,15 @@ edit_init_menu (struct WMenuBar *menubar)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
edit_menu_cmd (WEdit * e)
|
||||
edit_menu_cmd (Dlg_head * h)
|
||||
{
|
||||
edit_drop_menu_cmd (e, -1);
|
||||
edit_drop_menu_cmd (h, -1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
edit_drop_hotkey_menu (WEdit * e, int key)
|
||||
gboolean
|
||||
edit_drop_hotkey_menu (Dlg_head * h, int key)
|
||||
{
|
||||
int m = 0;
|
||||
switch (key)
|
||||
@ -303,11 +303,11 @@ edit_drop_hotkey_menu (WEdit * e, int key)
|
||||
m = 5;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
edit_drop_menu_cmd (e, m);
|
||||
return 1;
|
||||
edit_drop_menu_cmd (h, m);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -309,16 +309,21 @@ edit_event (Gpm_Event * event, void *data)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
edit_command_execute (WEdit * edit, unsigned long command)
|
||||
edit_dialog_command_execute (Dlg_head * h, unsigned long command)
|
||||
{
|
||||
if (command == CK_Menu)
|
||||
edit_menu_cmd (edit);
|
||||
else
|
||||
gboolean ret = MSG_HANDLED;
|
||||
|
||||
switch (command)
|
||||
{
|
||||
edit_execute_key_command (edit, command, -1);
|
||||
edit_update_screen (edit);
|
||||
case CK_Menu:
|
||||
edit_menu_cmd (h);
|
||||
break;
|
||||
default:
|
||||
ret = MSG_NOT_HANDLED;
|
||||
break;
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -334,7 +339,7 @@ edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
|
||||
buttonbar_set_label (bb, 6, Q_ ("ButtonBar|Move"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 9, Q_ ("ButtonBar|PullDn"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 9, Q_ ("ButtonBar|PullDn"), editor_map, NULL);
|
||||
buttonbar_set_label (bb, 10, Q_ ("ButtonBar|Quit"), editor_map, (Widget *) edit);
|
||||
}
|
||||
|
||||
@ -374,12 +379,55 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_ACTION:
|
||||
/* shortcut */
|
||||
if (sender == NULL)
|
||||
return edit_dialog_command_execute (h, parm);
|
||||
/* message from menu */
|
||||
if (sender == (Widget *) menubar)
|
||||
return send_message ((Widget *) edit, WIDGET_COMMAND, parm);
|
||||
{
|
||||
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 */
|
||||
if (sender == (Widget *) buttonbar)
|
||||
return send_message ((Widget *) edit, WIDGET_COMMAND, parm);
|
||||
{
|
||||
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:
|
||||
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
|
||||
if (edit_ok_to_exit (edit))
|
||||
@ -425,15 +473,15 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
edit_update_screen (e);
|
||||
ret = MSG_HANDLED;
|
||||
}
|
||||
else if (edit_drop_hotkey_menu (e, parm))
|
||||
ret = MSG_HANDLED;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
case WIDGET_COMMAND:
|
||||
/* command from menubar or buttonbar */
|
||||
return edit_command_execute (e, parm);
|
||||
edit_execute_key_command (e, parm, -1);
|
||||
edit_update_screen (e);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
widget_move (w, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET + EDIT_WITH_FRAME,
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user