Debian Codegraph @

src/widgets/DesktopWindow.vala

raw
1 /*
2 * Copyright (c) 2017-2019 José Amuedo (https://github.com/spheras)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /**
19 * @class
20 * Folder Window that is shown above the desktop to manage files and folders
21 */
22 public class DesktopFolder.DesktopWindow : DesktopFolder.FolderWindow {
23
24 /**
25 * @constructor
26 * @param FolderManager manager the manager of this window
27 */
28 public DesktopWindow (FolderManager manager) {
29 base (manager);
30 this.scroll.get_vscrollbar ().visible = false;
31 this.scroll.get_hscrollbar ().visible = false;
32 }
33
34 /**
35 * @name on_enter_notify
36 * @description On mouse entering the window
37 */
38 protected override bool on_enter_notify (Gdk.EventCrossing event) {
39 // debug("DESKTOP enter notify");
40 return true;
41 }
42
43 protected override bool on_press (Gdk.EventButton event) {
44 if (event.type == Gdk.EventType.@2BUTTON_PRESS) {
45 debug ("toggling desktop visiblity");
46 base.get_manager ().get_application ().toggle_desktop_visibility ();
47 }
48 base.on_press (event);
49 return true;
50 }
51
52 /**
53 * @name move_to
54 * @description move the window to other position
55 */
56 protected override void move_to (int x, int y) {
57 // we cannot move move the desktop window
58 }
59
60 /**
61 * @name resize_to
62 * @description resize the window to other position
63 */
64 protected override void resize_to (int width, int height) {
65 // we cannot resize the desktop window
66 }
67
68 /**
69 * @name on_enter_leave
70 * @description On mouse leaving the window
71 */
72 protected override bool on_leave_notify (Gdk.EventCrossing event) {
73 // debug("DESKTOP leave notify");
74 return true;
75 }
76
77 /**
78 * @overrided
79 */
80 public override void reload_settings () {
81 base.reload_settings ();
82 this.get_style_context ().remove_class ("df_fadeout");
83 this.get_style_context ().add_class ("df_fadein");
84 this.opacity = 1;
85 }
86
87 /**
88 * @overrided
89 */
90 public override void refresh () {
91 var app = this.manager.get_application ();
92 if (app.get_desktop_visibility () && app.get_desktopicons_enabled ()) {
93 debug ("refresh, icons enabled and desktop visibility = true");
94 this.show_all ();
95 } else {
96 debug ("trying to hide");
97 this.manager.hide_items ();
98 }
99 }
100
101 /**
102 * @overrided
103 */
104 protected override void create_headerbar () {
105 this.set_titlebar (new Gtk.HeaderBar ());
106 }
107
108 /**
109 * @overrided
110 */
111 protected override void show_popup (Gdk.EventButton event) {
112 // debug("evento:%f,%f",event.x,event.y);
113 // if(this.menu==null) { // we need the event coordinates for the menu, we need to recreate?!
114
115 // Forcing desktop mode to avoid minimization in certain extreme cases without on_press signal!
116 // TODO: Is there a way to make a desktop window resizable and movable?
117
118 bool show_icon_options = this.manager.get_application ().get_desktoppanel_enabled () && this.manager.get_application ().get_desktopicons_enabled () && this.manager.get_application ().get_desktop_visibility ();
119
120 this.type_hint = Gdk.WindowTypeHint.DESKTOP;
121 this.context_menu = new Gtk.Menu ();
122 Clipboard.ClipboardManager cm = Clipboard.ClipboardManager.get_for_display ();
123
124 // Creating items (please try and keep these in the same order as appended to the menu)
125 var new_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_SUBMENU);
126
127 var new_submenu = new Gtk.Menu ();
128 var newfolder_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_FOLDER);
129 var emptyfile_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_EMPTY_FILE);
130 var newlink_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_FILE_LINK);
131 var newlinkdir_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_FOLDER_LINK);
132 var newpanel_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_DESKTOP_FOLDER);
133 var newlinkpanel_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_LINK_PANEL);
134 var newnote_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_NOTE);
135 var newphoto_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_PHOTO);
136 var properties_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_PROPERTIES_TOOLTIP);
137 var desktop_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_CHANGEDESKTOP);
138 Gtk.MenuItem show_desktop_item;
139 if (this.manager.get_application ().get_desktop_visibility ()) {
140 show_desktop_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_HIDE_DESKTOP);
141 } else {
142 show_desktop_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SHOW_DESKTOP);
143 }
144 var openterminal_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_OPENTERMINAL);
145
146 // sortby submenu -----------
147 var sortby_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY);
148 var sortby_submenu = new Gtk.Menu ();
149 var sortby_name_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY_NAME);
150 var sortby_size_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY_SIZE);
151 var sortby_type_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY_TYPE);
152 var sortby_reverse_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_REVERSE);
153 var sortby_vertical_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_VERTICAL);
154 var organize_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_ORGANIZE);
155 // ----------------------------
156
157 var textcolor_item = new MenuItemColor (HEAD_TAGS_COLORS, null);
158
159 // Events (please try and keep these in the same order as appended to the menu)
160 if (show_icon_options) {
161 newfolder_item.activate.connect (() => { this.new_folder ((int) event.x, (int) event.y); });
162 emptyfile_item.activate.connect (() => { this.new_text_file ((int) event.x, (int) event.y); });
163 newlink_item.activate.connect (() => { this.new_link ((int) event.x, (int) event.y, false); });
164 newlinkdir_item.activate.connect (() => { this.new_link ((int) event.x, (int) event.y, true); });
165 }
166 newpanel_item.activate.connect (() => { this.new_desktop_folder ((int) event.x, (int) event.y); });
167 newlinkpanel_item.activate.connect (() => { this.new_link_panel ((int) event.x, (int) event.y); });
168 newnote_item.activate.connect (() => { this.new_note ((int) event.x, (int) event.y); });
169 newphoto_item.activate.connect (() => { this.new_photo ((int) event.x, (int) event.y); });
170 if (show_icon_options) {
171 // sortby submenu ---------
172 sortby_name_item.set_active (this.manager.get_settings ().sort_by_type == FolderSort.SORT_BY_NAME);
173 sortby_size_item.set_active (this.manager.get_settings ().sort_by_type == FolderSort.SORT_BY_SIZE);
174 sortby_type_item.set_active (this.manager.get_settings ().sort_by_type == FolderSort.SORT_BY_TYPE);
175 sortby_reverse_item.set_active (this.manager.get_settings ().sort_reverse == true);
176 sortby_vertical_item.set_active (this.manager.is_vertical_arragement ());
177 sortby_name_item.toggled.connect ((item) => {
178 this.on_sort_by (FolderSort.SORT_BY_NAME);
179 });
180 sortby_size_item.toggled.connect ((item) => {
181 this.on_sort_by (FolderSort.SORT_BY_SIZE);
182 });
183 sortby_type_item.toggled.connect ((item) => {
184 this.on_sort_by (FolderSort.SORT_BY_TYPE);
185 });
186 sortby_reverse_item.toggled.connect ((item) => {
187 this.manager.get_settings ().sort_reverse = !this.manager.get_settings ().sort_reverse;
188 this.manager.get_settings ().save ();
189 this.manager.organize_panel_items ();
190 });
191 sortby_vertical_item.toggled.connect ((item) => {
192 if (this.manager.is_vertical_arragement ()) {
193 this.manager.get_settings ().arrangement_orientation = FolderSettings.ARRANGEMENT_ORIENTATION_HORIZONTAL;
194 } else {
195 this.manager.get_settings ().arrangement_orientation = FolderSettings.ARRANGEMENT_ORIENTATION_VERTICAL;
196 }
197 this.manager.get_settings ().save ();
198 this.manager.organize_panel_items ();
199 });
200 organize_item.activate.connect (this.manager.organize_panel_items);
201
202 // ------------------------
203
204 ((MenuItemColor) textcolor_item).color_changed.connect (change_head_color);
205 }
206
207 ((Gtk.MenuItem)properties_item).activate.connect (this.show_properties_dialog);
208 ((Gtk.MenuItem)desktop_item).activate.connect (this.show_desktop_dialog);
209
210 ((Gtk.MenuItem)show_desktop_item).activate.connect (this.manager.get_application ().toggle_desktop_visibility);
211
212 if (show_icon_options) {
213 openterminal_item.activate.connect (this.open_terminal);
214
215 // Appending (in order)
216 if (cm.can_paste) {
217 var paste_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_PASTE);
218 paste_item.activate.connect (this.manager.paste);
219 context_menu.append (paste_item);
220 context_menu.append (new MenuItemSeparator ());
221 }
222 }
223 context_menu.append (new_item);
224 new_item.set_submenu (new_submenu);
225 if (show_icon_options) {
226 new_submenu.append (newfolder_item);
227 new_submenu.append (emptyfile_item);
228 new_submenu.append (new MenuItemSeparator ());
229 new_submenu.append (newlink_item);
230 new_submenu.append (newlinkdir_item);
231 new_submenu.append (new MenuItemSeparator ());
232 }
233 new_submenu.append (newpanel_item);
234 new_submenu.append (newlinkpanel_item);
235 new_submenu.append (newnote_item);
236 new_submenu.append (newphoto_item);
237 context_menu.append (new MenuItemSeparator ());
238
239 if (show_icon_options) {
240 // sortby submenu ---------
241 context_menu.append (sortby_item);
242 sortby_item.set_submenu (sortby_submenu);
243 sortby_submenu.append (sortby_name_item);
244 sortby_submenu.append (sortby_size_item);
245 sortby_submenu.append (sortby_type_item);
246 sortby_submenu.append (new MenuItemSeparator ());
247 sortby_submenu.append (sortby_reverse_item);
248 sortby_submenu.append (sortby_vertical_item);
249 if (this.manager.get_arrangement ().can_organize ()) {
250 context_menu.append (organize_item);
251 }
252 context_menu.append (new MenuItemSeparator ());
253 }
254 context_menu.append (desktop_item);
255 context_menu.append (show_desktop_item);
256 context_menu.append (openterminal_item);
257
258 if (show_icon_options) {
259 context_menu.append (new MenuItemSeparator ());
260 context_menu.append (properties_item);
261 context_menu.append (textcolor_item);
262 }
263
264 context_menu.show_all ();
265 context_menu.popup_at_pointer (null);
266 }
267
268 /**
269 * @name show_desktop_dialog
270 * @description show the desktop dialog
271 */
272 protected void show_desktop_dialog () {
273 try {
274 var current_desktop = GLib.Environment.get_variable ("XDG_CURRENT_DESKTOP");
275 var command = "";
276
277 if (current_desktop == "Pantheon") {
278 debug ("We are in pantheon...");
279 command = "xdg-open settings://desktop";
280 } else {
281 command = "gnome-control-center background";
282 }
283
284 var appinfo = AppInfo.create_from_commandline (command, null, AppInfoCreateFlags.SUPPORTS_URIS);
285 appinfo.launch_uris (null, null);
286 } catch (Error err) {
287 // TODO
288 }
289 }
290
291 }