Add functions to say whether multiple tabs/windows are supported

The file chooser will leave these off by default; file managers
like Nautilus will turn them on.

These control whether the places sidebar shows 'open in new tab' and similar
items in its context menu.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
This commit is contained in:
Federico Mena Quintero
2011-10-04 09:22:11 -05:00
parent 01020ccc81
commit 7be881982f
2 changed files with 57 additions and 17 deletions

View File

@ -75,6 +75,9 @@ struct _GtkPlacesSidebar {
GtkPlacesOpenMode go_to_after_mount_open_mode;
GtkTreePath *eject_highlight_path;
guint multiple_tabs_supported : 1;
guint multiple_windows_supported : 1;
};
struct _GtkPlacesSidebarClass {
@ -202,6 +205,10 @@ G_DEFINE_TYPE (GtkPlacesSidebar, gtk_places_sidebar, GTK_TYPE_SCROLLED_WINDOW);
static void
emit_location_selected (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode)
{
if ((!sidebar->multiple_tabs_supported && open_mode == GTK_PLACES_OPEN_MODE_NEW_TAB)
|| (!sidebar->multiple_windows_supported && open_mode == GTK_PLACES_OPEN_MODE_NEW_WINDOW))
open_mode = GTK_PLACES_OPEN_MODE_NORMAL;
g_signal_emit (sidebar, places_sidebar_signals[LOCATION_SELECTED], 0,
location, open_mode);
}
@ -2545,15 +2552,11 @@ static void
bookmarks_build_popup_menu (GtkPlacesSidebar *sidebar)
{
GtkWidget *item;
gboolean use_browser;
if (sidebar->popup_menu) {
return;
}
use_browser = g_settings_get_boolean (nautilus_preferences,
NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER);
sidebar->popup_menu = gtk_menu_new ();
gtk_menu_attach_to_widget (GTK_MENU (sidebar->popup_menu),
GTK_WIDGET (sidebar),
@ -2573,7 +2576,7 @@ bookmarks_build_popup_menu (GtkPlacesSidebar *sidebar)
G_CALLBACK (open_shortcut_in_new_tab_cb), sidebar);
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
if (use_browser) {
if (settings->multiple_tabs_supported) {
gtk_widget_show (item);
}
@ -2582,7 +2585,7 @@ bookmarks_build_popup_menu (GtkPlacesSidebar *sidebar)
G_CALLBACK (open_shortcut_in_new_window_cb), sidebar);
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
if (use_browser) {
if (sidebar->multiple_windows_supported) {
gtk_widget_show (item);
}
@ -2873,13 +2876,13 @@ bookmarks_button_press_event_cb (GtkWidget *widget,
&path, NULL, NULL, NULL);
gtk_tree_model_get_iter (model, &iter, path);
if (g_settings_get_boolean (nautilus_preferences,
NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) {
open_mode = ((event->state & GDK_CONTROL_MASK) ?
GTK_PLACES_OPEN_MODE_NEW_WINDOW :
GTK_PLACES_OPEN_MODE_NEW_TAB);
if (sidebar->multiple_tabs_supported) {
if (event->state & GDK_CONTROL_MASK)
open_mode = GTK_PLACES_OPEN_MODE_NEW_WINDOW;
else
open_mode = GTK_PLACES_OPEN_MODE_NEW_TAB;
} else {
open_mode = GTK_PLACES_OPEN_MODE_NEW_WINDOW; /* FIXME: was CLOSE_BEHIND; make Nautilus handle this */
open_mode = GTK_PLACES_OPEN_MODE_NEW_WINDOW;
}
open_selected_bookmark (sidebar, model, &iter, open_mode);
@ -3315,10 +3318,6 @@ gtk_places_sidebar_dispose (GObject *object)
desktop_setting_changed_callback,
sidebar);
g_signal_handlers_disconnect_by_func (nautilus_preferences,
bookmarks_popup_menu_detach_cb,
sidebar);
g_signal_handlers_disconnect_by_func (gnome_background_preferences,
desktop_setting_changed_callback,
sidebar);
@ -3491,3 +3490,39 @@ gtk_places_sidebar_set_current_uri (GtkPlacesSidebar *sidebar, const char *uri)
}
}
}
/**
* gtk_places_sidebar_set_multiple_tabs_supported:
* @sidebar: a places sidebar
* @supported: whether the appliacation supports multiple notebook tabs for file browsing
*
* Sets whether the calling appliacation supports multiple tabs for file browsing.
* When @supported is #TRUE, the context menu for the @sidebar's items will show
* items relevant to opening folders in new tabs.
*/
void
gtk_places_sidebar_set_multiple_tabs_supported (GtkPlacesSidebar *sidebar, gboolean supported)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
sidebar->multiple_tabs_supported = !!supported;
bookmarks_popup_menu_detach_cb (sidebar, NULL);
}
/**
* gtk_places_sidebar_set_multiple_windows_supported:
* @sidebar: a places sidebar
* @supported: whether the appliacation supports multiple windows for file browsing
*
* Sets whether the calling appliacation supports multiple windows for file browsing.
* When @supported is #TRUE, the context menu for the @sidebar's items will show
* items relevant to opening folders in new windows.
*/
void
gtk_places_sidebar_set_multiple_windows_supported (GtkPlacesSidebar *sidebar, gboolean supported)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
sidebar->multiple_windows_supported = !!supported;
bookmarks_popup_menu_detach_cb (sidebar, NULL);
}

View File

@ -50,9 +50,14 @@ typedef enum {
GType gtk_places_sidebar_get_type (void);
GtkWidget *gtk_places_sidebar_new (void);
/* FIXME: add an "uri" property so this can be set via g_object_set() */
/* FIXME: add GObject properties for the following things */
void gtk_places_sidebar_set_current_uri (GtkPlacesSidebar *sidebar, const char *uri);
void gtk_places_sidebar_set_multiple_tabs_supported (GtkPlacesSidebar *sidebar, gboolean supported);
void gtk_places_sidebar_set_multiple_windows_supported (GtkPlacesSidebar *sidebar, gboolean supported);
G_END_DECLS
#endif /* __GTK_PLACES_SIDEBAR_H__ */