diff options
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.c | 26 | ||||
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.h | 1 | ||||
-rw-r--r-- | libstorycode/narrative.c | 20 | ||||
-rw-r--r-- | libstorycode/narrative.h | 2 | ||||
-rw-r--r-- | libstorycode/presentation.c | 12 | ||||
-rw-r--r-- | libstorycode/presentation.h | 1 | ||||
-rw-r--r-- | src/narrative_window.c | 2 |
7 files changed, 63 insertions, 1 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 6a08857..66ed570 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -1214,3 +1214,29 @@ void gtk_narrative_view_set_cursor_para(GtkNarrativeView *e, signed int pos) e->cpos.trail = 0; redraw(e); } + +void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e) +{ + Narrative *n; + Slide *s; + int pos; + + n = presentation_get_narrative(e->p); + + s = slide_new(); + if ( s == NULL ) return; + + split_paragraph_at_cursor(n, e->cpos); + pos = narrative_get_slide_number(n, e->cpos.para); + presentation_insert_slide(e->p, s, pos); + narrative_insert_slide(n, s, e->cpos.para+1); + + rewrap_range(e, e->cpos.para, e->cpos.para+2); + e->cpos.para++; + e->cpos.pos = 0; + e->cpos.trail = 0; + update_size(e); + check_cursor_visible(e); + emit_change_sig(e); + redraw(e); +} diff --git a/libstorycode/gtk/gtknarrativeview.h b/libstorycode/gtk/gtknarrativeview.h index 9cbdcbd..c85ca1f 100644 --- a/libstorycode/gtk/gtknarrativeview.h +++ b/libstorycode/gtk/gtknarrativeview.h @@ -110,5 +110,6 @@ extern void gtk_narrative_view_paste(GtkNarrativeView *e); extern void gtk_narrative_view_set_para_highlight(GtkNarrativeView *e, int para_highlight); extern int gtk_narrative_view_get_cursor_para(GtkNarrativeView *e); extern void gtk_narrative_view_set_cursor_para(GtkNarrativeView *e, signed int pos); +extern void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e); #endif /* GTK_NARRATIVE_VIEW_H */ diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index c0ae0d7..5dfe117 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -157,6 +157,15 @@ void narrative_add_slide(Narrative *n, Slide *slide) } +void narrative_insert_slide(Narrative *n, Slide *slide, int pos) +{ + struct narrative_item *item = insert_item(n, pos-1); + item->type = NARRATIVE_ITEM_SLIDE; + item->slide = slide; + item->slide_thumbnail = NULL; +} + + static void delete_item(Narrative *n, int del) { int i; @@ -262,3 +271,14 @@ Slide *narrative_get_slide(Narrative *n, int para) if ( n->items[para].type != NARRATIVE_ITEM_SLIDE ) return NULL; return n->items[para].slide; } + + +int narrative_get_slide_number(Narrative *n, int para) +{ + int i; + int ns = 0; + for ( i=0; i<n->n_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) ns++; + } + return ns; +} diff --git a/libstorycode/narrative.h b/libstorycode/narrative.h index 3ee215f..193339d 100644 --- a/libstorycode/narrative.h +++ b/libstorycode/narrative.h @@ -38,11 +38,13 @@ extern void narrative_add_prestitle(Narrative *n, char *text); extern void narrative_add_bp(Narrative *n, char *text); extern void narrative_add_text(Narrative *n, char *text); extern void narrative_add_slide(Narrative *n, Slide *slide); +extern void narrative_insert_slide(Narrative *n, Slide *slide, int pos); extern void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2); extern void narrative_split_item(Narrative *n, int i1, size_t o1); extern int narrative_get_num_items(Narrative *n); extern Slide *narrative_get_slide(Narrative *n, int para); +extern int narrative_get_slide_number(Narrative *n, int para); #endif /* NARRATIVE_H */ diff --git a/libstorycode/presentation.c b/libstorycode/presentation.c index 817a55a..925f011 100644 --- a/libstorycode/presentation.c +++ b/libstorycode/presentation.c @@ -155,6 +155,18 @@ void presentation_add_slide(Presentation *p, Slide *s) } +void presentation_insert_slide(Presentation *p, Slide *s, int pos) +{ + int i; + presentation_add_slide(p, NULL); + assert(pos < p->n_slides); + for ( i=p->n_slides-1; i>pos+1; i-- ) { + p->slides[i] = p->slides[i-1]; + } + p->slides[pos] = s; +} + + int presentation_get_num_slides(Presentation *p) { return p->n_slides; diff --git a/libstorycode/presentation.h b/libstorycode/presentation.h index 444024b..f2f22f4 100644 --- a/libstorycode/presentation.h +++ b/libstorycode/presentation.h @@ -45,6 +45,7 @@ extern int presentation_get_unsaved(Presentation *p); extern void presentation_add_stylesheet(Presentation *p, Stylesheet *ss); extern void presentation_add_narrative(Presentation *p, Narrative *n); extern void presentation_add_slide(Presentation *p, Slide *s); +extern void presentation_insert_slide(Presentation *p, Slide *s, int pos); extern int presentation_get_num_slides(Presentation *p); extern Slide *presentation_get_slide_by_number(Presentation *p, int i); diff --git a/src/narrative_window.c b/src/narrative_window.c index 1e66af2..94515df 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -308,7 +308,7 @@ static void add_slide_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { NarrativeWindow *nw = vp; - + gtk_narrative_view_add_slide_at_cursor(GTK_NARRATIVE_VIEW(nw->nv)); presentation_set_unsaved(nw->p); update_titlebar(nw); } |