[gnome-characters] character: Don't show missing character



commit 7d4723af21d291a90fdc7113bbf34819020d90e7
Author: Daiki Ueno <dueno src gnome org>
Date:   Tue Dec 15 16:05:11 2015 +0900

    character: Don't show missing character
    
    Instead, show a message in the content area - "<character> is not
    included in <font>".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744591

 data/character.ui |   43 +++++++++++++++++++++++++++++++++++--------
 src/character.js  |   39 +++++++++++++++++++++++++++++----------
 2 files changed, 64 insertions(+), 18 deletions(-)
---
diff --git a/data/character.ui b/data/character.ui
index 946764e..4bc3921 100644
--- a/data/character.ui
+++ b/data/character.ui
@@ -17,15 +17,42 @@
                <property name="orientation">vertical</property>
                <property name="row_spacing">50</property>
                <child>
-                 <object class="GtkLabel" id="character-label">
+                 <object class="GtkStack" id="character-stack">
                    <property name="visible">True</property>
-                   <property name="can_focus">False</property>
-                   <property name="ellipsize">end</property>
-                   <property name="halign">center</property>
-                   <property name="valign">center</property>
-                   <style>
-                     <class name="character-label"/>
-                   </style>
+                   <child>
+                     <object class="GtkLabel" id="character-label">
+                       <property name="visible">True</property>
+                       <property name="can_focus">False</property>
+                       <property name="ellipsize">end</property>
+                       <property name="halign">center</property>
+                       <property name="valign">center</property>
+                       <style>
+                         <class name="character-label"/>
+                       </style>
+                     </object>
+                     <packing>
+                       <property name="name">character</property>
+                     </packing>
+                   </child>
+                   <child>
+                     <object class="GtkLabel" id="missing-label">
+                       <property name="visible">True</property>
+                       <property name="can_focus">False</property>
+                       <property name="halign">center</property>
+                       <property name="valign">center</property>
+                       <property name="wrap">True</property>
+                       <property name="wrap-mode">word</property>
+                       <property name="width-chars">28</property>
+                       <property name="max-width-chars">28</property>
+                       <property name="justify">center</property>
+                       <style>
+                         <class name="missing-label"/>
+                       </style>
+                     </object>
+                     <packing>
+                       <property name="name">missing</property>
+                     </packing>
+                   </child>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
diff --git a/src/character.js b/src/character.js
index bd01eed..8b0451a 100644
--- a/src/character.js
+++ b/src/character.js
@@ -31,7 +31,8 @@ const CharacterDialog = new Lang.Class({
     Name: 'CharacterDialog',
     Extends: Gtk.Dialog,
     Template: 'resource:///org/gnome/Characters/character.ui',
-    InternalChildren: ['main-stack', 'character-label', 'detail-label',
+    InternalChildren: ['main-stack', 'character-stack',
+                       'character-label', 'missing-label', 'detail-label',
                        'copy-button', 'copy-revealer', 'related-listbox'],
 
     _init: function(params) {
@@ -62,7 +63,7 @@ const CharacterDialog = new Lang.Class({
                     this._main_stack.visible_child_name = 'character';
             }));
 
-        this._character_label.override_font(filtered.fontDescription);
+        this._fontDescription = filtered.fontDescription;
         this._setCharacter(filtered.character);
     },
 
@@ -106,11 +107,34 @@ const CharacterDialog = new Lang.Class({
     _setCharacter: function(uc) {
         this._character = uc;
 
-        this._character = this._character;
-        this._character_label.label = this._character;
-
         let codePoint = Util.toCodePoint(this._character);
         let codePointHex = codePoint.toString(16).toUpperCase();
+
+        let name = Gc.character_name(this._character);
+        if (name != null) {
+            name = Util.capitalize(name);
+        } else {
+            name = _("Unicode U+%04s").format(codePointHex);
+        }
+
+        let headerBar = this.get_header_bar();
+        headerBar.title = name;
+
+        this._character_label.override_font(this._fontDescription);
+        this._character_label.label = this._character;
+
+        var pangoContext = this._character_label.get_pango_context();
+        var pangoLayout = Pango.Layout.new(pangoContext);
+        pangoLayout.set_text(this._character, -1);
+        if (pangoLayout.get_unknown_glyphs_count() == 0) {
+            this._character_stack.visible_child_name = 'character';
+        } else {
+            var fontFamily = this._fontDescription.get_family();
+            this._missing_label.label =
+                _("%s is not included in %s").format(name, fontFamily);
+            this._character_stack.visible_child_name = 'missing';
+        }
+
         this._detail_label.label = _("Unicode U+%04s").format(codePointHex);
 
         this._cancellable.cancel();
@@ -132,11 +156,6 @@ const CharacterDialog = new Lang.Class({
         this._relatedButton.active = false;
         this._main_stack.visible_child_name = 'character';
         this._main_stack.show_all();
-
-        let headerBar = this.get_header_bar();
-        let name = Gc.character_name(this._character);
-        if (name != null)
-            headerBar.title = Util.capitalize(name);
     },
 
     _hideCopyRevealer: function() {


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