From: "Rodolfo García Peñas (kix)" <k...@kix.es>

The function dockMenuCreate is splitted in four functions:

- create_clip_main_menu(WScreen*)
- create_dock_main_menu(WScreen*)
- create_drawer_main_menu(WScreen*)
- dockMenuCreate(WScreen*, int*)

The function create_clip_main_menu() creates the menu and the menu items
when the menu is for a Clip.

The function create_dock_main_menu() creates the menu and the menu items
when the menu is for a Dock.

The function create_drawer_main_menu() creates the menu and the menu items
when the menu is for a Drawer.

The function dockMenuCreate() is now smaller, and more clear. The function
select if the menu creation is for a clip, drawer or dock, and then call the
right function. The function uses switch-case instead if-else and controls
if the Clip or Drawer were previously created. The menu and menuitem creation
is outside then, is easier to understand it.

This patch introduces a "code duplication" for some items, but removes some
checks about "is Clip?", "is Drawer",... This code duplication is better
because the menuitem position could be differente for Clip, Dock or Drawer.
---
 src/dock.c |  194 +++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 134 insertions(+), 60 deletions(-)

diff --git a/src/dock.c b/src/dock.c
index 7f277c5..2801617 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -1184,79 +1184,130 @@ static WMenu *makeDockPositionMenu(WScreen *scr)
        return menu;
 }
 
-
-static WMenu *dockMenuCreate(WScreen *scr, int type)
+static WMenu *create_dock_main_menu(WScreen *scr)
 {
        WMenu *menu;
        WMenuEntry *entry;
 
-       if (type == WM_CLIP && scr->clip_menu)
-               return scr->clip_menu;
+       menu = wMenuCreate(scr, NULL, False);
+       entry = wMenuAddCallback(menu, _("Dock position"), NULL, NULL);
+       if (scr->dock_pos_menu == NULL)
+               scr->dock_pos_menu = makeDockPositionMenu(scr);
+       wMenuEntrySetCascade(menu, entry, scr->dock_pos_menu);
+
+       if (!wPreferences.flags.nodrawer)
+               entry = wMenuAddCallback(menu, _("Add a drawer"), 
addADrawerCallback, NULL);
+
+       wMenuAddCallback(menu, _("Launch"), launchCallback, NULL);
+       wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
+
+       entry = wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Hide"); /* can be: Unhide */
 
-       if (type == WM_DRAWER && scr->drawer_menu)
-               return scr->drawer_menu;
+       wMenuAddCallback(menu, _("Settings..."), settingsCallback, NULL);
+
+       entry = wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Kill"); /* can be: Remove drawer */
+
+       return menu;
+}
+
+static WMenu *create_clip_main_menu(WScreen *scr)
+{
+       WMenu *menu;
+       WMenuEntry *entry;
 
        menu = wMenuCreate(scr, NULL, False);
-       if (type == WM_DOCK) {
-               entry = wMenuAddCallback(menu, _("Dock position"), NULL, NULL);
-               if (scr->dock_pos_menu == NULL)
-                       scr->dock_pos_menu = makeDockPositionMenu(scr);
-               wMenuEntrySetCascade(menu, entry, scr->dock_pos_menu);
+       entry = wMenuAddCallback(menu, _("Clip Options"), NULL, NULL);
 
-               if (!wPreferences.flags.nodrawer) {
-                       entry = wMenuAddCallback(menu, _("Add a drawer"), 
addADrawerCallback, NULL);
-               }
-       } else {
-               if (type == WM_CLIP)
-                       entry = wMenuAddCallback(menu, _("Clip Options"), NULL, 
NULL);
-               else /* if (type == WM_DRAWER) */
-                       entry = wMenuAddCallback(menu, _("Drawer options"), 
NULL, NULL);
-
-               if (scr->clip_options == NULL)
-                       scr->clip_options = makeClipOptionsMenu(scr);
-               wMenuEntrySetCascade(menu, entry, scr->clip_options);
-
-                /* The same menu is used for the dock and its appicons. If the 
menu
-                 * entry text is different between the two contexts, or if it 
can
-                 * change depending on some state, free the duplicated string 
(from
-                 * wMenuInsertCallback) and use gettext's string */
-               if (type == WM_CLIP) {
-                       entry = wMenuAddCallback(menu, _("Rename Workspace"), 
renameCallback, NULL);
-                       wfree(entry->text);
-                       entry->text = _("Rename Workspace"); /* can be: 
(Toggle) Omnipresent */
-               }
+       if (scr->clip_options == NULL)
+               scr->clip_options = makeClipOptionsMenu(scr);
 
-               entry = wMenuAddCallback(menu, _("Selected"), selectCallback, 
NULL);
-               entry->flags.indicator = 1;
-               entry->flags.indicator_on = 1;
-               entry->flags.indicator_type = MI_CHECK;
+       wMenuEntrySetCascade(menu, entry, scr->clip_options);
 
-               entry = wMenuAddCallback(menu, _("Select All Icons"), 
selectIconsCallback, NULL);
-               wfree(entry->text);
-               entry->text = _("Select All Icons"); /* can be: Unselect all 
icons */
+       /* The same menu is used for the dock and its appicons. If the menu
+        * entry text is different between the two contexts, or if it can
+        * change depending on some state, free the duplicated string (from
+        * wMenuInsertCallback) and use gettext's string */
+       entry = wMenuAddCallback(menu, _("Rename Workspace"), renameCallback, 
NULL);
+       wfree(entry->text);
+       entry->text = _("Rename Workspace"); /* can be: (Toggle) Omnipresent */
 
-               entry = wMenuAddCallback(menu, _("Keep Icon"), 
keepIconsCallback, NULL);
-               wfree(entry->text);
-               entry->text = _("Keep Icon"); /* can be: Keep Icons */
+       entry = wMenuAddCallback(menu, _("Selected"), selectCallback, NULL);
+       entry->flags.indicator = 1;
+       entry->flags.indicator_on = 1;
+       entry->flags.indicator_type = MI_CHECK;
 
-               if (type == WM_CLIP) {
-                       entry = wMenuAddCallback(menu, _("Move Icon To"), NULL, 
NULL);
-                       wfree(entry->text);
-                       entry->text = _("Move Icon To"); /* can be: Move Icons 
to */
-                       scr->clip_submenu = makeWorkspaceMenu(scr);
-                       if (scr->clip_submenu)
-                               wMenuEntrySetCascade(menu, entry, 
scr->clip_submenu);
-               }
+       entry = wMenuAddCallback(menu, _("Select All Icons"), 
selectIconsCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Select All Icons"); /* can be: Unselect all icons */
 
-               entry = wMenuAddCallback(menu, _("Remove Icon"), 
removeIconsCallback, NULL);
-               wfree(entry->text);
-               entry->text = _("Remove Icon"); /* can be: Remove Icons */
+       entry = wMenuAddCallback(menu, _("Keep Icon"), keepIconsCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Keep Icon"); /* can be: Keep Icons */
 
-               wMenuAddCallback(menu, _("Attract Icons"), colectIconsCallback, 
NULL);
-       }
+       entry = wMenuAddCallback(menu, _("Move Icon To"), NULL, NULL);
+       wfree(entry->text);
+       entry->text = _("Move Icon To"); /* can be: Move Icons to */
+       scr->clip_submenu = makeWorkspaceMenu(scr);
+       if (scr->clip_submenu)
+               wMenuEntrySetCascade(menu, entry, scr->clip_submenu);
 
+       entry = wMenuAddCallback(menu, _("Remove Icon"), removeIconsCallback, 
NULL);
+       wfree(entry->text);
+       entry->text = _("Remove Icon"); /* can be: Remove Icons */
+
+       wMenuAddCallback(menu, _("Attract Icons"), colectIconsCallback, NULL);
        wMenuAddCallback(menu, _("Launch"), launchCallback, NULL);
+       wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
+
+       entry = wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Hide"); /* can be: Unhide */
+
+       wMenuAddCallback(menu, _("Settings..."), settingsCallback, NULL);
+
+       entry = wMenuAddCallback(menu, _("Kill"), killCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Kill"); /* can be: Remove drawer */
+
+       return menu;
+}
+
+static WMenu *create_drawer_main_menu(WScreen *scr)
+{
+       WMenu *menu;
+       WMenuEntry *entry;
 
+       menu = wMenuCreate(scr, NULL, False);
+       entry = wMenuAddCallback(menu, _("Drawer options"), NULL, NULL);
+
+       if (scr->clip_options == NULL)
+               scr->clip_options = makeClipOptionsMenu(scr);
+
+       wMenuEntrySetCascade(menu, entry, scr->clip_options);
+
+       entry = wMenuAddCallback(menu, _("Selected"), selectCallback, NULL);
+       entry->flags.indicator = 1;
+       entry->flags.indicator_on = 1;
+       entry->flags.indicator_type = MI_CHECK;
+
+       entry = wMenuAddCallback(menu, _("Select All Icons"), 
selectIconsCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Select All Icons"); /* can be: Unselect all icons */
+
+       entry = wMenuAddCallback(menu, _("Keep Icon"), keepIconsCallback, NULL);
+       wfree(entry->text);
+       entry->text = _("Keep Icon"); /* can be: Keep Icons */
+
+       entry = wMenuAddCallback(menu, _("Remove Icon"), removeIconsCallback, 
NULL);
+       wfree(entry->text);
+       entry->text = _("Remove Icon"); /* can be: Remove Icons */
+
+       wMenuAddCallback(menu, _("Attract Icons"), colectIconsCallback, NULL);
+       wMenuAddCallback(menu, _("Launch"), launchCallback, NULL);
        wMenuAddCallback(menu, _("Unhide Here"), unhideHereCallback, NULL);
 
        entry = wMenuAddCallback(menu, _("Hide"), hideCallback, NULL);
@@ -1269,11 +1320,34 @@ static WMenu *dockMenuCreate(WScreen *scr, int type)
        wfree(entry->text);
        entry->text = _("Kill"); /* can be: Remove drawer */
 
-       if (type == WM_CLIP)
-               scr->clip_menu = menu;
+       return menu;
+}
 
-       if (type == WM_DRAWER)
-               scr->drawer_menu = menu;
+static WMenu *dockMenuCreate(WScreen *scr, int type)
+{
+       WMenu *menu = NULL;
+
+       switch (type) {
+       case WM_DOCK:
+               menu = create_dock_main_menu(scr);
+               break;
+       case WM_CLIP:
+               if (scr->clip_menu) {
+                       menu = scr->clip_menu;
+               } else {
+                       menu = create_clip_main_menu(scr);
+                       scr->clip_menu = menu;
+               }
+               break;
+       case WM_DRAWER:
+               if (scr->drawer_menu) {
+                       menu = scr->drawer_menu;
+               } else {
+                       menu = create_drawer_main_menu(scr);
+                       scr->drawer_menu = menu;
+               }
+               break;
+       }
 
        return menu;
 }
-- 
1.7.10.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to