1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 
3 /*
4  * Nemo
5  *
6  * Copyright (C) 2000, 2001 Eazel, Inc.
7  *
8  * Nemo 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  * Nemo 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., 51 Franklin Street, Suite 500, MA 02110-1335, USA.
21  *
22  * Author: John Sullivan <sullivan@eazel.com>
23  */
24 
25 /* nemo-window-menus.h - implementation of nemo window menu operations,
26  *                           split into separate file just for convenience.
27  */
28 #include <config.h>
29 
30 #include <locale.h>
31 
32 #include "nemo-window-menus.h"
33 #include "nemo-actions.h"
34 #include "nemo-application.h"
35 #include "nemo-connect-server-dialog.h"
36 #include "nemo-file-management-properties.h"
37 #include "nemo-navigation-action.h"
38 #include "nemo-notebook.h"
39 #include "nemo-window-manage-views.h"
40 #include "nemo-window-bookmarks.h"
41 #include "nemo-window-private.h"
42 #include "nemo-desktop-window.h"
43 #include "nemo-location-bar.h"
44 #include "nemo-icon-view.h"
45 #include "nemo-list-view.h"
46 #include "nemo-toolbar.h"
47 
48 #include <gtk/gtk.h>
49 #include <gio/gio.h>
50 #include <glib/gi18n.h>
51 
52 #include <eel/eel-gtk-extensions.h>
53 #include <eel/eel-stock-dialogs.h>
54 
55 #include <libnemo-extension/nemo-menu-provider.h>
56 #include <libnemo-private/nemo-file-utilities.h>
57 #include <libnemo-private/nemo-global-preferences.h>
58 #include <libnemo-private/nemo-icon-names.h>
59 #include <libnemo-private/nemo-ui-utilities.h>
60 #include <libnemo-private/nemo-module.h>
61 #include <libnemo-private/nemo-undo-manager.h>
62 #include <libnemo-private/nemo-program-choosing.h>
63 #include <libnemo-private/nemo-search-directory.h>
64 #include <libnemo-private/nemo-search-engine.h>
65 #include <libnemo-private/nemo-signaller.h>
66 #include <libnemo-private/nemo-trash-monitor.h>
67 #include <string.h>
68 
69 #define MENU_PATH_EXTENSION_ACTIONS                     "/MenuBar/File/Extension Actions"
70 #define POPUP_PATH_EXTENSION_ACTIONS                     "/background/Before Zoom Items/Extension Actions"
71 
72 #define NETWORK_URI          "network:"
73 #define COMPUTER_URI         "computer:"
74 
75 static void set_content_view_type(NemoWindow *window,
76                                   const gchar *view_id);
77 
78 enum {
79     NULL_VIEW,
80     ICON_VIEW,
81     LIST_VIEW,
82     COMPACT_VIEW,
83     SIDEBAR_PLACES,
84     SIDEBAR_TREE
85 };
86 
87 static void
action_close_window_slot_callback(GtkAction * action,gpointer user_data)88 action_close_window_slot_callback (GtkAction *action,
89 				   gpointer user_data)
90 {
91 	NemoWindow *window;
92 	NemoWindowSlot *slot;
93 
94 	window = NEMO_WINDOW (user_data);
95 	slot = nemo_window_get_active_slot (window);
96 
97 	nemo_window_pane_close_slot (slot->pane, slot);
98 }
99 
100 static void
action_connect_to_server_callback(GtkAction * action,gpointer user_data)101 action_connect_to_server_callback (GtkAction *action,
102 				   gpointer user_data)
103 {
104 	NemoWindow *window = NEMO_WINDOW (user_data);
105 	GtkWidget *dialog;
106 
107 	dialog = nemo_connect_server_dialog_new (window);
108 
109 	gtk_widget_show (dialog);
110 }
111 
112 static void
action_stop_callback(GtkAction * action,gpointer user_data)113 action_stop_callback (GtkAction *action,
114 		      gpointer user_data)
115 {
116 	NemoWindow *window;
117 	NemoWindowSlot *slot;
118 
119 	window = NEMO_WINDOW (user_data);
120 	slot = nemo_window_get_active_slot (window);
121 
122 	nemo_window_slot_stop_loading (slot);
123 }
124 
125 #ifdef TEXT_CHANGE_UNDO
126 static void
action_undo_callback(GtkAction * action,gpointer user_data)127 action_undo_callback (GtkAction *action,
128 		      gpointer user_data)
129 {
130 	NemoApplication *app;
131 
132 	app = nemo_application_get_singleton ();
133 	nemo_undo_manager_undo (app->undo_manager);
134 }
135 #endif
136 
137 static void
action_home_callback(GtkAction * action,gpointer user_data)138 action_home_callback (GtkAction *action,
139 		      gpointer user_data)
140 {
141     if (!NEMO_IS_DESKTOP_WINDOW (user_data)) {
142         NemoWindow *window;
143         NemoWindowSlot *slot;
144 
145         window = NEMO_WINDOW (user_data);
146 g_printerr ("what\n");
147         slot = nemo_window_get_active_slot (window);
148 
149         nemo_window_slot_go_home (slot, nemo_event_get_window_open_flags ());
150     }
151 }
152 
153 static void
action_go_to_computer_callback(GtkAction * action,gpointer user_data)154 action_go_to_computer_callback (GtkAction *action,
155 				gpointer user_data)
156 {
157 	NemoWindow *window;
158 	NemoWindowSlot *slot;
159 	GFile *computer;
160 
161 	window = NEMO_WINDOW (user_data);
162 	slot = nemo_window_get_active_slot (window);
163 
164 	computer = g_file_new_for_uri (COMPUTER_URI);
165 	nemo_window_slot_open_location (slot, computer,
166 					    nemo_event_get_window_open_flags ());
167 	g_object_unref (computer);
168 }
169 
170 static void
action_go_to_network_callback(GtkAction * action,gpointer user_data)171 action_go_to_network_callback (GtkAction *action,
172 				gpointer user_data)
173 {
174 	NemoWindow *window;
175 	NemoWindowSlot *slot;
176 	GFile *network;
177 
178 	window = NEMO_WINDOW (user_data);
179 	slot = nemo_window_get_active_slot (window);
180 
181 	network = g_file_new_for_uri (NETWORK_URI);
182 	nemo_window_slot_open_location (slot, network,
183 					    nemo_event_get_window_open_flags ());
184 	g_object_unref (network);
185 }
186 
187 static void
action_go_to_templates_callback(GtkAction * action,gpointer user_data)188 action_go_to_templates_callback (GtkAction *action,
189 				 gpointer user_data)
190 {
191 	NemoWindow *window;
192 	NemoWindowSlot *slot;
193 	char *path;
194 	GFile *location;
195 
196 	window = NEMO_WINDOW (user_data);
197 	slot = nemo_window_get_active_slot (window);
198 
199 	path = nemo_get_templates_directory ();
200 	location = g_file_new_for_path (path);
201 	g_free (path);
202 	nemo_window_slot_open_location (slot, location,
203 					    nemo_event_get_window_open_flags ());
204 	g_object_unref (location);
205 }
206 
207 static void
action_go_to_trash_callback(GtkAction * action,gpointer user_data)208 action_go_to_trash_callback (GtkAction *action,
209 			     gpointer user_data)
210 {
211 	NemoWindow *window;
212 	NemoWindowSlot *slot;
213 	GFile *trash;
214 
215 	window = NEMO_WINDOW (user_data);
216 	slot = nemo_window_get_active_slot (window);
217 
218 	trash = g_file_new_for_uri ("trash:///");
219 	nemo_window_slot_open_location (slot, trash,
220 					    nemo_event_get_window_open_flags ());
221 	g_object_unref (trash);
222 }
223 
224 static void
action_reload_callback(GtkAction * action,gpointer user_data)225 action_reload_callback (GtkAction *action,
226 			gpointer user_data)
227 {
228 	NemoWindowSlot *slot;
229 
230 	slot = nemo_window_get_active_slot (NEMO_WINDOW (user_data));
231 	nemo_window_slot_queue_reload (slot, TRUE);
232 }
233 
234 static NemoView *
get_current_view(NemoWindow * window)235 get_current_view (NemoWindow *window)
236 {
237 	NemoWindowSlot *slot;
238 	NemoView *view;
239 
240 	slot = nemo_window_get_active_slot (window);
241 	view = nemo_window_slot_get_current_view (slot);
242 
243 	return view;
244 }
245 
246 static void
action_zoom_in_callback(GtkAction * action,gpointer user_data)247 action_zoom_in_callback (GtkAction *action,
248 			 gpointer user_data)
249 {
250     if (!NEMO_IS_DESKTOP_WINDOW (user_data)) {
251         nemo_view_bump_zoom_level (get_current_view (user_data), 1);
252     }
253 }
254 
255 static void
action_zoom_out_callback(GtkAction * action,gpointer user_data)256 action_zoom_out_callback (GtkAction *action,
257 			  gpointer user_data)
258 {
259     if (!NEMO_IS_DESKTOP_WINDOW (user_data)) {
260         nemo_view_bump_zoom_level (get_current_view (user_data), -1);
261     }
262 }
263 
264 static void
action_zoom_normal_callback(GtkAction * action,gpointer user_data)265 action_zoom_normal_callback (GtkAction *action,
266 			     gpointer user_data)
267 {
268     if (!NEMO_IS_DESKTOP_WINDOW (user_data)) {
269         nemo_view_restore_default_zoom_level (get_current_view (user_data));
270     }
271 }
272 
273 static void
action_show_hidden_files_callback(GtkAction * action,gpointer callback_data)274 action_show_hidden_files_callback (GtkAction *action,
275 				   gpointer callback_data)
276 {
277 	NemoWindow *window;
278 	NemoWindowShowHiddenFilesMode mode;
279 
280 	window = NEMO_WINDOW (callback_data);
281 
282 	if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
283 		mode = NEMO_WINDOW_SHOW_HIDDEN_FILES_ENABLE;
284 	} else {
285 		mode = NEMO_WINDOW_SHOW_HIDDEN_FILES_DISABLE;
286 	}
287 
288 	nemo_window_set_hidden_files_mode (window, mode);
289 }
290 
291 static void
action_preferences_callback(GtkAction * action,gpointer user_data)292 action_preferences_callback (GtkAction *action,
293 			     gpointer user_data)
294 {
295 	GtkWindow *window;
296 
297 	window = GTK_WINDOW (user_data);
298 
299 	nemo_file_management_properties_dialog_show (window, NULL);
300 }
301 
302 static void
action_plugins_callback(GtkAction * action,gpointer user_data)303 action_plugins_callback (GtkAction *action,
304                          gpointer user_data)
305 {
306     GtkWindow *window;
307 
308     window = GTK_WINDOW (user_data);
309 
310     nemo_file_management_properties_dialog_show (window, "plugins");
311 }
312 
313 static void
action_about_nemo_callback(GtkAction * action,gpointer user_data)314 action_about_nemo_callback (GtkAction *action,
315 				gpointer user_data)
316 {
317 	const gchar *license[] = {
318 		N_("Nemo is free software; you can redistribute it and/or modify "
319 		   "it under the terms of the GNU General Public License as published by "
320 		   "the Free Software Foundation; either version 2 of the License, or "
321 		   "(at your option) any later version."),
322 		N_("Nemo is distributed in the hope that it will be useful, "
323 		   "but WITHOUT ANY WARRANTY; without even the implied warranty of "
324 		   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
325 		   "GNU General Public License for more details."),
326 		N_("You should have received a copy of the GNU General Public License "
327 		   "along with Nemo; if not, write to the Free Software Foundation, Inc., "
328 		   "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA")
329 	};
330 	gchar *license_trans;
331 	GDateTime *date;
332 
333 	license_trans = g_strjoin ("\n\n", _(license[0]), _(license[1]),
334 					     _(license[2]), NULL);
335 
336 	date = g_date_time_new_now_local ();
337 
338 	gtk_show_about_dialog (GTK_WINDOW (user_data),
339 			       "program-name", _("Nemo"),
340 			       "version", VERSION,
341 			       "comments", _("Nemo lets you organize "
342 					     "files and folders, both on "
343 					     "your computer and online."),
344 			       "license", license_trans,
345 			       "wrap-license", TRUE,
346 			      "logo-icon-name", "folder",
347 			      NULL);
348 
349 	g_free (license_trans);
350 	g_date_time_unref (date);
351 }
352 
353 static void
action_up_callback(GtkAction * action,gpointer user_data)354 action_up_callback (GtkAction *action,
355 		     gpointer user_data)
356 {
357 	NemoWindow *window = user_data;
358 	NemoWindowSlot *slot;
359 
360 	slot = nemo_window_get_active_slot (window);
361 	nemo_window_slot_go_up (slot, nemo_event_get_window_open_flags ());
362 }
363 
364 static void
action_nemo_manual_callback(GtkAction * action,gpointer user_data)365 action_nemo_manual_callback (GtkAction *action,
366 				 gpointer user_data)
367 {
368 	NemoWindow *window;
369 	GError *error;
370 	GtkWidget *dialog;
371 	const char* helpuri;
372 	const char* name = gtk_action_get_name (action);
373 
374 	error = NULL;
375 	window = NEMO_WINDOW (user_data);
376 
377 	if (g_str_equal (name, "NemoHelpSearch")) {
378 		helpuri = "help:gnome-help/files-search";
379 	} else if (g_str_equal (name,"NemoHelpSort")) {
380 		helpuri = "help:gnome-help/files-sort";
381 	} else if (g_str_equal (name, "NemoHelpLost")) {
382 		helpuri = "help:gnome-help/files-lost";
383 	} else if (g_str_equal (name, "NemoHelpShare")) {
384 		helpuri = "help:gnome-help/files-share";
385 	} else {
386 		helpuri = "help:gnome-help/files";
387 	}
388 
389 	if (NEMO_IS_DESKTOP_WINDOW (window)) {
390 		nemo_launch_application_from_command (gtk_window_get_screen (GTK_WINDOW (window)), "gnome-help", FALSE, NULL);
391 	} else {
392 		gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (window)),
393 			      helpuri,
394 			      gtk_get_current_event_time (), &error);
395 	}
396 
397 	if (error) {
398 		dialog = gtk_message_dialog_new (GTK_WINDOW (window),
399 						 GTK_DIALOG_MODAL,
400 						 GTK_MESSAGE_ERROR,
401 						 GTK_BUTTONS_OK,
402 						 _("There was an error displaying help: \n%s"),
403 						 error->message);
404 		g_signal_connect (G_OBJECT (dialog), "response",
405 				  G_CALLBACK (gtk_widget_destroy),
406 				  NULL);
407 
408 		gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
409 		gtk_widget_show (dialog);
410 		g_error_free (error);
411 	}
412 }
413 
414 static void
action_show_shortcuts_window(GtkAction * action,gpointer user_data)415 action_show_shortcuts_window (GtkAction *action,
416                               gpointer user_data)
417 {
418     NemoWindow *window;
419     static GtkWidget *shortcuts_window;
420 
421     window = NEMO_WINDOW (user_data);
422 
423     if (shortcuts_window == NULL)
424     {
425         GtkBuilder *builder;
426 
427         builder = gtk_builder_new_from_resource ("/org/nemo/nemo-shortcuts.ui");
428         shortcuts_window = GTK_WIDGET (gtk_builder_get_object (builder, "keyboard_shortcuts"));
429 
430         gtk_window_set_position (GTK_WINDOW (shortcuts_window), GTK_WIN_POS_CENTER);
431 
432         g_signal_connect (shortcuts_window, "destroy",
433                           G_CALLBACK (gtk_widget_destroyed), &shortcuts_window);
434 
435         g_object_unref (builder);
436     }
437 
438     if (GTK_WINDOW (window) != gtk_window_get_transient_for (GTK_WINDOW (shortcuts_window)))
439     {
440         gtk_window_set_transient_for (GTK_WINDOW (shortcuts_window), GTK_WINDOW (window));
441     }
442 
443     gtk_widget_show_all (shortcuts_window);
444     gtk_window_present (GTK_WINDOW (shortcuts_window));
445 }
446 
447 static void
menu_item_select_cb(GtkMenuItem * proxy,NemoWindow * window)448 menu_item_select_cb (GtkMenuItem *proxy,
449 		     NemoWindow *window)
450 {
451 	GtkAction *action;
452 	char *message;
453 
454 	action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (proxy));
455 	g_return_if_fail (action != NULL);
456 
457 	g_object_get (G_OBJECT (action), "tooltip", &message, NULL);
458 	if (message) {
459 		gtk_statusbar_push (GTK_STATUSBAR (window->details->statusbar),
460 				    window->details->help_message_cid, message);
461 		g_free (message);
462 	}
463 }
464 
465 static void
menu_item_deselect_cb(GtkMenuItem * proxy,NemoWindow * window)466 menu_item_deselect_cb (GtkMenuItem *proxy,
467 		       NemoWindow *window)
468 {
469 	gtk_statusbar_pop (GTK_STATUSBAR (window->details->statusbar),
470 			   window->details->help_message_cid);
471 }
472 
473 static void
disconnect_proxy_cb(GtkUIManager * manager,GtkAction * action,GtkWidget * proxy,NemoWindow * window)474 disconnect_proxy_cb (GtkUIManager *manager,
475 		     GtkAction *action,
476 		     GtkWidget *proxy,
477 		     NemoWindow *window)
478 {
479 	if (GTK_IS_MENU_ITEM (proxy)) {
480 		g_signal_handlers_disconnect_by_func
481 			(proxy, G_CALLBACK (menu_item_select_cb), window);
482 		g_signal_handlers_disconnect_by_func
483 			(proxy, G_CALLBACK (menu_item_deselect_cb), window);
484 	}
485 }
486 
487 static void
trash_state_changed_cb(NemoTrashMonitor * monitor,gboolean state,NemoWindow * window)488 trash_state_changed_cb (NemoTrashMonitor *monitor,
489 			gboolean state,
490 			NemoWindow *window)
491 {
492 	GtkActionGroup *action_group;
493 	GtkAction *action;
494     gchar *icon_name;
495 
496 	action_group = nemo_window_get_main_action_group (window);
497 	action = gtk_action_group_get_action (action_group, "Go to Trash");
498 
499     icon_name = nemo_trash_monitor_get_symbolic_icon_name ();
500 
501     if (icon_name) {
502         g_object_set (action, "icon-name", icon_name, NULL);
503         g_clear_pointer (&icon_name, g_free);
504     }
505 }
506 
507 static void
nemo_window_initialize_trash_icon_monitor(NemoWindow * window)508 nemo_window_initialize_trash_icon_monitor (NemoWindow *window)
509 {
510 	NemoTrashMonitor *monitor;
511 
512 	monitor = nemo_trash_monitor_get ();
513 
514 	trash_state_changed_cb (monitor, TRUE, window);
515 
516 	g_signal_connect (monitor, "trash_state_changed",
517 			  G_CALLBACK (trash_state_changed_cb), window);
518 }
519 
520 #define MENU_ITEM_MAX_WIDTH_CHARS 32
521 
522 static void
action_close_all_windows_callback(GtkAction * action,gpointer user_data)523 action_close_all_windows_callback (GtkAction *action,
524 				   gpointer user_data)
525 {
526 	nemo_application_close_all_windows (nemo_application_get_singleton ());
527 }
528 
529 static void
action_back_callback(GtkAction * action,gpointer user_data)530 action_back_callback (GtkAction *action,
531 		      gpointer user_data)
532 {
533 	nemo_window_back_or_forward (NEMO_WINDOW (user_data),
534 					 TRUE, 0, nemo_event_get_window_open_flags ());
535 }
536 
537 static void
action_forward_callback(GtkAction * action,gpointer user_data)538 action_forward_callback (GtkAction *action,
539 			 gpointer user_data)
540 {
541 	nemo_window_back_or_forward (NEMO_WINDOW (user_data),
542 					 FALSE, 0, nemo_event_get_window_open_flags ());
543 }
544 
545 static void
action_split_view_switch_next_pane_callback(GtkAction * action,gpointer user_data)546 action_split_view_switch_next_pane_callback(GtkAction *action,
547 					    gpointer user_data)
548 {
549 	nemo_window_pane_grab_focus (nemo_window_get_next_pane (NEMO_WINDOW (user_data)));
550 }
551 
552 static void
action_split_view_same_location_callback(GtkAction * action,gpointer user_data)553 action_split_view_same_location_callback (GtkAction *action,
554 					  gpointer user_data)
555 {
556 	NemoWindow *window;
557 	NemoWindowPane *next_pane;
558 	GFile *location;
559 
560 	window = NEMO_WINDOW (user_data);
561 	next_pane = nemo_window_get_next_pane (window);
562 
563 	if (!next_pane) {
564 		return;
565 	}
566 	location = nemo_window_slot_get_location (next_pane->active_slot);
567 	if (location) {
568 		nemo_window_slot_open_location (nemo_window_get_active_slot (window),
569 						    location, 0);
570 		g_object_unref (location);
571 	}
572 }
573 
574 static void
action_show_hide_sidebar_callback(GtkAction * action,gpointer user_data)575 action_show_hide_sidebar_callback (GtkAction *action,
576 				   gpointer user_data)
577 {
578 	NemoWindow *window;
579 
580 	window = NEMO_WINDOW (user_data);
581 
582 	if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
583 		nemo_window_show_sidebar (window);
584 	} else {
585 		nemo_window_hide_sidebar (window);
586 	}
587 }
588 
589 static void
action_split_view_callback(GtkAction * action,gpointer user_data)590 action_split_view_callback (GtkAction *action,
591 			    gpointer user_data)
592 {
593 	NemoWindow *window;
594 	gboolean is_active;
595 
596     if (NEMO_IS_DESKTOP_WINDOW (user_data)) {
597         return;
598     }
599 
600 	window = NEMO_WINDOW (user_data);
601 
602 	is_active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
603 	if (is_active != nemo_window_split_view_showing (window)) {
604 		NemoWindowSlot *slot;
605 
606 		if (is_active) {
607 			nemo_window_split_view_on (window);
608 		} else {
609 			nemo_window_split_view_off (window);
610 		}
611 
612 		slot = nemo_window_get_active_slot (window);
613 		if (slot != NULL) {
614 			nemo_view_update_menus (slot->content_view);
615 		}
616 	}
617 }
618 
619 static void
nemo_window_update_split_view_actions_sensitivity(NemoWindow * window)620 nemo_window_update_split_view_actions_sensitivity (NemoWindow *window)
621 {
622 	GtkActionGroup *action_group;
623 	GtkAction *action;
624 	gboolean have_multiple_panes;
625 	gboolean next_pane_is_in_same_location;
626 	GFile *active_pane_location;
627 	GFile *next_pane_location;
628 	NemoWindowPane *next_pane;
629 	NemoWindowSlot *active_slot;
630 
631 	active_slot = nemo_window_get_active_slot (window);
632 	action_group = nemo_window_get_main_action_group (window);
633 
634 	/* collect information */
635 	have_multiple_panes = nemo_window_split_view_showing (window);
636 	if (active_slot != NULL) {
637 		active_pane_location = nemo_window_slot_get_location (active_slot);
638 	} else {
639 		active_pane_location = NULL;
640 	}
641 
642 	next_pane = nemo_window_get_next_pane (window);
643 	if (next_pane && next_pane->active_slot) {
644 		next_pane_location = nemo_window_slot_get_location (next_pane->active_slot);
645 		next_pane_is_in_same_location = (active_pane_location && next_pane_location &&
646 						 g_file_equal (active_pane_location, next_pane_location));
647 	} else {
648 		next_pane_location = NULL;
649 		next_pane_is_in_same_location = FALSE;
650 	}
651 
652 	/* switch to next pane */
653 	action = gtk_action_group_get_action (action_group, "SplitViewNextPane");
654 	gtk_action_set_sensitive (action, have_multiple_panes);
655 
656 	/* same location */
657 	action = gtk_action_group_get_action (action_group, "SplitViewSameLocation");
658 	gtk_action_set_sensitive (action, have_multiple_panes && !next_pane_is_in_same_location);
659 
660 	/* clean up */
661 	g_clear_object (&active_pane_location);
662 	g_clear_object (&next_pane_location);
663 }
664 
665 static void
sidebar_radio_entry_changed_cb(GtkAction * action,GtkRadioAction * current,gpointer user_data)666 sidebar_radio_entry_changed_cb (GtkAction *action,
667                 GtkRadioAction *current,
668                 gpointer user_data)
669 {
670     gint current_value;
671     NemoWindow *window = NEMO_WINDOW (user_data);
672 
673     current_value = gtk_radio_action_get_current_value (current);
674 
675     switch (current_value) {
676         case SIDEBAR_PLACES:
677             nemo_window_set_sidebar_id (window, NEMO_WINDOW_SIDEBAR_PLACES);
678             break;
679         case SIDEBAR_TREE:
680             nemo_window_set_sidebar_id (window, NEMO_WINDOW_SIDEBAR_TREE);
681             break;
682         default:
683             ;
684             break;
685     }
686 }
687 
688 static void
view_radio_entry_changed_cb(GtkAction * action,GtkRadioAction * current,gpointer user_data)689 view_radio_entry_changed_cb (GtkAction *action,
690                              GtkRadioAction *current,
691                              gpointer user_data)
692 {
693     gint current_value;
694     NemoWindow *window = NEMO_WINDOW (user_data);
695 
696     if (NEMO_IS_DESKTOP_WINDOW (window)) {
697         return;
698     }
699 
700     current_value = gtk_radio_action_get_current_value (current);
701 
702     switch (current_value) {
703         case ICON_VIEW:
704             set_content_view_type (window, NEMO_ICON_VIEW_ID);
705             break;
706         case LIST_VIEW:
707             set_content_view_type (window, NEMO_LIST_VIEW_ID);
708             break;
709         case COMPACT_VIEW:
710             set_content_view_type (window, FM_COMPACT_VIEW_ID);
711             break;
712         default:
713             ;
714             break;
715     }
716 }
717 
718 /* TODO: bind all of this with g_settings_bind and GBinding */
719 static guint
sidebar_id_to_value(const gchar * sidebar_id)720 sidebar_id_to_value (const gchar *sidebar_id)
721 {
722 	guint retval = SIDEBAR_PLACES;
723 
724 	if (g_strcmp0 (sidebar_id, NEMO_WINDOW_SIDEBAR_TREE) == 0)
725 		retval = SIDEBAR_TREE;
726 
727 	return retval;
728 }
729 
730 static void
update_side_bar_radio_buttons(NemoWindow * window)731 update_side_bar_radio_buttons (NemoWindow *window)
732 {
733     GtkActionGroup *action_group;
734     GtkAction *action;
735     guint current_value;
736 
737     action_group = nemo_window_get_main_action_group (window);
738 
739     action = gtk_action_group_get_action (action_group,
740                           "Sidebar Places");
741     current_value = sidebar_id_to_value (nemo_window_get_sidebar_id (window));
742 
743     g_signal_handlers_block_by_func (action, sidebar_radio_entry_changed_cb, window);
744     gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), current_value);
745     g_signal_handlers_unblock_by_func (action, sidebar_radio_entry_changed_cb, window);
746 }
747 
748 void
nemo_window_update_show_hide_menu_items(NemoWindow * window)749 nemo_window_update_show_hide_menu_items (NemoWindow *window)
750 {
751 	GtkActionGroup *action_group;
752 	GtkAction *action;
753 
754 	action_group = nemo_window_get_main_action_group (window);
755 
756 	action = gtk_action_group_get_action (action_group,
757 					      NEMO_ACTION_SHOW_HIDE_EXTRA_PANE);
758 	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
759 				      nemo_window_split_view_showing (window));
760 	nemo_window_update_split_view_actions_sensitivity (window);
761 
762     update_side_bar_radio_buttons (window);
763 }
764 
765 static void
action_add_bookmark_callback(GtkAction * action,gpointer user_data)766 action_add_bookmark_callback (GtkAction *action,
767 			      gpointer user_data)
768 {
769         nemo_window_add_bookmark_for_current_location (NEMO_WINDOW (user_data));
770 }
771 
772 static void
action_edit_bookmarks_callback(GtkAction * action,gpointer user_data)773 action_edit_bookmarks_callback (GtkAction *action,
774 				gpointer user_data)
775 {
776         nemo_window_edit_bookmarks (NEMO_WINDOW (user_data));
777 }
778 
779 static void
connect_proxy_cb(GtkActionGroup * action_group,GtkAction * action,GtkWidget * proxy,NemoWindow * window)780 connect_proxy_cb (GtkActionGroup *action_group,
781                   GtkAction *action,
782                   GtkWidget *proxy,
783                   NemoWindow *window)
784 {
785     GtkWidget *label;
786 
787 	if (!GTK_IS_MENU_ITEM (proxy))
788 		return;
789 
790     label = gtk_bin_get_child (GTK_BIN (proxy));
791 
792     if (GTK_IS_LABEL (label)) {
793        gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
794        gtk_label_set_max_width_chars (GTK_LABEL (label), MENU_ITEM_MAX_WIDTH_CHARS);
795     }
796 
797 	g_signal_connect (proxy, "select",
798 			  G_CALLBACK (menu_item_select_cb), window);
799 	g_signal_connect (proxy, "deselect",
800 			  G_CALLBACK (menu_item_deselect_cb), window);
801 }
802 
803 static void
action_new_window_callback(GtkAction * action,gpointer user_data)804 action_new_window_callback (GtkAction *action,
805                             gpointer user_data)
806 {
807     NemoWindow *current_window;
808 
809     current_window = NEMO_WINDOW (user_data);
810 
811     if (NEMO_IS_DESKTOP_WINDOW (current_window)) {
812         NemoFile *file;
813         NemoView *view;
814         gchar *desktop_uri;
815 
816         desktop_uri = nemo_get_desktop_directory_uri ();
817 
818         file = nemo_file_get_existing_by_uri (desktop_uri);
819 
820         view = nemo_window_slot_get_current_view (nemo_window_get_active_slot (current_window));
821         nemo_view_activate_file (view, file, 0);
822 
823         g_free (desktop_uri);
824         nemo_file_unref (file);
825     } else {
826         NemoApplication *application;
827         NemoWindow *new_window;
828         gchar *uri;
829         GFile *loc;
830 
831         uri = nemo_window_slot_get_current_uri (nemo_window_get_active_slot (current_window));
832         loc = g_file_new_for_uri (uri);
833 
834         application = nemo_application_get_singleton ();
835 
836         new_window = nemo_application_create_window (application,
837                                                      gtk_window_get_screen (GTK_WINDOW (current_window)));
838 
839         nemo_window_slot_open_location (nemo_window_get_active_slot (new_window), loc, 0);
840 
841         g_object_unref (loc);
842         g_free (uri);
843     }
844 }
845 
846 static void
action_new_tab_callback(GtkAction * action,gpointer user_data)847 action_new_tab_callback (GtkAction *action,
848 			 gpointer user_data)
849 {
850 	NemoWindow *window;
851 
852 	window = NEMO_WINDOW (user_data);
853 	nemo_window_new_tab (window);
854 }
855 
856 void action_toggle_location_entry_callback (GtkToggleAction *action, gpointer user_data);
857 
858 static void
toggle_location_entry_setting(NemoWindow * window,NemoWindowPane * pane,gboolean from_accel_or_menu)859 toggle_location_entry_setting (NemoWindow     *window,
860                                NemoWindowPane *pane,
861                                gboolean        from_accel_or_menu)
862 {
863     gboolean current_view, temp_toolbar_visible, default_toolbar_visible, grab_focus_only, already_has_focus;
864     GtkToggleAction *button_action;
865     GtkActionGroup *action_group;
866 
867 
868     current_view = nemo_toolbar_get_show_location_entry (NEMO_TOOLBAR (pane->tool_bar));
869     temp_toolbar_visible = pane->temporary_navigation_bar;
870     default_toolbar_visible = g_settings_get_boolean (nemo_window_state,
871                                                       NEMO_WINDOW_STATE_START_WITH_TOOLBAR);
872     already_has_focus = nemo_location_bar_has_focus (NEMO_LOCATION_BAR (pane->location_bar));
873 
874     grab_focus_only = from_accel_or_menu && (pane->last_focus_widget == NULL || !already_has_focus) && current_view;
875 
876     if ((temp_toolbar_visible || default_toolbar_visible) && !grab_focus_only) {
877         nemo_toolbar_set_show_location_entry (NEMO_TOOLBAR (pane->tool_bar), !current_view);
878         g_settings_set_boolean (nemo_preferences, NEMO_PREFERENCES_SHOW_LOCATION_ENTRY, !current_view);
879 
880         action_group = pane->toolbar_action_group;
881         button_action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (action_group, NEMO_ACTION_TOGGLE_LOCATION));
882 
883         g_signal_handlers_block_by_func (button_action, action_toggle_location_entry_callback, window);
884         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (button_action), !current_view);
885         g_signal_handlers_unblock_by_func (button_action, action_toggle_location_entry_callback, window);
886     } else {
887         nemo_window_pane_ensure_location_bar (pane);
888     }
889 }
890 
891 void
action_toggle_location_entry_callback(GtkToggleAction * action,gpointer user_data)892 action_toggle_location_entry_callback (GtkToggleAction *action,
893                                         gpointer user_data)
894 {
895     NemoWindow *window = user_data;
896     NemoWindowPane *pane;
897 
898     pane = nemo_window_get_active_pane (window);
899     toggle_location_entry_setting(window, pane, FALSE);
900 }
901 
nemo_window_show_location_entry(NemoWindow * window)902 void nemo_window_show_location_entry (NemoWindow *window) {
903 	NemoWindowPane *pane;
904 
905     pane = nemo_window_get_active_pane (window);
906     toggle_location_entry_setting(window, pane, TRUE);
907 }
908 
909 static void
action_menu_edit_location_callback(GtkAction * action,gpointer user_data)910 action_menu_edit_location_callback (GtkAction *action,
911 				gpointer user_data)
912 {
913 	NemoWindow *window = user_data;
914 	NemoWindowPane *pane;
915 
916     pane = nemo_window_get_active_pane (window);
917     toggle_location_entry_setting(window, pane, TRUE);
918 }
919 
920 static void
action_show_thumbnails_callback(GtkAction * action,gpointer user_data)921 action_show_thumbnails_callback (GtkAction * action,
922                                  gpointer user_data)
923 {
924     NemoWindowSlot *slot;
925     NemoWindowPane *pane;
926     NemoWindow *window;
927     gboolean value;
928 
929     window = NEMO_WINDOW (user_data);
930 
931     slot = nemo_window_get_active_slot (window);
932     pane = nemo_window_get_active_pane(window);
933 
934     value = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
935     nemo_window_slot_set_show_thumbnails(slot, value);
936 
937     toolbar_set_show_thumbnails_button (value, pane);
938     menu_set_show_thumbnails_action(value, window);
939 }
940 
941 static void
set_content_view_type(NemoWindow * window,const gchar * view_id)942 set_content_view_type(NemoWindow *window,
943                       const gchar *view_id)
944 {
945     NemoWindowSlot *slot;
946 
947     slot = nemo_window_get_active_slot (window);
948     nemo_window_slot_set_content_view (slot, view_id);
949 }
950 
951 static void
action_icon_view_callback(GtkAction * action,gpointer user_data)952 action_icon_view_callback (GtkAction *action,
953                            gpointer user_data)
954 {
955     NemoWindow *window;
956 
957     window = NEMO_WINDOW (user_data);
958 
959     set_content_view_type (window, NEMO_ICON_VIEW_ID);
960     toolbar_set_view_button (ICON_VIEW, nemo_window_get_active_pane(window));
961 }
962 
963 
964 static void
action_list_view_callback(GtkAction * action,gpointer user_data)965 action_list_view_callback (GtkAction *action,
966                            gpointer user_data)
967 {
968     NemoWindow *window;
969 
970     window = NEMO_WINDOW (user_data);
971 
972     set_content_view_type (window, NEMO_LIST_VIEW_ID);
973     toolbar_set_view_button (LIST_VIEW, nemo_window_get_active_pane(window));
974 }
975 
976 
977 static void
action_compact_view_callback(GtkAction * action,gpointer user_data)978 action_compact_view_callback (GtkAction *action,
979                            gpointer user_data)
980 {
981     NemoWindow *window;
982 
983     window = NEMO_WINDOW (user_data);
984 
985     set_content_view_type (window, FM_COMPACT_VIEW_ID);
986     toolbar_set_view_button (COMPACT_VIEW, nemo_window_get_active_pane(window));
987 }
988 
989 guint
action_for_view_id(const char * view_id)990 action_for_view_id (const char *view_id)
991 {
992     if (g_strcmp0(view_id, NEMO_ICON_VIEW_ID) == 0) {
993         return ICON_VIEW;
994     } else if (g_strcmp0(view_id, NEMO_LIST_VIEW_ID) == 0) {
995         return LIST_VIEW;
996     } else if (g_strcmp0(view_id, FM_COMPACT_VIEW_ID) == 0) {
997         return COMPACT_VIEW;
998     } else {
999         return NULL_VIEW;
1000     }
1001 }
1002 
1003 void
toolbar_set_view_button(guint action_id,NemoWindowPane * pane)1004 toolbar_set_view_button (guint action_id, NemoWindowPane *pane)
1005 {
1006     GtkAction *action, *action1, *action2;
1007     GtkActionGroup *action_group;
1008     if (action_id == NULL_VIEW) {
1009         return;
1010     }
1011     action_group = nemo_window_pane_get_toolbar_action_group (pane);
1012 
1013 
1014     action = gtk_action_group_get_action(action_group,
1015                                          NEMO_ACTION_ICON_VIEW);
1016     action1 = gtk_action_group_get_action(action_group,
1017                                          NEMO_ACTION_LIST_VIEW);
1018     action2 = gtk_action_group_get_action(action_group,
1019                                          NEMO_ACTION_COMPACT_VIEW);
1020 
1021     g_signal_handlers_block_matched (action,
1022                          G_SIGNAL_MATCH_FUNC,
1023                          0, 0,
1024                          NULL,
1025                          action_icon_view_callback,
1026                          NULL);
1027 
1028     g_signal_handlers_block_matched (action1,
1029                          G_SIGNAL_MATCH_FUNC,
1030                          0, 0,
1031                          NULL,
1032                          action_list_view_callback,
1033                          NULL);
1034     g_signal_handlers_block_matched (action2,
1035                          G_SIGNAL_MATCH_FUNC,
1036                          0, 0,
1037                          NULL,
1038                          action_compact_view_callback,
1039                          NULL);
1040 
1041     if (action_id != ICON_VIEW) {
1042         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
1043     } else {
1044         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
1045     }
1046 
1047     if (action_id != LIST_VIEW) {
1048         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action1), FALSE);
1049     } else {
1050         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action1), TRUE);
1051     }
1052 
1053     if (action_id != COMPACT_VIEW) {
1054         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action2), FALSE);
1055     } else {
1056         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action2), TRUE);
1057     }
1058 
1059     g_signal_handlers_unblock_matched (action,
1060                            G_SIGNAL_MATCH_FUNC,
1061                            0, 0,
1062                            NULL,
1063                            action_icon_view_callback,
1064                            NULL);
1065 
1066 
1067     g_signal_handlers_unblock_matched (action1,
1068                            G_SIGNAL_MATCH_FUNC,
1069                            0, 0,
1070                            NULL,
1071                            action_list_view_callback,
1072                            NULL);
1073 
1074 
1075     g_signal_handlers_unblock_matched (action2,
1076                            G_SIGNAL_MATCH_FUNC,
1077                            0, 0,
1078                            NULL,
1079                            action_compact_view_callback,
1080                            NULL);
1081 
1082 }
1083 
1084 void
toolbar_set_show_thumbnails_button(gboolean value,NemoWindowPane * pane)1085 toolbar_set_show_thumbnails_button (gboolean value, NemoWindowPane *pane)
1086 {
1087     GtkAction *action;
1088     GtkActionGroup *action_group;
1089 
1090     action_group = nemo_window_pane_get_toolbar_action_group (pane);
1091 
1092 
1093     action = gtk_action_group_get_action(action_group,
1094                                          NEMO_ACTION_SHOW_THUMBNAILS);
1095 
1096     g_signal_handlers_block_matched (action,
1097                          G_SIGNAL_MATCH_FUNC,
1098                          0, 0,
1099                          NULL,
1100                          action_show_thumbnails_callback,
1101                          NULL);
1102 
1103     gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), value);
1104 
1105     g_signal_handlers_unblock_matched (action,
1106                            G_SIGNAL_MATCH_FUNC,
1107                            0, 0,
1108                            NULL,
1109                            action_show_thumbnails_callback,
1110                            NULL);
1111 }
1112 
1113 void
menu_set_show_thumbnails_action(gboolean value,NemoWindow * window)1114 menu_set_show_thumbnails_action (gboolean value, NemoWindow *window)
1115 {
1116     GtkAction *action;
1117 
1118     action = gtk_action_group_get_action (window->details->main_action_group,
1119                                           NEMO_ACTION_SHOW_THUMBNAILS);
1120 
1121     g_signal_handlers_block_matched (action,
1122                          G_SIGNAL_MATCH_FUNC,
1123                          0, 0,
1124                          NULL,
1125                          action_show_thumbnails_callback,
1126                          NULL);
1127 
1128     gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), value);
1129 
1130     g_signal_handlers_unblock_matched (action,
1131                            G_SIGNAL_MATCH_FUNC,
1132                            0, 0,
1133                            NULL,
1134                            action_show_thumbnails_callback,
1135                            NULL);
1136 }
1137 
1138 void
menu_set_view_selection(guint action_id,NemoWindow * window)1139 menu_set_view_selection (guint action_id,
1140                          NemoWindow *window)
1141 {
1142     GtkAction *action;
1143 
1144     if (action_id == NULL_VIEW) {
1145         return;
1146     }
1147 
1148     g_signal_handlers_block_by_func (window->details->main_action_group,
1149                                      view_radio_entry_changed_cb,
1150                                      window);
1151 
1152     action = gtk_action_group_get_action (window->details->main_action_group,
1153                                           NEMO_ACTION_ICON_VIEW);
1154 
1155     gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), action_id);
1156 
1157     g_signal_handlers_unblock_by_func (window->details->main_action_group,
1158                                        view_radio_entry_changed_cb,
1159                                        window);
1160 }
1161 
1162 static void
action_tabs_previous_callback(GtkAction * action,gpointer user_data)1163 action_tabs_previous_callback (GtkAction *action,
1164 			       gpointer user_data)
1165 {
1166 	NemoWindowPane *pane;
1167 	NemoWindow *window = user_data;
1168 
1169 	pane = nemo_window_get_active_pane (window);
1170 	nemo_notebook_set_current_page_relative (NEMO_NOTEBOOK (pane->notebook), -1);
1171 }
1172 
1173 static void
action_tabs_next_callback(GtkAction * action,gpointer user_data)1174 action_tabs_next_callback (GtkAction *action,
1175 			   gpointer user_data)
1176 {
1177 	NemoWindowPane *pane;
1178 	NemoWindow *window = user_data;
1179 
1180 	pane = nemo_window_get_active_pane (window);
1181 	nemo_notebook_set_current_page_relative (NEMO_NOTEBOOK (pane->notebook), 1);
1182 }
1183 
1184 static void
reorder_tab(NemoWindowPane * pane,int offset)1185 reorder_tab (NemoWindowPane *pane, int offset)
1186 {
1187 	int page_num;
1188 
1189 	g_return_if_fail (pane != NULL);
1190 
1191 	page_num = gtk_notebook_get_current_page (
1192 		GTK_NOTEBOOK (pane->notebook));
1193 	g_return_if_fail (page_num != -1);
1194 	nemo_notebook_reorder_child_relative (
1195 		NEMO_NOTEBOOK (pane->notebook), page_num, offset);
1196 }
1197 
1198 static void
action_tabs_move_left_callback(GtkAction * action,gpointer user_data)1199 action_tabs_move_left_callback (GtkAction *action,
1200 				gpointer user_data)
1201 {
1202 	NemoWindow *window = user_data;
1203 	reorder_tab (nemo_window_get_active_pane (window), -1);
1204 }
1205 
1206 static void
action_tabs_move_right_callback(GtkAction * action,gpointer user_data)1207 action_tabs_move_right_callback (GtkAction *action,
1208 				 gpointer user_data)
1209 {
1210 	NemoWindow *window = user_data;
1211 	reorder_tab (nemo_window_get_active_pane (window), 1);
1212 }
1213 
1214 static void
action_tab_change_action_activate_callback(GtkAction * action,gpointer user_data)1215 action_tab_change_action_activate_callback (GtkAction *action,
1216 					    gpointer user_data)
1217 {
1218 	NemoWindowPane *pane;
1219 	NemoWindow *window = user_data;
1220 	GtkNotebook *notebook;
1221 	int num;
1222 
1223 	pane = nemo_window_get_active_pane (window);
1224 	notebook = GTK_NOTEBOOK (pane->notebook);
1225 
1226 	num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action), "num"));
1227 	if (num < gtk_notebook_get_n_pages (notebook)) {
1228 		gtk_notebook_set_current_page (notebook, num);
1229 	}
1230 }
1231 
1232 static void
action_new_folder_callback(GtkAction * action,gpointer user_data)1233 action_new_folder_callback (GtkAction *action,
1234                             gpointer user_data)
1235 {
1236     g_assert (NEMO_IS_WINDOW (user_data));
1237     NemoWindow *window = user_data;
1238     NemoView *view = get_current_view (window);
1239 
1240     nemo_view_new_folder (view);
1241 }
1242 
1243 static void
open_in_terminal_other(const gchar * path)1244 open_in_terminal_other (const gchar *path)
1245 {
1246     gchar *argv[2];
1247     argv[0] = g_settings_get_string (gnome_terminal_preferences, GNOME_DESKTOP_TERMINAL_EXEC);
1248     argv[1] = NULL;
1249     g_spawn_async(path, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
1250 }
1251 
1252 
1253 static void
action_open_terminal_callback(GtkAction * action,gpointer callback_data)1254 action_open_terminal_callback(GtkAction *action, gpointer callback_data)
1255 {
1256     NemoWindow *window;
1257     NemoView *view;
1258 
1259     window = NEMO_WINDOW(callback_data);
1260 
1261     view = get_current_view (window);
1262 
1263     gchar *path;
1264     gchar *uri = nemo_view_get_uri (view);
1265     GFile *gfile = g_file_new_for_uri (uri);
1266     path = g_file_get_path (gfile);
1267     open_in_terminal_other (path);
1268     g_free (uri);
1269     g_free (path);
1270     g_object_unref (gfile);
1271 }
1272 
1273 static const GtkActionEntry main_entries[] = {
1274   /* name, stock id, label */  { "File", NULL, N_("_File") },
1275   /* name, stock id, label */  { "Edit", NULL, N_("_Edit") },
1276   /* name, stock id, label */  { "View", NULL, N_("_View") },
1277   /* name, stock id, label */  { "Help", NULL, N_("_Help") },
1278   /* name, stock id */         { "Close", "window-close-symbolic",
1279   /* label, accelerator */       N_("_Close"), "<control>W",
1280   /* tooltip */                  N_("Close this folder"),
1281                                  G_CALLBACK (action_close_window_slot_callback) },
1282                                { "Preferences", "preferences-other-symbolic",
1283                                  N_("Prefere_nces"),
1284                                  NULL, N_("Edit Nemo preferences"),
1285                                  G_CALLBACK (action_preferences_callback) },
1286                                { NEMO_ACTION_PLUGIN_MANAGER, NULL,
1287                                  N_("Plugins"),
1288                                  "<alt>p", N_("Manage extensions, actions and scripts"),
1289                                  G_CALLBACK (action_plugins_callback) },
1290 #ifdef TEXT_CHANGE_UNDO
1291   /* name, stock id, label */  { "Undo", NULL, N_("_Undo"),
1292                                  "<control>Z", N_("Undo the last text change"),
1293                                  G_CALLBACK (action_undo_callback) },
1294 #endif
1295   /* name, stock id, label */  { "Up", "go-up-symbolic", N_("Open _Parent"),
1296                                  "<alt>Up", N_("Open the parent folder"),
1297                                  G_CALLBACK (action_up_callback) },
1298   /* name, stock id, label */  { "UpAccel", NULL, "UpAccel",
1299                                  "", NULL,
1300                                  G_CALLBACK (action_up_callback) },
1301   /* name, stock id */         { "Stop", "process-stop-symbolic",
1302   /* label, accelerator */       N_("_Stop"), NULL,
1303   /* tooltip */                  N_("Stop loading the current location"),
1304                                  G_CALLBACK (action_stop_callback) },
1305   /* name, stock id */         { "Reload", "view-refresh-symbolic",
1306   /* label, accelerator */       N_("_Reload"), "<control>R",
1307   /* tooltip */                  N_("Reload the current location"),
1308                                  G_CALLBACK (action_reload_callback) },
1309   /* name, stock id */         { "NemoHelp", "help-contents-symbolic",
1310   /* label, accelerator */       N_("_All Topics"), "F1",
1311   /* tooltip */                  N_("Display Nemo help"),
1312                                  G_CALLBACK (action_nemo_manual_callback) },
1313                                { "NemoShortcuts", "preferences-desktop-keyboard-shortcuts-symbolic",
1314                                  N_("_Keyboard Shortcuts"), "<control>F1",
1315                                  N_("Display keyboard shortcuts"),
1316                                  G_CALLBACK (action_show_shortcuts_window) },
1317   /** name, stock id          { "NemoHelpSearch", NULL,
1318      label, accelerator        N_("Search for files"), NULL,
1319      tooltip                   N_("Locate files based on file name and type. Save your searches for later use."),
1320                                  G_CALLBACK (action_nemo_manual_callback) },
1321      name, stock id          { "NemoHelpSort", NULL,
1322      label, accelerator        N_("Sort files and folders"), NULL,
1323      tooltip                   N_("Arrange files by name, size, type, or when they were changed."),
1324                                  G_CALLBACK (action_nemo_manual_callback) },
1325      name, stock id          { "NemoHelpLost", NULL,
1326      label, accelerator        N_("Find a lost file"), NULL,
1327      tooltip                   N_("Follow these tips if you can't find a file you created or downloaded."),
1328                                  G_CALLBACK (action_nemo_manual_callback) },
1329      name, stock id          { "NemoHelpShare", NULL,
1330      label, accelerator        N_("Share and transfer files"), NULL,
1331      tooltip                   N_("Easily transfer files to your contacts and devices from the file manager."),
1332                                  G_CALLBACK (action_nemo_manual_callback) }, **/
1333   /* name, stock id */         { "About Nemo", "help-about-symbolic",
1334   /* label, accelerator */       N_("_About"), NULL,
1335   /* tooltip */                  N_("Display credits for the creators of Nemo"),
1336                                  G_CALLBACK (action_about_nemo_callback) },
1337   /* name, stock id */         { "Zoom In", "zoom-in-symbolic",
1338   /* label, accelerator */       N_("Zoom _In"), "<control>plus",
1339   /* tooltip */                  N_("Increase the view size"),
1340                                  G_CALLBACK (action_zoom_in_callback) },
1341   /* name, stock id */         { "ZoomInAccel", NULL,
1342   /* label, accelerator */       "ZoomInAccel", "<control>equal",
1343   /* tooltip */                  NULL,
1344                                  G_CALLBACK (action_zoom_in_callback) },
1345   /* name, stock id */         { "ZoomInAccel2", NULL,
1346   /* label, accelerator */       "ZoomInAccel2", "<control>KP_Add",
1347   /* tooltip */                  NULL,
1348                                  G_CALLBACK (action_zoom_in_callback) },
1349   /* name, stock id */         { "Zoom Out", "zoom-out-symbolic",
1350   /* label, accelerator */       N_("Zoom _Out"), "<control>minus",
1351   /* tooltip */                  N_("Decrease the view size"),
1352                                  G_CALLBACK (action_zoom_out_callback) },
1353   /* name, stock id */         { "ZoomOutAccel", NULL,
1354   /* label, accelerator */       "ZoomOutAccel", "<control>KP_Subtract",
1355   /* tooltip */                  NULL,
1356                                  G_CALLBACK (action_zoom_out_callback) },
1357   /* name, stock id */         { "Zoom Normal", "zoom-original-symbolic",
1358   /* label, accelerator */       N_("Normal Si_ze"), "<control>0",
1359   /* tooltip */                  N_("Use the normal view size"),
1360                                  G_CALLBACK (action_zoom_normal_callback) },
1361   /* name, stock id */         { "Connect to Server", NULL,
1362   /* label, accelerator */       N_("Connect to _Server..."), NULL,
1363   /* tooltip */                  N_("Connect to a remote computer or shared disk"),
1364                                  G_CALLBACK (action_connect_to_server_callback) },
1365   /* name, stock id */         { "Home", NEMO_ICON_SYMBOLIC_HOME,
1366   /* label, accelerator */       N_("_Home"), "<alt>Home",
1367   /* tooltip */                  N_("Open your personal folder"),
1368                                  G_CALLBACK (action_home_callback) },
1369   /* name, stock id */         { "Go to Computer", NEMO_ICON_SYMBOLIC_COMPUTER,
1370   /* label, accelerator */       N_("_Computer"), NULL,
1371   /* tooltip */                  N_("Browse all local and remote disks and folders accessible from this computer"),
1372                                  G_CALLBACK (action_go_to_computer_callback) },
1373   /* name, stock id */         { "Go to Network", NEMO_ICON_SYMBOLIC_NETWORK,
1374   /* label, accelerator */       N_("_Network"), NULL,
1375   /* tooltip */                  N_("Browse bookmarked and local network locations"),
1376                                  G_CALLBACK (action_go_to_network_callback) },
1377   /* name, stock id */         { "Go to Templates", NEMO_ICON_SYMBOLIC_FOLDER_TEMPLATES,
1378   /* label, accelerator */       N_("T_emplates"), NULL,
1379   /* tooltip */                  N_("Open your personal templates folder"),
1380                                  G_CALLBACK (action_go_to_templates_callback) },
1381   /* name, stock id */         { "Go to Trash", NEMO_ICON_SYMBOLIC_TRASH,
1382   /* label, accelerator */       N_("_Trash"), NULL,
1383   /* tooltip */                  N_("Open your personal trash folder"),
1384                                  G_CALLBACK (action_go_to_trash_callback) },
1385   /* name, stock id, label */  { "Go", NULL, N_("_Go") },
1386   /* name, stock id, label */  { "Bookmarks", NULL, N_("_Bookmarks") },
1387   /* name, stock id, label */  { "Tabs", NULL, N_("_Tabs") },
1388   /* name, stock id, label */  { "New Window", NULL, N_("New _Window"),
1389                                  "<control>N", N_("Open another Nemo window for the displayed location"),
1390                                  G_CALLBACK (action_new_window_callback) },
1391   /* name, stock id, label */  { "New Tab", "tab-new-symbolic", N_("New _Tab"),
1392                                  "<control>T", N_("Open another tab for the displayed location"),
1393                                  G_CALLBACK (action_new_tab_callback) },
1394   /* name, stock id, label */  { "Close All Windows", NULL, N_("Close _All Windows"),
1395                                  "<control>Q", N_("Close all Navigation windows"),
1396                                  G_CALLBACK (action_close_all_windows_callback) },
1397   /* name, stock id, label */  { NEMO_ACTION_BACK, "go-previous-symbolic", N_("_Back"),
1398 				 "<alt>Left", N_("Go to the previous visited location"),
1399 				 G_CALLBACK (action_back_callback) },
1400   /* name, stock id, label */  { NEMO_ACTION_FORWARD, "go-next-symbolic", N_("_Forward"),
1401 				 "<alt>Right", N_("Go to the next visited location"),
1402 				 G_CALLBACK (action_forward_callback) },
1403   /* name, stock id, label */  { NEMO_ACTION_EDIT_LOCATION, NULL, N_("Toggle _Location Entry"),
1404                                  "<control>L", N_("Switch between location entry and breadcrumbs"),
1405                                  G_CALLBACK (action_menu_edit_location_callback) },
1406   /* name, stock id, label */  { "SplitViewNextPane", NULL, N_("S_witch to Other Pane"),
1407 				 "F6", N_("Move focus to the other pane in a split view window"),
1408 				 G_CALLBACK (action_split_view_switch_next_pane_callback) },
1409   /* name, stock id, label */  { "SplitViewSameLocation", NULL, N_("Sa_me Location as Other Pane"),
1410 				 NULL, N_("Go to the same location as in the extra pane"),
1411 				 G_CALLBACK (action_split_view_same_location_callback) },
1412   /* name, stock id, label */  { "Add Bookmark", "bookmark-new-symbolic", N_("_Add Bookmark"),
1413                                  "<control>d", N_("Add a bookmark for the current location to this menu"),
1414                                  G_CALLBACK (action_add_bookmark_callback) },
1415   /* name, stock id, label */  { "Edit Bookmarks", NULL, N_("_Edit Bookmarks..."),
1416                                  "<control>b", N_("Display a window that allows editing the bookmarks in this menu"),
1417                                  G_CALLBACK (action_edit_bookmarks_callback) },
1418   { "TabsPrevious", NULL, N_("_Previous Tab"), "<control>Page_Up",
1419     N_("Activate previous tab"),
1420     G_CALLBACK (action_tabs_previous_callback) },
1421   { "TabsNext", NULL, N_("_Next Tab"), "<control>Page_Down",
1422     N_("Activate next tab"),
1423     G_CALLBACK (action_tabs_next_callback) },
1424   { "TabsMoveLeft", NULL, N_("Move Tab _Left"), "<shift><control>Page_Up",
1425     N_("Move current tab to left"),
1426     G_CALLBACK (action_tabs_move_left_callback) },
1427   { "TabsMoveRight", NULL, N_("Move Tab _Right"), "<shift><control>Page_Down",
1428     N_("Move current tab to right"),
1429     G_CALLBACK (action_tabs_move_right_callback) },
1430   { "Sidebar List", NULL, N_("Sidebar") }
1431 };
1432 
1433 static const GtkToggleActionEntry main_toggle_entries[] = {
1434   /* name, stock id */         { "Show Hidden Files", NULL,
1435   /* label, accelerator */       N_("Show _Hidden Files"), "<control>H",
1436   /* tooltip */                  N_("Toggle the display of hidden files in the current window"),
1437                                  G_CALLBACK (action_show_hidden_files_callback),
1438                                  TRUE },
1439   /* name, stock id */     { "Show Hide Toolbar", NULL,
1440   /* label, accelerator */   N_("_Main Toolbar"), NULL,
1441   /* tooltip */              N_("Change the visibility of this window's main toolbar"),
1442 			     NULL,
1443   /* is_active */            TRUE },
1444   /* name, stock id */     { "Show Hide Sidebar", NULL,
1445   /* label, accelerator */   N_("_Show Sidebar"), "F9",
1446   /* tooltip */              N_("Change the visibility of this window's side pane"),
1447                              G_CALLBACK (action_show_hide_sidebar_callback),
1448   /* is_active */            TRUE },
1449   /* name, stock id */     { "Show Hide Statusbar", NULL,
1450   /* label, accelerator */   N_("St_atusbar"), NULL,
1451   /* tooltip */              N_("Change the visibility of this window's statusbar"),
1452                              NULL,
1453   /* is_active */            TRUE },
1454   /* name, stock id */     { NEMO_ACTION_SHOW_HIDE_MENUBAR, NULL,
1455   /* label, accelerator */   N_("M_enubar"), NULL,
1456   /* tooltip */              N_("Change the default visibility of the menubar"),
1457                              NULL,
1458   /* is_active */            TRUE },
1459   /* name, stock id */     { "Search", "edit-find-symbolic",
1460   /* label, accelerator */   N_("_Search for Files..."), "<control>f",
1461   /* tooltip */              N_("Search documents and folders by name"),
1462 			     NULL,
1463   /* is_active */            FALSE },
1464   /* name, stock id */     { NEMO_ACTION_SHOW_HIDE_EXTRA_PANE, NULL,
1465   /* label, accelerator */   N_("E_xtra Pane"), "F3",
1466   /* tooltip */              N_("Open an extra folder view side-by-side"),
1467                              G_CALLBACK (action_split_view_callback),
1468   /* is_active */            FALSE },
1469     /* name, stock id */         { NEMO_ACTION_SHOW_THUMBNAILS, NULL,
1470   /* label, accelerator */       N_("Show _Thumbnails"), NULL,
1471   /* tooltip */                  N_("Toggle the display of thumbnails in the current directory"),
1472   /* callback */                 G_CALLBACK (action_show_thumbnails_callback),
1473   /* default */                  FALSE },
1474 };
1475 
1476 static const GtkRadioActionEntry sidebar_radio_entries[] = {
1477 	{ "Sidebar Places", NULL,
1478 	  N_("Places"), NULL, N_("Select Places as the default sidebar"),
1479 	  SIDEBAR_PLACES },
1480 	{ "Sidebar Tree", NULL,
1481 	  N_("Tree"), NULL, N_("Select Tree as the default sidebar"),
1482 	  SIDEBAR_TREE }
1483 };
1484 
1485 static const GtkRadioActionEntry view_radio_entries[] = {
1486     { "IconView", NULL,
1487       N_("Icon View"), "<ctrl>1", N_("Icon View"),
1488       ICON_VIEW },
1489     { "ListView", NULL,
1490       N_("List View"), "<ctrl>2", N_("List View"),
1491       LIST_VIEW },
1492     { "CompactView", NULL,
1493       N_("Compact View"), "<ctrl>3", N_("Compact View"),
1494       COMPACT_VIEW }
1495 };
1496 
1497 GtkActionGroup *
nemo_window_create_toolbar_action_group(NemoWindow * window)1498 nemo_window_create_toolbar_action_group (NemoWindow *window)
1499 {
1500     gboolean show_location_entry_initially;
1501 
1502 	NemoNavigationState *navigation_state;
1503 	GtkActionGroup *action_group;
1504 	GtkAction *action;
1505 
1506 	action_group = gtk_action_group_new ("ToolbarActions");
1507 	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
1508 
1509 	action = g_object_new (NEMO_TYPE_NAVIGATION_ACTION,
1510 			       "name", NEMO_ACTION_BACK,
1511 			       "label", _("_Back"),
1512 			       "icon_name", "go-previous-symbolic",
1513 			       "tooltip", _("Go to the previous visited location"),
1514 			       "arrow-tooltip", _("Back history"),
1515 			       "window", window,
1516 			       "direction", NEMO_NAVIGATION_DIRECTION_BACK,
1517 			       "sensitive", FALSE,
1518 			       NULL);
1519 	g_signal_connect (action, "activate",
1520 			  G_CALLBACK (action_back_callback), window);
1521 	gtk_action_group_add_action (action_group, action);
1522 
1523 	g_object_unref (action);
1524 
1525 	action = g_object_new (NEMO_TYPE_NAVIGATION_ACTION,
1526 			       "name", NEMO_ACTION_FORWARD,
1527 			       "label", _("_Forward"),
1528 			       "icon_name", "go-next-symbolic",
1529 			       "tooltip", _("Go to the next visited location"),
1530 			       "arrow-tooltip", _("Forward history"),
1531 			       "window", window,
1532 			       "direction", NEMO_NAVIGATION_DIRECTION_FORWARD,
1533 			       "sensitive", FALSE,
1534 			       NULL);
1535 	g_signal_connect (action, "activate",
1536 			  G_CALLBACK (action_forward_callback), window);
1537 	gtk_action_group_add_action (action_group, action);
1538 
1539 	g_object_unref (action);
1540 
1541 	/**
1542 	 * Nemo 2.30/2.32 type actions
1543 	 */
1544    	action = g_object_new (NEMO_TYPE_NAVIGATION_ACTION,
1545    			       "name", NEMO_ACTION_UP,
1546    			       "label", _("_Up"),
1547    			       "icon_name", "go-up-symbolic",
1548    			       "tooltip", _("Go to parent folder"),
1549    			       "arrow-tooltip", _("Forward history"),
1550    			       "window", window,
1551    			       "direction", NEMO_NAVIGATION_DIRECTION_UP,
1552    			       NULL);
1553    	g_signal_connect (action, "activate",
1554    			  G_CALLBACK (action_up_callback), window);
1555    	gtk_action_group_add_action (action_group, action);
1556 
1557    	g_object_unref (action);
1558 
1559    	action = g_object_new (NEMO_TYPE_NAVIGATION_ACTION,
1560    			       "name", NEMO_ACTION_RELOAD,
1561    			       "label", _("_Reload"),
1562    			       "icon_name", "view-refresh-symbolic",
1563    			       "tooltip", _("Reload the current location"),
1564    			       "window", window,
1565    			       "direction", NEMO_NAVIGATION_DIRECTION_RELOAD,
1566    			       NULL);
1567    	g_signal_connect (action, "activate",
1568    			  G_CALLBACK (action_reload_callback), window);
1569    	gtk_action_group_add_action (action_group, action);
1570 
1571    	g_object_unref (action);
1572 
1573    	action = g_object_new (NEMO_TYPE_NAVIGATION_ACTION,
1574    			       "name", NEMO_ACTION_HOME,
1575    			       "label", _("_Home"),
1576    			       "icon_name", "go-home-symbolic",
1577    			       "tooltip", _("Go to home directory"),
1578    			       "window", window,
1579    			       "direction", NEMO_NAVIGATION_DIRECTION_HOME,
1580    			       NULL);
1581    	g_signal_connect (action, "activate",
1582    			  G_CALLBACK (action_home_callback), window);
1583    	gtk_action_group_add_action (action_group, action);
1584 
1585    	g_object_unref (action);
1586 
1587    	action = g_object_new (NEMO_TYPE_NAVIGATION_ACTION,
1588    			       "name", NEMO_ACTION_COMPUTER,
1589    			       "label", _("_Computer"),
1590    			       "icon_name", "computer-symbolic",
1591    			       "tooltip", _("Go to Computer"),
1592    			       "window", window,
1593    			       "direction", NEMO_NAVIGATION_DIRECTION_COMPUTER,
1594    			       NULL);
1595    	g_signal_connect (action, "activate",
1596    			  G_CALLBACK (action_go_to_computer_callback), window);
1597    	gtk_action_group_add_action (action_group, action);
1598 
1599    	g_object_unref (action);
1600 
1601     action = GTK_ACTION (gtk_toggle_action_new (NEMO_ACTION_TOGGLE_LOCATION,
1602                                                 _("Location"),
1603                                                 _("Toggle Location Entry"),
1604                                                 NULL));
1605     gtk_action_group_add_action (action_group, GTK_ACTION (action));
1606     show_location_entry_initially = g_settings_get_boolean (nemo_preferences, NEMO_PREFERENCES_SHOW_LOCATION_ENTRY);
1607     gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_location_entry_initially);
1608     g_signal_connect (action, "activate",
1609                       G_CALLBACK (action_toggle_location_entry_callback), window);
1610     gtk_action_set_icon_name (GTK_ACTION (action), "location-symbolic");
1611 
1612     g_object_unref (action);
1613 
1614     action = GTK_ACTION (gtk_action_new (NEMO_ACTION_NEW_FOLDER,
1615                                                 _("New folder"),
1616                                                 _("Create a new folder"),
1617                                                 NULL));
1618     gtk_action_group_add_action (action_group, GTK_ACTION (action));
1619     g_signal_connect (action, "activate",
1620                       G_CALLBACK (action_new_folder_callback), window);
1621     gtk_action_set_icon_name (GTK_ACTION (action), "folder-new-symbolic");
1622     g_object_unref (action);
1623 
1624     action = GTK_ACTION (gtk_action_new (NEMO_ACTION_OPEN_IN_TERMINAL,
1625                                                 _("Open in Terminal"),
1626                                                 _("Open a terminal in the active folder"),
1627                                                 NULL));
1628     gtk_action_group_add_action (action_group, GTK_ACTION (action));
1629     g_signal_connect (action, "activate",
1630                       G_CALLBACK (action_open_terminal_callback), window);
1631     gtk_action_set_icon_name (GTK_ACTION (action), "utilities-terminal-symbolic");
1632     g_object_unref (action);
1633 
1634 
1635     action = GTK_ACTION (gtk_toggle_action_new (NEMO_ACTION_ICON_VIEW,
1636                          _("Icons"),
1637                          _("Icon View"),
1638                          NULL));
1639     g_signal_connect (action, "activate",
1640                       G_CALLBACK (action_icon_view_callback),
1641                       window);
1642    	gtk_action_group_add_action (action_group, action);
1643     gtk_action_set_icon_name (GTK_ACTION (action), "view-grid-symbolic");
1644    	g_object_unref (action);
1645 
1646     action = GTK_ACTION (gtk_toggle_action_new (NEMO_ACTION_LIST_VIEW,
1647                          _("List"),
1648                          _("List View"),
1649                          NULL));
1650     g_signal_connect (action, "activate",
1651                       G_CALLBACK (action_list_view_callback),
1652                       window);
1653    	gtk_action_group_add_action (action_group, action);
1654     gtk_action_set_icon_name (GTK_ACTION (action), "view-list-symbolic");
1655 
1656    	g_object_unref (action);
1657 
1658     action = GTK_ACTION (gtk_toggle_action_new (NEMO_ACTION_COMPACT_VIEW,
1659                          _("Compact"),
1660                          _("Compact View"),
1661                          NULL));
1662    	g_signal_connect (action, "activate",
1663                       G_CALLBACK (action_compact_view_callback),
1664                       window);
1665    	gtk_action_group_add_action (action_group, action);
1666     gtk_action_set_icon_name (GTK_ACTION (action), "view-compact-symbolic");
1667 
1668    	g_object_unref (action);
1669 
1670  	action = GTK_ACTION (gtk_toggle_action_new (NEMO_ACTION_SEARCH,
1671  				_("Search"),_("Search documents and folders by name"),
1672  				NULL));
1673 
1674   	gtk_action_group_add_action (action_group, action);
1675     gtk_action_set_icon_name (GTK_ACTION (action), "edit-find-symbolic");
1676 
1677   	g_object_unref (action);
1678 
1679     action = GTK_ACTION (gtk_toggle_action_new (NEMO_ACTION_SHOW_THUMBNAILS,
1680                          _("Show Thumbnails"),
1681                          _("Show Thumbnails"),
1682                          NULL));
1683    	g_signal_connect (action, "activate",
1684                       G_CALLBACK (action_show_thumbnails_callback),
1685                       window);
1686    	gtk_action_group_add_action (action_group, action);
1687     gtk_action_set_icon_name (GTK_ACTION (action), "xapp-prefs-preview-symbolic");
1688 
1689    	g_object_unref (action);
1690 
1691 	navigation_state = nemo_window_get_navigation_state (window);
1692 	nemo_navigation_state_add_group (navigation_state, action_group);
1693 
1694 	return action_group;
1695 }
1696 
1697 static void
window_menus_set_bindings(NemoWindow * window)1698 window_menus_set_bindings (NemoWindow *window)
1699 {
1700 	GtkActionGroup *action_group;
1701 	GtkAction *action;
1702 
1703 	action_group = nemo_window_get_main_action_group (window);
1704 
1705 	action = gtk_action_group_get_action (action_group,
1706 					      NEMO_ACTION_SHOW_HIDE_TOOLBAR);
1707 
1708 	g_settings_bind (nemo_window_state,
1709 			 NEMO_WINDOW_STATE_START_WITH_TOOLBAR,
1710 			 action,
1711 			 "active",
1712 			 G_SETTINGS_BIND_DEFAULT);
1713 
1714 	action = gtk_action_group_get_action (action_group,
1715 					      NEMO_ACTION_SHOW_HIDE_STATUSBAR);
1716 
1717 	g_settings_bind (nemo_window_state,
1718 			 NEMO_WINDOW_STATE_START_WITH_STATUS_BAR,
1719 			 action,
1720 			 "active",
1721 			 G_SETTINGS_BIND_DEFAULT);
1722 
1723     action = gtk_action_group_get_action (action_group,
1724                           NEMO_ACTION_SHOW_HIDE_MENUBAR);
1725 
1726     g_settings_bind (nemo_window_state,
1727              NEMO_WINDOW_STATE_START_WITH_MENU_BAR,
1728              action,
1729              "active",
1730              G_SETTINGS_BIND_DEFAULT);
1731 
1732 	action = gtk_action_group_get_action (action_group,
1733 					      NEMO_ACTION_SHOW_HIDE_SIDEBAR);
1734 
1735     g_object_bind_property (window,
1736                             "show-sidebar",
1737                             action,
1738                             "active",
1739                             G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
1740 }
1741 
1742 void
nemo_window_initialize_actions(NemoWindow * window)1743 nemo_window_initialize_actions (NemoWindow *window)
1744 {
1745 	GtkActionGroup *action_group;
1746 	const gchar *nav_state_actions[] = {
1747 		NEMO_ACTION_BACK, NEMO_ACTION_FORWARD, NEMO_ACTION_UP, NEMO_ACTION_RELOAD, NEMO_ACTION_COMPUTER, NEMO_ACTION_HOME, NEMO_ACTION_EDIT_LOCATION,
1748 		NEMO_ACTION_TOGGLE_LOCATION, NEMO_ACTION_SEARCH, NULL
1749 	};
1750 
1751 	action_group = nemo_window_get_main_action_group (window);
1752 	window->details->nav_state = nemo_navigation_state_new (action_group,
1753 								    nav_state_actions);
1754 
1755 	window_menus_set_bindings (window);
1756 	nemo_window_update_show_hide_menu_items (window);
1757 
1758 	g_signal_connect (window, "loading_uri",
1759 			  G_CALLBACK (nemo_window_update_split_view_actions_sensitivity),
1760 			  NULL);
1761 }
1762 
1763 /**
1764  * nemo_window_initialize_menus
1765  *
1766  * Create and install the set of menus for this window.
1767  * @window: A recently-created NemoWindow.
1768  */
1769 void
nemo_window_initialize_menus(NemoWindow * window)1770 nemo_window_initialize_menus (NemoWindow *window)
1771 {
1772 	GtkActionGroup *action_group;
1773 	GtkUIManager *ui_manager;
1774 	GtkAction *action;
1775       GtkAction *action_to_hide;
1776 	gint i;
1777 
1778 	if (window->details->ui_manager == NULL){
1779         window->details->ui_manager = gtk_ui_manager_new ();
1780     }
1781 	ui_manager = window->details->ui_manager;
1782 
1783 	/* shell actions */
1784 	action_group = gtk_action_group_new ("ShellActions");
1785 	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
1786 	window->details->main_action_group = action_group;
1787 	gtk_action_group_add_actions (action_group,
1788 				      main_entries, G_N_ELEMENTS (main_entries),
1789 				      window);
1790 
1791       /* if root then hide menu items that do not work */
1792       if (geteuid() == 0) {
1793           action_to_hide = gtk_action_group_get_action (action_group, "Go to Computer");
1794           gtk_action_set_visible (action_to_hide, FALSE);
1795           action_to_hide = gtk_action_group_get_action (action_group, "Go to Templates");
1796           gtk_action_set_visible (action_to_hide, FALSE);
1797           action_to_hide = gtk_action_group_get_action (action_group, "Go to Trash");
1798           gtk_action_set_visible (action_to_hide, FALSE);
1799           action_to_hide = gtk_action_group_get_action (action_group, "Go to Network");
1800           gtk_action_set_visible (action_to_hide, FALSE);
1801       }
1802 
1803 	gtk_action_group_add_toggle_actions (action_group,
1804 					     main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
1805 					     window);
1806 	gtk_action_group_add_radio_actions (action_group,
1807 					    sidebar_radio_entries, G_N_ELEMENTS (sidebar_radio_entries),
1808 					    0, G_CALLBACK (sidebar_radio_entry_changed_cb),
1809 					    window);
1810     gtk_action_group_add_radio_actions (action_group,
1811                         view_radio_entries, G_N_ELEMENTS (view_radio_entries),
1812                         0, G_CALLBACK (view_radio_entry_changed_cb),
1813                         window);
1814 	action = gtk_action_group_get_action (action_group, NEMO_ACTION_UP);
1815 	g_object_set (action, "short_label", _("_Up"), NULL);
1816 
1817 	action = gtk_action_group_get_action (action_group, NEMO_ACTION_HOME);
1818 	g_object_set (action, "short_label", _("_Home"), NULL);
1819 
1820   	action = gtk_action_group_get_action (action_group, NEMO_ACTION_EDIT_LOCATION);
1821   	g_object_set (action, "short_label", _("_Location"), NULL);
1822 
1823 	action = gtk_action_group_get_action (action_group, NEMO_ACTION_SHOW_HIDDEN_FILES);
1824 
1825     if (NEMO_IS_DESKTOP_WINDOW (window)) {
1826         gtk_action_set_visible (action, FALSE);
1827     } else {
1828         g_signal_handlers_block_by_func (action, action_show_hidden_files_callback, window);
1829         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
1830                                       g_settings_get_boolean (nemo_preferences,
1831                                       NEMO_PREFERENCES_SHOW_HIDDEN_FILES));
1832         g_signal_handlers_unblock_by_func (action, action_show_hidden_files_callback, window);
1833     }
1834 
1835     g_signal_connect_object ( NEMO_WINDOW (window), "notify::sidebar-view-id",
1836                              G_CALLBACK (update_side_bar_radio_buttons), window, 0);
1837 
1838 	/* Alt+N for the first 10 tabs */
1839 	for (i = 0; i < 10; ++i) {
1840 		gchar action_name[80];
1841 		gchar accelerator[80];
1842 
1843 		snprintf(action_name, sizeof (action_name), "Tab%d", i);
1844 		action = gtk_action_new (action_name, NULL, NULL, NULL);
1845 		g_object_set_data (G_OBJECT (action), "num", GINT_TO_POINTER (i));
1846 		g_signal_connect (action, "activate",
1847 				G_CALLBACK (action_tab_change_action_activate_callback), window);
1848 		snprintf(accelerator, sizeof (accelerator), "<alt>%d", (i+1)%10);
1849 		gtk_action_group_add_action_with_accel (action_group, action, accelerator);
1850 		g_object_unref (action);
1851 		gtk_ui_manager_add_ui (ui_manager,
1852 				gtk_ui_manager_new_merge_id (ui_manager),
1853 				"/",
1854 				action_name,
1855 				action_name,
1856 				GTK_UI_MANAGER_ACCELERATOR,
1857 				FALSE);
1858 
1859 	}
1860 
1861 	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
1862 	g_object_unref (action_group); /* owned by ui_manager */
1863 
1864 	gtk_window_add_accel_group (GTK_WINDOW (window),
1865 				    gtk_ui_manager_get_accel_group (ui_manager));
1866 
1867 	g_signal_connect (ui_manager, "connect_proxy",
1868 			  G_CALLBACK (connect_proxy_cb), window);
1869 	g_signal_connect (ui_manager, "disconnect_proxy",
1870 			  G_CALLBACK (disconnect_proxy_cb), window);
1871 
1872 	/* add the UI */
1873 	gtk_ui_manager_add_ui_from_resource (ui_manager, "/org/nemo/nemo-shell-ui.xml", NULL);
1874 
1875 	nemo_window_initialize_trash_icon_monitor (window);
1876 }
1877 
1878 void
nemo_window_finalize_menus(NemoWindow * window)1879 nemo_window_finalize_menus (NemoWindow *window)
1880 {
1881 	g_signal_handlers_disconnect_by_func (nemo_trash_monitor_get(),
1882 					      trash_state_changed_cb, window);
1883 }
1884 
1885 static GList *
get_extension_menus(NemoWindow * window)1886 get_extension_menus (NemoWindow *window)
1887 {
1888 	NemoWindowSlot *slot;
1889 	GList *providers;
1890 	GList *items;
1891 	GList *l;
1892 
1893 	providers = nemo_module_get_extensions_for_type (NEMO_TYPE_MENU_PROVIDER);
1894 	items = NULL;
1895 
1896 	slot = nemo_window_get_active_slot (window);
1897 
1898 	for (l = providers; l != NULL; l = l->next) {
1899 		NemoMenuProvider *provider;
1900 		GList *file_items;
1901 
1902 		provider = NEMO_MENU_PROVIDER (l->data);
1903 		file_items = nemo_menu_provider_get_background_items (provider,
1904 									  GTK_WIDGET (window),
1905 									  slot->viewed_file);
1906 		items = g_list_concat (items, file_items);
1907 	}
1908 
1909 	nemo_module_extension_list_free (providers);
1910 
1911 	return items;
1912 }
1913 
1914 static void
add_extension_menu_items(NemoWindow * window,guint merge_id,GtkActionGroup * action_group,GList * menu_items,const char * subdirectory)1915 add_extension_menu_items (NemoWindow *window,
1916 			  guint merge_id,
1917 			  GtkActionGroup *action_group,
1918 			  GList *menu_items,
1919 			  const char *subdirectory)
1920 {
1921 	GtkUIManager *ui_manager;
1922 	GList *l;
1923 
1924 	ui_manager = window->details->ui_manager;
1925 
1926 	for (l = menu_items; l; l = l->next) {
1927 		NemoMenuItem *item;
1928 		NemoMenu *menu;
1929 		GtkAction *action;
1930 		char *path;
1931 
1932 		item = NEMO_MENU_ITEM (l->data);
1933 
1934 		g_object_get (item, "menu", &menu, NULL);
1935 
1936 		action = nemo_action_from_menu_item (item, GTK_WIDGET (window));
1937 		gtk_action_group_add_action_with_accel (action_group, action, NULL);
1938 
1939 		path = g_build_path ("/", POPUP_PATH_EXTENSION_ACTIONS, subdirectory, NULL);
1940 		gtk_ui_manager_add_ui (ui_manager,
1941 				       merge_id,
1942 				       path,
1943 				       gtk_action_get_name (action),
1944 				       gtk_action_get_name (action),
1945 				       (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM,
1946 				       FALSE);
1947 		g_free (path);
1948 
1949 		path = g_build_path ("/", MENU_PATH_EXTENSION_ACTIONS, subdirectory, NULL);
1950 		gtk_ui_manager_add_ui (ui_manager,
1951 				       merge_id,
1952 				       path,
1953 				       gtk_action_get_name (action),
1954 				       gtk_action_get_name (action),
1955 				       (menu != NULL) ? GTK_UI_MANAGER_MENU : GTK_UI_MANAGER_MENUITEM,
1956 				       FALSE);
1957 		g_free (path);
1958 
1959 		/* recursively fill the menu */
1960 		if (menu != NULL) {
1961 			char *subdir;
1962 			GList *children;
1963 
1964 			children = nemo_menu_get_items (menu);
1965 
1966 			subdir = g_build_path ("/", subdirectory, "/", gtk_action_get_name (action), NULL);
1967 			add_extension_menu_items (window,
1968 						  merge_id,
1969 						  action_group,
1970 						  children,
1971 						  subdir);
1972 
1973 			nemo_menu_item_list_free (children);
1974 			g_free (subdir);
1975 		}
1976 	}
1977 }
1978 
1979 void
nemo_window_load_extension_menus(NemoWindow * window)1980 nemo_window_load_extension_menus (NemoWindow *window)
1981 {
1982 	GtkActionGroup *action_group;
1983 	GList *items;
1984 	guint merge_id;
1985 
1986 	if (window->details->extensions_menu_merge_id != 0) {
1987 		gtk_ui_manager_remove_ui (window->details->ui_manager,
1988 					  window->details->extensions_menu_merge_id);
1989 		window->details->extensions_menu_merge_id = 0;
1990 	}
1991 
1992 	if (window->details->extensions_menu_action_group != NULL) {
1993 		gtk_ui_manager_remove_action_group (window->details->ui_manager,
1994 						    window->details->extensions_menu_action_group);
1995 		window->details->extensions_menu_action_group = NULL;
1996 	}
1997 
1998 	merge_id = gtk_ui_manager_new_merge_id (window->details->ui_manager);
1999 	window->details->extensions_menu_merge_id = merge_id;
2000 	action_group = gtk_action_group_new ("ExtensionsMenuGroup");
2001 	window->details->extensions_menu_action_group = action_group;
2002 	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
2003 	gtk_ui_manager_insert_action_group (window->details->ui_manager, action_group, 0);
2004 	g_object_unref (action_group); /* owned by ui manager */
2005 
2006 	items = get_extension_menus (window);
2007 
2008 	if (items != NULL) {
2009 		add_extension_menu_items (window, merge_id, action_group, items, "");
2010 
2011 		g_list_foreach (items, (GFunc) g_object_unref, NULL);
2012 		g_list_free (items);
2013 	}
2014 }
2015