oooooh - look at this - the desktop left click menu is......... CONFIGURABLE

yes - it generates it from a..... DATABASE - there's a script that builds the
menu - it's a default set - but easily editable in the script (an example of
how to build a menu db - but... eventually we'd need a gui.) This only builds
a menu from a db file - it also monitors it for changes and updates the menu
to match any changes that happen. I need to write later a fs menu builder that
builds a menu from the filing system.


SVN revision: 4164
This commit is contained in:
Carsten Haitzler 2001-02-03 17:17:07 +00:00
parent 8a3bd1b04c
commit 7fe641df37
8 changed files with 316 additions and 107 deletions

Binary file not shown.

109
data/scripts/build_app_menu_db.sh Executable file
View File

@ -0,0 +1,109 @@
#!/bin/sh
# this is the databse to create
DB="./apps_menu.db"
# shell function calls that setup, cleanup and build menus in a menus database
setup ()
{
NUM=0
ENTRYNUM=0
MENUNUM=0
rm -f $DB
}
finish ()
{
edb_ed $DB add "/menu/count" int $MENUNUM
}
menu ()
{
ENTRYNUM=0
MENUNUM=$1;
M1=$[ $MENUNUM + 1 ];
if [ $M1 -gt $NUM ]; then
NUM=$M1;
fi
}
end_menu ()
{
edb_ed $DB add "/menu/"$MENUNUM"/count" int $ENTRYNUM
}
entry ()
{
if [ $1 = "text" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/text" str "$2"
if [ "$3" = "sub" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/submenu" int $4
else
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/command" str "$3"
fi
else if [ $1 = "icon" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/icon" str "$2"
if [ "$3" = "sub" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/submenu" int $4
else
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/command" str "$3"
fi
else if [ $1 = "both" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/text" str "$2"
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/icon" str "$3"
if [ "$4" = "sub" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/submenu" int $5
else
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/command" str "$4"
fi
else if [ $1 = "separator" ]; then
edb_ed $DB add "/menu/"$MENUNUM"/"$ENTRYNUM"/separator" int 1
fi; fi; fi; fi
ENTRYNUM=$[ $ENTRYNUM + 1 ];
}
###############################################################################
##
## Menus are defined here
##
## IF you want to edit anything - edit this - it's REALLY simple.
setup
menu 0
entry both 'Eterm' '/usr/share/pixmaps/gnome-eterm.png' 'Eterm'
entry both 'Netscape' '/usr/share/pixmaps/netscape.png' 'netscape'
entry both 'TkRat' '/usr/share/pixmaps/gnome-ccdesktop.png' 'tkrat'
entry both 'X Chat' '/usr/share/pixmaps/gnome-irc.png' 'xchat'
entry both 'XMMS' '/usr/share/pixmaps/mc/gnome-audio.png' 'xmms'
entry both 'The GIMP' '/usr/share/pixmaps/gimp.png' 'gimp'
entry separator
entry both 'XTerm' '/usr/share/pixmaps/gnome-term.png' 'xterm'
entry both 'XMag' '/usr/share/pixmaps/gnome-applets.png' 'xmag'
entry separator
entry text 'Network' 'sub' 1
entry text 'System' 'sub' 2
end_menu
menu 1
entry text 'Ethernet On' 'sudo -S /sbin/ifup eth0'
entry text 'Ethernet Off' 'sudo -S /sbin/ifdown eth0'
end_menu
menu 2
entry text 'Shut Down' 'sudo -S /sbin/shutdown -h now'
entry text 'Reboot' 'sudo -S /sbin/shutdown -r now'
end_menu
finish

View File

@ -75,7 +75,7 @@ e_idle(void *data)
evas_render(b->evas.b);
}
}
e_db_runtime_flush();
e_db_flush();
return;
UN(data);
}

View File

@ -16,7 +16,8 @@ static char cfg_grabs_db[4096] = "";
static char cfg_settings_db[4096] = "";
static char cfg_actions_db[4096] = "";
static char cfg_borders_db[4096] = "";
static char cfg_menus_db[4096] = "";
static char cfg_apps_menu_db[4096] = "";
static char cfg_menus_dir[4096] = "";
static char cfg_user_dir[4096] = "";
static char cfg_images_dir[4096] = "";
static char cfg_fonts_dir[4096] = "";
@ -45,9 +46,11 @@ e_config_get(char *type)
PACKAGE_DATA_DIR"/data/config/behavior/default/settings.db");
E_CONF("actions", cfg_actions_db,
PACKAGE_DATA_DIR"/data/config/behavior/default/actions.db");
E_CONF("apps_menu", cfg_apps_menu_db,
PACKAGE_DATA_DIR"/data/config/behavior/default/apps_menu.db");
E_CONF("borders", cfg_borders_db,
PACKAGE_DATA_DIR"/data/config/appearance/default/borders/");
E_CONF("menus", cfg_menus_db,
E_CONF("menus", cfg_menus_dir,
PACKAGE_DATA_DIR"/data/config/appearance/default/menus/");
E_CONF("images", cfg_images_dir,
PACKAGE_DATA_DIR"/data/images/");

View File

@ -26,7 +26,7 @@ e_idle(void *data)
desk = l->data;
e_desktops_update(desk);
}
e_db_runtime_flush();
e_db_flush();
return;
UN(data);
}
@ -132,112 +132,22 @@ e_mouse_down(Eevent * ev)
evas_event_button_down(evas, x, y, e->button);
if (e->button == 1)
{
int count;
static E_Menu *menu = NULL;
char buf[4096];
static E_Build_Menu *buildmenu = NULL;
if (!menu)
if (!buildmenu)
{
menu = e_menu_new();
menu->pad.icon = 2;
menu->pad.state = 2;
for (count = 1; count <= 16; count++)
{
int count2;
E_Menu *menu2;
E_Menu_Item *menuitem;
char *icons[] =
{
"cd.png",
"drawer_closed.png",
"drawer_cube_closed.png",
"drawer_cube_open.png",
"drawer_cube_open_socks.png",
"drawer_image_closed.png",
"drawer_image_open.png",
"drawer_image_open_socks.png",
"drawer_light_closed.png",
"drawer_light_open.png",
"drawer_light_open_socks.png",
"drawer_open.png",
"drawer_open_socks.png",
"drawer_palette_closed.png",
"drawer_palette_open.png",
"drawer_palette_open_socks.png",
"drawer_style_closed.png",
"drawer_style_open.png",
"drawer_style_open_socks.png",
"drawer_text_closed.png",
"drawer_text_open.png",
"drawer_text_open_socks.png",
"palette.png",
"quake3.png",
"trash_closed.png",
"trash_full_closed.png",
"trash_full_open.png",
"trash_open.png",
"watch.png"
};
sprintf(buf, "Menu item %i", count);
menuitem = e_menu_item_new(buf);
sprintf(buf, "/home/raster/icons/%s", icons[rand() % 29]);
menuitem->icon = strdup(buf);
menuitem->scale_icon = 1;
menuitem->radio = rand() & 0x1;
menuitem->check = rand() & 0x1;
menuitem->on = rand() & 0x1;
if (count < 10)
{
menu2 = e_menu_new();
menu2->pad.icon = 2;
menu2->pad.state = 2;
menuitem->submenu = menu2;
}
e_menu_add_item(menu, menuitem);
if (count < 10)
{
for (count2 = 1; count2 <= 14; count2++)
{
E_Menu_Item *menuitem2;
E_Menu *menu3;
int count3;
sprintf(buf, "Submenu item %i", count2);
if (!(rand()%3)) menuitem2 = e_menu_item_new(buf);
else menuitem2 = e_menu_item_new("");
menu3 = e_menu_new();
menu3->pad.icon = 2;
menu3->pad.state = 2;
menuitem2->submenu = menu3;
sprintf(buf, "/home/raster/icons/%s", icons[rand() % 29]);
if (!(rand()%3)) menuitem2->icon = strdup(buf);
menuitem2->scale_icon = 1;
menuitem2->radio = rand() & 0x1;
menuitem2->check = rand() & 0x1;
menuitem2->on = rand() & 0x1;
if (!(rand()%3)) menuitem2->separator = 1;
e_menu_add_item(menu2, menuitem2);
for (count3 = 1; count3 <= 12; count3++)
{
E_Menu_Item *menuitem3;
sprintf(buf, "Submenu item %i", count3);
menuitem3 = e_menu_item_new(NULL);
sprintf(buf, "/home/raster/icons/%s", icons[rand() % 29]);
menuitem3->icon = strdup(buf);
menuitem3->scale_icon = 1;
menuitem3->radio = rand() & 0x1;
menuitem3->check = rand() & 0x1;
menuitem3->on = rand() & 0x1;
if (!(rand()%3)) menuitem3->separator = 1;
e_menu_add_item(menu3, menuitem3);
}
}
}
}
char *apps_menu_db;
apps_menu_db = e_config_get("apps_menu");
if (apps_menu_db) buildmenu = e_build_menu_new_from_db(apps_menu_db);
}
if (buildmenu)
{
menu = buildmenu->menu;
if (menu)
e_menu_show_at_mouse(menu, e->rx, e->ry, e->time);
}
e_menu_show_at_mouse(menu, e->rx, e->ry, e->time);
}
if (e->button == 3)
e_exec_restart();

20
src/e.h
View File

@ -132,6 +132,7 @@ typedef struct _E_Active_Action_Timer E_Active_Action_Timer;
typedef struct _E_View E_View;
typedef struct _E_Menu E_Menu;
typedef struct _E_Menu_Item E_Menu_Item;
typedef struct _E_Build_Menu E_Build_Menu;
struct _E_Object
{
@ -382,6 +383,19 @@ struct _E_Menu_Item
void *func_select_data;
};
struct _E_Build_Menu
{
OBJ_PROPERTIES;
char *file;
time_t mod_time;
E_Menu *menu;
Evas_List menus;
Evas_List commands;
};
void e_action_add_proto(char *action,
void (*func_start) (void *o, E_Action *a, void *data, int x, int y, int rx, int ry),
void (*func_stop) (void *o, E_Action *a, void *data, int x, int y, int rx, int ry),
@ -513,3 +527,9 @@ void e_menu_update_finish(E_Menu *m);
void e_menu_update_shows(E_Menu *m);
void e_menu_update_hides(E_Menu *m);
void e_menu_update(E_Menu *m);
void e_build_menu_unbuild(E_Build_Menu *bm);
E_Menu *e_build_menu_build_number(E_Build_Menu *bm, E_DB_File *db, int num);
void e_build_menu_build(E_Build_Menu *bm);
void e_build_menu_free(E_Build_Menu *bm);
E_Build_Menu *e_build_menu_new_from_db(char *file);

View File

@ -171,7 +171,7 @@ e_idle(void *data)
if (m->first_expose)
evas_render(m->evas);
}
e_db_runtime_flush();
e_db_flush();
return;
UN(data);
}

View File

@ -1 +1,168 @@
#include "e.h"
Evas_List build_menus = NULL;
static void e_build_menu_poll(int val, void *data);
static void
e_build_menu_poll(int val, void *data)
{
time_t mod;
E_Build_Menu *bm;
bm = data;
mod = e_file_modified_time(bm->file);
if (mod <= bm->mod_time)
{
e_add_event_timer(bm->file, 1.0, e_build_menu_poll, 0, data);
return;
}
bm->mod_time = mod;
e_build_menu_unbuild(bm);
e_build_menu_build(bm);
if (!bm->menu) bm->mod_time = 0;
e_add_event_timer(bm->file, 1.0, e_build_menu_poll, 0, data);
UN(val);
}
static void
e_build_menu_cb_exec(E_Menu *m, E_Menu_Item *mi, void *data)
{
char *exe;
exe = data;
e_exec_run(exe);
UN(m);
UN(mi);
}
void
e_build_menu_unbuild(E_Build_Menu *bm)
{
Evas_List l;
bm->menu = NULL;
if (bm->menus)
{
for (l = bm->menus; l; l = l->next)
{
E_Menu *m;
m = l->data;
e_menu_hide(m);
e_menu_update_shows(m);
e_menu_update_hides(m);
e_menu_update_finish(m);
OBJ_DO_FREE(m);
}
bm->menus = evas_list_free(bm->menus);
}
if (bm->commands)
{
for (l = bm->commands; l; l = l->next)
{
IF_FREE(l->data);
}
bm->commands = evas_list_free(bm->commands);
}
}
E_Menu *
e_build_menu_build_number(E_Build_Menu *bm, E_DB_File *db, int num)
{
E_Menu *menu;
char buf[4096];
int num2, i2;
sprintf(buf, "/menu/%i/count", num);
if (!e_db_int_get(db, buf, &num2)) return NULL;
menu = e_menu_new();
menu->pad.icon = 2;
menu->pad.state = 2;
for (i2 = 0; i2 < num2; i2++)
{
E_Menu_Item *menuitem;
char *text, *icon, *exe;
int ok, sub, sep;
sprintf(buf, "/menu/%i/%i/text", num, i2);
text = e_db_str_get(db, buf);
sprintf(buf, "/menu/%i/%i/icon", num, i2);
icon = e_db_str_get(db, buf);
sprintf(buf, "/menu/%i/%i/command", num, i2);
exe = e_db_str_get(db, buf);
sprintf(buf, "/menu/%i/%i/submenu", num, i2);
ok = e_db_int_get(db, buf, &sub);
sep = 0;
sprintf(buf, "/menu/%i/%i/separator", num, i2);
e_db_int_get(db, buf, &sep);
menuitem = e_menu_item_new(text);
menuitem->icon = icon;
if ((icon) && (text)) menuitem->scale_icon = 1;
if (sep)
menuitem->separator = 1;
else
{
if (ok)
{
E_Menu *menu2;
menu2 = e_build_menu_build_number(bm, db, sub);
menuitem->submenu = menu2;
}
}
if (exe)
{
e_menu_item_set_callback(menuitem, e_build_menu_cb_exec, exe);
bm->commands = evas_list_prepend(bm->commands, exe);
}
e_menu_add_item(menu, menuitem);
}
bm->menus = evas_list_prepend(bm->menus, menu);
return menu;
}
void
e_build_menu_build(E_Build_Menu *bm)
{
E_DB_File *db;
int num;
e_db_flush();
db = e_db_open_read(bm->file);
if (!db) return;
if (!e_db_int_get(db, "/menu/count", &num)) goto error;
if (num > 0) bm->menu = e_build_menu_build_number(bm, db, 0);
error:
e_db_close(db);
}
void
e_build_menu_free(E_Build_Menu *bm)
{
e_del_event_timer(bm->file);
e_build_menu_unbuild(bm);
IF_FREE(bm->file);
build_menus = evas_list_remove(build_menus, bm);
FREE(bm);
}
E_Build_Menu *
e_build_menu_new_from_db(char *file)
{
E_Build_Menu *bm;
if (!file) return NULL;
bm = NEW(E_Build_Menu, 1);
ZERO(bm, E_Build_Menu, 1);
OBJ_INIT(bm, e_build_menu_free);
bm->file = strdup(file);
build_menus = evas_list_prepend(build_menus, bm);
e_build_menu_poll(0, bm);
return bm;
}