1717* Boston, MA 02110-1301 USA
1818*/
1919
20- public class Files.Plugins.SendByEmailMenuItem : Gtk . MenuItem {
20+ public class Files.Plugins.SendByEmail : Files . Plugins . Base {
2121 private GLib . File [] files;
22+ private Gdk . Window ? parent;
23+
24+ public override void context_menu (Gtk .Widget widget , List<Files . File > gof_files ) {
25+ if (gof_files == null || gof_files. length () == 0 ) {
26+ return ;
27+ }
28+
29+ files = get_file_array (gof_files);
30+ if (files == null || files. length <= 0 ) {
31+ return ;
32+ }
33+
34+ var email_action = new SimpleAction (" send" , null );
35+ email_action. activate. connect (action_email);
36+
37+ var action_group = new SimpleActionGroup ();
38+ action_group. add_action (email_action);
39+
40+ var separator = new Gtk .SeparatorMenuItem ();
2241
23- public SendByEmailMenuItem (GLib .File [] files ) {
24- this . files = files;
42+ var send_by_email_menuitem = new Gtk .MenuItem .with_label (_(" Send by Email" )) {
43+ action_name = " email.send"
44+ };
2545
26- label = _(" Send by Email" );
46+ var menu = (Gtk . Menu ) widget;
47+ menu. append (separator);
48+ menu. append (send_by_email_menuitem);
49+ menu. insert_action_group (" email" , action_group);
50+
51+ plugins. menuitem_references. add (separator);
52+ plugins. menuitem_references. add (send_by_email_menuitem);
53+
54+ parent = menu. get_toplevel (). get_window ();
2755 }
2856
29- public override void activate () {
57+ private static GLib .File [] get_file_array (List<Files . File > files ) {
58+ GLib . File [] file_array = new GLib.File [0 ];
59+
60+ foreach (unowned Files . File file in files) {
61+ if (file. location != null && ! file. is_directory && file. is_readable ()) {
62+ if (file. location. get_uri_scheme () == " recent" ) {
63+ file_array + = GLib . File . new_for_uri (file. get_display_target_uri ());
64+ } else {
65+ file_array + = file. location;
66+ }
67+ }
68+ }
69+
70+ return file_array;
71+ }
72+
73+ private void action_email () {
3074 try {
3175 var portal = Portal . Email . get ();
3276
@@ -76,14 +120,12 @@ public class Files.Plugins.SendByEmailMenuItem : Gtk.MenuItem {
76120 }
77121
78122 private async string window_export () {
79- var window = get_toplevel (). get_window ();
80-
81- if (window is Gdk . X11. Window ) {
82- var xid = ((Gdk . X11. Window ) window). get_xid ();
123+ if (parent is Gdk . X11. Window ) {
124+ var xid = ((Gdk . X11. Window ) parent). get_xid ();
83125 return " x11:%x " . printf ((uint ) xid);
84- } else if (window is Gdk . Wayland . Window ) {
126+ } else if (parent is Gdk . Wayland . Window ) {
85127 var handle = " wayland:" ;
86- ((Gdk . Wayland . Window ) window ). export_handle ((w, h) = > {
128+ ((Gdk . Wayland . Window ) parent ). export_handle ((w, h) = > {
87129 handle + = h;
88130 window_export. callback ();
89131 });
@@ -102,45 +144,6 @@ public class Files.Plugins.SendByEmailMenuItem : Gtk.MenuItem {
102144 }
103145}
104146
105- public class Files.Plugins.SendByEmail : Files .Plugins .Base {
106-
107- public override void context_menu (Gtk .Widget widget , List<Files . File > gof_files ) {
108- var menu = widget as Gtk . Menu ;
109-
110- if (gof_files == null || gof_files. length () == 0 ) {
111- return ;
112- }
113-
114- var files = get_file_array (gof_files);
115- if (files != null && files. length > 0 ) {
116- add_menuitem (menu, new Gtk .SeparatorMenuItem ());
117- add_menuitem (menu, new SendByEmailMenuItem (files));
118- }
119- }
120-
121- private void add_menuitem (Gtk .Menu menu , Gtk .MenuItem menu_item ) {
122- menu. append (menu_item);
123- menu_item. show ();
124- plugins. menuitem_references. add (menu_item);
125- }
126-
127- private static GLib .File [] get_file_array (List<Files . File > files ) {
128- GLib . File [] file_array = new GLib.File [0 ];
129-
130- foreach (unowned Files . File file in files) {
131- if (file. location != null && ! file. is_directory && file. is_readable ()) {
132- if (file. location. get_uri_scheme () == " recent" ) {
133- file_array + = GLib . File . new_for_uri (file. get_display_target_uri ());
134- } else {
135- file_array + = file. location;
136- }
137- }
138- }
139-
140- return file_array;
141- }
142- }
143-
144147public Files . Plugins . Base module_init () {
145148 return new Files .Plugins .SendByEmail ();
146149}
0 commit comments