Skip to content

Commit

Permalink
code review #151
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Aug 6, 2022
1 parent b4cd4dd commit 9c60653
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
30 changes: 16 additions & 14 deletions emoji-selector@maestroschan.fr/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const Main = imports.ui.main;
const Shell = imports.gi.Shell;

// it is needed to grab the focus for the search entry
const Mainloop = imports.mainloop;
const {St, Clutter, Shell, Meta, GLib} = imports.gi;

// for the keybinding
const Meta = imports.gi.Meta;
const Main = imports.ui.main;

/* Import PanelMenu and PopupMenu */
const PanelMenu = imports.ui.panelMenu;
Expand All @@ -50,6 +43,7 @@ const EmojiSearchItem = Me.imports.emojiSearchItem.EmojiSearchItem;

var SETTINGS;
let SIGNAUX = [];
let timeoutSourceId = null;

// Global variable : GLOBAL_BUTTON to click in the topbar
var GLOBAL_BUTTON;
Expand Down Expand Up @@ -148,19 +142,22 @@ class EmojisMenu {
this.super_btn.menu.toggle();
}

// Executed when the user opens/closes the menu, the main goals are to clear
// and to focus the search entry.
/**
* Executed when the user opens/closes the menu, the main goals are to clear
* and to focus the search entry.
*/
_onOpenStateChanged(self, open) {
this.super_btn.visible = open || SETTINGS.get_boolean('always-show');
this.clearCategories();
this.searchItem.searchEntry.set_text('');
// this.unloadCategories();

let a = Mainloop.timeout_add(20, () => {
timeoutSourceId = GLib.timeout_add(20, () => {
if (open) {
global.stage.set_key_focus(this.searchItem.searchEntry);
}
Mainloop.source_remove(a);
timeoutSourceId = null;
return GLib.SOURCE_REMOVE;
});
}

Expand Down Expand Up @@ -227,7 +224,7 @@ class EmojisMenu {

// Cleans the interface & close the opened category (if any). Called from the
// outside, be careful.
clearCategories(){
clearCategories() {
// removing the style class of previously opened category's button
for (let i = 0; i< 9; i++) {
this.emojiCategories[i].getButton().set_checked(false);
Expand Down Expand Up @@ -339,6 +336,11 @@ function disable() {

GLOBAL_BUTTON.super_btn.destroy();
// GLOBAL_BUTTON.destroy();

if(timeoutSourceId) {
GLib.Source.remove(timeoutSourceId);
timeoutSourceId = null;
}
}

//------------------------------------------------------------------------------
8 changes: 2 additions & 6 deletions emoji-selector@maestroschan.fr/prefs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// prefs.js (https://github.com/maoschanz/emoji-selector-for-gnome)

const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Mainloop = imports.mainloop;
const {GLib, GObject, Gio, Gtk, GdkPixbuf} = imports.gi;

const Gettext = imports.gettext.domain('emoji-selector');
const _ = Gettext.gettext;
Expand Down

0 comments on commit 9c60653

Please sign in to comment.