Просмотр исходного кода

Optimize menu activation.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 9 лет назад
Родитель
Сommit
c9a437a9c2
5 измененных файлов с 36 добавлено и 21 удалено
  1. 26 0
      lib/widget/menu.c
  2. 2 0
      lib/widget/menu.h
  3. 1 11
      src/editor/editmenu.c
  4. 1 1
      src/editor/editwidget.c
  5. 6 9
      src/filemanager/midnight.c

+ 26 - 0
lib/widget/menu.c

@@ -998,3 +998,29 @@ find_menubar (const WDialog * h)
 }
 
 /* --------------------------------------------------------------------------------------------- */
+
+/**
+ * Activate menu bar.
+ *
+ * @param menubar menu bar object
+ * @param dropped whether dropdown menus should be drooped or not
+ * @which number of active dropdown menu
+ */
+void
+menubar_activate (WMenuBar * menubar, gboolean dropped, int which)
+{
+    Widget *w = WIDGET (menubar);
+
+    if (!menubar->is_active)
+    {
+        menubar->is_active = TRUE;
+        menubar->is_dropped = dropped;
+        if (which >= 0)
+            menubar->selected = (guint) which;
+
+        menubar->previous_widget = dlg_get_current_widget_id (w->owner);
+        dlg_select_widget (w);
+    }
+}
+
+/* --------------------------------------------------------------------------------------------- */

+ 2 - 0
lib/widget/menu.h

@@ -56,6 +56,8 @@ void menubar_arrange (WMenuBar * menubar);
 
 WMenuBar *find_menubar (const WDialog * h);
 
+void menubar_activate (WMenuBar * menubar, gboolean dropped, int which);
+
 /*** inline functions ****************************************************************************/
 
 static inline void

+ 1 - 11
src/editor/editmenu.c

@@ -268,17 +268,7 @@ edit_drop_menu_cmd (WDialog * h, int which)
     WMenuBar *menubar;
 
     menubar = find_menubar (h);
-
-    if (!menubar->is_active)
-    {
-        menubar->is_active = TRUE;
-        menubar->is_dropped = (drop_menus != 0);
-        if (which >= 0)
-            menubar->selected = (guint) which;
-
-        menubar->previous_widget = dlg_get_current_widget_id (h);
-        dlg_select_widget (menubar);
-    }
+    menubar_activate (menubar, drop_menus != 0, which);
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 1 - 1
src/editor/editwidget.c

@@ -916,7 +916,7 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
             }
 
             if (unhandled)
-                dlg_select_widget (b);
+                menubar_activate (b, drop_menus != 0, -1);
         }
     }
 

+ 6 - 9
src/filemanager/midnight.c

@@ -368,10 +368,7 @@ init_menu (void)
 static void
 menu_last_selected_cmd (void)
 {
-    the_menubar->is_active = TRUE;
-    the_menubar->is_dropped = (drop_menus != 0);
-    the_menubar->previous_widget = dlg_get_current_widget_id (midnight_dlg);
-    dlg_select_widget (the_menubar);
+    menubar_activate (the_menubar, drop_menus != 0, -1);
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -379,14 +376,14 @@ menu_last_selected_cmd (void)
 static void
 menu_cmd (void)
 {
-    if (the_menubar->is_active)
-        return;
+    int selected;
 
     if ((get_current_index () == 0) == (current_panel->active != 0))
-        the_menubar->selected = 0;
+        selected = 0;
     else
-        the_menubar->selected = g_list_length (the_menubar->menu) - 1;
-    menu_last_selected_cmd ();
+        selected = g_list_length (the_menubar->menu) - 1;
+
+    menubar_activate (the_menubar, drop_menus != 0, selected);
 }
 
 /* --------------------------------------------------------------------------------------------- */