[Xfce4-commits] [panel-plugins/xfce4-clipman-plugin] 03/03: menu: Indicate primary and clipboard content

noreply at xfce.org noreply at xfce.org
Sun Apr 5 23:45:30 CEST 2020


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-clipman-plugin.

commit 0f6742ca48a72c52a1c5eab50567a7121959f972
Author: Florian Schüller <florian.schueller at gmail.com>
Date:   Sun Apr 5 11:56:22 2020 +0200

    menu: Indicate primary and clipboard content
    
    Indicate primary even if it is ignored/not collected in the history.
---
 panel-plugin/menu.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 8 deletions(-)

diff --git a/panel-plugin/menu.c b/panel-plugin/menu.c
index 8261189..3ce09df 100644
--- a/panel-plugin/menu.c
+++ b/panel-plugin/menu.c
@@ -339,6 +339,7 @@ _clipman_menu_update_list (ClipmanMenu *menu)
   gint pos = 0;
   gint i = 0;
   gchar *selection_primary;
+  gchar *selection_clipboard;
   gboolean skip_primary = FALSE;
 
   /* Get the most recent item in the history */
@@ -354,6 +355,13 @@ _clipman_menu_update_list (ClipmanMenu *menu)
   list = clipman_history_get_list (menu->priv->history);
   if (menu->priv->reverse_order)
     list = g_slist_reverse (list);
+
+  clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+  selection_clipboard = gtk_clipboard_wait_for_text (clipboard);
+
+  clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+  selection_primary = gtk_clipboard_wait_for_text (clipboard);
+
   for (i = 0, l = list; i < menu->priv->max_menu_items; i++, l = l->next)
     {
       if (l == NULL)
@@ -384,13 +392,37 @@ G_GNUC_END_IGNORE_DEPRECATIONS
       g_signal_connect (mi, "activate", G_CALLBACK (cb_set_clipboard), item);
       g_object_set_data (G_OBJECT (mi), "paste-on-activate", GUINT_TO_POINTER (menu->priv->paste_on_activate));
 
-      if (item == item_to_restore)
+      if (selection_clipboard && (item->type == CLIPMAN_HISTORY_TYPE_TEXT)
+          && (g_strcmp0 (selection_clipboard, item->content.text) == 0))
         {
-          image = gtk_image_new_from_icon_name ("go-next-symbolic", GTK_ICON_SIZE_MENU);
+          image = gtk_image_new_from_icon_name ("edit-paste-symbolic",
+                                                GTK_ICON_SIZE_MENU);
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
+          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), image);
 G_GNUC_END_IGNORE_DEPRECATIONS
         }
+      else
+        if (selection_primary && (item->type == CLIPMAN_HISTORY_TYPE_TEXT)
+            && (g_strcmp0 (selection_primary, item->content.text) == 0))
+          {
+            image = gtk_image_new_from_icon_name ("input-mouse-symbolic",
+                                                  GTK_ICON_SIZE_MENU);
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+            gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), image);
+  G_GNUC_END_IGNORE_DEPRECATIONS
+          }
+        else
+          /* not sure if "item_to_restore" can be neither primary nor clipboard...
+           * but let's leave this as fallback
+           */
+          if (item == item_to_restore)
+            {
+              image = gtk_image_new_from_icon_name ("go-next-symbolic",
+                                            GTK_ICON_SIZE_MENU);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+              gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), image);
+G_GNUC_END_IGNORE_DEPRECATIONS
+            }
 
       menu->priv->list = g_slist_prepend (menu->priv->list, mi);
       gtk_menu_shell_insert (GTK_MENU_SHELL (menu), mi, pos++);
@@ -444,13 +476,14 @@ G_GNUC_END_IGNORE_DEPRECATIONS
       gtk_widget_set_sensitive (menu->priv->mi_clear_history, FALSE);
     }
 
-  /* Show the primary clipboard item so it can be selected for keyboard pasting */
-  clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
-  selection_primary = gtk_clipboard_wait_for_text (clipboard);
+  /* Show the primary clipboard item so it can be selected for keyboard pasting
+   * even if "ignore selection" is enabled!
+   */
   if (selection_primary)
     {
-      skip_primary = (item_to_restore
-          && g_strcmp0 (selection_primary, item_to_restore->content.text) == 0);
+      skip_primary = (g_strcmp0 (selection_primary, selection_clipboard) == 0) ||
+      (item_to_restore && (item_to_restore->type == CLIPMAN_HISTORY_TYPE_TEXT) && g_strcmp0 (selection_primary, item_to_restore->content.text) == 0);
+
       if (skip_primary == FALSE)
         {
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@@ -465,6 +498,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
         }
       g_free (selection_primary);
     }
+  g_free (selection_clipboard);
 
   _clipman_menu_adjust_geometry(menu);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list