From 02828602d6f2f1ec2a7e718dea8d4bedc9dc300d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 4 Jan 2018 22:35:55 +0100 Subject: Copy and paste entire frames --- src/colloquium.c | 4 ++++ src/sc_editor.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/sc_editor.h | 2 ++ src/sc_parse.c | 12 ++++++++++++ src/sc_parse.h | 2 ++ src/slide_window.c | 19 +++++++++++++++++++ 6 files changed, 81 insertions(+) (limited to 'src') diff --git a/src/colloquium.c b/src/colloquium.c index c89d61e..001786c 100644 --- a/src/colloquium.c +++ b/src/colloquium.c @@ -321,6 +321,10 @@ static void colloquium_startup(GApplication *papp) " win.deleteframe" " " " " + " Copy Frame" + " win.copyframe" + " " + " " " Delete slide" " win.deleteslide" " " diff --git a/src/sc_editor.c b/src/sc_editor.c index c94dcba..fa86706 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -431,6 +431,48 @@ void sc_editor_redraw(SCEditor *e) } +void paste_received(GtkClipboard *cb, const gchar *t, gpointer vp) +{ + SCEditor *e = vp; + SCBlock *nf; + nf = sc_parse(t); + sc_block_append_block(e->scblocks, nf); + full_rerender(e); +} + + +void sc_editor_paste(SCEditor *e) +{ + GtkClipboard *cb; + GdkAtom atom; + + atom = gdk_atom_intern("CLIPBOARD", FALSE); + if ( atom == GDK_NONE ) return; + cb = gtk_clipboard_get(atom); + gtk_clipboard_request_text(cb, paste_received, e); +} + + +void sc_editor_copy_selected_frame(SCEditor *e) +{ + char *t; + GtkClipboard *cb; + GdkAtom atom; + + if ( e->selection == NULL ) return; + + atom = gdk_atom_intern("CLIPBOARD", FALSE); + if ( atom == GDK_NONE ) return; + + cb = gtk_clipboard_get(atom); + + t = serialise_sc_block(e->selection->scblocks); + + gtk_clipboard_set_text(cb, t, -1); + free(t); +} + + void sc_editor_delete_selected_frame(SCEditor *e) { sc_block_delete(&e->scblocks, e->selection->scblocks); diff --git a/src/sc_editor.h b/src/sc_editor.h index b2fd6a5..9996834 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -186,6 +186,8 @@ 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 sc_editor_paste(SCEditor *e); +extern void sc_editor_copy_selected_frame(SCEditor *e); extern void sc_editor_delete_selected_frame(SCEditor *e); extern void sc_editor_remove_cursor(SCEditor *e); extern SCBlock *split_paragraph_at_cursor(SCEditor *e); diff --git a/src/sc_parse.c b/src/sc_parse.c index 3853800..a8b2c09 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -140,6 +140,18 @@ SCBlock *sc_block_append_end(SCBlock *bl, char *name, char *opt, char *contents) } +void sc_block_append_block(SCBlock *bl, SCBlock *bln) +{ + + if ( bl == NULL ) return; + + while ( bl->next != NULL ) bl = bl->next; + + bl->next = bln; + bln->next = NULL; +} + + /* Append a new block to the chain inside "parent". * "name", "options" and "contents" will not be copied. Returns the block just * created, or NULL on error. */ diff --git a/src/sc_parse.h b/src/sc_parse.h index 41a1112..6f8cb51 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -50,6 +50,8 @@ extern SCBlock *sc_block_append(SCBlock *bl, extern void sc_block_append_p(SCBlock *bl, SCBlock *bln); +extern void sc_block_append_block(SCBlock *bl, SCBlock *bln); + extern SCBlock *sc_block_append_end(SCBlock *bl, char *name, char *opt, char *contents); diff --git a/src/slide_window.c b/src/slide_window.c index 21df394..ae89062 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -75,6 +75,23 @@ struct menu_pl }; +static void paste_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + SlideWindow *sw = vp; + sc_editor_paste(sw->sceditor); +} + + + +static void copy_frame_sig(GSimpleAction *action, GVariant *parameter, + gpointer vp) +{ + SlideWindow *sw = vp; + sc_editor_copy_selected_frame(sw->sceditor); +} + + static void delete_frame_sig(GSimpleAction *action, GVariant *parameter, gpointer vp) { @@ -195,6 +212,8 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, GActionEntry sw_entries[] = { + { "paste", paste_sig, NULL, NULL, NULL }, + { "copyframe", copy_frame_sig, NULL, NULL, NULL }, { "deleteframe", delete_frame_sig, NULL, NULL, NULL }, { "first", first_slide_sig, NULL, NULL, NULL }, { "prev", prev_slide_sig, NULL, NULL, NULL }, -- cgit v1.2.3