diff options
author | Thomas White <taw@bitwiz.org.uk> | 2015-02-22 16:12:20 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2015-02-22 16:12:20 +0100 |
commit | 24e5163fd377e860a62595d01b187be8df1d7a7d (patch) | |
tree | 14ee72c70fc6a7c7f4ab8c243f78d1b390c6b4b2 | |
parent | c12f041d4e151cf0bbbb4e2c92c4bbc45e5fa67a (diff) |
WIP on slide adding
-rw-r--r-- | src/narrative_window.c | 4 | ||||
-rw-r--r-- | src/sc_editor.c | 29 | ||||
-rw-r--r-- | src/sc_editor.h | 1 | ||||
-rw-r--r-- | src/sc_parse.c | 13 | ||||
-rw-r--r-- | src/sc_parse.h | 3 |
5 files changed, 48 insertions, 2 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c index a1d79bd..0a2a11f 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -124,6 +124,10 @@ static void delete_frame_sig(GSimpleAction *action, GVariant *parameter, gpointe static void add_slide_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { + SCBlock *slide; + NarrativeWindow *nw = vp; + slide = sc_parse("\\slide{}"); + insert_scblock(slide, nw->sceditor); } diff --git a/src/sc_editor.c b/src/sc_editor.c index da66ce4..d261e7c 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -506,6 +506,35 @@ static void move_cursor(SCEditor *e, signed int x, signed int y) } +void insert_scblock(SCBlock *scblock, SCEditor *e) +{ + int sln, sbx, sps; + struct wrap_box *sbox; + struct frame *fr = e->cursor_frame; + + if ( fr == NULL ) return; + + /* If this is, say, the top level frame, do nothing */ + if ( fr->boxes == NULL ) return; + + sln = e->cursor_line; + sbx = e->cursor_box; + sps = e->cursor_pos; + sbox = &e->cursor_frame->lines[sln].boxes[sbx]; + + sc_insert_block(sbox->scblock, sps+sbox->offs_char, scblock); + + fr->empty = 0; + + rerender(e); + + fixup_cursor(e); + advance_cursor(e); + + redraw_editor(e); +} + + static void insert_text(char *t, SCEditor *e) { int sln, sbx, sps; diff --git a/src/sc_editor.h b/src/sc_editor.h index 81e0bae..93f2313 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -162,5 +162,6 @@ extern void sc_editor_set_min_border(SCEditor *e, double min_border); extern void sc_editor_set_top_frame_editable(SCEditor *e, int top_frame_editable); extern void sc_editor_set_callbacks(SCEditor *e, SCCallbackList *cbl); +extern void insert_scblock(SCBlock *scblock, SCEditor *e); #endif /* SC_EDITOR_H */ diff --git a/src/sc_parse.c b/src/sc_parse.c index e4f0e0e..1f3645a 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -1,7 +1,7 @@ /* * sc_parse.c * - * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -555,6 +555,17 @@ void sc_insert_text(SCBlock *b1, int o1, const char *t) } +void sc_insert_block(SCBlock *b1, int o1, SCBlock *ins) +{ + char *p1 = g_utf8_offset_to_pointer(b1->contents, o1); + SCBlock *old_next = b1->next; + b1->next = ins; + if ( strlen(p1) > 0 ) { + // sc_block_append_end(b1, NULL, NULL, p1); + } +} + + static void delete_from_block(SCBlock *b, int o1, int o2) { if ( o1 == o2 ) return; /* nothing to delete */ diff --git a/src/sc_parse.h b/src/sc_parse.h index b86293c..373f2cd 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -1,7 +1,7 @@ /* * sc_parse.h * - * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -68,6 +68,7 @@ extern SCBlock *find_last_child(SCBlock *bl); extern void sc_block_set_options(SCBlock *bl, char *opt); extern void sc_block_set_contents(SCBlock *bl, char *con); extern void sc_insert_text(SCBlock *b1, int o1, const char *t); +extern void sc_insert_block(SCBlock *b1, int o1, SCBlock *ins); extern void sc_delete_text(SCBlock *b1, int o1, SCBlock *b2, int o2); extern void show_sc_blocks(const SCBlock *bl); |