Prepare to move menus in menus.cfg to simple files.

SVN revision: 30190
This commit is contained in:
Kim Woelders 2007-06-02 10:01:34 +00:00
parent 49b0eefe30
commit 60800f3067
3 changed files with 47 additions and 35 deletions

View File

@ -37,8 +37,6 @@
static char menu_scan_recursive = 0;
static Menu *MenuCreateFromFlatFile(const char *name, Menu * parent,
MenuStyle * ms, const char *file);
static Menu *MenuCreateFromDirectory(const char *name, Menu * parent,
MenuStyle * ms, const char *dir);
@ -277,12 +275,12 @@ void
ScanBackgroundMenu(void)
{
menu_scan_recursive = 1;
MenuLoad(MenuFind("BACKGROUNDS_MENU"));
MenuLoad(MenuFind("BACKGROUNDS_MENU", NULL));
menu_scan_recursive = 0;
}
static void
FillFlatFileMenu(Menu * m, const char *name, const char *file)
FillFlatFileMenu(Menu * m, const char *file)
{
FILE *f;
char first = 1;
@ -354,8 +352,7 @@ FillFlatFileMenu(Menu * m, const char *name, const char *file)
}
else if ((act) && (!strcmp(act, "menu")) && (params))
{
Esnprintf(wd, sizeof(wd), "__FM.%s.%i", name, count++);
mm = MenuCreateFromFlatFile(wd, m, NULL, params);
mm = MenuFind(params, NULL);
if (mm)
{
mi = MenuItemCreate(txt, icc, NULL, mm);
@ -385,7 +382,7 @@ MenuLoadFromFlatFile(Menu * m)
MenuSetTimestamp(m, lastmod);
MenuEmpty(m, 0);
FillFlatFileMenu(m, MenuGetName(m), ff);
FillFlatFileMenu(m, ff);
return 1;
}
@ -402,19 +399,27 @@ MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms,
return NULL;
calls++;
ff = FindFile(file, NULL, 0);
if (!ff)
if (!file)
file = name;
if (isabspath(file))
{
if (isabspath(file))
goto done;
/* Check also menus subdir */
ff = FindFile(file, NULL, 0);
}
else
{
/* Check menus subdir first */
Esnprintf(buf, sizeof(buf), "menus/%s", file);
ff = FindFile(buf, NULL, 0);
if (!ff)
goto done;
ff = FindFile(file, NULL, 0);
}
if (!ff)
goto done;
m = MenuCreate(name, NULL, parent, ms);
m = MenuCreate(file, NULL, parent, ms);
if (name != file)
MenuSetAlias(m, name);
MenuSetData(m, ff);
MenuSetLoader(m, MenuLoadFromFlatFile);
@ -598,6 +603,7 @@ MenuCreateFromBorders(const char *name, MenuStyle * ms)
MenuItem *mi;
m = MenuCreate(name, NULL, NULL, ms);
MenuSetTitle(m, _("Border"));
lst = BordersGetList(&num);
if (lst)
@ -804,7 +810,13 @@ MenusCreateInternal(const char *type, const char *name, const char *style,
if (style)
ms = MenuStyleFind(style);
if (!strcmp(type, "file"))
if (!type)
{
if (!strstr(name, ".menu"))
type = name;
}
if (!type || !strcmp(type, "file"))
{
m = MenuCreateFromFlatFile(name, NULL, ms, prm);
}

View File

@ -460,10 +460,6 @@ void
MenuSetName(Menu * m, const char *name)
{
_EFDUP(m->name, name);
if (!menu_list)
menu_list = ecore_list_new();
ecore_list_prepend(menu_list, m);
}
void
@ -553,6 +549,10 @@ MenuCreate(const char *name, const char *title, Menu * parent, MenuStyle * ms)
MenuSetStyle(m, ms);
m->icon_size = -1; /* Use image size */
if (!menu_list)
menu_list = ecore_list_new();
ecore_list_prepend(menu_list, m);
return m;
}
@ -1075,7 +1075,7 @@ _MenuMatchName(const void *data, const void *match)
}
Menu *
MenuFind(const char *name)
MenuFind(const char *name, const char *param)
{
Menu *m;
@ -1084,13 +1084,13 @@ MenuFind(const char *name)
return (m);
/* Not in list - try if we can load internal */
m = MenusCreateInternal(name, name, NULL, NULL);
m = MenusCreateInternal(NULL, name, NULL, param);
return m;
}
static void
MenusShowNamed(const char *name)
MenusShowNamed(const char *name, const char *param)
{
Menu *m;
@ -1098,7 +1098,7 @@ MenusShowNamed(const char *name)
if (MenusActive())
MenusHide();
m = MenuFind(name);
m = MenuFind(name, param);
if (!m)
return;
@ -1846,7 +1846,6 @@ MenuConfigLoad(FILE * fs)
int i1, i2;
Menu *m = NULL, *mm;
MenuItem *mi;
MenuStyle *ms;
ImageClass *ic = NULL;
int fields, len2, len;
@ -1901,13 +1900,10 @@ MenuConfigLoad(FILE * fs)
MenuSetName(m, s2);
break;
case MENU_USE_STYLE:
ms = MenuStyleFind(s2);
if (ms)
MenuSetStyle(m, ms);
MenuSetStyle(m, MenuStyleFind(s2));
break;
case MENU_TITLE:
if (m)
MenuSetTitle(m, s + len2);
MenuSetTitle(m, s + len2);
break;
case MENU_ITEM:
#if 0 /* FIXME - Why ? */
@ -1951,7 +1947,7 @@ MenuConfigLoad(FILE * fs)
ic = NULL;
if (strcmp("NULL", s3))
ic = ImageclassFind(s3, 0);
mm = MenuFind(s2);
mm = MenuFind(s2, NULL);
#if 0 /* FIXME - Remove? */
/* if submenu empty - dont put it in - only if menu found */
if (MenuIsEmpty(mm))
@ -2116,7 +2112,9 @@ MenusIpc(const char *params)
}
else if (!strncmp(cmd, "list", 2))
{
ECORE_LIST_FOR_EACH(menu_list, m) IpcPrintf("%s\n", m->name);
#define SS(s) ((s) ? (s) : "-")
ECORE_LIST_FOR_EACH(menu_list, m)
IpcPrintf("%s(%s): %s\n", m->name, SS(m->alias), SS(m->title));
}
else if (!strncmp(cmd, "reload", 2))
{
@ -2125,10 +2123,12 @@ MenusIpc(const char *params)
}
else if (!strncmp(cmd, "show", 2))
{
if (strcmp(prm, "named"))
p = prm;
if (*p == '\0')
p = NULL;
if (p && !strcmp(prm, "named"))
Esnprintf(prm, sizeof(prm), "%s", p);
SoundPlay("SOUND_MENU_SHOW");
MenusShowNamed(p);
MenusShowNamed(prm, p);
}
}

View File

@ -44,7 +44,7 @@ void MenuHide(Menu * m);
void MenuEmpty(Menu * m, int destroying);
void MenuRepack(Menu * m);
int MenuLoad(Menu * m);
Menu *MenuFind(const char *name);
Menu *MenuFind(const char *name, const char *param);
MenuItem *MenuItemCreate(const char *text, ImageClass * ic,
const char *action_params, Menu * child);
void MenuSetInternal(Menu * m);