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 ++ src/narrative_window.c | 44 +++++++++++++++++++ 3 files changed, 111 insertions(+), 21 deletions(-) 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); diff --git a/src/narrative_window.c b/src/narrative_window.c index e414556..9ccdafa 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -326,6 +326,16 @@ static void add_slide_sig(GSimpleAction *action, GVariant *parameter, update_titlebar(nw); } +static void add_prestitle_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + NarrativeWindow *nw = vp; + gtk_narrative_view_add_prestitle_at_cursor(GTK_NARRATIVE_VIEW(nw->nv)); + narrative_set_unsaved(nw->n); + update_titlebar(nw); +} + + static void add_bp_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { @@ -336,6 +346,36 @@ static void add_bp_sig(GSimpleAction *action, GVariant *parameter, } +static void add_segstart_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + NarrativeWindow *nw = vp; + gtk_narrative_view_add_segstart_at_cursor(GTK_NARRATIVE_VIEW(nw->nv)); + narrative_set_unsaved(nw->n); + update_titlebar(nw); +} + + +static void add_segend_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + NarrativeWindow *nw = vp; + gtk_narrative_view_add_segend_at_cursor(GTK_NARRATIVE_VIEW(nw->nv)); + narrative_set_unsaved(nw->n); + update_titlebar(nw); +} + + +static void add_eop_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + NarrativeWindow *nw = vp; + gtk_narrative_view_add_eop_at_cursor(GTK_NARRATIVE_VIEW(nw->nv)); + narrative_set_unsaved(nw->n); + update_titlebar(nw); +} + + static void set_clock_pos(NarrativeWindow *nw) { int pos = gtk_narrative_view_get_cursor_para(GTK_NARRATIVE_VIEW(nw->nv)); @@ -680,6 +720,10 @@ GActionEntry nw_entries[] = { { "saveas", saveas_sig, NULL, NULL, NULL }, { "slide", add_slide_sig, NULL, NULL, NULL }, { "bp", add_bp_sig, NULL, NULL, NULL }, + { "eop", add_eop_sig, NULL, NULL, NULL }, + { "prestitle", add_prestitle_sig, NULL, NULL, NULL }, + { "segstart", add_segstart_sig, NULL, NULL, NULL }, + { "segend", add_segend_sig, NULL, NULL, NULL }, { "loadstylesheet", load_ss_sig, NULL, NULL, NULL }, { "stylesheet", edit_ss_sig, NULL, NULL, NULL }, { "startslideshow", start_slideshow_sig, NULL, NULL, NULL }, -- cgit v1.2.3