[gnome-calculator/gnome-3-38] Use shell copy to clipboard (fixes #178)



commit c840c69c2a95cda083368a93070ef472db0f07b2
Author: Robert Roth <robert roth off gmail com>
Date:   Thu Sep 24 09:02:56 2020 +0300

    Use shell copy to clipboard (fixes #178)

 search-provider/search-provider.vala | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/search-provider/search-provider.vala b/search-provider/search-provider.vala
index 7aa5f44f..f37d24dc 100644
--- a/search-provider/search-provider.vala
+++ b/search-provider/search-provider.vala
@@ -20,7 +20,7 @@ public class SearchProvider : Object
     private Queue<string> queued_equations;
     private HashTable<string, string> cached_equations;
 
-    private const string COPY_TO_CLIPBOARD_ID = "copy-to-clipboard";
+    private const string COPY_TO_CLIPBOARD_ID = "copy-to-clipboard-";
 
     public SearchProvider (SearchProviderApp app)
     {
@@ -136,7 +136,7 @@ public class SearchProvider : Object
         /* We have at most one result: the search terms as one string */
         var equation = terms_to_equation (terms);
         if (yield solve_equation (equation))
-            return { equation, COPY_TO_CLIPBOARD_ID };
+            return { equation, COPY_TO_CLIPBOARD_ID+equation };
         else
             return new string[0];
     }
@@ -158,10 +158,10 @@ public class SearchProvider : Object
         string result;
         uint32 equation_index;
 
-        if (results.length == 1 && results[0] == COPY_TO_CLIPBOARD_ID)
+        if (results.length == 1 && results[0].has_prefix(COPY_TO_CLIPBOARD_ID))
             return new HashTable<string, Variant>[0];
 
-        if (results.length == 1 || results[1] == COPY_TO_CLIPBOARD_ID)
+        if (results.length == 1 || results[1].has_prefix(COPY_TO_CLIPBOARD_ID))
             equation_index = 0;
         else
             equation_index = 1;
@@ -185,9 +185,10 @@ public class SearchProvider : Object
         {
             uint32 copy_index = (equation_index + 1) % 2;
             metadata[copy_index] = new HashTable<string, Variant> (str_hash, str_equal);
-            metadata[copy_index].insert ("id", COPY_TO_CLIPBOARD_ID);
+            metadata[copy_index].insert ("id", COPY_TO_CLIPBOARD_ID+equation);
             metadata[copy_index].insert ("name", _("Copy"));
             metadata[copy_index].insert ("description", _("Copy result to clipboard"));
+            metadata[copy_index].insert ("clipboardText", @"$result");
         }
 
         return metadata;
@@ -209,7 +210,7 @@ public class SearchProvider : Object
 
     public async void activate_result (string result_id, string[] terms, uint32 timestamp) throws Error
     {
-        if (result_id == COPY_TO_CLIPBOARD_ID)
+        if (result_id.has_prefix(COPY_TO_CLIPBOARD_ID))
         {
             string equation = terms_to_equation (terms);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]