aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-09-08 09:19:32 +0200
committerThomas White <taw@bitwiz.org.uk>2014-09-08 09:19:32 +0200
commit72c3ff616107bef50a7e996176c5f2cd35218b89 (patch)
treedcb7a440cfa243fd1305608cec57731ad05057d6
parent013f650a3ddccd1b2f23840bee909236b7a03a35 (diff)
Restore style menu
-rw-r--r--src/mainwindow.c78
-rw-r--r--src/presentation.h2
-rw-r--r--src/sc_interp.c18
-rw-r--r--src/sc_interp.h9
4 files changed, 49 insertions, 58 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 39d19f5..a95fd26 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -235,15 +235,15 @@ static gint add_furniture(GtkWidget *widget, struct menu_pl *pl)
static void update_style_menus(struct presentation *p)
{
-#if 0
-/* FIXME: Menus */
GtkWidget *menu;
- struct slide_template *t;
- TemplateIterator *iter;
- int i, j, k, n_j, n_k;
+ SCInterpreter *scin;
+ struct style_id *styles;
+ int i, n_sty;
for ( i=0; i<p->n_menu_rebuild; i++ ) {
gtk_widget_destroy(p->menu_rebuild_list[i]);
+ free(p->menu_path_list[i].name);
+ free(p->menu_path_list[i].friendlyname);
}
free(p->menu_rebuild_list);
free(p->menu_path_list);
@@ -252,71 +252,35 @@ static void update_style_menus(struct presentation *p)
menu = gtk_ui_manager_get_widget(p->ui, "/displaywindow/insert");
menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
- n_k = 0; n_j = 0;
- for ( t = template_first(p->ss, &iter);
- t != NULL;
- t = template_next(p->ss, iter) )
- {
- n_k += t->n_styles;
- n_j++;
- n_k++; /* For "Everything" */
+ scin = sc_interp_new(NULL, NULL);
+ if ( scin == NULL ) {
+ fprintf(stderr, "Failed to set up interpreter.\n");
+ return;
}
+ sc_interp_run_stylesheet(scin, p->stylesheet);
+
+ styles = list_styles(scin, &n_sty);
+ if ( styles == NULL ) return;
- p->menu_rebuild_list = calloc(n_j, sizeof(GtkWidget *));
+ p->menu_rebuild_list = calloc(n_sty, sizeof(GtkWidget *));
if ( p->menu_rebuild_list == NULL ) return;
- p->menu_path_list = calloc(n_k, sizeof(struct menu_pl));
- if ( p->menu_path_list == NULL ) return;
+ for ( i=0; i<n_sty; i++ ) {
- j = 0;
- k = 0;
- for ( t = template_first(p->ss, &iter);
- t != NULL;
- t = template_next(p->ss, iter) )
- {
- GtkWidget *submenu;
GtkWidget *item;
- submenu = gtk_menu_new();
- item = gtk_menu_item_new_with_label(t->name);
+ item = gtk_menu_item_new_with_label(styles[i].friendlyname);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
- gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
- p->menu_rebuild_list[j++] = item;
-
- p->menu_path_list[k].p = p;
- p->menu_path_list[k].sty = NULL;
- p->menu_path_list[k].st = t;
- item = gtk_menu_item_new_with_label("Everything");
- gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
+ p->menu_rebuild_list[i] = item;
+
g_signal_connect(G_OBJECT(item), "activate",
G_CALLBACK(add_furniture),
- &p->menu_path_list[k]);
- k++;
-
- item = gtk_separator_menu_item_new();
- gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
-
- for ( i=0; i<t->n_styles; i++ ) {
-
- struct style *s = t->styles[i];
-
- p->menu_path_list[k].p = p;
- p->menu_path_list[k].sty = s;
- p->menu_path_list[k].st = t;
-
- item = gtk_menu_item_new_with_label(s->name);
- gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
- g_signal_connect(G_OBJECT(item), "activate",
- G_CALLBACK(add_furniture),
- &p->menu_path_list[k]);
- k++;
-
- }
+ &styles[i]);
}
gtk_widget_show_all(menu);
- p->n_menu_rebuild = j;
-#endif
+ p->n_menu_rebuild = n_sty;
+ p->menu_path_list = styles;
}
diff --git a/src/presentation.h b/src/presentation.h
index d2dd4c0..f8f9429 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -121,7 +121,7 @@ struct presentation
GtkActionGroup *action_group;
GtkIMContext *im_context;
GtkWidget **menu_rebuild_list;
- struct menu_pl *menu_path_list;
+ struct style_id *menu_path_list;
int n_menu_rebuild;
PangoContext *pc;
ImageStore *is;
diff --git a/src/sc_interp.c b/src/sc_interp.c
index d59c509..7b63b0d 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -773,3 +773,21 @@ void find_stylesheet(struct presentation *p)
fprintf(stderr, "No style sheet.\n");
}
+
+
+struct style_id *list_styles(SCInterpreter *scin, int *np)
+{
+ struct style_id *list;
+ int i;
+
+ list = malloc(sizeof(struct style_id)*scin->state->n_macros);
+ if ( list == NULL ) return NULL;
+
+ for ( i=0; i<scin->state->n_macros; i++ ) {
+ list[i].name = strdup(scin->state->macros[i].name);
+ list[i].friendlyname = strdup(scin->state->macros[i].name);
+ }
+
+ *np = scin->state->n_macros;
+ return list;
+}
diff --git a/src/sc_interp.h b/src/sc_interp.h
index 067fd60..20e2150 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -52,4 +52,13 @@ extern int sc_interp_get_ascent(SCInterpreter *scin);
extern int sc_interp_get_height(SCInterpreter *scin);
extern void update_geom(struct frame *fr);
+
+struct style_id
+{
+ char *name;
+ char *friendlyname;
+};
+
+extern struct style_id *list_styles(SCInterpreter *scin, int *n);
+
#endif /* SC_INTERP_H */