Commit 1d32182f authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

do tornoff menu saving in a nicer way. The old tornoff menus that were

Mon Jan 24 13:28:34 2000  George Lebl <jirka@5z.com>

	* menu.[ch],session.[ch],main.c: do tornoff menu saving in a nicer
	  way.  The old tornoff menus that were saved will be ignored, but
	  "oh well ..."
parent 716a6c7b
Mon Jan 24 13:28:34 2000 George Lebl <jirka@5z.com>
* menu.[ch],session.[ch],main.c: do tornoff menu saving in a nicer
way. The old tornoff menus that were saved will be ignored, but
"oh well ..."
2000-01-24 Jacob Berkman <jacob@helixcode.com>
* session.c (apply_global_config): save large menu setting
......
Mon Jan 24 13:28:34 2000 George Lebl <jirka@5z.com>
* menu.[ch],session.[ch],main.c: do tornoff menu saving in a nicer
way. The old tornoff menus that were saved will be ignored, but
"oh well ..."
2000-01-24 Jacob Berkman <jacob@helixcode.com>
* session.c (apply_global_config): save large menu setting
......
......@@ -231,7 +231,8 @@ main(int argc, char **argv)
init_user_panels();
init_user_applets();
init_user_tearoffs();
load_tornoff();
gnome_triggers_do("Session startup", NULL, "gnome", "login", NULL);
......
......@@ -70,6 +70,7 @@ struct _TearoffMenu {
char *wmclass;
};
/* list of TearoffMenu s */
static GSList *tearoffs = NULL;
/*to be called on startup to load in some of the directories,
......@@ -3774,41 +3775,164 @@ load_menu_applet(char *params, int main_menu_flags,
}
}
/* the data can be title:wmclass:x:y:path:applets:dirname:pixmapname:path ... */
/* note that it kills and frees 'data' */
void
save_tornoff(void)
{
GSList *li;
char *s;
int i;
s = g_concat_dir_and_file(PANEL_CONFIG_PATH,"panel/Config/");
gnome_config_push_prefix (s);
g_free(s);
gnome_config_set_int("tearoffs_count",g_slist_length(tearoffs));
gnome_config_pop_prefix ();
for(i=0,li=tearoffs;li;i++,li=li->next) {
TearoffMenu *tm = li->data;
int x = 0,y = 0;
GtkWidget *tw;
int menu_panel = 0;
PanelWidget *menu_panel_widget = NULL;
GSList *l;
int j;
s = g_strdup_printf("%spanel/TornoffMenu_%d/",
PANEL_CONFIG_PATH,i);
gnome_config_push_prefix (s);
g_free(s);
tw = GTK_MENU(tm->menu)->tearoff_window;
if(tw && tw->window) {
gdk_window_get_root_origin(tw->window, &x, &y);
/* unfortunately we must do this or set_uposition
will crap out */
if(x<0) x=0;
if(y<0) y=0;
}
gnome_config_set_string("title",tm->title);
gnome_config_set_string("wmclass",tm->wmclass);
gnome_config_set_int("x", x);
gnome_config_set_int("y", y);
menu_panel_widget = gtk_object_get_data(GTK_OBJECT(tm->menu),
"menu_panel");
menu_panel = g_slist_index(panels,menu_panel_widget);
if(menu_panel<0) menu_panel = 0;
gnome_config_set_int("menu_panel", menu_panel);
gnome_config_set_int("workspace",
gnome_win_hints_get_workspace(tw));
gnome_config_set_int("hints",
gnome_win_hints_get_hints(tw));
gnome_config_set_int("state",
gnome_win_hints_get_state(tw));
gnome_config_set_string("special",
tm->special?tm->special:"");
gnome_config_set_int("mfl_count", g_slist_length(tm->mfl));
for(j=0,l=tm->mfl;l;j++,l=l->next) {
MenuFinfo *mf = l->data;
char name[256];
g_snprintf(name, 256, "name_%d", j);
gnome_config_set_string(name, mf->fr->name);
g_snprintf(name, 256, "dir_name_%d", j);
gnome_config_set_string(name, mf->dir_name);
g_snprintf(name, 256, "pixmap_name_%d", j);
gnome_config_set_string(name, mf->pixmap_name);
g_snprintf(name, 256, "applets_%d", j);
gnome_config_set_bool(name, mf->applets);
}
gnome_config_pop_prefix();
}
}
static GtkWidget *
create_special_menu(char *special, PanelWidget *menu_panel_widget)
{
GtkWidget *menu;
if(strcmp(special,"ADD_PANEL")==0) {
menu = create_add_panel_submenu(FALSE);
} else if(strcmp(special,"PANEL")==0) {
menu = create_panel_root_menu(
menu_panel_widget->panel_parent, FALSE);
gtk_signal_connect_object_while_alive(
GTK_OBJECT(menu_panel_widget),
"destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(menu));
} else if(strcmp(special,"DESKTOP")==0) {
menu = create_desktop_menu (NULL, TRUE, FALSE);
} else if(strcmp(special,"ADD_TO_PANEL")==0) {
menu = gtk_menu_new();
make_add_submenu(menu, TRUE);
gtk_signal_connect_object_while_alive(
GTK_OBJECT(menu_panel_widget),
"destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(menu));
} else if(strcmp(special,"PANEL_SUBMENU")==0) {
menu = create_panel_submenu (NULL, TRUE, FALSE);
gtk_signal_connect_object_while_alive(
GTK_OBJECT(menu_panel_widget),
"destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(menu));
}
return menu;
}
static void
make_tearoff_from_data(char *data)
load_tearoff_menu(void)
{
GtkWidget *menu;
char *title,*wmclass,*geom,*menu_panel;
char *special;
int ix,iy,i;
int workspace;
int hints;
int state;
char *title, *wmclass, *special;
int x, y, i;
int workspace, hints, state;
int mfl_count;
TearoffMenu *tm;
gulong wmclass_num;
PanelWidget *menu_panel_widget = NULL;
title = strtok_with_escape(data,":",TRUE);
if(!title) return;
wmclass = strtok_with_escape(NULL,":",TRUE);
if(!wmclass) return;
menu_panel = strtok_with_escape(NULL,":",TRUE);
if(!menu_panel) return;
geom = strtok_with_escape(NULL,":",TRUE);
if(!geom) return;
title = gnome_config_get_string("title=");
wmclass = gnome_config_get_string("wmclass=");
if(!*title || !*wmclass) {
g_free(title);
g_free(wmclass);
return;
}
ix = iy = 0;
workspace = hints = state = 0;
sscanf(geom,"%d,%d,%d,%d,%d",&ix,&iy,&workspace,&hints,&state);
x = gnome_config_get_int("x=0");
y = gnome_config_get_int("y=0");
workspace = gnome_config_get_int("workspace=0");
hints = gnome_config_get_int("hints=0");
state = gnome_config_get_int("state=0");
i = atoi(menu_panel);
i = gnome_config_get_int("menu_panel=0");
if(i<0) i = 0;
menu_panel_widget = g_slist_nth_data(panels,i);
if(!menu_panel_widget)
menu_panel_widget = panels->data;
mfl_count = gnome_config_get_int("mfl_count=0");
special = gnome_config_get_string("special=");
if(!*special) {
g_free(special);
special = NULL;
}
/* find out the wmclass_number that was used
for this wmclass and make our default one 1 higher
so that we will always get unique wmclasses */
......@@ -3818,73 +3942,39 @@ make_tearoff_from_data(char *data)
wmclass_number = wmclass_num+1;
menu = NULL;
special = NULL;
while(1) {
char *path;
path = strtok_with_escape(NULL,":",TRUE);
if(!path) break;
if(strcmp(path,"ADD_PANEL")==0) {
menu = create_add_panel_submenu(FALSE);
title = _("Create panel");
special = "ADD_PANEL";
} else if(strcmp(path,"PANEL")==0) {
menu = create_panel_root_menu(
menu_panel_widget->panel_parent,FALSE);
title = _("Panel");
special = "PANEL";
gtk_signal_connect_object_while_alive(
GTK_OBJECT(menu_panel_widget),
"destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(menu));
} else if(strcmp(path,"DESKTOP")==0) {
menu = create_desktop_menu (NULL, TRUE, FALSE);
title = _("Desktop");
special = "DESKTOP";
} else if(strcmp(path,"ADD_TO_PANEL")==0) {
menu = gtk_menu_new();
make_add_submenu(menu, TRUE);
gtk_signal_connect_object_while_alive(
GTK_OBJECT(menu_panel_widget),
"destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(menu));
title = _("Add to panel");
special = "ADD_TO_PANEL";
} else if(strcmp(path,"PANEL_SUBMENU")==0) {
menu = create_panel_submenu (NULL, TRUE, FALSE);
gtk_signal_connect_object_while_alive(
GTK_OBJECT(menu_panel_widget),
"destroy", GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(menu));
title = _("Panel");
special = "PANEL_SUBMENU";
} else {
char *applets;
if(special) {
menu = create_special_menu(special, menu_panel_widget);
} else {
for(i = 0; i < mfl_count; i++) {
char propname[256];
char *name;
gboolean applets;
char *dir_name;
char *pixmap_name;
applets = strtok_with_escape(NULL,":",TRUE);
if(!applets) applets="0";
dir_name = strtok_with_escape(NULL,":",TRUE);
if(!dir_name) dir_name=g_basename(path);
pixmap_name = strtok_with_escape(NULL,":",TRUE);
if(!pixmap_name) pixmap_name="";
menu = create_menu_at(gtk_menu_new (),
path,
*applets=='1'?TRUE:FALSE,
dir_name,
pixmap_name,
TRUE,
FALSE);
g_snprintf(propname, 256, "name_%d=", i);
name = gnome_config_get_string(propname);
g_snprintf(propname, 256, "applets_%d=", i);
applets = gnome_config_get_bool(propname);
g_snprintf(propname, 256, "dir_name_%d=", i);
dir_name = gnome_config_get_string(propname);
g_snprintf(propname, 256, "pixmap_name_%d=", i);
pixmap_name = gnome_config_get_string(propname);
menu = create_menu_at(menu, name, applets, dir_name,
pixmap_name, TRUE, FALSE);
g_free(name);
g_free(dir_name);
g_free(pixmap_name);
}
}
if(!menu) {
g_free(data);
g_free(special);
g_free(title);
g_free(wmclass);
return;
}
......@@ -3893,7 +3983,7 @@ make_tearoff_from_data(char *data)
menu_panel_widget);
/* This is so that we get size of the menu right */
show_tearoff_menu(menu,title,FALSE,ix,iy,wmclass);
show_tearoff_menu(menu,title,FALSE,x,y,wmclass);
{
GtkWidget *window = GTK_MENU(menu)->tearoff_window;
......@@ -3905,97 +3995,37 @@ make_tearoff_from_data(char *data)
tm = g_new0(TearoffMenu,1);
tm->menu = menu;
tm->mfl = gtk_object_get_data(GTK_OBJECT(menu), "mf");
tm->title = g_strdup(title);
tm->special = special?g_strdup(special):NULL;
tm->wmclass = g_strdup(wmclass);
tm->title = title;
tm->special = special;
tm->wmclass = wmclass;
gtk_signal_connect(GTK_OBJECT(menu), "destroy",
GTK_SIGNAL_FUNC(tearoff_destroyed), tm);
tearoffs = g_slist_prepend(tearoffs,tm);
g_free(data);
}
/* this function also frees the list as a byproduct */
void
make_tearoffs_from_data(GSList *list)
load_tornoff(void)
{
GSList *li;
for(li=list;li;li=li->next)
make_tearoff_from_data(li->data);
g_slist_free(list);
}
/* returns a list of strings that can be loaded later with
make_tearoffs_from_data */
GSList *
make_data_from_tearoffs(void)
{
GSList *li;
GSList *data = NULL;
for(li=tearoffs;li;li=li->next) {
GString *gs = g_string_new("");
GSList *l;
TearoffMenu *tm = li->data;
int x = 0,y = 0;
GtkWidget *tw;
int workspace = 0;
int hints = 0;
int state = 0;
int menu_panel = 0;
PanelWidget *menu_panel_widget = NULL;
tw = GTK_MENU(tm->menu)->tearoff_window;
if(tw && tw->window) {
gdk_window_get_root_origin(tw->window, &x, &y);
/* unfortunately we must do this or set_uposition
will crap out */
if(x<0) x=0;
if(y<0) y=0;
}
char *s;
int i,length;
workspace = gnome_win_hints_get_workspace(tw);
hints = gnome_win_hints_get_hints(tw);
state = gnome_win_hints_get_state(tw);
s = g_strdup_printf("%spanel/Config/", PANEL_CONFIG_PATH);
gnome_config_push_prefix(s);
g_free(s);
length = gnome_config_get_int("tearoffs_count=0");
gnome_config_pop_prefix();
menu_panel_widget = gtk_object_get_data(GTK_OBJECT(tm->menu),
"menu_panel");
menu_panel = g_slist_index(panels,menu_panel_widget);
if(menu_panel<0) menu_panel = 0;
if(length==0) return;
{
char *etitle = escape_string(tm->title,":");
char *ewmclass = escape_string(tm->wmclass,":");
g_string_sprintf(gs,"%s:%s:%d:%d,%d,%d,%d,%d",
etitle,ewmclass,menu_panel,
x,y,workspace,hints,state);
g_free(etitle);
g_free(ewmclass);
}
for(i=0;i<length;i++) {
s = g_strdup_printf("%spanel/TornoffMenu_%d/",
PANEL_CONFIG_PATH, i);
gnome_config_push_prefix(s);
g_free(s);
if(tm->special)
g_string_sprintfa(gs,":%s",tm->special);
load_tearoff_menu();
for(l=tm->mfl;l;l=l->next) {
MenuFinfo *mf = l->data;
char *ename = escape_string(mf->fr->name,":");
char *edir_name = escape_string(mf->dir_name,":");
char *epixmap_name = escape_string(mf->pixmap_name,":");
g_string_sprintfa(gs,":%s:%d:%s:%s",
ename,
mf->applets?1:0,
edir_name?edir_name:"",
epixmap_name?epixmap_name:"");
g_free(ename);
g_free(edir_name);
g_free(epixmap_name);
}
data = g_slist_prepend(data,gs->str);
g_string_free(gs,FALSE);
gnome_config_pop_prefix();
}
return data;
}
......@@ -63,13 +63,8 @@ void panel_lock (GtkWidget *widget, void *data);
/*to be called on startup to load in some of the directories*/
void init_menus(void);
/* two functions for saving and loading torn off menus in state */
/* this function also frees the list as a byproduct */
void make_tearoffs_from_data(GSList *list);
/* returns a list of strings that can be loaded later with the function
above */
GSList * make_data_from_tearoffs(void);
void save_tornoff(void);
void load_tornoff(void);
#define MENU_PATH "menu_path"
......@@ -99,6 +94,7 @@ enum {
HIDEBUTTONS_NONE
};
#define MENU_SIZES "sizes_menu"
#define MENU_SIZE_TINY "Tiny (24 pixels)"
#define MENU_SIZE_SMALL "Small (36 pixels)"
......
......@@ -529,27 +529,6 @@ save_next_applet(void)
gnome_config_drop_all();
}
static void
save_tornoff(void)
{
GSList *tornoff,*li;
GString *gs;
int i;
/* here we save the torn off menus */
tornoff = make_data_from_tearoffs();
gnome_config_set_int("tornoff_count",g_slist_length(tornoff));
gs = g_string_new(NULL);
for(i=0,li=tornoff;li;i++,li=li->next) {
g_string_sprintf(gs,"tornoff_menu_%d",i);
gnome_config_set_string(gs->str,li->data);
g_free(li->data);
}
g_slist_free(tornoff);
g_string_free(gs,TRUE);
}
......@@ -606,11 +585,11 @@ do_session_save(GnomeClient *client,
#ifdef PANEL_DEBUG
printf(" 4\n"); fflush(stdout);
#endif
gnome_config_pop_prefix ();
if(complete_sync)
save_tornoff();
gnome_config_pop_prefix ();
gnome_config_sync();
if(complete_sync || sync_applets) {
......@@ -1200,38 +1179,6 @@ init_user_panels(void)
g_string_free(buf,TRUE);
}
void
init_user_tearoffs(void)
{
GSList *tornoff = NULL;
GString *gs;
int i,length;
gs = g_string_new(NULL);
g_string_sprintf(gs,"%spanel/Config/", PANEL_CONFIG_PATH);
gnome_config_push_prefix(gs->str);
length = gnome_config_get_int("tornoff_count=0");
if(length==0) {
gnome_config_pop_prefix();
g_string_free(gs,TRUE);
return;
}
for(i=0;i<length;i++) {
char *s;
g_string_sprintf(gs,"tornoff_menu_%d=",i);
s = gnome_config_get_string(gs->str);
if(s)
tornoff = g_slist_prepend(tornoff,s);
}
g_string_free(gs,TRUE);
gnome_config_pop_prefix();
/* this call will free the strings and the list */
make_tearoffs_from_data(tornoff);
}
void
load_up_globals(void)
......
......@@ -43,7 +43,6 @@ void load_up_globals(void);
void init_user_applets(void);
void init_user_panels(void);
void init_user_tearoffs(void);
void apply_global_config(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment