1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

Make OPEN_MENU be able to include PropList menus

Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
Tamas TEVESZ
2010-09-30 17:36:22 +02:00
committed by Carlos R. Mafra
parent c37046e6a9
commit 70abda81d0

View File

@@ -63,6 +63,7 @@ extern WPreferences wPreferences;
static WMenu *readMenuPipe(WScreen * scr, char **file_name); static WMenu *readMenuPipe(WScreen * scr, char **file_name);
static WMenu *readMenuFile(WScreen * scr, char *file_name); static WMenu *readMenuFile(WScreen * scr, char *file_name);
static WMenu *readMenuDirectory(WScreen * scr, char *title, char **file_name, char *command); static WMenu *readMenuDirectory(WScreen * scr, char *title, char **file_name, char *command);
static WMenu *configureMenu(WScreen * scr, WMPropList * definition, Bool includeGlobals);
typedef struct Shortcut { typedef struct Shortcut {
struct Shortcut *next; struct Shortcut *next;
@@ -575,6 +576,26 @@ static void separateCommand(char *line, char ***file, char **command)
WMFreeArray(array); WMFreeArray(array);
} }
static WMenu *constructPLMenu(WScreen *screen, char *path)
{
WMPropList *pl = NULL;
WMenu *menu = NULL;
if (!path)
return NULL;
pl = WMReadPropListFromFile(path);
if (!pl)
return NULL;
menu = configureMenu(screen, pl, False);
if (!menu)
return NULL;
menu->on_destroy = removeShortcutsForMenu;
return menu;
}
static void constructMenu(WMenu * menu, WMenuEntry * entry) static void constructMenu(WMenu * menu, WMenuEntry * entry)
{ {
WMenu *submenu; WMenu *submenu;
@@ -610,67 +631,74 @@ static void constructMenu(WMenu * menu, WMenuEntry * entry)
} }
} else { } else {
i = 0;
while (path[i] != NULL) {
char *tmp;
if (strcmp(path[i], "-noext") == 0) { /* try interpreting path as a proplist file */
submenu = constructPLMenu(menu->frame->screen_ptr, path[0]);
/* if unsuccessful, try it as an old-style file */
if (!submenu) {
i = 0;
while (path[i] != NULL) {
char *tmp;
if (strcmp(path[i], "-noext") == 0) {
i++;
continue;
}
tmp = wexpandpath(path[i]);
wfree(path[i]);
lpath = getLocalizedMenuFile(tmp);
if (lpath) {
wfree(tmp);
path[i] = lpath;
lpath = NULL;
} else {
path[i] = tmp;
}
if (stat(path[i], &stat_buf) == 0) {
if (last < stat_buf.st_mtime)
last = stat_buf.st_mtime;
if (first < 0)
first = i;
} else {
werror(_("%s:could not stat menu"), path[i]);
/*goto finish; */
}
i++; i++;
continue;
} }
tmp = wexpandpath(path[i]); if (first < 0) {
wfree(path[i]); werror(_("%s:could not stat menu:%s"), "OPEN_MENU", (char *)entry->clientdata);
lpath = getLocalizedMenuFile(tmp); goto finish;
if (lpath) {
wfree(tmp);
path[i] = lpath;
lpath = NULL;
} else {
path[i] = tmp;
} }
stat(path[first], &stat_buf);
if (!menu->cascades[entry->cascade]
|| menu->cascades[entry->cascade]->timestamp < last) {
if (stat(path[i], &stat_buf) == 0) { if (S_ISDIR(stat_buf.st_mode)) {
if (last < stat_buf.st_mtime) /* menu directory */
last = stat_buf.st_mtime; submenu = readMenuDirectory(menu->frame->screen_ptr, entry->text, path, cmd);
if (first < 0) if (submenu)
first = i; submenu->timestamp = last;
} else { } else if (S_ISREG(stat_buf.st_mode)) {
werror(_("%s:could not stat menu"), path[i]); /* menu file */
/*goto finish; */
}
i++; if (cmd || path[1])
} wwarning(_("too many parameters in OPEN_MENU: %s"),
(char *)entry->clientdata);
if (first < 0) { submenu = readMenuFile(menu->frame->screen_ptr, path[first]);
werror(_("%s:could not stat menu:%s"), "OPEN_MENU", (char *)entry->clientdata); if (submenu)
goto finish; submenu->timestamp = stat_buf.st_mtime;
} } else {
stat(path[first], &stat_buf); submenu = NULL;
if (!menu->cascades[entry->cascade] }
|| menu->cascades[entry->cascade]->timestamp < last) {
if (S_ISDIR(stat_buf.st_mode)) {
/* menu directory */
submenu = readMenuDirectory(menu->frame->screen_ptr, entry->text, path, cmd);
if (submenu)
submenu->timestamp = last;
} else if (S_ISREG(stat_buf.st_mode)) {
/* menu file */
if (cmd || path[1])
wwarning(_("too many parameters in OPEN_MENU: %s"),
(char *)entry->clientdata);
submenu = readMenuFile(menu->frame->screen_ptr, path[first]);
if (submenu)
submenu->timestamp = stat_buf.st_mtime;
} else { } else {
submenu = NULL; submenu = NULL;
} }
} else {
submenu = NULL;
} }
} }
@@ -1473,7 +1501,7 @@ static WMenu *makeDefaultMenu(WScreen * scr)
* *
*---------------------------------------------------------------------- *----------------------------------------------------------------------
*/ */
static WMenu *configureMenu(WScreen * scr, WMPropList * definition) static WMenu *configureMenu(WScreen * scr, WMPropList * definition, Bool includeGlobals)
{ {
WMenu *menu = NULL; WMenu *menu = NULL;
WMPropList *elem; WMPropList *elem;
@@ -1552,7 +1580,7 @@ static WMenu *configureMenu(WScreen * scr, WMPropList * definition)
menu->on_destroy = removeShortcutsForMenu; menu->on_destroy = removeShortcutsForMenu;
#ifdef GLOBAL_SUBMENU_FILE #ifdef GLOBAL_SUBMENU_FILE
{ if (includeGlobals) {
WMenu *submenu; WMenu *submenu;
WMenuEntry *mentry; WMenuEntry *mentry;
@@ -1583,7 +1611,7 @@ static WMenu *configureMenu(WScreen * scr, WMPropList * definition)
WMenuEntry *mentry; WMenuEntry *mentry;
/* submenu */ /* submenu */
submenu = configureMenu(scr, elem); submenu = configureMenu(scr, elem, True);
if (submenu) { if (submenu) {
mentry = wMenuAddCallback(menu, submenu->frame->title, NULL, NULL); mentry = wMenuAddCallback(menu, submenu->frame->title, NULL, NULL);
wMenuEntrySetCascade(menu, mentry, submenu); wMenuEntrySetCascade(menu, mentry, submenu);
@@ -1678,14 +1706,14 @@ void OpenRootMenu(WScreen * scr, int x, int y, int keyboard)
if (definition) { if (definition) {
if (WMIsPLArray(definition)) { if (WMIsPLArray(definition)) {
if (!scr->root_menu || WDRootMenu->timestamp > scr->root_menu->timestamp) { if (!scr->root_menu || WDRootMenu->timestamp > scr->root_menu->timestamp) {
menu = configureMenu(scr, definition); menu = configureMenu(scr, definition, True);
if (menu) if (menu)
menu->timestamp = WDRootMenu->timestamp; menu->timestamp = WDRootMenu->timestamp;
} else } else
menu = NULL; menu = NULL;
} else { } else {
menu = configureMenu(scr, definition); menu = configureMenu(scr, definition, True);
} }
} }