[gnome-characters/wip/properties] character: Show character decomposition if any



commit 7bd5a4626e82f8d146edbb619bf37aee48289fa6
Author: Daiki Ueno <ueno gnu org>
Date:   Mon Feb 9 18:42:09 2015 +0900

    character: Show character decomposition if any

 data/application.css |    3 ++-
 data/character.ui    |    4 ++--
 src/character.js     |   42 +++++++++++++++++++++++++++++++++++++++---
 src/util.js          |    5 +++++
 4 files changed, 48 insertions(+), 6 deletions(-)
---
diff --git a/data/application.css b/data/application.css
index 7a29980..3e329d5 100644
--- a/data/application.css
+++ b/data/application.css
@@ -34,7 +34,8 @@
     font-weight: bold;
 }
 
-.detail-label {
+.detail {
+    margin-left: 20px;
     font-size: small;
 }
 
diff --git a/data/character.ui b/data/character.ui
index b413eb8..0781d65 100644
--- a/data/character.ui
+++ b/data/character.ui
@@ -7,7 +7,7 @@
       <object class="GtkGrid" id="character-grid">
        <property name="visible">True</property>
        <property name="halign">fill</property>
-       <property name="valign">fill</property>
+       <property name="valign">end</property>
        <property name="border_width">5</property>
        <property name="orientation">vertical</property>
        <property name="row_spacing">20</property>
@@ -33,7 +33,7 @@
            <property name="halign">fill</property>
            <property name="valign">fill</property>
            <property name="column-spacing">20</property>
-           <property name="margin-left">20</property>
+           <property name="row_spacing">10</property>
            <style>
              <class name="detail"/>
            </style>
diff --git a/src/character.js b/src/character.js
index ebd740a..564c5a9 100644
--- a/src/character.js
+++ b/src/character.js
@@ -135,18 +135,54 @@ const CharacterDialog = new Lang.Class({
             this._relatedList.get_children().length > 0;
     },
 
+    _activateLink: function(label, uri) {
+        let match = uri.match(/^character:([0-9A-F]+)/);
+        if (match) {
+            let uc = String.fromCharCode(parseInt(match[1], 16));
+            this._setCharacter(uc);
+            let toplevel = this.get_transient_for();
+            let action = toplevel.lookup_action('character');
+            action.activate(new GLib.Variant('s', uc));
+        }
+    },
+
     _setCharacter: function(uc) {
         this._character = uc;
 
         this._character = this._character;
         this._characterLabel.label = this._character;
 
-        let codePoint = this._character.charCodeAt(0);
-        let codePointHex = codePoint.toString(16).toUpperCase();
-        this._codepointLabel.label = _("U+%04s").format(codePointHex);
+        this._codepointLabel.label =
+            _("U+%04s").format(Util.hexCodepoint(uc));
         this._categoryLabel.label = Gc.character_category(uc);
         this._scriptLabel.label = Gc.character_script(uc);
         this._blockLabel.label = Gc.character_block(uc);
+        let result = Gc.character_decomposition(uc);
+        if (result.len > 0) {
+            let decomposition = [];
+            for (let index = 0; index < result.len; index++) {
+                decomposition.push(Gc.search_result_get(result, index));
+            }
+            let title = new Gtk.Label({ halign: Gtk.Align.START,
+                                        label: _("Decomposition: ") });
+            this._detailGrid.attach(title, 0, 4, 1, 1);
+            let label = new Gtk.Label({ halign: Gtk.Align.START,
+                                        wrap: true,
+                                        max_width_chars: 30,
+                                        use_markup: true });
+            label.label = decomposition.map(function(d) {
+                let hex = Util.hexCodepoint(d);
+                return _("<a href=\"character:%s\">U+%04s %s</a>").format(
+                    hex, hex, Gc.character_name(d));
+            }).join(', ');
+            label.connect('activate-link', Lang.bind(this, this._activateLink));
+            this._detailGrid.attach_next_to(label,
+                                            title,
+                                            Gtk.PositionType.RIGHT,
+                                            1, 1);
+        } else {
+            this._detailGrid.remove_row(4);
+        }
 
         let children = this._relatedList.get_children();
         for (let index in children)
diff --git a/src/util.js b/src/util.js
index 72dbcad..c89a99a 100644
--- a/src/util.js
+++ b/src/util.js
@@ -131,3 +131,8 @@ function capitalize(s) {
         return w;
     }).join(' ');
 }
+
+function hexCodepoint(uc) {
+    let codePoint = uc.charCodeAt(0);
+    return codePoint.toString(16).toUpperCase();
+}


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