[gnome-characters: 2/3] ES6 arrow functions added



commit c52cd5bf23d1dd8a92860a93f37c3f3f4648069e
Author: tommy <>
Date:   Tue Jul 10 02:17:13 2018 +0100

    ES6 arrow functions added

 src/categoryList.js    | 12 +++---------
 src/characterDialog.js | 36 ++++++++++++------------------------
 src/characterList.js   | 40 +++++++++++++---------------------------
 src/menu.js            | 13 +++++--------
 src/searchProvider.js  |  9 ++++-----
 src/window.js          | 26 ++++++++++----------------
 6 files changed, 47 insertions(+), 89 deletions(-)
---
diff --git a/src/categoryList.js b/src/categoryList.js
index f97e96b..d3e9b16 100644
--- a/src/categoryList.js
+++ b/src/categoryList.js
@@ -17,10 +17,9 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
-const {Gc, Gio, GLib, GObject, Gtk, GnomeDesktop} = imports.gi;
+const {Gc, GLib, GObject, Gtk, GnomeDesktop} = imports.gi;
 
 const Gettext = imports.gettext;
-const Lang = imports.lang;
 const Params = imports.params;
 
 const Util = imports.util;
@@ -267,11 +266,7 @@ const LetterCategoryListWidget = GObject.registerClass({
         ibus.init();
         let bus = new ibus.Bus();
         if (bus.is_connected()) {
-            bus.list_engines_async(-1,
-                                   null,
-                                   Lang.bind(this, function (bus, res) {
-                                       this._finishListEngines(sources, bus, res);
-                                   }));
+            bus.list_engines_async(-1, null, (sources, bus, res) => this._finishListEngines(sources, bus, 
res));
         } else
             this._finishBuildScriptList(sources);
     }
@@ -424,8 +419,7 @@ var CategoryListView = GObject.registerClass({
 
         this._categoryList = CategoryList.slice();
 
-        this.connect('notify::visible-child-name',
-                     Lang.bind(this, this._ensureTransitionType));
+        this.connect('notify::visible-child-name', () => this._ensureTransitionType());
     }
 
     _ensureTransitionType() {
diff --git a/src/characterDialog.js b/src/characterDialog.js
index 0a4c246..49f8139 100644
--- a/src/characterDialog.js
+++ b/src/characterDialog.js
@@ -18,10 +18,8 @@
 
 const {Gc, GLib, Gio,GObject,Gtk, Pango} = imports.gi;
 
-const Lang = imports.lang;
 const Params = imports.params;
 
-const Main = imports.main;
 const Util = imports.util;
 
 var CharacterDialog = GObject.registerClass({
@@ -44,23 +42,20 @@ var CharacterDialog = GObject.registerClass({
 
         this._cancellable = new Gio.Cancellable();
 
-        this._copy_button.connect('clicked', Lang.bind(this, this._copyCharacter));
+        this._copy_button.connect('clicked', () => this._copyCharacter());
 
-        this._related_listbox.connect('row-selected',
-                                      Lang.bind(this, this._handleRowSelected));
+        this._related_listbox.connect('row-selected', (listBox, row) => this._handleRowSelected(listBox, 
row));
 
         this._relatedButton = new Gtk.ToggleButton({ label: _("See Also") });
         this.add_action_widget(this._relatedButton, Gtk.ResponseType.HELP);
         this._relatedButton.show();
 
-        this._relatedButton.connect(
-            'toggled',
-            Lang.bind(this, function() {
+        this._relatedButton.connect('toggled', () => {
                 if (this._main_stack.visible_child_name == 'character')
                     this._main_stack.visible_child_name = 'related';
                 else
                     this._main_stack.visible_child_name = 'character';
-            }));
+            });
 
         this._fontDescription = filtered.fontDescription;
         this._setCharacter(filtered.character);
@@ -146,14 +141,14 @@ var CharacterDialog = GObject.registerClass({
         context.search(
             -1,
             this._cancellable,
-            Lang.bind(this, function(context, res, user_data) {
+            (context, res) => {
                 try {
                     let result = context.search_finish(res);
                     this._finishSearch(result);
                 } catch (e) {
                     log(`Failed to search related: ${e.message}`);
                 }
-            }));
+            });
 
         this._relatedButton.active = false;
         this._main_stack.visible_child_name = 'character';
@@ -168,7 +163,7 @@ var CharacterDialog = GObject.registerClass({
         }
     }
 
-    _clipboardOwnerChanged(clipboard, event) {
+    _clipboardOwnerChanged(clipboard) {
         let text = clipboard.wait_for_text();
         if (text != this._character)
             this._hideCopyRevealer();
@@ -178,13 +173,8 @@ var CharacterDialog = GObject.registerClass({
         if (this._clipboard == null) {
             this._clipboard = Gc.gtk_clipboard_get();
             let clipboardOwnerChanged =
-                this._clipboard.connect('owner-change',
-                                        Lang.bind(this,
-                                                  this._clipboardOwnerChanged));
-            this.connect('destroy',
-                         Lang.bind(this, function() {
-                             this._clipboard.disconnect(clipboardOwnerChanged);
-                         }));
+                this._clipboard.connect('owner-change', (clipboard) => 
this._clipboardOwnerChanged(clipboard));
+            this.connect('destroy', () => this._clipboard.disconnect(clipboardOwnerChanged));
         }
         this._clipboard.set_text(this._character, -1);
         this.emit('character-copied', this._character);
@@ -195,13 +185,11 @@ var CharacterDialog = GObject.registerClass({
         this._hideCopyRevealer();
         this._copy_revealer.set_reveal_child(true);
         this._copyRevealerTimeoutId =
-            GLib.timeout_add(GLib.PRIORITY_DEFAULT, 2000,
-                             Lang.bind(this, this._hideCopyRevealer));
-        this.connect('destroy',
-                     Lang.bind(this, function() {
+            GLib.timeout_add(GLib.PRIORITY_DEFAULT, 2000, () => this._hideCopyRevealer());
+        this.connect('destroy', () => {
                          if (this._copyRevealerTimeoutId > 0)
                              GLib.source_remove(this._copyRevealerTimeoutId);
-                     }));
+                     });
     }
 
     _handleRowSelected(listBox, row) {
diff --git a/src/characterList.js b/src/characterList.js
index cddda1d..2147078 100644
--- a/src/characterList.js
+++ b/src/characterList.js
@@ -16,7 +16,6 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-const Lang = imports.lang;
 const Params = imports.params;
 const {Gc, Gdk, GLib, Gio,GObject,Gtk, Pango, PangoCairo} = imports.gi;
 
@@ -32,8 +31,7 @@ const NUM_COLUMNS = 5;
 const CELL_SIZE = 50;
 
 function getCellSize(fontDescription) {
-    if (fontDescription == null
-        || fontDescription.get_size() == 0)
+    if (fontDescription == null || fontDescription.get_size() == 0)
         return CELL_SIZE;
     return fontDescription.get_size() * 2 / Pango.SCALE;
 }
@@ -459,10 +457,7 @@ var CharacterListView = GObject.registerClass({
             vexpand: true,
             fontDescription: this._fontFilter.fontDescription
         });
-        this._characterList.connect('character-selected',
-                                    Lang.bind(this, function(w, c) {
-                                        this.emit('character-selected', c);
-                                    }));
+        this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
         let scroll = new Gtk.ScrolledWindow({
             hscrollbar_policy: Gtk.PolicyType.NEVER,
             visible: true
@@ -476,32 +471,30 @@ var CharacterListView = GObject.registerClass({
         this.add_named(scroll, 'character-list');
         this.visible_child_name = 'character-list';
 
-        this._fontFilter.connect('filter-set',
-                                 Lang.bind(this, this._updateCharacterList));
+        this._fontFilter.connect('filter-set', () => this._updateCharacterList());
 
         this._characters = [];
         this._spinnerTimeoutId = 0;
         this._searchContext = null;
         this._cancellable = new Gio.Cancellable();
-        this._cancellable.connect(Lang.bind(this, function () {
+        this._cancellable.connect(() => {
             this._stopSpinner();
             this._searchContext = null;
             this._characters = [];
             this._updateCharacterList();
-        }));
-        scroll.connect('edge-reached', Lang.bind(this, this._onEdgeReached));
-        scroll.connect('size-allocate', Lang.bind(this, this._onSizeAllocate));
+        });
+        scroll.connect('edge-reached', (scrolled, pos) => this._onEdgeReached(scrolled, pos));
+        scroll.connect('size-allocate', (scrolled, allocation) => this._onSizeAllocate(scrolled, 
allocation));
     }
 
     _startSpinner() {
         this._stopSpinner();
         this._spinnerTimeoutId =
-            GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000,
-                             Lang.bind(this, function () {
+            GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
                                  this._loading_spinner.start();
                                  this.visible_child_name = 'loading';
                                  this.show_all();
-                             }));
+                             });
     }
 
     _stopSpinner() {
@@ -578,10 +571,7 @@ var CharacterListView = GObject.registerClass({
 
     _searchWithContext(context, count) {
         this._startSpinner();
-        context.search(
-            count,
-            this._cancellable,
-            Lang.bind(this, function(context, res, user_data) {
+        context.search(count, this._cancellable, (context, res, user_data) => {
                 this._stopSpinner();
                 try {
                     let result = context.search_finish(res);
@@ -589,7 +579,7 @@ var CharacterListView = GObject.registerClass({
                 } catch (e) {
                     log(`Failed to search: ${e.message}`);
                 }
-            }));
+            });
     }
 
     searchByCategory(category) {
@@ -647,14 +637,10 @@ var RecentCharacterListView = GObject.registerClass({
             fontDescription: this._fontFilter.fontDescription,
             numRows: 0
         });
-        this._characterList.connect('character-selected',
-                                    Lang.bind(this, function(w, c) {
-                                        this.emit('character-selected', c);
-                                    }));
+        this._characterList.connect('character-selected', (w, c) => this.emit('character-selected', c));
         this.add(this._characterList);
 
-        this._fontFilter.connect('filter-set',
-                                 Lang.bind(this, this._updateCharacterList));
+        this._fontFilter.connect('filter-set', () => this._updateCharacterList());
 
         this._category = filtered.category;
         this._characters = [];
diff --git a/src/menu.js b/src/menu.js
index 427b804..c7510f5 100644
--- a/src/menu.js
+++ b/src/menu.js
@@ -16,9 +16,8 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-const {GLib, GObject, Gtk, Pango} = imports.gi;
+const {GLib, GObject, Gtk} = imports.gi;
 
-const Lang = imports.lang;
 const Params = imports.params;
 
 var MenuPopover = GObject.registerClass({
@@ -57,12 +56,10 @@ var MenuPopover = GObject.registerClass({
         }
 
         this._keywords = [];
-        this._search_entry.connect('search-changed',
-                                   Lang.bind(this, this._handleSearchChanged));
-        this._font_listbox.connect('row-activated',
-                                   Lang.bind(this, this._handleRowActivated));
-        this._font_listbox.set_filter_func(Lang.bind(this, this._filterFunc));
-        this._font_listbox.set_header_func(Lang.bind(this, this._headerFunc));
+        this._search_entry.connect('search-changed', (entry) => this._handleSearchChanged(entry));
+        this._font_listbox.connect('row-activated', (listBox, row) => this._handleRowActivated(listBox, 
row));
+        this._font_listbox.set_filter_func((row) => this._filterFunc(row));
+        this._font_listbox.set_header_func((row, before) => this._headerFunc(row, before));
 
         // This silents warning at Characters exit about this widget being
         // visible but not mapped.  Borrowed from Maps.
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 6db9267..83e8b94 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -19,7 +19,6 @@
 
 const {Gc, Gdk, Gio, GLib, GObject} = imports.gi;
 
-const Lang = imports.lang;
 const Util = imports.util;
 
 const MAX_SEARCH_RESULTS = 100;
@@ -55,7 +54,7 @@ const SearchProvider = GObject.registerClass({
         context.search(
             MAX_SEARCH_RESULTS,
             this._cancellable,
-            Lang.bind(this, function(source_object, res, user_data) {
+            (source_object, res, user_data) => {
                 let characters = [];
                 try {
                     let result = context.search_finish(res);
@@ -66,7 +65,7 @@ const SearchProvider = GObject.registerClass({
                 invocation.return_value(new GLib.Variant('(as)', [characters]));
 
                 this._app.release();
-            }));
+            });
     }
 
     GetInitialResultSetAsync(params, invocation) {
@@ -139,7 +138,7 @@ const SearchProvider = GObject.registerClass({
                                                               this._getPlatformData(timestamp)]),
                               null,
                               Gio.DBusCallFlags.NONE,
-                              -1, null, Lang.bind(this, function(connection, result) {
+                              -1, null, (connection, result) => {
                                   try {
                                       connection.call_finish(result);
                                   } catch(e) {
@@ -147,7 +146,7 @@ const SearchProvider = GObject.registerClass({
                                   }
 
                                   this._app.release();
-                              }));
+                              });
     }
 
     LaunchSearch(terms, timestamp) {
diff --git a/src/window.js b/src/window.js
index 5e8d38c..c64cedc 100644
--- a/src/window.js
+++ b/src/window.js
@@ -26,7 +26,6 @@
 
 const {Gio, GLib, GObject, Gtk } = imports.gi;
 
-const Lang = imports.lang;
 const Params = imports.params;
 const CategoryList = imports.categoryList;
 const Character = imports.characterDialog;
@@ -93,14 +92,12 @@ var MainWindow = GObject.registerClass({
                            GObject.BindingFlags.SYNC_CREATE |
                            GObject.BindingFlags.BIDIRECTIONAL);
         this._search_bar.connect_entry(this._search_entry);
-        this._search_entry.connect('search-changed',
-                                   Lang.bind(this, this._handleSearchChanged));
+        this._search_entry.connect('search-changed', (entry) => this._handleSearchChanged(entry));
 
-        this._back_button.connect('clicked',
-                                  Lang.bind(this, function() {
+        this._back_button.connect('clicked', () => {
                                       let action = this.lookup_action('category');
                                       action.activate(new GLib.Variant('s', 'emojis'));
-                                  }));
+                                  });
         this._back_button.bind_property('visible',
                                         this._search_active_button, 'visible',
                                         GObject.BindingFlags.SYNC_CREATE |
@@ -127,7 +124,7 @@ var MainWindow = GObject.registerClass({
 
         // Due to limitations of gobject-introspection wrt GdkEvent
         // and GdkEventKey, this needs to be a signal handler
-        this.connect('key-press-event', Lang.bind(this, this._handleKeyPress));
+        this.connect('key-press-event', (self, event) => this._handleKeyPress(self, event));
     }
 
     vfunc_map() {
@@ -222,7 +219,7 @@ var MainWindow = GObject.registerClass({
     _category(action, v) {
         this.search_active = false;
 
-        let [name, length] = v.get_string()
+        let [name, length] = v.get_string();
 
         this._categoryListView.set_visible_child_name(name);
         let categoryList = this._categoryListView.get_visible_child();
@@ -246,7 +243,7 @@ var MainWindow = GObject.registerClass({
     _subcategory(action, v) {
         this.search_active = false;
 
-        let [name, length] = v.get_string()
+        let [name, length] = v.get_string();
 
         let categoryList = this._categoryListView.get_visible_child();
         if (categoryList == null)
@@ -265,7 +262,7 @@ var MainWindow = GObject.registerClass({
     }
 
     _filterFont(action, v) {
-        let [family, length] = v.get_string()
+        let [family, length] = v.get_string();
         if (family == 'None')
             family = null;
         this._mainView.filterFontFamily = family;
@@ -385,8 +382,7 @@ const MainView = GObject.registerClass({
             fontFilter: this._fontFilter,
         });
         characterList.get_accessible().accessible_name = accessible_name;
-        characterList.connect('character-selected',
-                              Lang.bind(this, this._handleCharacterSelected));
+        characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget, 
uc));
 
         this._characterLists[name] = characterList;
         return characterList;
@@ -398,8 +394,7 @@ const MainView = GObject.registerClass({
             category: category
         });
         characterList.get_accessible().accessible_name = accessible_name;
-        characterList.connect('character-selected',
-                              Lang.bind(this, this._handleCharacterSelected));
+        characterList.connect('character-selected', (widget, uc) => this._handleCharacterSelected(widget, 
uc));
 
         this._characterLists[name] = characterList;
         return characterList;
@@ -460,8 +455,7 @@ const MainView = GObject.registerClass({
         });
 
         dialog.show();
-        dialog.connect('character-copied',
-                       Lang.bind(this, this._addToRecent));
+        dialog.connect('character-copied', (widget, uc) => this._addToRecent(widget, uc));
         dialog.connect('response', function(self, response_id) {
             if (response_id == Gtk.ResponseType.CLOSE)
                 dialog.destroy();


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