Insert bullet points
authorThomas White <taw@physics.org>
Fri, 24 Jan 2020 13:58:45 +0000 (14:58 +0100)
committerThomas White <taw@physics.org>
Fri, 24 Jan 2020 13:58:45 +0000 (14:58 +0100)
data/menus.ui
libstorycode/gtk/gtknarrativeview.c
libstorycode/gtk/gtknarrativeview.h
src/narrative_window.c

index 019bbed..988f88a 100644 (file)
           <attribute name='label' translatable='yes'>Slide</attribute>
           <attribute name='action'>win.slide</attribute>
         </item>
+        <item>
+          <attribute name='label' translatable='yes'>Bullet point</attribute>
+          <attribute name='action'>win.bp</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>Presentation title</attribute>
+          <attribute name='action'>win.prestitle</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>Start of segment</attribute>
+          <attribute name='action'>win.segstart</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>End of segment</attribute>
+          <attribute name='action'>win.segend</attribute>
+        </item>
       </section>
       <section>
         <item>
index 24e4949..11d17c0 100644 (file)
@@ -1304,27 +1304,35 @@ void gtk_narrative_view_set_cursor_para(GtkNarrativeView *e, signed int pos)
 }
 
 
-void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e)
+int maybe_split_para(GtkNarrativeView *e)
 {
-       Slide *s;
-
-       s = slide_new();
-       if ( s == NULL ) return;
-
        if ( narrative_item_is_text(e->n, e->cpos.para) ) {
                size_t off = narrative_pos_trail_to_offset(e->n, e->cpos.para,
                                                           e->cpos.pos, e->cpos.trail);
                if ( (off > 0) && (off < gtknv_end_offset_of_para(e->n, e->cpos.para)) ) {
                        narrative_split_item(e->n, e->cpos.para, off);
-                       narrative_insert_slide(e->n, s, e->cpos.para+1);
+                       return e->cpos.para+1;
                } else if ( off == 0 ) {
-                       narrative_insert_slide(e->n, s, e->cpos.para);
+                       return e->cpos.para;
                } else {
-                       narrative_insert_slide(e->n, s, e->cpos.para+1);
+                       return e->cpos.para+1;
                }
        } else {
-               narrative_insert_slide(e->n, s, e->cpos.para+1);
+               return e->cpos.para+1;
        }
+}
+
+
+void gtk_narrative_view_add_slide_at_cursor(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++;
@@ -1337,6 +1345,34 @@ void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e)
 }
 
 
+void gtk_narrative_view_add_bp_at_cursor(GtkNarrativeView *e)
+{
+       int insert_pos;
+       struct text_run *runs;
+
+       runs = malloc(sizeof(struct text_run));
+       if ( runs == NULL ) return;
+
+       runs[0].text = strdup("");
+       runs[0].type = TEXT_RUN_NORMAL;
+       if ( runs[0].text == NULL ) {
+               free(runs);
+               return;
+       }
+
+       insert_pos = maybe_split_para(e);
+       narrative_insert_bp(e->n, insert_pos, runs, 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);
+       gtknv_emit_change_sig(e);
+       gtknv_redraw(e);
+}
+
 void gtk_narrative_view_redraw(GtkNarrativeView *e)
 {
        e->rewrap_needed = 1;
index 2a2b0e9..73cc19e 100644 (file)
@@ -113,6 +113,7 @@ extern void gtk_narrative_view_set_para_highlight(GtkNarrativeView *e, int para_
 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_redraw(GtkNarrativeView *e);
 
index 9a06a07..e414556 100644 (file)
@@ -326,6 +326,15 @@ static void add_slide_sig(GSimpleAction *action, GVariant *parameter,
        update_titlebar(nw);
 }
 
+static void add_bp_sig(GSimpleAction *action, GVariant *parameter,
+                          gpointer vp)
+{
+       NarrativeWindow *nw = vp;
+       gtk_narrative_view_add_bp_at_cursor(GTK_NARRATIVE_VIEW(nw->nv));
+       narrative_set_unsaved(nw->n);
+       update_titlebar(nw);
+}
+
 
 static void set_clock_pos(NarrativeWindow *nw)
 {
@@ -670,6 +679,7 @@ GActionEntry nw_entries[] = {
        { "save", save_sig, NULL, NULL, NULL },
        { "saveas", saveas_sig, NULL, NULL, NULL },
        { "slide", add_slide_sig, NULL, NULL, NULL },
+       { "bp", add_bp_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 },