[gnome-characters] character: Add notification for clipboard access



commit 8c7a5d3b890d3faaadc0ce9f83b1529ddf234706
Author: Daiki Ueno <dueno src gnome org>
Date:   Wed Oct 7 18:02:03 2015 +0900

    character: Add notification for clipboard access

 data/character.ui |   52 +++++++++++++++++++++++++++++++++++++++++++++++-----
 src/character.js  |   35 ++++++++++++++++++++++++++++++++---
 2 files changed, 79 insertions(+), 8 deletions(-)
---
diff --git a/data/character.ui b/data/character.ui
index b123d76..946764e 100644
--- a/data/character.ui
+++ b/data/character.ui
@@ -11,7 +11,7 @@
              <object class="GtkGrid" id="character-grid">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
-               <property name="halign">center</property>
+               <property name="halign">fill</property>
                <property name="valign">center</property>
                <property name="border_width">5</property>
                <property name="orientation">vertical</property>
@@ -33,11 +33,53 @@
                  </packing>
                </child>
                <child>
-                 <object class="GtkButton" id="copy-button">
-                   <property name="label" translatable="yes">Copy Character</property>
+                 <object class="GtkBox" id="vbox2">
                    <property name="visible">True</property>
-                   <property name="can_focus">True</property>
-                   <property name="receives_default">False</property>
+                   <property name="orientation">vertical</property>
+                   <child>
+                     <object class="GtkButton" id="copy-button">
+                       <property name="label" translatable="yes">Copy Character</property>
+                       <property name="visible">True</property>
+                       <property name="can_focus">True</property>
+                       <property name="receives_default">False</property>
+                       <property name="halign">center</property>
+                     </object>
+                   </child>
+                   <child>
+                     <object class="GtkOverlay" id="overlay">
+                       <property name="visible">True</property>
+                       <property name="can_focus">False</property>
+                       <child type="overlay">
+                         <object class="GtkRevealer" id="copy-revealer">
+                           <property name="visible">True</property>
+                           <property name="can_focus">False</property>
+                           <property name="transition-type">crossfade</property>
+                           <child>
+                             <object class="GtkLabel" id="copy-label">
+                               <property name="label" translatable="yes">Character copied to 
clipboard</property>
+                               <property name="visible">True</property>
+                               <property name="can_focus">False</property>
+                               <property name="ellipsize">end</property>
+                               <property name="halign">center</property>
+                               <property name="hexpand">True</property>
+                               <property name="valign">center</property>
+                             </object>
+                           </child>
+                         </object>
+                       </child>
+                       <child>
+                         <object class="GtkLabel" id="placeholder-label">
+                           <property name="visible">True</property>
+                           <property name="can_focus">False</property>
+                           <property name="halign">center</property>
+                           <property name="valign">center</property>
+                           <style>
+                             <class name="character-notification"/>
+                           </style>
+                         </object>
+                       </child>
+                     </object>
+                   </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
diff --git a/src/character.js b/src/character.js
index d39e663..7f93af9 100644
--- a/src/character.js
+++ b/src/character.js
@@ -32,7 +32,7 @@ const CharacterDialog = new Lang.Class({
     Extends: Gtk.Dialog,
     Template: 'resource:///org/gnome/Characters/character.ui',
     InternalChildren: ['main-stack', 'character-label', 'detail-label',
-                       'copy-button', 'related-listbox'],
+                       'copy-button', 'copy-revealer', 'related-listbox'],
 
     _init: function(params) {
         let filtered = Params.filter(params, { character: null,
@@ -138,13 +138,42 @@ const CharacterDialog = new Lang.Class({
             headerBar.title = Util.capitalize(name);
     },
 
+    _hideCopyRevealer: function() {
+        if (this._copyRevealerTimeoutId > 0) {
+            GLib.source_remove(this._copyRevealerTimeoutId);
+            this._copyRevealerTimeoutId = 0;
+            this._copy_revealer.set_reveal_child(false);
+        }
+    },
+
+    _clipboardOwnerChanged: function(clipboard, event) {
+        let text = clipboard.wait_for_text();
+        if (text != this._character)
+            this._hideCopyRevealer();
+    },
+
     _copyCharacter: function() {
-        let clipboard = Gc.gtk_clipboard_get();
+        if (this._clipboard == null) {
+            this._clipboard = Gc.gtk_clipboard_get();
+            this._clipboard.connect('owner-change',
+                                    Lang.bind(this,
+                                              this._clipboardOwnerChanged));
+        }
+
         // FIXME: GLib.unichar_to_utf8() has missing (nullable)
         // annotation to the outbuf argument.
         let outbuf = '      ';
         let length = GLib.unichar_to_utf8(this._character, outbuf);
-        clipboard.set_text(this._character, length);
+        this._clipboard.set_text(this._character, length);
+
+        // Show a feedback message with a revealer.  The message is
+        // hidden after 2 seconds, or when another client set a
+        // different text to clipboard.
+        this._hideCopyRevealer();
+        this._copy_revealer.set_reveal_child(true);
+        this._copyRevealerTimeoutId =
+            GLib.timeout_add(GLib.PRIORITY_DEFAULT, 2000,
+                             Lang.bind(this, this._hideCopyRevealer));
     },
 
     _handleRowSelected: function(listBox, row) {


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