aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2016-11-18 10:56:50 +0100
committerThomas White <taw@bitwiz.org.uk>2016-11-18 10:56:50 +0100
commita7de2d4816b4ae4727d53f0650d67afbafb01225 (patch)
treea9fee919eeabfbdba7d3ef076ebe688404e8175f /src
parent03a3f56bebae2902b63c90223a096d01d3224163 (diff)
Use slide template for new slides
Diffstat (limited to 'src')
-rw-r--r--src/narrative_window.c62
-rw-r--r--src/sc_interp.c17
-rw-r--r--src/sc_interp.h6
-rw-r--r--src/sc_parse.c14
-rw-r--r--src/sc_parse.h2
-rw-r--r--src/slide_window.c60
6 files changed, 87 insertions, 74 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 507e212..ca0d624 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -161,18 +161,77 @@ static void delete_slide_sig(GSimpleAction *action, GVariant *parameter,
}
+static struct template_id *get_templates(SCBlock *ss, int *n)
+{
+ struct template_id *list;
+ SCInterpreter *scin;
+
+ scin = sc_interp_new(NULL, NULL, NULL);
+ sc_interp_run_stylesheet(scin, ss); /* ss == NULL is OK */
+ list = sc_interp_get_templates(scin, n);
+ sc_interp_destroy(scin);
+ return list;
+}
+
+
+static void update_template_menus(NarrativeWindow *nw)
+{
+ struct template_id *templates;
+ int i, n_templates;
+
+ templates = get_templates(nw->p->stylesheet, &n_templates);
+
+ for ( i=0; i<n_templates; i++ ) {
+ printf("%2i: %s %s\n", i, templates[i].name,
+ templates[i].friendlyname);
+ free(templates[i].name);
+ free(templates[i].friendlyname);
+ sc_block_free(templates[i].scblock);
+ }
+
+ free(templates);
+}
+
+
+static SCBlock *get_slide_template(SCBlock *ss)
+{
+ struct template_id *templates;
+ int i, n_templates;
+ SCBlock *ret = NULL;
+
+ templates = get_templates(ss, &n_templates);
+
+ for ( i=0; i<n_templates; i++ ) {
+ if ( strcmp(templates[i].name, "slide") == 0 ) {
+ ret = templates[i].scblock;
+ } else {
+ sc_block_free(templates[i].scblock);
+ }
+ free(templates[i].name);
+ free(templates[i].friendlyname);
+ }
+ free(templates);
+ return ret; /* NB this is a copy of the one owned by the interpreter */
+}
+
+
static void add_slide_sig(GSimpleAction *action, GVariant *parameter,
gpointer vp)
{
SCBlock *nsblock;
+ SCBlock *templ;
NarrativeWindow *nw = vp;
/* Split the current paragraph */
nsblock = split_paragraph_at_cursor(nw->sceditor);
+ /* Get the template */
+ templ = get_slide_template(nw->p->stylesheet); /* our copy */
+ show_sc_blocks(templ);
+
/* Link the new SCBlock in */
if ( nsblock != NULL ) {
- sc_block_append(nsblock, "slide", NULL, NULL, NULL);
+ sc_block_append_p(nsblock, templ);
} else {
fprintf(stderr, "Failed to split paragraph\n");
}
@@ -609,6 +668,7 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *app)
"win.last");
update_toolbar(nw);
+ update_template_menus(nw);
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 2b9f294..86617de 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -606,6 +606,8 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang,
void sc_interp_destroy(SCInterpreter *scin)
{
+ /* FIXME: Free all templates and macros */
+
/* Empty the stack */
while ( scin->j > 0 ) {
sc_interp_restore(scin);
@@ -1326,19 +1328,20 @@ void find_stylesheet(struct presentation *p)
}
-struct style_id *list_styles(SCInterpreter *scin, int *np)
+struct template_id *sc_interp_get_templates(SCInterpreter *scin, int *np)
{
- struct style_id *list;
+ struct template_id *list;
int i;
- list = malloc(sizeof(struct style_id)*scin->state->n_macros);
+ list = malloc(sizeof(struct template_id)*scin->state->n_templates);
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);
+ for ( i=0; i<scin->state->n_templates; i++ ) {
+ list[i].name = strdup(scin->state->templates[i].name);
+ list[i].friendlyname = strdup(scin->state->templates[i].name);
+ list[i].scblock = sc_block_copy(scin->state->templates[i].bl);
}
- *np = scin->state->n_macros;
+ *np = scin->state->n_templates;
return list;
}
diff --git a/src/sc_interp.h b/src/sc_interp.h
index 54e2233..ad9048c 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -77,12 +77,14 @@ extern void update_geom(struct frame *fr);
extern SCBlock *sc_interp_get_macro_real_block(SCInterpreter *scin);
-struct style_id
+struct template_id
{
char *name;
char *friendlyname;
+ SCBlock *scblock;
};
-extern struct style_id *list_styles(SCInterpreter *scin, int *n);
+extern struct template_id *sc_interp_get_templates(SCInterpreter *scin,
+ int *np);
#endif /* SC_INTERP_H */
diff --git a/src/sc_parse.c b/src/sc_parse.c
index ed2785a..56b72bf 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -86,6 +86,15 @@ const char *sc_block_contents(const SCBlock *bl)
}
+void sc_block_append_p(SCBlock *bl, SCBlock *bln)
+{
+ if ( bl != NULL ) {
+ bln->next = bl->next;
+ bl->next = bln;
+ }
+}
+
+
/* Insert a new block after "bl". "name", "options" and "contents"
* will not be copied. Returns the block just created, or NULL on error.
* If *blfp points to NULL, it will updated to point at the new block. */
@@ -102,10 +111,7 @@ SCBlock *sc_block_append(SCBlock *bl, char *name, char *opt, char *contents,
bln->child = NULL;
bln->next = NULL;
- if ( bl != NULL ) {
- bln->next = bl->next;
- bl->next = bln;
- }
+ sc_block_append_p(bl, bln);
if ( (blfp != NULL) && (*blfp == NULL) ) {
*blfp = bln;
diff --git a/src/sc_parse.h b/src/sc_parse.h
index 2d8b0d7..66b3ff9 100644
--- a/src/sc_parse.h
+++ b/src/sc_parse.h
@@ -47,6 +47,8 @@ extern SCBlock *sc_block_append(SCBlock *bl,
char *name, char *opt, char *contents,
SCBlock **blfp);
+extern void sc_block_append_p(SCBlock *bl, SCBlock *bln);
+
extern SCBlock *sc_block_append_end(SCBlock *bl,
char *name, char *opt, char *contents);
diff --git a/src/slide_window.c b/src/slide_window.c
index 33a4fe0..be7215a 100644
--- a/src/slide_window.c
+++ b/src/slide_window.c
@@ -85,66 +85,6 @@ static gint UNUSED add_furniture(GtkWidget *widget, struct menu_pl *pl)
}
-static void UNUSED update_style_menus(SlideWindow *sw)
-{
- //GtkWidget *menu;
- SCInterpreter *scin;
- struct style_id *styles;
- int i, n_sty;
-
- /* Free old list */
- for ( i=0; i<sw->n_style_menu; i++ ) {
- gtk_widget_destroy(sw->style_menu[i].widget);
- free(sw->style_menu[i].style_name);
- }
- free(sw->style_menu);
-
- /* Get the list of styles from the style sheet */
- scin = sc_interp_new(NULL, sw->p->lang, NULL);
- if ( scin == NULL ) {
- fprintf(stderr, "Failed to set up interpreter.\n");
- return;
- }
- sc_interp_run_stylesheet(scin, sw->p->stylesheet);
-
- styles = list_styles(scin, &n_sty);
- if ( styles == NULL ) return;
-
- sc_interp_destroy(scin);
-
- /* Set up list for next time */
- sw->style_menu = calloc(n_sty, sizeof(struct menu_pl));
- if ( sw->style_menu == NULL ) return;
-
-#if 0 // FIXME
- /* Add the styles to the "Insert" menu */
- menu = gtk_ui_manager_get_widget(sw->ui, "/displaywindow/insert");
- menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
-
- for ( i=0; i<n_sty; i++ ) {
-
- GtkWidget *item;
-
- item = gtk_menu_item_new_with_label(styles[i].friendlyname);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
-
- sw->style_menu[i].sw = sw;
- sw->style_menu[i].widget = item;
- sw->style_menu[i].style_name = styles[i].name;
-
- g_signal_connect(G_OBJECT(item), "activate",
- G_CALLBACK(add_furniture),
- &sw->style_menu[i]);
-
- free(styles[i].friendlyname);
- }
-
- gtk_widget_show_all(menu);
- free(styles);
-#endif
-}
-
-
static void delete_frame_sig(GSimpleAction *action, GVariant *parameter,
gpointer vp)
{