From e6d94b1b6c9a8b74d7faa7e80d7a44f604c4e814 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 24 Jan 2020 19:59:06 +0100 Subject: Add all remaining narrative items --- libstorycode/gtk/gtknarrativeview.c | 84 +++++++++++++++++++++++++++---------- libstorycode/gtk/gtknarrativeview.h | 4 ++ 2 files changed, 67 insertions(+), 21 deletions(-) (limited to 'libstorycode') diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 11d17c0..b47f4a4 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -1323,17 +1323,8 @@ int maybe_split_para(GtkNarrativeView *e) } -void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e) +static void post_add_stuff(GtkNarrativeView *e) { - Slide *s; - int insert_pos; - - s = slide_new(); - if ( s == NULL ) return; - - insert_pos = maybe_split_para(e); - narrative_insert_slide(e->n, insert_pos, s); - rewrap_range(e, e->cpos.para, e->cpos.para+2); e->cpos.para++; e->cpos.pos = 0; @@ -1345,34 +1336,85 @@ void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e) } -void gtk_narrative_view_add_bp_at_cursor(GtkNarrativeView *e) +void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e) { int insert_pos; + Slide *s = slide_new(); + if ( s == NULL ) return; + insert_pos = maybe_split_para(e); + narrative_insert_slide(e->n, insert_pos, s); + post_add_stuff(e); +} + + +static struct text_run *blank_run() +{ struct text_run *runs; runs = malloc(sizeof(struct text_run)); - if ( runs == NULL ) return; + if ( runs == NULL ) return NULL; runs[0].text = strdup(""); runs[0].type = TEXT_RUN_NORMAL; if ( runs[0].text == NULL ) { free(runs); - return; + return NULL; } + return runs; +} + + +void gtk_narrative_view_add_prestitle_at_cursor(GtkNarrativeView *e) +{ + int insert_pos; + struct text_run *runs = blank_run(); + if ( runs == NULL ) return; + insert_pos = maybe_split_para(e); + narrative_insert_prestitle(e->n, insert_pos, runs, 1); + post_add_stuff(e); +} + + +void gtk_narrative_view_add_segstart_at_cursor(GtkNarrativeView *e) +{ + int insert_pos; + struct text_run *runs = blank_run(); + if ( runs == NULL ) return; + insert_pos = maybe_split_para(e); + narrative_insert_segstart(e->n, insert_pos, runs, 1); + post_add_stuff(e); +} + + +void gtk_narrative_view_add_segend_at_cursor(GtkNarrativeView *e) +{ + int insert_pos; + insert_pos = maybe_split_para(e); + narrative_insert_segend(e->n, insert_pos); + post_add_stuff(e); +} + + +void gtk_narrative_view_add_bp_at_cursor(GtkNarrativeView *e) +{ + int insert_pos; + struct text_run *runs = blank_run(); + if ( runs == NULL ) return; insert_pos = maybe_split_para(e); narrative_insert_bp(e->n, insert_pos, runs, 1); + post_add_stuff(e); +} - 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); - gtknv_emit_change_sig(e); - gtknv_redraw(e); + +void gtk_narrative_view_add_eop_at_cursor(GtkNarrativeView *e) +{ + int insert_pos = maybe_split_para(e); + narrative_insert_eop(e->n, insert_pos); + post_add_stuff(e); } + void gtk_narrative_view_redraw(GtkNarrativeView *e) { e->rewrap_needed = 1; diff --git a/libstorycode/gtk/gtknarrativeview.h b/libstorycode/gtk/gtknarrativeview.h index 73cc19e..03217b0 100644 --- a/libstorycode/gtk/gtknarrativeview.h +++ b/libstorycode/gtk/gtknarrativeview.h @@ -114,6 +114,10 @@ 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); extern void gtk_narrative_view_add_bp_at_cursor(GtkNarrativeView *e); +extern void gtk_narrative_view_add_segend_at_cursor(GtkNarrativeView *e); +extern void gtk_narrative_view_add_eop_at_cursor(GtkNarrativeView *e); +extern void gtk_narrative_view_add_segstart_at_cursor(GtkNarrativeView *e); +extern void gtk_narrative_view_add_prestitle_at_cursor(GtkNarrativeView *e); extern void gtk_narrative_view_redraw(GtkNarrativeView *e); -- cgit v1.2.3