node-editor: Add Ctrl-Shift-V

Make Ctrl-Shift-V trigger a 'paste-as-node' action which replaces
the current content with the render node in the clipboard.
This commit is contained in:
Matthias Clasen 2024-08-18 13:47:28 -04:00
parent 29b6eab0ea
commit cefaec5d6f
2 changed files with 40 additions and 0 deletions

View File

@ -1205,6 +1205,19 @@ node_editor_window_add_renderer (NodeEditorWindow *self,
g_object_unref (paintable);
}
static void
update_paste_action (GdkClipboard *clipboard,
GParamSpec *pspec,
gpointer data)
{
GtkWidget *widget = GTK_WIDGET (data);
gboolean has_node;
has_node = gdk_content_formats_contain_mime_type (gdk_clipboard_get_formats (clipboard), "application/x-gtk-render-node");
gtk_widget_action_set_enabled (widget, "paste-node", has_node);
}
static void
node_editor_window_realize (GtkWidget *widget)
{
@ -1242,6 +1255,7 @@ node_editor_window_realize (GtkWidget *widget)
self->after_paint_handler = g_signal_connect (frameclock, "after-paint",
G_CALLBACK (after_paint), self);
g_signal_connect (gtk_widget_get_clipboard (widget), "notify::formats", G_CALLBACK (update_paste_action), widget);
}
static void
@ -1251,6 +1265,8 @@ node_editor_window_unrealize (GtkWidget *widget)
GdkFrameClock *frameclock;
guint i;
g_signal_handlers_disconnect_by_func (gtk_widget_get_clipboard (widget), update_paste_action, widget);
frameclock = gtk_widget_get_frame_clock (widget);
g_signal_handler_disconnect (frameclock, self->after_paint_handler);
self->after_paint_handler = 0;
@ -1615,6 +1631,19 @@ edit_action_cb (GtkWidget *widget,
node_editor_window_edit (self, &start);
}
static void
paste_node_cb (GtkWidget *widget,
const char *action_name,
GVariant *parameter)
{
NodeEditorWindow *self = NODE_EDITOR_WINDOW (widget);
GtkTextBuffer *buffer;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->text_view));
gtk_text_buffer_set_text (buffer, "", 0);
gtk_text_buffer_paste_clipboard (buffer, gtk_widget_get_clipboard (widget), NULL, TRUE);
}
static void
node_editor_window_set_property (GObject *object,
guint prop_id,
@ -1727,6 +1756,13 @@ node_editor_window_class_init (NodeEditorWindowClass *class)
action = gtk_named_action_new ("smart-edit");
shortcut = gtk_shortcut_new (trigger, action);
gtk_widget_class_add_shortcut (widget_class, shortcut);
gtk_widget_class_install_action (widget_class, "paste-node", NULL, paste_node_cb);
trigger = gtk_keyval_trigger_new (GDK_KEY_v, GDK_CONTROL_MASK | GDK_SHIFT_MASK);
action = gtk_named_action_new ("paste-node");
shortcut = gtk_shortcut_new (trigger, action);
gtk_widget_class_add_shortcut (widget_class, shortcut);
}
static GtkWidget *

View File

@ -22,6 +22,10 @@
</menu>
<menu id="extra_menu">
<section>
<item>
<attribute name="label" translatable="yes">Paste _Node</attribute>
<attribute name="action">paste-node</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Assisted _Edit</attribute>
<attribute name="action">smart-edit</attribute>