aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-01-04 22:35:55 +0100
committerThomas White <taw@physics.org>2018-01-04 22:35:55 +0100
commit02828602d6f2f1ec2a7e718dea8d4bedc9dc300d (patch)
tree983ba5c7cdeaef546f28cec786ee3ac5e5848491
parent785c8853383711e6e0bcbdbbcc806907cab391dc (diff)
Copy and paste entire frames
-rw-r--r--src/colloquium.c4
-rw-r--r--src/sc_editor.c42
-rw-r--r--src/sc_editor.h2
-rw-r--r--src/sc_parse.c12
-rw-r--r--src/sc_parse.h2
-rw-r--r--src/slide_window.c19
6 files changed, 81 insertions, 0 deletions
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)
" <attribute name='action'>win.deleteframe</attribute>"
" </item>"
" <item>"
+ " <attribute name='label'>Copy Frame</attribute>"
+ " <attribute name='action'>win.copyframe</attribute>"
+ " </item>"
+ " <item>"
" <attribute name='label'>Delete slide</attribute>"
" <attribute name='action'>win.deleteslide</attribute>"
" </item>"
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 },