Browse Source

Modified menu command handling using DLG_ACTION message.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 15 years ago
parent
commit
b7f367542a
7 changed files with 50 additions and 49 deletions
  1. 0 2
      edit/edit-impl.h
  2. 0 12
      edit/editmenu.c
  3. 17 3
      edit/editwidget.c
  4. 0 12
      src/dialog.h
  5. 22 17
      src/main.c
  6. 9 3
      src/menu.c
  7. 2 0
      src/menu.h

+ 0 - 2
edit/edit-impl.h

@@ -152,8 +152,6 @@ 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_command_execute (struct Widget *sender, struct Widget *receiver,
-				unsigned long 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);

+ 0 - 12
edit/editmenu.c

@@ -52,18 +52,6 @@
 #include "edit-impl.h"
 #include "edit-widget.h"
 
-cb_ret_t
-edit_command_execute (Widget *sender, Widget *receiver,
-			unsigned long command, const void *data)
-{
-    (void) sender;
-    (void) receiver;
-    (void) data;
-    edit_execute_key_command (wedit, command, -1);
-    edit_update_screen (wedit);
-    return MSG_HANDLED;
-}
-
 static GList *
 create_file_menu (void)
 {

+ 17 - 3
edit/editwidget.c

@@ -176,12 +176,23 @@ edit_adjust_size (Dlg_head *h)
 #endif
 }
 
+static cb_ret_t
+edit_command_execute (WEdit *edit, unsigned long command)
+{
+    edit_execute_key_command (edit, command, -1);
+    edit_update_screen (edit);
+    return MSG_HANDLED;
+}
+
 /* Callback for the edit dialog */
 static cb_ret_t
 edit_dialog_callback (Dlg_head *h, Widget *sender,
 			dlg_msg_t msg, int parm, void *data)
 {
     WEdit *edit;
+    WMenuBar *menubar;
+
+    edit = (WEdit *) find_widget_type (h, edit_callback);
 
     switch (msg) {
     case DLG_RESIZE:
@@ -189,11 +200,16 @@ edit_dialog_callback (Dlg_head *h, Widget *sender,
 	return MSG_HANDLED;
 
     case DLG_VALIDATE:
-	edit = (WEdit *) find_widget_type (h, edit_callback);
 	if (!edit_ok_to_exit (edit))
 	    h->running = 1;
 	return MSG_HANDLED;
 
+    case DLG_ACTION:
+	menubar = find_menubar (h);
+	if (sender == &menubar->widget)
+	    return edit_command_execute (edit, parm);
+	return MSG_HANDLED;
+
     default:
 	return default_dlg_callback (h, sender, msg, parm, data);
     }
@@ -221,13 +237,11 @@ edit_file (const char *_file, int line)
 	create_dlg (0, 0, LINES, COLS, NULL, edit_dialog_callback,
 		    "[Internal File Editor]", NULL, DLG_WANT_TAB);
 
-    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);
     edit_init_menu (edit_menubar);
 
-
     init_widget (&(wedit->widget), 0, 0, LINES - 1, COLS,
 		 edit_callback, edit_event);
     widget_want_cursor (wedit->widget, 1);

+ 0 - 12
src/dialog.h

@@ -87,17 +87,6 @@ typedef struct Dlg_head Dlg_head;
 typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, Widget *sender,
 				dlg_msg_t msg, int parm, void *data);
 
-/* 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,
-		    unsigned long command, const void *data);
-
 /* get string representation of shortcut assigned  with command */
 /* as menu is a widget of dialog, ask dialog about shortcut string */
 typedef char * (*dlg_shortcut_str) (unsigned long command);
@@ -133,7 +122,6 @@ struct Dlg_head {
     struct Widget *current;		/* Curently active widget */
     void *data;				/* Data can be passed to dialog */
     dlg_cb_fn callback;
-    dlg_exec_fn execute;		/* Execute commands, associated with key bindings  */
     dlg_shortcut_str get_shortcut;	/* Shortcut string */
     struct Dlg_head *parent;		/* Parent dialog */
 };

+ 22 - 17
src/main.c

@@ -1135,14 +1135,11 @@ ctl_x_cmd (void)
 }
 
 static cb_ret_t
-midnight_execute_cmd (Widget *sender, Widget *receiver,
-			unsigned long command, const void *data)
+midnight_execute_cmd (Widget *sender, unsigned long command)
 {
     cb_ret_t res = MSG_HANDLED;
 
     (void) sender;
-    (void) receiver;
-    (void) data;
 
     switch (command) {
     case CK_AddHotlist:
@@ -1593,11 +1590,20 @@ midnight_callback (Dlg_head *h, Widget *sender,
 
     switch (msg) {
 
+    case DLG_DRAW:
+	load_hint (1);
+	/* We handle the special case of the output lines */
+	if (console_flag && output_lines)
+	    show_console_contents (output_start_y,
+				   LINES - output_lines - keybar_visible -
+				   1, LINES - keybar_visible - 1);
+	return MSG_HANDLED;
+
     case DLG_IDLE:
 	/* We only need the first idle event to show user menu after start */
 	set_idle_proc (h, 0);
 	if (auto_menu)
-	    midnight_execute_cmd (NULL, NULL, CK_UserMenuCmd, NULL);
+	    midnight_execute_cmd (NULL, CK_UserMenuCmd);
 	return MSG_HANDLED;
 
     case DLG_KEY:
@@ -1605,7 +1611,7 @@ midnight_callback (Dlg_head *h, Widget *sender,
 	    ctl_x_map_enabled = FALSE;
 	    command = lookup_keymap_command (main_x_map, parm);
 	    if (command != CK_Ignore_Key)
-		return midnight_execute_cmd (NULL, NULL, command, NULL);
+		return midnight_execute_cmd (NULL, command);
 	}
 
 	/* FIXME: should handle all menu shortcuts before this point */
@@ -1708,22 +1714,22 @@ midnight_callback (Dlg_head *h, Widget *sender,
 
 	return (command == CK_Ignore_Key)
 			? MSG_NOT_HANDLED
-			: midnight_execute_cmd (NULL, NULL, command, NULL);
-
-    case DLG_DRAW:
-	load_hint (1);
-	/* We handle the special case of the output lines */
-	if (console_flag && output_lines)
-	    show_console_contents (output_start_y,
-				   LINES - output_lines - keybar_visible -
-				   1, LINES - keybar_visible - 1);
-	return MSG_HANDLED;
+			: midnight_execute_cmd (NULL, command);
 
     case DLG_POST_KEY:
 	if (!the_menubar->is_active)
 	    update_dirty_panels ();
 	return MSG_HANDLED;
 
+    case DLG_ACTION:
+	/* shortcut */
+	if (sender == NULL)
+	    midnight_execute_cmd (NULL, parm);
+	/* message from menu */
+	else if (sender == &the_menubar->widget)
+	    midnight_execute_cmd (sender, parm);
+	return MSG_HANDLED;
+
     default:
 	return default_dlg_callback (h, sender, msg, parm, data);
     }
@@ -1798,7 +1804,6 @@ load_hint (int force)
 static void
 setup_panels_and_run_mc (void)
 {
-    midnight_dlg->execute = midnight_execute_cmd;
     midnight_dlg->get_shortcut = midnight_get_shortcut;
 
     add_widget (midnight_dlg, the_menubar);

+ 9 - 3
src/menu.c

@@ -314,9 +314,8 @@ menubar_execute (WMenuBar *menubar)
     if ((entry != NULL) && (entry->command != CK_Ignore_Key)) {
 	is_right = (menubar->selected != 0);
 	menubar_finish (menubar);
-	menubar->widget.parent->execute (
-			find_widget_type (menubar->widget.parent, menubar_callback),
-			NULL, entry->command, NULL);
+	menubar->widget.parent->callback (menubar->widget.parent, &menubar->widget,
+					    DLG_ACTION, entry->command, NULL);
 	do_refresh ();
     }
 }
@@ -779,3 +778,10 @@ menubar_arrange (WMenuBar* menubar)
     }
 #endif /* RESIZABLE_MENUBAR */
 }
+
+/* Find MenuBar widget in the dialog */
+WMenuBar *
+find_menubar (const Dlg_head *h)
+{
+    return (WMenuBar *) find_widget_type (h, menubar_callback);
+}

+ 2 - 0
src/menu.h

@@ -71,4 +71,6 @@ void menubar_set_menu (WMenuBar *menubar, GList *menu);
 void menubar_add_menu (WMenuBar *menubar, Menu *menu);
 void menubar_arrange (WMenuBar *menubar);
 
+WMenuBar *find_menubar (const Dlg_head *h);
+
 #endif					/* MC_MENU_H */