Skip to content

Commit

Permalink
#596: support copy image (#601)
Browse files Browse the repository at this point in the history
make it work
  • Loading branch information
lidaobing authored Jun 20, 2024
1 parent 8ea6c1c commit a28cf30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/iptux/DialogBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,14 @@ gboolean DialogBase::OnImageButtonPress(DialogBase*,
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
g_signal_connect_swapped(menu_item, "activate",
G_CALLBACK(DialogBase::OnSaveImage), image);
menu_item = gtk_menu_item_new_with_label(_("Copy Image"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
g_signal_connect_swapped(menu_item, "activate",
G_CALLBACK(DialogBase::OnCopyImage), image);
gtk_widget_show_all(menu);

gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent*)&event);
g_signal_connect(menu, "hide", G_CALLBACK(gtk_widget_destroy), menu);
return TRUE;
}

Expand Down Expand Up @@ -910,4 +915,15 @@ void DialogBase::OnSaveImage(GtkImage* image) {
gtk_widget_destroy(dialog);
}

void DialogBase::OnCopyImage(GtkImage* image) {
GdkPixbuf* pixbuf = gtk_image_get_pixbuf(image);
if (!pixbuf) {
LOG_ERROR("Failed to create pixbuf from image.");
return;
}

GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_image(clipboard, pixbuf);
}

} // namespace iptux
1 change: 1 addition & 0 deletions src/iptux/DialogBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class DialogBase : public SessionAbstract, public sigc::trackable {
GtkTextChildAnchor* anchor,
GtkTextBuffer* buffer);
static void OnSaveImage(GtkImage* self);
static void OnCopyImage(GtkImage* self);

protected:
Application* app;
Expand Down

0 comments on commit a28cf30

Please sign in to comment.