places-sidebar: add optional enter location place

https://bugzilla.gnome.org/show_bug.cgi?id=722211
This commit is contained in:
William Jon McCann 2014-04-07 18:43:28 -04:00 committed by Matthias Clasen
parent e2b2339b89
commit 1e925a85ca
2 changed files with 109 additions and 0 deletions

View File

@ -165,6 +165,7 @@ struct _GtkPlacesSidebar {
guint show_desktop_set : 1;
guint show_desktop : 1;
guint show_connect_to_server : 1;
guint show_enter_location : 1;
guint local_only : 1;
};
@ -192,6 +193,7 @@ struct _GtkPlacesSidebarClass {
GFile *dest_file,
GList *source_file_list,
GdkDragAction action);
void (* show_enter_location) (GtkPlacesSidebar *sidebar);
};
enum {
@ -219,6 +221,7 @@ typedef enum {
PLACES_BOOKMARK,
PLACES_HEADING,
PLACES_CONNECT_TO_SERVER,
PLACES_ENTER_LOCATION,
PLACES_DROP_FEEDBACK
} PlaceType;
@ -234,6 +237,7 @@ enum {
POPULATE_POPUP,
SHOW_ERROR_MESSAGE,
SHOW_CONNECT_TO_SERVER,
SHOW_ENTER_LOCATION,
DRAG_ACTION_REQUESTED,
DRAG_ACTION_ASK,
DRAG_PERFORM_DROP,
@ -245,6 +249,7 @@ enum {
PROP_OPEN_FLAGS,
PROP_SHOW_DESKTOP,
PROP_SHOW_CONNECT_TO_SERVER,
PROP_SHOW_ENTER_LOCATION,
PROP_LOCAL_ONLY,
NUM_PROPERTIES
};
@ -363,6 +368,12 @@ emit_show_connect_to_server (GtkPlacesSidebar *sidebar)
g_signal_emit (sidebar, places_sidebar_signals[SHOW_CONNECT_TO_SERVER], 0);
}
static void
emit_show_enter_location (GtkPlacesSidebar *sidebar)
{
g_signal_emit (sidebar, places_sidebar_signals[SHOW_ENTER_LOCATION], 0);
}
static GdkDragAction
emit_drag_action_requested (GtkPlacesSidebar *sidebar,
GdkDragContext *context,
@ -852,6 +863,17 @@ update_places (GtkPlacesSidebar *sidebar)
/* XDG directories */
add_special_dirs (sidebar);
if (sidebar->show_enter_location)
{
icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
add_place (sidebar, PLACES_ENTER_LOCATION,
SECTION_COMPUTER,
_("Enter Location"), icon, NULL,
NULL, NULL, NULL, 0,
_("Manually enter a location"));
g_object_unref (icon);
}
/* Trash */
if (!sidebar->local_only)
{
@ -2327,6 +2349,10 @@ open_selected_bookmark (GtkPlacesSidebar *sidebar,
{
emit_show_connect_to_server (sidebar);
}
else if (place_type == PLACES_ENTER_LOCATION)
{
emit_show_enter_location (sidebar);
}
else
{
open_selected_volume (sidebar, model, iter, open_flags);
@ -3899,6 +3925,10 @@ gtk_places_sidebar_set_property (GObject *obj,
gtk_places_sidebar_set_show_connect_to_server (sidebar, g_value_get_boolean (value));
break;
case PROP_SHOW_ENTER_LOCATION:
gtk_places_sidebar_set_show_enter_location (sidebar, g_value_get_boolean (value));
break;
case PROP_LOCAL_ONLY:
gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
break;
@ -3935,6 +3965,10 @@ gtk_places_sidebar_get_property (GObject *obj,
g_value_set_boolean (value, gtk_places_sidebar_get_show_connect_to_server (sidebar));
break;
case PROP_SHOW_ENTER_LOCATION:
g_value_set_boolean (value, gtk_places_sidebar_get_show_enter_location (sidebar));
break;
case PROP_LOCAL_ONLY:
g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
break;
@ -4134,6 +4168,26 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkPlacesSidebar::show-enter-location:
* @sidebar: the object which received the signal.
*
* The places sidebar emits this signal when it needs the calling
* application to present an way to directly enter a location.
* For example, the application may bring up a dialog box asking for
* a URL like "http://http.example.com".
*
* Since: 3.14
*/
places_sidebar_signals [SHOW_ENTER_LOCATION] =
g_signal_new (I_("show-enter-location"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_enter_location),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkPlacesSidebar::drag-action-requested:
* @sidebar: the object which received the signal.
@ -4244,6 +4298,12 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
P_("Whether the sidebar includes a builtin shortcut to a 'Connect to server' dialog"),
FALSE,
G_PARAM_READWRITE);
properties[PROP_SHOW_ENTER_LOCATION] =
g_param_spec_boolean ("show-enter-location",
P_("Show 'Enter Location'"),
P_("Whether the sidebar includes a builtin shortcut to manually enter a location"),
FALSE,
G_PARAM_READWRITE);
properties[PROP_LOCAL_ONLY] =
g_param_spec_boolean ("local-only",
P_("Local Only"),
@ -4605,6 +4665,50 @@ gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSidebar *sidebar)
return sidebar->show_connect_to_server;
}
/**
* gtk_places_sidebar_set_show_enter_location:
* @sidebar: a places sidebar
* @show_enter_location: whether to show an item for the Connect to Server command
*
* Sets whether the @sidebar should show an item for connecting to a network server; this is off by default.
* An application may want to turn this on if it implements a way for the user to connect
* to network servers directly.
*
* Since: 3.14
*/
void
gtk_places_sidebar_set_show_enter_location (GtkPlacesSidebar *sidebar,
gboolean show_enter_location)
{
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
show_enter_location = !!show_enter_location;
if (sidebar->show_enter_location != show_enter_location)
{
sidebar->show_enter_location = show_enter_location;
update_places (sidebar);
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_ENTER_LOCATION]);
}
}
/**
* gtk_places_sidebar_get_show_enter_location:
* @sidebar: a places sidebar
*
* Returns the value previously set with gtk_places_sidebar_set_show_enter_location()
*
* Returns: %TRUE if the sidebar will display an Enter Location item.
*
* Since: 3.14
*/
gboolean
gtk_places_sidebar_get_show_enter_location (GtkPlacesSidebar *sidebar)
{
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
return sidebar->show_enter_location;
}
/**
* gtk_places_sidebar_set_local_only:
* @sidebar: a places sidebar

View File

@ -105,6 +105,11 @@ gboolean gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSideb
GDK_AVAILABLE_IN_3_10
void gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar *sidebar,
gboolean show_connect_to_server);
GDK_AVAILABLE_IN_3_14
gboolean gtk_places_sidebar_get_show_enter_location (GtkPlacesSidebar *sidebar);
GDK_AVAILABLE_IN_3_14
void gtk_places_sidebar_set_show_enter_location (GtkPlacesSidebar *sidebar,
gboolean show_enter_location);
GDK_AVAILABLE_IN_3_12
void gtk_places_sidebar_set_local_only (GtkPlacesSidebar *sidebar,