Skip to content

Commit 369ee7e

Browse files
authored
cinnamonEntry: Modernize and clean up (#13571)
Move to new style classes and remove all uses of Lang.bind. No functional changes.
1 parent c25b61d commit 369ee7e

1 file changed

Lines changed: 34 additions & 46 deletions

File tree

js/ui/cinnamonEntry.js

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
const Clutter = imports.gi.Clutter;
22
const Cinnamon = imports.gi.Cinnamon;
33
const GObject = imports.gi.GObject;
4-
const Gtk = imports.gi.Gtk;
5-
const Lang = imports.lang;
64
const Pango = imports.gi.Pango;
75
const St = imports.gi.St;
86

97
const Main = imports.ui.main;
108
const Params = imports.misc.params;
119
const PopupMenu = imports.ui.popupMenu;
1210

11+
var _EntryMenu = class extends PopupMenu.PopupMenu {
12+
constructor (entry, params) {
13+
super(entry, 0, St.Side.TOP)
1314

14-
function _EntryMenu(entry, params) {
15-
this._init(entry, params);
16-
};
17-
18-
_EntryMenu.prototype = {
19-
__proto__: PopupMenu.PopupMenu.prototype,
20-
21-
_init: function(entry, params) {
22-
params = Params.parse (params, { isPassword: false });
23-
24-
PopupMenu.PopupMenu.prototype._init.call(this, entry, St.Side.TOP);
15+
params = Params.parse(params, { isPassword: false });
2516

2617
this.actor.add_style_class_name('entry-context-menu');
2718

@@ -31,29 +22,28 @@ _EntryMenu.prototype = {
3122
// Populate menu
3223
let item;
3324
item = new PopupMenu.PopupMenuItem(_("Copy"));
34-
item.connect('activate', Lang.bind(this, this._onCopyActivated));
25+
item.connect('activate', this._onCopyActivated.bind(this));
3526
this.addMenuItem(item);
3627
this._copyItem = item;
3728

3829
item = new PopupMenu.PopupMenuItem(_("Paste"));
39-
item.connect('activate', Lang.bind(this, this._onPasteActivated));
30+
item.connect('activate', this._onPasteActivated.bind(this));
4031
this.addMenuItem(item);
4132
this._pasteItem = item;
4233

4334
this._passwordItem = null;
4435
if (params.isPassword) {
4536
item = new PopupMenu.PopupMenuItem('');
46-
item.connect('activate', Lang.bind(this,
47-
this._onPasswordActivated));
37+
item.connect('activate', this._onPasswordActivated.bind(this));
4838
this.addMenuItem(item);
4939
this._passwordItem = item;
5040
}
5141

5242
Main.uiGroup.add_actor(this.actor);
5343
this.actor.hide();
54-
},
44+
}
5545

56-
open: function() {
46+
open() {
5747
this._updatePasteItem();
5848
this._updateCopyItem();
5949
if (this._passwordItem)
@@ -67,46 +57,44 @@ _EntryMenu.prototype = {
6757
this.shiftToPosition(x);
6858
}
6959

70-
PopupMenu.PopupMenu.prototype.open.call(this);
71-
},
60+
super.open();
61+
}
7262

73-
_updateCopyItem: function() {
63+
_updateCopyItem() {
7464
let selection = this._entry.clutter_text.get_selection();
7565
this._copyItem.setSensitive(selection && selection != '');
76-
},
66+
}
7767

78-
_updatePasteItem: function() {
79-
this._clipboard.get_text(St.ClipboardType.CLIPBOARD, Lang.bind(this,
80-
function(clipboard, text) {
81-
this._pasteItem.setSensitive(text && text != '');
82-
}));
83-
},
68+
_updatePasteItem() {
69+
this._clipboard.get_text(St.ClipboardType.CLIPBOARD, (clipboard, text) => {
70+
this._pasteItem.setSensitive(text && text != '');
71+
});
72+
}
8473

85-
_updatePasswordItem: function() {
74+
_updatePasswordItem() {
8675
let textHidden = (this._entry.clutter_text.password_char);
8776
if (textHidden)
8877
this._passwordItem.label.set_text(_("Show Text"));
8978
else
9079
this._passwordItem.label.set_text(_("Hide Text"));
91-
},
80+
}
9281

93-
_onCopyActivated: function() {
82+
_onCopyActivated() {
9483
let selection = this._entry.clutter_text.get_selection();
9584
this._clipboard.set_text(St.ClipboardType.CLIPBOARD, selection);
96-
},
97-
98-
_onPasteActivated: function() {
99-
this._clipboard.get_text(St.ClipboardType.CLIPBOARD, Lang.bind(this,
100-
function(clipboard, text) {
101-
if (!text)
102-
return;
103-
this._entry.clutter_text.delete_selection();
104-
let pos = this._entry.clutter_text.get_cursor_position();
105-
this._entry.clutter_text.insert_text(text, pos);
106-
}));
107-
},
108-
109-
_onPasswordActivated: function() {
85+
}
86+
87+
_onPasteActivated() {
88+
this._clipboard.get_text(St.ClipboardType.CLIPBOARD, (clipboard, text) => {
89+
if (!text)
90+
return;
91+
this._entry.clutter_text.delete_selection();
92+
let pos = this._entry.clutter_text.get_cursor_position();
93+
this._entry.clutter_text.insert_text(text, pos);
94+
});
95+
}
96+
97+
_onPasswordActivated() {
11098
let visible = !!(this._entry.clutter_text.password_char);
11199
this._entry.clutter_text.set_password_char(visible ? '' : '\u25cf');
112100
}

0 commit comments

Comments
 (0)