Ticket #212: implemented keybindings for ButtonBar.

First step: renamed type of dialog command execution function.
Made execution function more flexible: added parameters for
sender and receiver widgets and user data.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-11-01 12:23:15 +03:00
parent 95312660df
commit 71c9e4c668
7 changed files with 50 additions and 30 deletions

View File

@ -143,6 +143,7 @@ typedef enum {
} LineBreaks;
#define LB_NAMES (LB_MAC + 1)
struct Widget;
struct WMenuBar;
extern const char VERTICAL_MAGIC[5];
@ -151,7 +152,8 @@ extern int enable_show_tabs_tws;
int edit_drop_hotkey_menu (WEdit *e, int key);
void edit_menu_cmd (WEdit *e);
void edit_init_menu (struct WMenuBar *menubar);
cb_ret_t edit_menu_execute (int command);
cb_ret_t edit_command_execute (struct Widget *sender, struct Widget *receiver,
int command, const void *data);
void menu_save_mode_cmd (void);
int edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch);
int edit_get_byte (WEdit * edit, long byte_index);

View File

@ -53,8 +53,11 @@
#include "edit-widget.h"
cb_ret_t
edit_menu_execute (int command)
edit_command_execute (Widget *sender, Widget *receiver, int command, const void *data)
{
(void) sender;
(void) receiver;
(void) data;
edit_execute_key_command (wedit, command, -1);
edit_update_screen (wedit);
return MSG_HANDLED;

View File

@ -231,7 +231,7 @@ edit_file (const char *_file, int line)
add_widget (edit_dlg, wedit);
edit_dlg->menu_executor = edit_menu_execute;
edit_dlg->execute = edit_command_execute;
edit_dlg->get_shortcut = edit_get_shortcut;
edit_menubar = menubar_new (0, 0, COLS, NULL);
add_widget (edit_dlg, edit_menubar);

View File

@ -440,22 +440,20 @@ int dlg_overlap (Widget *a, Widget *b)
Widget *
find_widget_type (Dlg_head *h, callback_fn callback)
{
Widget *w;
Widget *item;
Widget *w = NULL;
if ((h != NULL) && (h->current != NULL)) {
int i;
Widget *item;
if (!h)
return 0;
if (!h->current)
return 0;
w = 0;
for (i = 0, item = h->current; i < h->count; i++, item = item->next) {
if (item->callback == callback) {
w = item;
break;
}
}
}
return w;
}

View File

@ -33,6 +33,8 @@
#define B_HELP 3
#define B_USER 100
typedef struct Widget Widget;
/* Widget messages */
typedef enum {
WIDGET_INIT, /* Initialize widget */
@ -81,11 +83,19 @@ typedef enum {
/* Dialog callback */
struct Dlg_head;
typedef struct Dlg_head Dlg_head;
typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, dlg_msg_t msg, int parm);
/* menu command execution */
typedef cb_ret_t (*menu_exec_fn) (int command);
/* keybinding commands execution
sender: the widget that sent the command with data
currently only two modes are available:
sender == NULL: the command was sent by shortcut
sender != NULL: the command was sent by menu
receiver: the widget that received command and data
should be NULL if sender is menu or buttonbar
*/
typedef cb_ret_t (*dlg_exec_fn) (Widget *sender, Widget *receiver,
int command, const void *data);
/* get string representation of shortcut assigned with command */
/* as menu is a widget of dialog, ask dialog about shortcut string */
@ -98,7 +108,7 @@ typedef char * (*dlg_shortcut_str) (int command);
#define DLG_HOT_NORMALC(h) ((h)->color[2])
#define DLG_HOT_FOCUSC(h) ((h)->color[3])
typedef struct Dlg_head {
struct Dlg_head {
/* Set by the user */
int flags; /* User flags */
const char *help_ctx; /* Name of the help entry */
@ -122,16 +132,15 @@ typedef struct Dlg_head {
struct Widget *current; /* Curently active widget */
void *data; /* Data can be passed to dialog */
dlg_cb_fn callback;
menu_exec_fn menu_executor; /* Execute menu commands */
dlg_exec_fn execute; /* Execute commands, associated with key bindings */
dlg_shortcut_str get_shortcut; /* Shortcut string */
struct Dlg_head *parent; /* Parent dialog */
} Dlg_head;
};
/* Color styles for normal and error dialogs */
extern int dialog_colors[4];
extern int alarm_colors[4];
typedef struct Widget Widget;
/* Widget callback */
typedef cb_ret_t (*callback_fn) (Widget *widget, widget_msg_t msg, int parm);

View File

@ -1126,10 +1126,15 @@ ctl_x_cmd (void)
}
static cb_ret_t
midnight_execute_cmd (int command)
midnight_execute_cmd (Widget *sender, Widget *receiver,
int command, const void *data)
{
cb_ret_t res = MSG_HANDLED;
(void) sender;
(void) receiver;
(void) data;
switch (command) {
case CK_AddHotlist:
add2hotlist_cmd ();
@ -1584,7 +1589,7 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
ctl_x_map_enabled = 0;
for (i = 0; main_x_map[i].key; i++)
if (parm == main_x_map[i].key)
return midnight_execute_cmd (main_x_map[i].command);
return midnight_execute_cmd (NULL, NULL, main_x_map[i].command, NULL);
}
/* FIXME: should handle all menu shortcuts before this point */
@ -1684,12 +1689,11 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
ctl_x_map_enabled = 0;
for (i = 0; main_x_map[i].key; i++)
if (parm == main_x_map[i].key)
return midnight_execute_cmd (main_x_map[i].command);
return midnight_execute_cmd (NULL, NULL, main_x_map[i].command, NULL);
} else {
for (i = 0; main_map[i].key; i++) {
for (i = 0; main_map[i].key; i++)
if (parm == main_map[i].key)
return midnight_execute_cmd (main_map[i].command);
}
return midnight_execute_cmd (NULL, NULL, main_map[i].command, NULL);
}
return MSG_NOT_HANDLED;
@ -1781,7 +1785,7 @@ load_hint (int force)
static void
setup_panels_and_run_mc (void)
{
midnight_dlg->menu_executor = midnight_execute_cmd;
midnight_dlg->execute = midnight_execute_cmd;
midnight_dlg->get_shortcut = midnight_get_shortcut;
add_widget (midnight_dlg, the_menubar);

View File

@ -42,6 +42,8 @@
int menubar_visible = 1; /* This is the new default */
static cb_ret_t menubar_callback (Widget *w, widget_msg_t msg, int parm);
menu_entry_t *
menu_entry_create (const char *name, int command)
{
@ -311,7 +313,9 @@ menubar_execute (WMenuBar *menubar)
if ((entry != NULL) && (entry->command != 0)) {
is_right = (menubar->selected != 0);
menubar_finish (menubar);
menubar->widget.parent->menu_executor (entry->command);
menubar->widget.parent->execute (
find_widget_type (menubar->widget.parent, menubar_callback),
NULL, entry->command, NULL);
do_refresh ();
}
}