From f851408cf93b3f4e65e1c32f13c04aff77d6c0ff Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Sat, 22 Jun 2024 18:05:08 -0700 Subject: [PATCH 1/2] fix bug --- src/iptux/DialogBase.cpp | 8 +------- src/iptux/DialogPeer.cpp | 2 +- src/iptux/DialogPeerTest.cpp | 2 ++ src/iptux/UiHelper.cpp | 9 +++++++++ src/iptux/UiHelper.h | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/iptux/DialogBase.cpp b/src/iptux/DialogBase.cpp index 05726ca5..de45fb00 100644 --- a/src/iptux/DialogBase.cpp +++ b/src/iptux/DialogBase.cpp @@ -803,13 +803,7 @@ void DialogBase::OnPasteClipboard(DialogBase*, GtkTextView* textview) { buffer = gtk_text_view_get_buffer(textview); gtk_text_buffer_get_iter_at_mark(buffer, &iter, gtk_text_buffer_get_insert(buffer)); - if (gtk_clipboard_wait_is_text_available(clipboard)) { - gchar* text = gtk_clipboard_wait_for_text(clipboard); - if (text) { - gtk_text_buffer_insert(buffer, &iter, text, -1); - g_free(text); - } - } else if (gtk_clipboard_wait_is_image_available(clipboard)) { + if (gtk_clipboard_wait_is_image_available(clipboard)) { GdkPixbuf* pixbuf = gtk_clipboard_wait_for_image(clipboard); if (pixbuf) { gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf); diff --git a/src/iptux/DialogPeer.cpp b/src/iptux/DialogPeer.cpp index 66ac8db4..ca39c075 100644 --- a/src/iptux/DialogPeer.cpp +++ b/src/iptux/DialogPeer.cpp @@ -501,7 +501,7 @@ void DialogPeer::onRequestSharedResources(void*, void*, DialogPeer& self) { void DialogPeer::onPaste(void*, void*, DialogPeer* self) { GtkTextView* textview = GTK_TEXT_VIEW(self->inputTextviewWidget); - DialogBase::OnPasteClipboard(self, textview); + g_signal_emit_by_name(textview, "paste-clipboard"); } void DialogPeer::insertPicture() { diff --git a/src/iptux/DialogPeerTest.cpp b/src/iptux/DialogPeerTest.cpp index b74ef0e1..9f1890d0 100644 --- a/src/iptux/DialogPeerTest.cpp +++ b/src/iptux/DialogPeerTest.cpp @@ -1,4 +1,5 @@ #include "Application.h" +#include "UiHelper.h" #include "gtest/gtest.h" #include "iptux-utils/TestHelper.h" @@ -27,6 +28,7 @@ TEST(DialogPeer, Constructor) { auto clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_text(clipboard, "hello world", -1); do_action(dlgpr, "paste"); + ASSERT_EQ(igtk_text_buffer_get_text(grpinf->getInputBuffer()), "hello world"); GError* error = NULL; auto pixbuf = diff --git a/src/iptux/UiHelper.cpp b/src/iptux/UiHelper.cpp index befcebf0..e3f6a146 100644 --- a/src/iptux/UiHelper.cpp +++ b/src/iptux/UiHelper.cpp @@ -376,4 +376,13 @@ GtkImage* igtk_image_new_with_size(const char* filename, return GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf)); } +string igtk_text_buffer_get_text(GtkTextBuffer* buffer) { + GtkTextIter start, end; + gtk_text_buffer_get_bounds(buffer, &start, &end); + char* res1 = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); + string res(res1); + g_free(res1); + return res; +} + } // namespace iptux diff --git a/src/iptux/UiHelper.h b/src/iptux/UiHelper.h index 7b2adc51..dc3bedb8 100644 --- a/src/iptux/UiHelper.h +++ b/src/iptux/UiHelper.h @@ -37,6 +37,7 @@ GSList* selection_data_get_path(GtkSelectionData* data); * @return GtkImage* null if failed */ GtkImage* igtk_image_new_with_size(const char* filename, int width, int height); +std::string igtk_text_buffer_get_text(GtkTextBuffer* buffer); /** * @brief only used for test, after call this, pop_info, pop_warning, From 467944a87120ccd138cf7befde291939344be94e Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Sat, 22 Jun 2024 18:10:09 -0700 Subject: [PATCH 2/2] add one more test --- src/iptux/DialogPeerTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/iptux/DialogPeerTest.cpp b/src/iptux/DialogPeerTest.cpp index 9f1890d0..c338ebcc 100644 --- a/src/iptux/DialogPeerTest.cpp +++ b/src/iptux/DialogPeerTest.cpp @@ -24,6 +24,7 @@ TEST(DialogPeer, Constructor) { GroupInfo* grpinf = app->getCoreThread()->GetPalRegularItem(pal.get()); grpinf->buffer = gtk_text_buffer_new(NULL); DialogPeer* dlgpr = new DialogPeer(app, grpinf); + ASSERT_EQ(igtk_text_buffer_get_text(grpinf->getInputBuffer()), ""); auto clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_text(clipboard, "hello world", -1);