No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | nautilus-window-menus.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3 /*
4 * Nautilus
5 *
6 * Copyright (C) 2000, 2001 Eazel, Inc.
7 *
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Author: John Sullivan <sullivan@eazel.com>
23 */
24
25 /* nautilus-window-menus.h - implementation of nautilus window menu operations,
26 * split into separate file just for convenience.
27 */
28 #include <config.h>
29
30 #include <locale.h>
31
32 #include "nautilus-actions.h"
33 #include "nautilus-application.h"
34 #include "nautilus-canvas-view.h"
35 #include "nautilus-connect-server-dialog.h"
36 #include "nautilus-file-management-properties.h"
37 #include "nautilus-list-view.h"
38 #include "nautilus-notebook.h"
39 #include "nautilus-window-manage-views.h"
40 #include "nautilus-window-private.h"
41 #include "nautilus-desktop-window.h"
42 #include "nautilus-properties-window.h"
43
44 #include <gtk/gtk.h>
45 #include <gio/gio.h>
46 #include <glib/gi18n.h>
47
48 #include <eel/eel-gtk-extensions.h>
49 #include <eel/eel-stock-dialogs.h>
50
51 #include <libnautilus-extension/nautilus-menu-provider.h>
52 #include <libnautilus-private/nautilus-file-utilities.h>
53 #include <libnautilus-private/nautilus-global-preferences.h>
54 #include <libnautilus-private/nautilus-icon-names.h>
55 #include <libnautilus-private/nautilus-ui-utilities.h>
56 #include <libnautilus-private/nautilus-module.h>
57 #include <libnautilus-private/nautilus-program-choosing.h>
58 #include <libnautilus-private/nautilus-search-directory.h>
59 #include <libnautilus-private/nautilus-search-engine.h>
60 #include <libnautilus-private/nautilus-signaller.h>
61 #include <libnautilus-private/nautilus-trash-monitor.h>
62 #include <string.h>
63
64 #define MENU_PATH_EXTENSION_ACTIONS "/ActionMenu/Extension Actions"
65 #define POPUP_PATH_EXTENSION_ACTIONS "/background/Before Zoom Items/Extension Actions"
66
67 #define NETWORK_URI "network:"
68
69 static void
70 action_close_window_slot_callback (GtkAction *action,
71 gpointer user_data)
72 {
73 NautilusWindow *window;
74 NautilusWindowSlot *slot;
75
76 window = NAUTILUS_WINDOW (user_data);
77 slot = nautilus_window_get_active_slot (window);
78
79 nautilus_window_slot_close (window, slot);
80 }
81
82 static void
83 action_connect_to_server_callback (GtkAction *action,
84 gpointer user_data)
85 {
86 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
87 "connect-to-server", NULL);
88 }
89
90 static void
91 action_bookmarks_callback (GtkAction *action,
92 gpointer user_data)
93 {
94 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
95 "bookmarks", NULL);
96 }
97
98 static void
99 action_stop_callback (GtkAction *action,
100 gpointer user_data)
101 {
102 NautilusWindow *window;
103 NautilusWindowSlot *slot;
104
105 window = NAUTILUS_WINDOW (user_data);
106 slot = nautilus_window_get_active_slot (window);
107
108 nautilus_window_slot_stop_loading (slot);
109 }
110
111 static void
112 action_home_callback (GtkAction *action,
113 gpointer user_data)
114 {
115 NautilusWindow *window;
116 NautilusWindowSlot *slot;
117
118 window = NAUTILUS_WINDOW (user_data);
119 slot = nautilus_window_get_active_slot (window);
120
121 nautilus_window_slot_go_home (slot,
122 nautilus_event_get_window_open_flags ());
123 }
124
125 static void
126 action_reload_callback (GtkAction *action,
127 gpointer user_data)
128 {
129 NautilusWindowSlot *slot;
130
131 slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
132 nautilus_window_slot_queue_reload (slot);
133 }
134
135 static void
136 action_location_properties_callback (GtkAction *action,
137 gpointer user_data)
138 {
139 NautilusWindowSlot *slot;
140 GList *files;
141 NautilusView *view;
142 NautilusFile *file;
143
144 slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
145 view = nautilus_window_slot_get_current_view (slot);
146 file = nautilus_view_get_directory_as_file (view);
147
148 files = g_list_append (NULL, file);
149
150 nautilus_properties_window_present (files, GTK_WIDGET (view), NULL);
151
152 nautilus_file_list_free (files);
153 }
154
155 static NautilusView *
156 get_current_view (NautilusWindow *window)
157 {
158 NautilusWindowSlot *slot;
159 NautilusView *view;
160
161 slot = nautilus_window_get_active_slot (window);
162 view = nautilus_window_slot_get_current_view (slot);
163
164 return view;
165 }
166
167 static void
168 action_zoom_in_callback (GtkAction *action,
169 gpointer user_data)
170 {
171
172 nautilus_view_bump_zoom_level (get_current_view (user_data), 1);
173 }
174
175 static void
176 action_zoom_out_callback (GtkAction *action,
177 gpointer user_data)
178 {
179 nautilus_view_bump_zoom_level (get_current_view (user_data), -1);
180 }
181
182 static void
183 action_zoom_normal_callback (GtkAction *action,
184 gpointer user_data)
185 {
186 nautilus_view_restore_default_zoom_level (get_current_view (user_data));
187 }
188
189 static void
190 action_preferences_callback (GtkAction *action,
191 gpointer user_data)
192 {
193 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
194 "preferences", NULL);
195 }
196
197 static void
198 action_about_nautilus_callback (GtkAction *action,
199 gpointer user_data)
200 {
201 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
202 "about", NULL);
203 }
204
205 static void
206 action_up_callback (GtkAction *action,
207 gpointer user_data)
208 {
209 NautilusWindow *window = user_data;
210 NautilusWindowSlot *slot;
211
212 slot = nautilus_window_get_active_slot (window);
213 nautilus_window_slot_go_up (slot, nautilus_event_get_window_open_flags ());
214 }
215
216 static void
217 action_nautilus_manual_callback (GtkAction *action,
218 gpointer user_data)
219 {
220 NautilusWindow *window;
221 GError *error;
222 GtkWidget *dialog;
223 const char* helpuri;
224 const char* name = gtk_action_get_name (action);
225
226 error = NULL;
227 window = NAUTILUS_WINDOW (user_data);
228
229 if (g_str_equal (name, "NautilusHelpSearch")) {
230 helpuri = "help:gnome-help/files-search";
231 } else if (g_str_equal (name,"NautilusHelpSort")) {
232 helpuri = "help:gnome-help/files-sort";
233 } else if (g_str_equal (name, "NautilusHelpLost")) {
234 helpuri = "help:gnome-help/files-lost";
235 } else if (g_str_equal (name, "NautilusHelpShare")) {
236 helpuri = "help:gnome-help/files-share";
237 } else {
238 helpuri = "help:gnome-help/files";
239 }
240
241 if (NAUTILUS_IS_DESKTOP_WINDOW (window)) {
242 nautilus_launch_application_from_command (gtk_window_get_screen (GTK_WINDOW (window)), "gnome-help", FALSE, NULL);
243 } else {
244 gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (window)),
245 helpuri,
246 gtk_get_current_event_time (), &error);
247 }
248
249 if (error) {
250 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
251 GTK_DIALOG_MODAL,
252 GTK_MESSAGE_ERROR,
253 GTK_BUTTONS_OK,
254 _("There was an error displaying help: \n%s"),
255 error->message);
256 g_signal_connect (G_OBJECT (dialog), "response",
257 G_CALLBACK (gtk_widget_destroy),
258 NULL);
259
260 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
261 gtk_widget_show (dialog);
262 g_error_free (error);
263 }
264 }
265
266 #define MENU_ITEM_MAX_WIDTH_CHARS 32
267
268 static void
269 action_close_all_windows_callback (GtkAction *action,
270 gpointer user_data)
271 {
272 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
273 "quit", NULL);
274 }
275
276 static void
277 action_back_callback (GtkAction *action,
278 gpointer user_data)
279 {
280 nautilus_window_back_or_forward (NAUTILUS_WINDOW (user_data),
281 TRUE, 0, nautilus_event_get_window_open_flags ());
282 }
283
284 static void
285 action_forward_callback (GtkAction *action,
286 gpointer user_data)
287 {
288 nautilus_window_back_or_forward (NAUTILUS_WINDOW (user_data),
289 FALSE, 0, nautilus_event_get_window_open_flags ());
290 }
291
292 static void
293 action_show_hide_sidebar_callback (GtkAction *action,
294 gpointer user_data)
295 {
296 NautilusWindow *window;
297
298 window = NAUTILUS_WINDOW (user_data);
299
300 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
301 nautilus_window_show_sidebar (window);
302 } else {
303 nautilus_window_hide_sidebar (window);
304 }
305 }
306
307 static void
308 action_add_bookmark_callback (GtkAction *action,
309 gpointer user_data)
310 {
311 NautilusWindow *window = user_data;
312 NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
313 NautilusBookmark *bookmark;
314 NautilusWindowSlot *slot;
315 NautilusBookmarkList *list;
316
317 slot = nautilus_window_get_active_slot (window);
318 bookmark = slot->current_location_bookmark;
319 list = nautilus_application_get_bookmarks (app);
320
321 if (!nautilus_bookmark_list_contains (list, bookmark)) {
322 nautilus_bookmark_list_append (list, bookmark);
323 }
324 }
325
326 static void
327 connect_proxy_cb (GtkActionGroup *action_group,
328 GtkAction *action,
329 GtkWidget *proxy,
330 NautilusWindow *window)
331 {
332 GtkLabel *label;
333
334 if (!GTK_IS_MENU_ITEM (proxy))
335 return;
336
337 label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (proxy)));
338
339 gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
340 gtk_label_set_max_width_chars (label, MENU_ITEM_MAX_WIDTH_CHARS);
341 }
342
343 static void
344 action_new_window_callback (GtkAction *action,
345 gpointer user_data)
346 {
347 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
348 "new-window", NULL);
349 }
350
351 static void
352 action_new_tab_callback (GtkAction *action,
353 gpointer user_data)
354 {
355 NautilusWindow *window;
356
357 window = NAUTILUS_WINDOW (user_data);
358 nautilus_window_new_tab (window);
359 }
360
361 static void
362 action_enter_location_callback (GtkAction *action,
363 gpointer user_data)
364 {
365 g_action_group_activate_action (G_ACTION_GROUP (g_application_get_default ()),
366 "enter-location", NULL);
367 }
368
369 static void
370 action_tabs_previous_callback (GtkAction *action,
371 gpointer user_data)
372 {
373 NautilusWindow *window = user_data;
374
375 nautilus_notebook_prev_page (NAUTILUS_NOTEBOOK (window->details->notebook));
376 }
377
378 static void
379 action_tabs_next_callback (GtkAction *action,
380 gpointer user_data)
381 {
382 NautilusWindow *window = user_data;
383
384 nautilus_notebook_next_page (NAUTILUS_NOTEBOOK (window->details->notebook));
385 }
386
387 static void
388 action_tabs_move_left_callback (GtkAction *action,
389 gpointer user_data)
390 {
391 NautilusWindow *window = user_data;
392
393 nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->details->notebook), -1);
394 }
395
396 static void
397 action_tabs_move_right_callback (GtkAction *action,
398 gpointer user_data)
399 {
400 NautilusWindow *window = user_data;
401
402 nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->details->notebook), 1);
403 }
404
405 static void
406 action_tab_change_action_activate_callback (GtkAction *action,
407 gpointer user_data)
408 {
409 NautilusWindow *window = user_data;
410 GtkNotebook *notebook;
411 int num;
412
413 notebook = GTK_NOTEBOOK (window->details->notebook);
414
415 num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action), "num"));
416 if (num < gtk_notebook_get_n_pages (notebook)) {
417 gtk_notebook_set_current_page (notebook, num);
418 }
419 }
420
421 static void
422 action_show_hide_search_callback (GtkAction *action,
423 NautilusWindow *window)
424 {
425 NautilusWindowSlot *slot;
426 gboolean active;
427
428 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
429 slot = nautilus_window_get_active_slot (window);
430 nautilus_window_slot_set_search_visible (slot, active);
431 }
432
433 static void
434 action_prompt_for_location_callback (GtkAction *action,
435 NautilusWindow *window)
436 {
437 nautilus_window_prompt_for_location (window, "/");
438 }
439
440 static void
441 action_view_radio_changed (GtkRadioAction *action,
442 GtkRadioAction *current,
443 NautilusWindow *window)
444 {
445 const gchar *name;
446 NautilusWindowSlot *slot;
447
448 name = gtk_action_get_name (GTK_ACTION (current));
449 slot = nautilus_window_get_active_slot (window);
450
451 if (g_strcmp0 (name, NAUTILUS_ACTION_VIEW_LIST) == 0) {
452 nautilus_window_slot_set_content_view (slot, NAUTILUS_LIST_VIEW_ID);
453 } else if (g_strcmp0 (name, NAUTILUS_ACTION_VIEW_GRID) == 0) {
454 nautilus_window_slot_set_content_view (slot, NAUTILUS_CANVAS_VIEW_ID);
455 }
456 }
457
458 static const GtkActionEntry main_entries[] = {
459 /* name, stock id, label */ { "Help", NULL, N_("_Help") },
460 /* name, stock id */ { NAUTILUS_ACTION_CLOSE, GTK_STOCK_CLOSE,
461 /* label, accelerator */ N_("_Close"), "<control>W",
462 /* tooltip */ N_("Close this folder"),
463 G_CALLBACK (action_close_window_slot_callback) },
464 { NAUTILUS_ACTION_PREFERENCES, GTK_STOCK_PREFERENCES,
465 N_("Prefere_nces"),
466 NULL, N_("Edit Nautilus preferences"),
467 G_CALLBACK (action_preferences_callback) },
468 /* name, stock id, label */ { NAUTILUS_ACTION_UP, GTK_STOCK_GO_UP, N_("Open _Parent"),
469 "<alt>Up", N_("Open the parent folder"),
470 G_CALLBACK (action_up_callback) },
471 /* name, stock id */ { NAUTILUS_ACTION_STOP, GTK_STOCK_STOP,
472 /* label, accelerator */ N_("_Stop"), NULL,
473 /* tooltip */ N_("Stop loading the current location"),
474 G_CALLBACK (action_stop_callback) },
475 /* name, stock id */ { NAUTILUS_ACTION_RELOAD, GTK_STOCK_REFRESH,
476 /* label, accelerator */ N_("_Reload"), "<control>R",
477 /* tooltip */ N_("Reload the current location"),
478 G_CALLBACK (action_reload_callback) },
479 /* name, stock id */ { "ReloadAccel", NULL,
480 /* label, accelerator */ "ReloadAccel", "F5",
481 /* tooltip */ NULL,
482 G_CALLBACK (action_reload_callback) },
483 /* name, stock id */ { NAUTILUS_ACTION_HELP, GTK_STOCK_HELP,
484 /* label, accelerator */ N_("_All Topics"), "F1",
485 /* tooltip */ N_("Display Nautilus help"),
486 G_CALLBACK (action_nautilus_manual_callback) },
487 /* name, stock id */ { "NautilusHelpSearch", NULL,
488 /* label, accelerator */ N_("Search for files"), NULL,
489 /* tooltip */ N_("Locate files based on file name and type. Save your searches for later use."),
490 G_CALLBACK (action_nautilus_manual_callback) },
491 /* name, stock id */ { "NautilusHelpSort", NULL,
492 /* label, accelerator */ N_("Sort files and folders"), NULL,
493 /* tooltip */ N_("Arrange files by name, size, type, or when they were changed."),
494 G_CALLBACK (action_nautilus_manual_callback) },
495 /* name, stock id */ { "NautilusHelpLost", NULL,
496 /* label, accelerator */ N_("Find a lost file"), NULL,
497 /* tooltip */ N_("Follow these tips if you can't find a file you created or downloaded."),
498 G_CALLBACK (action_nautilus_manual_callback) },
499 /* name, stock id */ { "NautilusHelpShare", NULL,
500 /* label, accelerator */ N_("Share and transfer files"), NULL,
501 /* tooltip */ N_("Easily transfer files to your contacts and devices from the file manager."),
502 G_CALLBACK (action_nautilus_manual_callback) },
503 /* name, stock id */ { NAUTILUS_ACTION_ABOUT, GTK_STOCK_ABOUT,
504 /* label, accelerator */ N_("_About"), NULL,
505 /* tooltip */ N_("Display credits for the creators of Nautilus"),
506 G_CALLBACK (action_about_nautilus_callback) },
507 /* name, stock id */ { NAUTILUS_ACTION_ZOOM_IN, GTK_STOCK_ZOOM_IN,
508 /* label, accelerator */ N_("Zoom _In"), "<control>plus",
509 /* tooltip */ N_("Increase the view size"),
510 G_CALLBACK (action_zoom_in_callback) },
511 /* name, stock id */ { "ZoomInAccel", NULL,
512 /* label, accelerator */ "ZoomInAccel", "<control>equal",
513 /* tooltip */ NULL,
514 G_CALLBACK (action_zoom_in_callback) },
515 /* name, stock id */ { "ZoomInAccel2", NULL,
516 /* label, accelerator */ "ZoomInAccel2", "<control>KP_Add",
517 /* tooltip */ NULL,
518 G_CALLBACK (action_zoom_in_callback) },
519 /* name, stock id */ { NAUTILUS_ACTION_ZOOM_OUT, GTK_STOCK_ZOOM_OUT,
520 /* label, accelerator */ N_("Zoom _Out"), "<control>minus",
521 /* tooltip */ N_("Decrease the view size"),
522 G_CALLBACK (action_zoom_out_callback) },
523 /* name, stock id */ { "ZoomOutAccel", NULL,
524 /* label, accelerator */ "ZoomOutAccel", "<control>KP_Subtract",
525 /* tooltip */ NULL,
526 G_CALLBACK (action_zoom_out_callback) },
527 /* name, stock id */ { NAUTILUS_ACTION_ZOOM_NORMAL, GTK_STOCK_ZOOM_100,
528 /* label, accelerator */ N_("Normal Si_ze"), "<control>0",
529 /* tooltip */ N_("Use the normal view size"),
530 G_CALLBACK (action_zoom_normal_callback) },
531 /* name, stock id */ { NAUTILUS_ACTION_CONNECT_TO_SERVER, NULL,
532 /* label, accelerator */ N_("Connect to _Server..."), NULL,
533 /* tooltip */ N_("Connect to a remote computer or shared disk"),
534 G_CALLBACK (action_connect_to_server_callback) },
535 /* name, stock id */ { NAUTILUS_ACTION_GO_HOME, NAUTILUS_ICON_HOME,
536 /* label, accelerator */ N_("_Home"), "<alt>Home",
537 /* tooltip */ N_("Open your personal folder"),
538 G_CALLBACK (action_home_callback) },
539 /* name, stock id, label */ { NAUTILUS_ACTION_NEW_WINDOW, "window-new", N_("New _Window"),
540 "<control>N", N_("Open another Nautilus window for the displayed location"),
541 G_CALLBACK (action_new_window_callback) },
542 /* name, stock id, label */ { NAUTILUS_ACTION_NEW_TAB, "tab-new", N_("New _Tab"),
543 "<control>T", N_("Open another tab for the displayed location"),
544 G_CALLBACK (action_new_tab_callback) },
545 /* name, stock id, label */ { NAUTILUS_ACTION_CLOSE_ALL_WINDOWS, NULL, N_("Close _All Windows"),
546 "<control>Q", N_("Close all Navigation windows"),
547 G_CALLBACK (action_close_all_windows_callback) },
548 /* name, stock id, label */ { NAUTILUS_ACTION_BACK, "go-previous-symbolic", N_("_Back"),
549 "<alt>Left", N_("Go to the previous visited location"),
550 G_CALLBACK (action_back_callback) },
551 /* name, stock id, label */ { NAUTILUS_ACTION_FORWARD, "go-next-symbolic", N_("_Forward"),
552 "<alt>Right", N_("Go to the next visited location"),
553 G_CALLBACK (action_forward_callback) },
554 /* name, stock id, label */ { NAUTILUS_ACTION_ENTER_LOCATION, NULL, N_("Enter _Location..."),
555 "<control>L", N_("Specify a location to open"),
556 G_CALLBACK (action_enter_location_callback) },
557 /* name, stock id, label */ { NAUTILUS_ACTION_ADD_BOOKMARK, GTK_STOCK_ADD, N_("Bookmark this Location"),
558 "<control>d", N_("Add a bookmark for the current location"),
559 G_CALLBACK (action_add_bookmark_callback) },
560 /* name, stock id, label */ { NAUTILUS_ACTION_EDIT_BOOKMARKS, NULL, N_("_Bookmarks..."),
561 "<control>b", N_("Display and edit bookmarks"),
562 G_CALLBACK (action_bookmarks_callback) },
563 { "TabsPrevious", NULL, N_("_Previous Tab"), "<control>Page_Up",
564 N_("Activate previous tab"),
565 G_CALLBACK (action_tabs_previous_callback) },
566 { "TabsNext", NULL, N_("_Next Tab"), "<control>Page_Down",
567 N_("Activate next tab"),
568 G_CALLBACK (action_tabs_next_callback) },
569 { "TabsMoveLeft", NULL, N_("Move Tab _Left"), "<shift><control>Page_Up",
570 N_("Move current tab to left"),
571 G_CALLBACK (action_tabs_move_left_callback) },
572 { "TabsMoveRight", NULL, N_("Move Tab _Right"), "<shift><control>Page_Down",
573 N_("Move current tab to right"),
574 G_CALLBACK (action_tabs_move_right_callback) },
575 /* name, stock id */ { NAUTILUS_ACTION_LOCATION_PROPERTIES, GTK_STOCK_PROPERTIES,
576 /* label, accelerator */ N_("P_roperties"), NULL,
577 /* tooltip */ N_("View or modify the properties of this folder"),
578 G_CALLBACK (action_location_properties_callback) },
579 /* name, stock id */ { "PromptLocationAccel", NULL,
580 /* label, accelerator */ "PromptLocationAccel", "slash",
581 /* tooltip */ NULL,
582 G_CALLBACK (action_prompt_for_location_callback) },
583 };
584
585 static const GtkToggleActionEntry main_toggle_entries[] = {
586 /* name, stock id */ { NAUTILUS_ACTION_SHOW_HIDE_SIDEBAR, NULL,
587 /* label, accelerator */ N_("_Show Sidebar"), "F9",
588 /* tooltip */ N_("Change the visibility of this window's side pane"),
589 G_CALLBACK (action_show_hide_sidebar_callback),
590 /* is_active */ TRUE },
591 /* name, stock id */ { NAUTILUS_ACTION_SEARCH, "edit-find-symbolic",
592 /* label, accelerator */ N_("_Search for Files..."), "<control>f",
593 /* tooltip */ N_("Search documents and folders by name"),
594 G_CALLBACK (action_show_hide_search_callback),
595 /* is_active */ FALSE },
596 };
597
598 static const GtkRadioActionEntry view_radio_entries[] = {
599 { NAUTILUS_ACTION_VIEW_LIST, "view-list-symbolic", N_("List"),
600 "<control>1", N_("View items as a list"), 0 },
601 { NAUTILUS_ACTION_VIEW_GRID, "view-grid-symbolic", N_("List"),
602 "<control>2", N_("View items as a grid of icons"), 1 }
603 };
604
605 static const gchar* app_actions[] = {
606 NAUTILUS_ACTION_NEW_WINDOW,
607 NAUTILUS_ACTION_CONNECT_TO_SERVER,
608 NAUTILUS_ACTION_ENTER_LOCATION,
609 NAUTILUS_ACTION_EDIT_BOOKMARKS,
610 NAUTILUS_ACTION_PREFERENCES,
611 NAUTILUS_ACTION_HELP,
612 NAUTILUS_ACTION_ABOUT,
613 NAUTILUS_ACTION_CLOSE_ALL_WINDOWS,
614
615 /* also hide the help menu entirely when using an app menu */
616 "Help"
617 };
618
619 static void
620 action_toggle_state (GSimpleAction *action,
621 GVariant *parameter,
622 gpointer user_data)
623 {
624 GVariant *state;
625
626 state = g_action_get_state (G_ACTION (action));
627 g_action_change_state (G_ACTION (action),
628 g_variant_new_boolean (!g_variant_get_boolean (state)));
629 g_variant_unref (state);
630 }
631
632 const GActionEntry win_entries[] = {
633 { "gear-menu", action_toggle_state, NULL, "false", NULL },
634 };
635
636 void
637 nautilus_window_initialize_actions (NautilusWindow *window)
638 {
639 g_action_map_add_action_entries (G_ACTION_MAP (window),
640 win_entries, G_N_ELEMENTS (win_entries),
641 window);
642 }
643
644 static void
645 nautilus_window_menus_set_visibility_for_app_menu (NautilusWindow *window)
646 {
647 const gchar *action_name;
648 gboolean shows_app_menu;
649 GtkSettings *settings;
650 GtkAction *action;
651 gint idx;
652
653 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
654 g_object_get (settings,
655 "gtk-shell-shows-app-menu", &shows_app_menu,
656 NULL);
657
658 for (idx = 0; idx < G_N_ELEMENTS (app_actions); idx++) {
659 action_name = app_actions[idx];
660 action = gtk_action_group_get_action (window->details->main_action_group, action_name);
661
662 gtk_action_set_visible (action, !shows_app_menu);
663 }
664 }
665
666 /**
667 * nautilus_window_initialize_menus
668 *
669 * Create and install the set of menus for this window.
670 * @window: A recently-created NautilusWindow.
671 */
672 void
673 nautilus_window_initialize_menus (NautilusWindow *window)
674 {
675 GtkActionGroup *action_group;
676 GtkUIManager *ui_manager;
677 GtkAction *action;
678 gint i;
679
680 window->details->ui_manager = gtk_ui_manager_new ();
681 ui_manager = window->details->ui_manager;
682
683 /* shell actions */
684 action_group = gtk_action_group_new ("ShellActions");
685 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
686 window->details->main_action_group = action_group;
687 gtk_action_group_add_actions (action_group,
688 main_entries, G_N_ELEMENTS (main_entries),
689 window);
690 gtk_action_group_add_toggle_actions (action_group,
691 main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
692 window);
693 gtk_action_group_add_radio_actions (action_group,
694 view_radio_entries, G_N_ELEMENTS (view_radio_entries),
695 -1, G_CALLBACK (action_view_radio_changed),
696 window);
697
698 nautilus_window_menus_set_visibility_for_app_menu (window);
699 window->details->app_menu_visibility_id =
700 g_signal_connect_swapped (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
701 "notify::gtk-shell-shows-app-menu",
702 G_CALLBACK (nautilus_window_menus_set_visibility_for_app_menu), window);
703
704 action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_UP);
705 g_object_set (action, "short_label", _("_Up"), NULL);
706
707 action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_HOME);
708 g_object_set (action, "short_label", _("_Home"), NULL);
709
710 /* Alt+N for the first 10 tabs */
711 for (i = 0; i < 10; ++i) {
712 gchar action_name[80];
713 gchar accelerator[80];
714
715 snprintf(action_name, sizeof (action_name), "Tab%d", i);
716 action = gtk_action_new (action_name, NULL, NULL, NULL);
717 g_object_set_data (G_OBJECT (action), "num", GINT_TO_POINTER (i));
718 g_signal_connect (action, "activate",
719 G_CALLBACK (action_tab_change_action_activate_callback), window);
720 snprintf(accelerator, sizeof (accelerator), "<alt>%d", (i+1)%10);
721 gtk_action_group_add_action_with_accel (action_group, action, accelerator);
722 g_object_unref (action);
723 gtk_ui_manager_add_ui (ui_manager,
724 gtk_ui_manager_new_merge_id (ui_manager),
725 "/",
726 action_name,
727 action_name,
728 GTK_UI_MANAGER_ACCELERATOR,
729 FALSE);
730
731 }
732
733 gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
734 g_object_unref (action_group); /* owned by ui_manager */
735
736 gtk_window_add_accel_group (GTK_WINDOW (window),
737 gtk_ui_manager_get_accel_group (ui_manager));
738
739 g_signal_connect (ui_manager, "connect_proxy",
740 G_CALLBACK (connect_proxy_cb), window);
741
742 /* add the UI */
743 gtk_ui_manager_add_ui_from_resource (ui_manager, "/org/gnome/nautilus/nautilus-shell-ui.xml", NULL);
744 }
745
746 void
747 nautilus_window_finalize_menus (NautilusWindow *window)
748 {
749 if (window->details->app_menu_visibility_id != 0) {
750 g_signal_handler_disconnect (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
751 window->details->app_menu_visibility_id);
752 window->details->app_menu_visibility_id = 0;
753 }
754 }
755
756 static GList *
757 get_extension_menus (NautilusWindow *window)
758 {
759 NautilusWindowSlot *slot;
760 GList *providers;
761 GList *items;
762 GList *l;
763
764 providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
765 items = NULL;
766
767 slot = nautilus_window_get_active_slot (window);
768
769 for (l = providers; l != NULL; l = l->next) {
770 NautilusMenuProvider *provider;
771 GList *file_items;
772
773 provider = NAUTILUS_MENU_PROVIDER (l->data);
774 file_items = nautilus_menu_provider_get_background_items (provider,
775 GTK_WIDGET (window),
776 slot->viewed_file);
777 items = g_list_concat (items, file_items);
778 }
779
780 nautilus_module_extension_list_free (providers);
781
782 return items;
783 }
784
785 static void
786 add_extension_menu_items (NautilusWindow *window,
787 guint merge_id,
788 GtkActionGroup *action_group,
789 GList *menu_items,
790 const char *subdirectory)
791 {
792 GtkUIManager *ui_manager;
793 GList *l;
794
795 ui_manager = window->details->ui_manager;
796
797 for (l = menu_items; l; l = l->next) {
798 NautilusMenuItem *item;
799 NautilusMenu *menu;
800 GtkAction *action;
801 char *path;
802
803 item = NAUTILUS_MENU_ITEM (l->data);
804
805 g_object_get (item, "menu", &menu, NULL);
806
807 action = nautilus_action_from_menu_item (item);
808 gtk_action_group_add_action_with_accel (action_group, action, NULL);
809
810 path = g_build_path ("/", POPUP_PATH_EXTENSION_ACTIONS, subdirectory, NULL);
811 gtk_ui_manager_add_ui (ui_manager,
812 merge_id,
813 path,
814 gtk_action_get_name (action),
815 gtk_action_get_name (action),
816 (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM,
817 FALSE);
818 g_free (path);
819
820 path = g_build_path ("/", MENU_PATH_EXTENSION_ACTIONS, subdirectory, NULL);
821 gtk_ui_manager_add_ui (ui_manager,
822 merge_id,
823 path,
824 gtk_action_get_name (action),
825 gtk_action_get_name (action),
826 (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM,
827 FALSE);
828 g_free (path);
829
830 /* recursively fill the menu */
831 if (menu != NULL) {
832 char *subdir;
833 GList *children;
834
835 children = nautilus_menu_get_items (menu);
836
837 subdir = g_build_path ("/", subdirectory, "/", gtk_action_get_name (action), NULL);
838 add_extension_menu_items (window,
839 merge_id,
840 action_group,
841 children,
842 subdir);
843
844 nautilus_menu_item_list_free (children);
845 g_free (subdir);
846 }
847 }
848 }
849
850 void
851 nautilus_window_load_extension_menus (NautilusWindow *window)
852 {
853 GtkActionGroup *action_group;
854 GList *items;
855 guint merge_id;
856
857 if (window->details->extensions_menu_merge_id != 0) {
858 gtk_ui_manager_remove_ui (window->details->ui_manager,
859 window->details->extensions_menu_merge_id);
860 window->details->extensions_menu_merge_id = 0;
861 }
862
863 if (window->details->extensions_menu_action_group != NULL) {
864 gtk_ui_manager_remove_action_group (window->details->ui_manager,
865 window->details->extensions_menu_action_group);
866 window->details->extensions_menu_action_group = NULL;
867 }
868
869 merge_id = gtk_ui_manager_new_merge_id (window->details->ui_manager);
870 window->details->extensions_menu_merge_id = merge_id;
871 action_group = gtk_action_group_new ("ExtensionsMenuGroup");
872 window->details->extensions_menu_action_group = action_group;
873 gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
874 gtk_ui_manager_insert_action_group (window->details->ui_manager, action_group, 0);
875 g_object_unref (action_group); /* owned by ui manager */
876
877 items = get_extension_menus (window);
878
879 if (items != NULL) {
880 add_extension_menu_items (window, merge_id, action_group, items, "");
881
882 g_list_foreach (items, (GFunc) g_object_unref, NULL);
883 g_list_free (items);
884 }
885 }