-
Notifications
You must be signed in to change notification settings - Fork 860
Expand file tree
/
Copy pathapplet.js
More file actions
3087 lines (2641 loc) · 112 KB
/
applet.js
File metadata and controls
3087 lines (2641 loc) · 112 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const Applet = imports.ui.applet;
const Mainloop = imports.mainloop;
const Cinnamon = imports.gi.Cinnamon;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
const PopupMenu = imports.ui.popupMenu;
const UserWidget = imports.ui.userWidget;
const AppFavorites = imports.ui.appFavorites;
const Gtk = imports.gi.Gtk;
const Atk = imports.gi.Atk;
const Gio = imports.gi.Gio;
const XApp = imports.gi.XApp;
const AccountsService = imports.gi.AccountsService;
const GnomeSession = imports.misc.gnomeSession;
const ScreenSaver = imports.misc.screenSaver;
const FileUtils = imports.misc.fileUtils;
const Util = imports.misc.util;
const DND = imports.ui.dnd;
const Meta = imports.gi.Meta;
const DocInfo = imports.misc.docInfo;
const GLib = imports.gi.GLib;
const Settings = imports.ui.settings;
const Pango = imports.gi.Pango;
const SearchProviderManager = imports.ui.searchProviderManager;
const SignalManager = imports.misc.signalManager;
const Params = imports.misc.params;
const INITIAL_BUTTON_LOAD = 30;
const USER_DESKTOP_PATH = FileUtils.getUserDesktopDir();
const PRIVACY_SCHEMA = "org.cinnamon.desktop.privacy";
const REMEMBER_RECENT_KEY = "remember-recent-files";
const AppUtils = require('./appUtils');
let appsys = Cinnamon.AppSystem.get_default();
const POPUP_MIN_WIDTH = 500;
const POPUP_MAX_WIDTH = 900;
const POPUP_MIN_HEIGHT = 400;
const POPUP_MAX_HEIGHT = 1400;
const RefreshFlags = Object.freeze({
APP: 0b000001,
FAV_APP: 0b000010,
FAV_DOC: 0b000100,
PLACE: 0b001000,
RECENT: 0b010000,
SYSTEM: 0b100000
});
const REFRESH_ALL_MASK = 0b111111;
const NO_MATCH = 99999;
const MATCH_ADDERS = [
0, // name
1000, // keywords
2000, // desc
3000 // id
];
function calc_angle(x, y) {
if (x === 0) { x = .001 }
if (y === 0) { y = .001 }
let r = Math.atan2(y, x) * (180 / Math.PI);
return r;
}
function shorten_path(path, filename) {
let str = path.replace("file://", "");
str = str.replace(GLib.get_home_dir(), "~");
str = str.replace("/" + filename, "");
return str;
}
/* VisibleChildIterator takes a container (boxlayout, etc.)
* and creates an array of its visible children and their index
* positions. We can then work through that list without
* mucking about with positions and math, just give a
* child, and it'll give you the next or previous, or first or
* last child in the list.
*
* We could have this object regenerate off a signal
* every time the visibles have changed in our applicationBox,
* but we really only need it when we start keyboard
* navigating, so increase speed, we reload only when we
* want to use it.
*/
class VisibleChildIterator {
constructor(container) {
this.container = container;
this.reloadVisible();
}
reloadVisible() {
this.array = this.container.get_focus_chain()
.filter(x => !(x._delegate instanceof PopupMenu.PopupSeparatorMenuItem));
}
next(curChild) {
return this.getVisibleItem(this.array.indexOf(curChild) + 1);
}
prev(curChild) {
return this.getVisibleItem(this.array.indexOf(curChild) - 1);
}
first() {
return this.array[0];
}
last() {
return this.array[this.array.length - 1];
}
getVisibleItem(index) {
let len = this.array.length;
index = ((index % len) + len) % len;
return this.array[index];
}
}
/**
* SimpleMenuItem type strings in use:
* -------------------------------------------------
* app ApplicationButton
* category CategoryButton
* fav FavoritesButton
* no-recent "No recent documents" button
* no-favorites "No favorite documents" button
* none Default type
* place PlaceButton
* favorite PathButton
* recent PathButton
* recent-clear "Clear recent documents" button
* search-provider SearchProviderResultButton
* system SystemButton
* transient TransientButton
*/
/**
* SimpleMenuItem default parameters.
*/
const SMI_DEFAULT_PARAMS = Object.freeze({
name: '',
description: '',
type: 'none',
styleClass: 'popup-menu-item',
reactive: true,
activatable: true,
withMenu: false
});
/**
* A simpler alternative to PopupBaseMenuItem - does not implement all interfaces of PopupBaseMenuItem. Any
* additional properties in the params object beyond defaults will also be set on the instance.
* @param {Object} applet - The menu applet instance
* @param {Object} params - Object containing item parameters, all optional.
* @param {string} params.name - The name for the menu item.
* @param {string} params.description - The description for the menu item.
* @param {string} params.type - A string describing the type of item.
* @param {string} params.styleClass - The item's CSS style class.
* @param {boolean} params.reactive - Item receives events.
* @param {boolean} params.activatable - Activates via primary click. Must provide an 'activate' function on
* the prototype or instance.
* @param {boolean} params.withMenu - Shows menu via secondary click. Must provide a 'populateMenu' function
* on the prototype or instance.
*/
class SimpleMenuItem {
constructor(applet, params) {
params = Params.parse(params, SMI_DEFAULT_PARAMS, true);
this._signals = new SignalManager.SignalManager();
this.actor = new St.BoxLayout({
style_class: params.styleClass,
reactive: params.reactive,
accessible_role: Atk.Role.MENU_ITEM,
});
this._signals.connect(this.actor, 'destroy', () => this.destroy(true));
this.actor._delegate = this;
this.applet = applet;
this.labelContainer = new St.BoxLayout({
vertical: true,
y_expand: true,
y_align: Clutter.ActorAlign.CENTER,
});
this.label = null;
this.descriptionLabel = null;
this.icon = null;
this.matchIndex = NO_MATCH;
for (let prop in params)
this[prop] = params[prop];
if (params.reactive) {
this._signals.connect(this.actor, 'enter-event', () => applet._buttonEnterEvent(this));
this._signals.connect(this.actor, 'leave-event', () => applet._buttonLeaveEvent(this));
if (params.activatable || params.withMenu) {
this._signals.connect(this.actor, 'button-release-event', this._onButtonReleaseEvent.bind(this));
this._signals.connect(this.actor, 'key-press-event', this._onKeyPressEvent.bind(this));
}
}
}
_onButtonReleaseEvent(actor, event) {
let button = event.get_button();
if (this.activate && button === Clutter.BUTTON_PRIMARY) {
this.activate();
return Clutter.EVENT_STOP;
} else if (this.populateMenu && button === Clutter.BUTTON_SECONDARY) {
this.applet.toggleContextMenu(this);
return Clutter.EVENT_STOP;
}
return Clutter.EVENT_PROPAGATE;
}
_onKeyPressEvent(actor, event) {
let symbol = event.get_key_symbol();
if (this.activate &&
(symbol === Clutter.KEY_space ||
symbol === Clutter.KEY_Return ||
symbol === Clutter.KEY_KP_Enter)) {
this.activate();
return Clutter.EVENT_STOP;
}
return Clutter.EVENT_PROPAGATE;
}
/**
* Adds an StIcon as the next child, accessible as `this.icon`.
*
* Either an icon name or gicon is required. Only one icon is supported by the
* base SimpleMenuItem.
*
* @param {number} iconSize - The icon size in px.
* @param {string} iconName - (optional) The icon name string.
* @param {object} gicon - (optional) A gicon.
* @param {boolean} symbolic - (optional) Whether the icon should be symbolic. Default: false.
*/
addIcon(iconSize, iconName='', gicon=null, symbolic=false) {
if (this.icon)
return;
let params = { icon_size: iconSize };
if (iconName)
params.icon_name = iconName;
else if (gicon)
params.gicon = gicon;
params.icon_type = symbolic ? St.IconType.SYMBOLIC : St.IconType.FULLCOLOR;
this.icon = new St.Icon(params);
this.actor.add_actor(this.icon);
}
/**
* Adds an StLabel as the next child, accessible as `this.label`.
*
* Only one label is supported by the base SimpleMenuItem prototype.
*
* @param {string} label - (optional) An unformatted string. If markup is required, use
* native methods directly: `this.label.clutter_text.set_markup()`.
* @param {string} styleClass - (optional) A style class for the label.
*/
addLabel(label='', styleClass=null) {
if (this.label)
return;
this.label = new St.Label({ text: label });
if (styleClass)
this.label.set_style_class_name(styleClass);
this.label.clutter_text.ellipsize = Pango.EllipsizeMode.END;
this.actor.add_actor(this.labelContainer);
this.labelContainer.add_actor(this.label);
this.actor.set_label_actor(this.label);
}
addDescription(label='', styleClass=null) {
if (this.descriptionLabel)
return;
if (label === '')
return;
this.descriptionLabel = new St.Label({
text: label,
y_expand: true,
y_align: Clutter.ActorAlign.CENTER
});
if (styleClass)
this.descriptionLabel.set_style_class_name(styleClass);
this.descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.END;
this.labelContainer.add_actor(this.descriptionLabel);
}
updateAccessibleName() {
this.actor.set_label_actor(null);
let name = "";
if (this.label)
name += this.label.get_text();
if (this.descriptionLabel) {
if (name.length > 0)
name += ". ";
name += this.descriptionLabel.get_text();
}
this.actor.set_accessible_name(name);
}
/**
* Adds a ClutterActor as the next child.
*
* @param {ClutterActor} child
*/
addActor(child) {
this.actor.add_actor(child);
}
destroy(actorDestroySignal=false) {
this._signals.disconnectAllSignals();
if (this.label)
this.label.destroy();
if (this.descriptionLabel)
this.descriptionLabel.destroy();
if (this.icon)
this.icon.destroy();
if (!actorDestroySignal)
this.actor.destroy();
delete this.actor._delegate;
delete this.actor;
delete this.label;
delete this.descriptionLabel;
delete this.icon;
}
}
class ApplicationContextMenuItem extends PopupMenu.PopupBaseMenuItem {
constructor(appButton, label, action, iconName) {
super({focusOnHover: false});
this._appButton = appButton;
this._action = action;
this.label = new St.Label({ text: label });
if (iconName != null) {
this.icon = new St.Icon({
icon_name: iconName,
icon_size: 12,
icon_type: St.IconType.SYMBOLIC,
});
if (this.icon)
this.addActor(this.icon);
}
this.addActor(this.label);
this.actor.set_label_actor(this.label);
this._signals.connect(this, "active-changed", () => {
if (this.active)
this.actor.add_accessible_state(Atk.StateType.FOCUSED);
else
this.actor.remove_accessible_state(Atk.StateType.FOCUSED);
});
}
activate (event) {
let closeMenu = true;
switch (this._action) {
case "add_to_panel":
if (!Main.AppletManager.get_role_provider_exists(Main.AppletManager.Roles.PANEL_LAUNCHER)) {
let new_applet_id = global.settings.get_int("next-applet-id");
global.settings.set_int("next-applet-id", (new_applet_id + 1));
let enabled_applets = global.settings.get_strv("enabled-applets");
enabled_applets.push("panel1:right:0:[email protected]:" + new_applet_id);
global.settings.set_strv("enabled-applets", enabled_applets);
}
// wait until the panel launchers instance is actually loaded
// 10 tries, delay 100ms
let retries = 10;
Mainloop.timeout_add(100, () => {
if (retries--) {
let launcherApplet = Main.AppletManager.get_role_provider(Main.AppletManager.Roles.PANEL_LAUNCHER);
if (!launcherApplet)
return true;
launcherApplet.acceptNewLauncher(this._appButton.app.get_id());
}
return false;
});
break;
case "add_to_desktop":
let file = Gio.file_new_for_path(this._appButton.app.get_app_info().get_filename());
let destFile = Gio.file_new_for_path(USER_DESKTOP_PATH+"/"+file.get_basename());
try{
file.copy(destFile, 0, null, function(){});
FileUtils.changeModeGFile(destFile, 755);
}catch(e){
global.log(e);
}
break;
case "add_to_favorites":
AppFavorites.getAppFavorites().addFavorite(this._appButton.app.get_id());
this.label.set_text(_("Remove from favorites"));
this.icon.icon_name = "xsi-starred";
this._action = "remove_from_favorites";
closeMenu = false;
break;
case "remove_from_favorites":
AppFavorites.getAppFavorites().removeFavorite(this._appButton.app.get_id());
this.label.set_text(_("Add to favorites"));
this.icon.icon_name = "xsi-non-starred";
this._action = "add_to_favorites";
closeMenu = false;
break;
case "app_properties":
Util.spawnCommandLine("cinnamon-desktop-editor -mlauncher -o" + GLib.shell_quote(this._appButton.app.get_app_info().get_filename()));
break;
case "uninstall":
Util.spawnCommandLine("/usr/bin/cinnamon-remove-application '" + this._appButton.app.get_app_info().get_filename() + "'");
break;
case "offload_launch":
try {
this._appButton.app.launch_offloaded(0, [], -1);
} catch (e) {
logError(e, "Could not launch app with dedicated gpu: ");
}
break;
default:
if (this._action.startsWith("action_")) {
let action = this._action.substring(7);
this._appButton.app.get_app_info().launch_action(action, global.create_app_launch_context());
} else return true;
}
if (closeMenu) {
this._appButton.applet.toggleContextMenu(this._appButton);
this._appButton.applet.menu.close();
}
return false;
}
}
class GenericApplicationButton extends SimpleMenuItem {
constructor(applet, app, type, withMenu=false, styleClass="") {
let desc = app.get_description() || "";
super(applet, {
name: app.get_name(),
description: desc.split("\n")[0],
type: type,
withMenu: withMenu,
styleClass: styleClass,
app: app,
});
}
set_application_icon(icon_size) {
this.icon = this.app.create_icon_texture(icon_size);
if (this.icon instanceof St.Icon) {
let gicon = this.icon.get_gicon();
if (gicon?.get_names) {
let iconTheme = Gtk.IconTheme.get_default();
let hasAnyIcon = gicon.get_names()
.some(name => iconTheme.lookup_icon(name, this.icon.icon_size, 0));
if (!hasAnyIcon) {
this.icon = new St.Icon({
icon_name: 'application-x-executable',
icon_size: icon_size,
icon_type: St.IconType.FULLCOLOR
});
}
}
}
}
highlight() {
if (this.actor.has_style_pseudo_class('highlighted'))
return;
this.actor.add_style_pseudo_class('highlighted');
}
unhighlight() {
if (!this.actor.has_style_pseudo_class('highlighted'))
return;
let appKey = this.app.get_id() || `${this.name}:${this.description}`;
this.applet._knownApps.add(appKey);
this.actor.remove_style_pseudo_class('highlighted');
}
activate() {
this.unhighlight();
this.app.open_new_window(-1);
this.applet.menu.close();
}
populateMenu(menu) {
let menuItem;
if (Main.gpu_offload_supported) {
menuItem = new ApplicationContextMenuItem(this, _("Run with dedicated GPU"), "offload_launch", "xsi-cpu");
menu.addMenuItem(menuItem);
}
menuItem = new ApplicationContextMenuItem(this, _("Add to panel"), "add_to_panel", "xsi-list-add");
menu.addMenuItem(menuItem);
if (USER_DESKTOP_PATH){
menuItem = new ApplicationContextMenuItem(this, _("Add to desktop"), "add_to_desktop", "xsi-computer");
menu.addMenuItem(menuItem);
}
if (AppFavorites.getAppFavorites().isFavorite(this.app.get_id())){
menuItem = new ApplicationContextMenuItem(this, _("Remove from favorites"), "remove_from_favorites", "xsi-starred");
menu.addMenuItem(menuItem);
} else {
menuItem = new ApplicationContextMenuItem(this, _("Add to favorites"), "add_to_favorites", "xsi-non-starred");
menu.addMenuItem(menuItem);
}
const appinfo = this.app.get_app_info();
if (appinfo.get_filename() != null) {
menuItem = new ApplicationContextMenuItem(this, _("Properties"), "app_properties", "xsi-document-properties-symbolic");
menu.addMenuItem(menuItem);
}
if (this.applet._canUninstallApps) {
menuItem = new ApplicationContextMenuItem(this, _("Uninstall"), "uninstall", "xsi-edit-delete");
menu.addMenuItem(menuItem);
}
for (const action of appinfo.list_actions()) {
let icon = Util.getDesktopActionIcon(action);
let label = appinfo.get_action_name(action);
menuItem = new ApplicationContextMenuItem(this, label, "action_" + action, icon);
menu.addMenuItem(menuItem);
}
}
}
class TransientButton extends SimpleMenuItem {
constructor(applet, pathOrCommand) {
super(applet, {
description: pathOrCommand,
type: 'transient',
styleClass: 'appmenu-application-button',
});
if (pathOrCommand.startsWith('~')) {
pathOrCommand = pathOrCommand.slice(1);
pathOrCommand = GLib.get_home_dir() + pathOrCommand;
}
this.isPath = pathOrCommand.substr(pathOrCommand.length - 1) == '/';
if (this.isPath) {
this.path = pathOrCommand;
} else {
let n = pathOrCommand.lastIndexOf('/');
if (n != 1) {
this.path = pathOrCommand.substr(0, n);
}
}
this.pathOrCommand = pathOrCommand;
this.file = Gio.file_new_for_path(this.pathOrCommand);
try {
this.handler = this.file.query_default_handler(null);
let contentType = Gio.content_type_guess(this.pathOrCommand, null);
let themedIcon = Gio.content_type_get_icon(contentType[0]);
this.icon = new St.Icon({
gicon: themedIcon,
icon_size: applet.applicationIconSize,
icon_type: St.IconType.FULLCOLOR,
});
} catch (e) {
this.handler = null;
let iconName = this.isPath ? 'folder' : 'unknown';
this.icon = new St.Icon({
icon_name: iconName,
icon_size: applet.applicationIconSize,
icon_type: St.IconType.FULLCOLOR,
});
// @todo Would be nice to indicate we don't have a handler for this file.
}
this.addActor(this.icon);
this.addLabel(this.description, 'appmenu-application-button-label');
this.isDraggableApp = false;
}
activate() {
if (this.handler != null) {
this.handler.launch([this.file], null);
} else {
// Try anyway, even though we probably shouldn't.
try {
Util.spawn(['gio', 'open', this.file.get_uri()]);
} catch (e) {
global.logError("No handler available to open " + this.file.get_uri());
}
}
this.applet.menu.close();
}
}
class ApplicationButton extends GenericApplicationButton {
constructor(applet, app) {
super(applet, app, 'app', true, 'appmenu-application-button');
this.category = [];
this.set_application_icon(applet.applicationIconSize);
this.addActor(this.icon);
this.addLabel(this.name, 'appmenu-application-button-label');
if (applet.showDescription)
this.addDescription(this.description, 'appmenu-application-button-description');
this.updateAccessibleName();
this._draggable = DND.makeDraggable(this.actor);
this._signals.connect(this._draggable, 'drag-end', this._onDragEnd.bind(this));
this.isDraggableApp = true;
this.searchStrings = [
AppUtils.decomp_string(app.get_name()).replace(/\s/g, ''),
app.get_keywords() ? AppUtils.decomp_string(app.get_keywords()) : "",
app.get_description() ? AppUtils.decomp_string(app.get_description()).replace(/\s/g, '') : "",
app.get_id() ? AppUtils.decomp_string(app.get_id()) : ""
];
}
get_app_id() {
return this.app.get_id();
}
getDragActor() {
return this.app.create_icon_texture(this.applet.sidebarIconSize);
}
// Returns the original actor that should align with the actor
// we show as the item is being dragged.
getDragActorSource() {
return this.actor;
}
_onDragEnd() {
this.applet.favoriteAppsBox._delegate._clearDragPlaceholder();
}
destroy() {
delete this._draggable;
super.destroy();
}
}
class SearchProviderResultButton extends SimpleMenuItem {
constructor(applet, provider, result) {
super(applet, {
name:result.label,
description: result.description,
type: 'search-provider',
styleClass: 'appmenu-application-button',
provider: provider,
result: result,
});
if (result.icon) {
this.icon = result.icon;
} else if (result.icon_app) {
this.icon = result.icon_app.create_icon_texture(applet.applicationIconSize);
} else if (result.icon_filename) {
this.icon = new St.Icon({
gicon: new Gio.FileIcon({ file: Gio.file_new_for_path(result.icon_filename) }),
icon_size: applet.applicationIconSize,
});
}
if (this.icon)
this.addActor(this.icon);
this.addLabel(result.label, 'appmenu-application-button-label');
}
activate() {
try {
this.provider.on_result_selected(this.result);
this.applet.menu.close();
} catch(e) {
global.logError(e);
}
}
destroy() {
delete this.provider;
delete this.result;
super.destroy();
}
}
class PlaceSearchResultButton extends SimpleMenuItem {
constructor(applet, place) {
super(applet, {
name: place.name,
type: 'search-result',
styleClass: 'appmenu-application-button',
place: place,
});
this.icon = place.iconFactory(applet.applicationIconSize);
if (this.icon)
this.addActor(this.icon);
else
this.addIcon(applet.applicationIconSize, 'folder');
this.addLabel(this.name, 'appmenu-application-button-label');
}
activate() {
this.place.launch();
this.applet.menu.close();
}
destroy() {
delete this.place;
super.destroy();
}
}
class PlaceButton extends SimpleMenuItem {
constructor(applet, place) {
let selectedAppId = place.idDecoded.substr(place.idDecoded.indexOf(':') + 1);
let fileIndex = selectedAppId.indexOf('file:///');
if (fileIndex !== -1)
selectedAppId = selectedAppId.substr(fileIndex + 7);
if (selectedAppId === "home" || selectedAppId === "desktop" || selectedAppId === "connect") {
selectedAppId = place.name
}
super(applet, {
name: place.name,
type: 'place',
styleClass: 'appmenu-sidebar-button',
place: place,
});
this.icon = place.iconFactory(applet.sidebarIconSize);
if (this.icon)
this.addActor(this.icon);
else
this.addIcon(applet.applicationIconSize, 'folder');
this.addLabel(this.name, 'appmenu-application-button-label');
}
activate() {
this.place.launch();
this.applet.menu.close();
}
}
class RecentButton extends SimpleMenuItem {
constructor(applet, recent) {
let path = recent.uriDecoded.replace("file://", "");
path = path.replace(GLib.get_home_dir(), "~").replace("/" + recent.name, "");
super(applet, {
name: recent.name,
description: path,
type: 'recent',
styleClass: 'appmenu-application-button',
withMenu: true,
uri: recent.uri,
});
this.icon = recent.createIcon(applet.applicationIconSize);
this.addActor(this.icon);
this.addLabel(this.name, 'appmenu-application-button-label');
if (applet.showDescription)
this.addDescription(this.description, 'appmenu-application-button-description');
this.searchStrings = [
AppUtils.decomp_string(recent.name).replace(/\s/g, '')
];
}
activate() {
try {
Gio.app_info_launch_default_for_uri(this.uri, global.create_app_launch_context());
this.applet.menu.close();
} catch (e) {
let source = new MessageTray.SystemNotificationSource();
Main.messageTray.add(source);
let notification = new MessageTray.Notification(source,
_("This file is no longer available"),
e.message);
notification.setTransient(true);
notification.setUrgency(MessageTray.Urgency.NORMAL);
source.notify(notification);
}
}
}
class PathButton extends SimpleMenuItem {
constructor(applet, type, name, uri, icon) {
super(applet, {
name: name,
description: shorten_path(uri, name),
type: type,
styleClass: 'appmenu-application-button',
withMenu: false,
uri: uri,
});
this.icon = icon;
this.addActor(this.icon);
this.addLabel(name, 'appmenu-application-button-label');
if (applet.showDescription)
this.addDescription(this.description, 'appmenu-application-button-description');
this.searchStrings = [
AppUtils.decomp_string(name).replace(/\s/g, '')
];
}
activate() {
try {
Gio.app_info_launch_default_for_uri(this.uri, global.create_app_launch_context());
this.applet.menu.close();
} catch (e) {
let source = new MessageTray.SystemNotificationSource();
Main.messageTray.add(source);
let notification = new MessageTray.Notification(source,
_("This file is no longer available"),
e.message);
notification.setTransient(true);
notification.setUrgency(MessageTray.Urgency.NORMAL);
source.notify(notification);
}
}
}
class CategoryButton extends SimpleMenuItem {
constructor(applet, categoryId, label, icon, symbolic=false) {
super(applet, {
name: label,
type: 'category',
styleClass: 'appmenu-category-button',
categoryId: categoryId,
});
let size = applet.categoryIconSize;
if (applet.symbolicCategoryIcons) {
symbolic = true;
if (typeof icon !== 'string')
if (icon?.get_names)
icon = icon.get_names()[0];
else
icon = "";
if (icon.startsWith("applications-") || icon === "folder-recent")
icon = "xsi-" + icon;
else if (icon == "xapp-user-favorites")
icon = "xsi-user-favorites-symbolic";
else if (icon == "preferences-system")
icon = "xsi-applications-administration";
else if (icon == "preferences-desktop")
icon = "xsi-applications-preferences";
else if (icon == "wine")
icon = "xsi-applications-wine";
else
icon = "xsi-applications-other";
}
if (typeof icon === 'string')
this.addIcon(size, icon, null, symbolic);
else if (icon)
this.addIcon(size, null, icon, symbolic);
this.addLabel(this.name, 'appmenu-category-button-label');
this.actor_motion_id = 0;
}
activate() {
if(this.applet.searchActive || this.categoryId === this.applet.lastSelectedCategory)
return;
this.applet._select_category(this.categoryId);
this.applet.hoveredApp = null;
this.applet.categoriesBox.get_children().forEach(child =>
child.set_style_class_name("appmenu-category-button"));
this.actor.style_class = "appmenu-category-button-selected";
}
}
class FavoritesButton extends GenericApplicationButton {
constructor(applet, app) {
super(applet, app, 'fav', false, 'appmenu-sidebar-button');
this.set_application_icon(applet.sidebarIconSize);
this.addActor(this.icon);
this.addLabel(this.name, 'appmenu-application-button-label');
this._draggable = DND.makeDraggable(this.actor);
this._signals.connect(this._draggable, 'drag-end', this._onDragEnd.bind(this));
this.isDraggableApp = true;
}
_onDragEnd() {
this.actor.get_parent()._delegate._clearDragPlaceholder();
}
get_app_id() {
return this.app.get_id();
}
getDragActor() {
return new Clutter.Clone({ source: this.actor });
}
// Returns the original actor that should align with the actor
// we show as the item is being dragged.
getDragActorSource() {
return this.actor;
}
destroy() {
delete this._draggable;
super.destroy();
}
}
class SystemButton extends SimpleMenuItem {
constructor(applet, iconName, name, desc) {
super(applet, {
name: name,
description: desc,
type: 'system',
styleClass: 'appmenu-system-button',
});
this.addIcon(16, iconName, null, true);
this.actor.set_accessible_name(name);
this.actor.set_accessible_role(Atk.Role.BUTTON);
}
}
class CategoriesApplicationsBox {
constructor() {
this.actor = new St.BoxLayout({ vertical: false, style_class: 'appmenu-categories-applications-box' });
this.actor._delegate = this;
}
acceptDrop (source, actor, x, y, time) {
if (source instanceof FavoritesButton){
source.actor.destroy();
actor.destroy();
AppFavorites.getAppFavorites().removeFavorite(source.app.get_id());
return true;
}
return false;
}
handleDragOver (source, actor, x, y, time) {
if (source instanceof FavoritesButton)
return DND.DragMotionResult.POINTING_DROP;
return DND.DragMotionResult.CONTINUE;
}
}
class SidebarScrollBox {
constructor() {
this.actor = new St.BoxLayout({
vertical: true,
y_expand: true,
y_align: Clutter.ActorAlign.START,
style_class: 'appmenu-sidebar-scrollbox'
});
this.actor._delegate = this;
}
}
class FavoriteAppsBox {
constructor() {