[Xfce4-commits] <postler:master> Implement inserting emoticons in composed text

Christian Dywan noreply at xfce.org
Mon Jun 21 20:12:07 CEST 2010


Updating branch refs/heads/master
         to 05301c23f527e55023fd2756cd5aeaf6676f000e (commit)
       from eba7d9512478272460ca8dbac13dfd1e86f402a6 (commit)

commit 05301c23f527e55023fd2756cd5aeaf6676f000e
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jun 20 19:34:34 2010 +0200

    Implement inserting emoticons in composed text

 postler/postler-composer.vala |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/postler/postler-composer.vala b/postler/postler-composer.vala
index cb434d0..41830d2 100644
--- a/postler/postler-composer.vala
+++ b/postler/postler-composer.vala
@@ -112,6 +112,29 @@ public class Postler.Composer : Gtk.Window {
         destroy ();
     }
 
+    void insert_text (string text) {
+        content.execute_script ("""
+            var text = '%s';
+            if (!document.execCommand ('inserthtml', false, text))
+                document.body.innerHTML = text + document.body.innerHTML;
+            """.
+            printf (text.replace ("'", "\\'")));
+    }
+
+    void action_insert_emoticon (Gtk.Action action) {
+        unowned string name = action.name;
+        string emoticon;
+        if (name.has_suffix ("Grin"))
+            emoticon = ":-D";
+        else if (name.has_suffix ("Wink"))
+            emoticon = ";-)";
+        else if (name.has_suffix ("Sad"))
+            emoticon = ":-(";
+        else
+            assert_not_reached ();
+        insert_text (emoticon);
+    }
+
     const Gtk.ActionEntry[] action_entries = {
         { "Mail", null, N_("_Mail") },
         { "MessageSend", STOCK_MAIL_SEND, null, "<Ctrl>Return",
@@ -128,11 +151,11 @@ public class Postler.Composer : Gtk.Window {
         { "Preferences", Gtk.STOCK_PREFERENCES, null, "<Ctrl><Alt>p",
           N_("Configure the application preferences"), action_preferences },
         { "InsertEmoticonGrin", STOCK_FACE_GRIN, N_("Insert _Grinning Face"), "",
-          N_("Insert a grinning face"), null },
+          N_("Insert a grinning face"), action_insert_emoticon },
         { "InsertEmoticonWink", STOCK_FACE_WINK, N_("Insert _Winking Face"), "",
-          N_("Insert a winking face"), null },
+          N_("Insert a winking face"), action_insert_emoticon },
         { "InsertEmoticonSad", STOCK_FACE_SAD, N_("Insert _Sad Face"), "",
-          N_("Insert a sad face"), null }
+          N_("Insert a sad face"), action_insert_emoticon }
     };
 
     public Composer () {
@@ -228,6 +251,7 @@ public class Postler.Composer : Gtk.Window {
 
         content.editable = true;
         var settings = content.settings;
+        settings.set ("enable-scripts", true, null);
         if (settings.get_class ().find_property ("enable-spell-checking") != null) {
             string languages = string.joinv (",", Intl.get_language_names ());
             settings.set ("enable-spell-checking", true,



More information about the Xfce4-commits mailing list