places sidebar: Preserve ::populate-popup functionality
We "fix" this signal the same way we did for GtkEntry and GtkTextView: slightly change the signature so that the passed widget may be a container other than a GtkMenu, and add a property to explicitly opt in to receiving the signal in this case.
This commit is contained in:
@ -166,6 +166,7 @@ struct _GtkPlacesSidebar {
|
|||||||
guint show_other_locations : 1;
|
guint show_other_locations : 1;
|
||||||
guint show_trash : 1;
|
guint show_trash : 1;
|
||||||
guint local_only : 1;
|
guint local_only : 1;
|
||||||
|
guint populate_all : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkPlacesSidebarClass {
|
struct _GtkPlacesSidebarClass {
|
||||||
@ -220,6 +221,7 @@ enum {
|
|||||||
PROP_SHOW_TRASH,
|
PROP_SHOW_TRASH,
|
||||||
PROP_LOCAL_ONLY,
|
PROP_LOCAL_ONLY,
|
||||||
PROP_SHOW_OTHER_LOCATIONS,
|
PROP_SHOW_OTHER_LOCATIONS,
|
||||||
|
PROP_POPULATE_ALL,
|
||||||
NUM_PROPERTIES
|
NUM_PROPERTIES
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -299,18 +301,6 @@ emit_open_location (GtkPlacesSidebar *sidebar,
|
|||||||
location, open_flags);
|
location, open_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void
|
|
||||||
emit_populate_popup (GtkPlacesSidebar *sidebar,
|
|
||||||
GtkMenu *menu,
|
|
||||||
GFile *selected_item,
|
|
||||||
GVolume *selected_volume)
|
|
||||||
{
|
|
||||||
g_signal_emit (sidebar, places_sidebar_signals[POPULATE_POPUP], 0,
|
|
||||||
menu, selected_item, selected_volume);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
emit_show_error_message (GtkPlacesSidebar *sidebar,
|
emit_show_error_message (GtkPlacesSidebar *sidebar,
|
||||||
const gchar *primary,
|
const gchar *primary,
|
||||||
@ -3395,6 +3385,33 @@ create_row_popover (GtkPlacesSidebar *sidebar,
|
|||||||
|
|
||||||
/* Update everything! */
|
/* Update everything! */
|
||||||
check_popover_sensitivity (row, &data);
|
check_popover_sensitivity (row, &data);
|
||||||
|
|
||||||
|
if (sidebar->populate_all)
|
||||||
|
{
|
||||||
|
gchar *uri;
|
||||||
|
GVolume *volume;
|
||||||
|
GFile *file;
|
||||||
|
|
||||||
|
g_object_get (row,
|
||||||
|
"uri", &uri,
|
||||||
|
"volume", &volume,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (uri)
|
||||||
|
file = g_file_new_for_uri (uri);
|
||||||
|
else
|
||||||
|
file = NULL;
|
||||||
|
|
||||||
|
g_signal_emit (sidebar, places_sidebar_signals[POPULATE_POPUP], 0,
|
||||||
|
box, file, volume);
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
g_object_unref (file);
|
||||||
|
|
||||||
|
g_free (uri);
|
||||||
|
if (volume)
|
||||||
|
g_object_unref (volume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3893,6 +3910,14 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||||||
gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
|
gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_POPULATE_ALL:
|
||||||
|
if (sidebar->populate_all != g_value_get_boolean (value))
|
||||||
|
{
|
||||||
|
sidebar->populate_all = g_value_get_boolean (value);
|
||||||
|
g_object_notify_by_pspec (obj, pspec);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -3947,6 +3972,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||||||
g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
|
g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_POPULATE_ALL:
|
||||||
|
g_value_set_boolean (value, sidebar->populate_all);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -4066,29 +4095,36 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
|
|||||||
/**
|
/**
|
||||||
* GtkPlacesSidebar::populate-popup:
|
* GtkPlacesSidebar::populate-popup:
|
||||||
* @sidebar: the object which received the signal.
|
* @sidebar: the object which received the signal.
|
||||||
* @menu: (type Gtk.Menu): a #GtkMenu.
|
* @container: (type Gtk.Widget): a #GtkMenu or another #GtkContainer
|
||||||
* @selected_item: (type Gio.File) (nullable): #GFile with the item to which the menu should refer, or #NULL in the case of a @selected_volume.
|
* @selected_item: (type Gio.File) (nullable): #GFile with the item to which the popup should refer, or #NULL in the case of a @selected_volume.
|
||||||
* @selected_volume: (type Gio.Volume) (nullable): #GVolume if the selected item is a volume, or #NULL if it is a file.
|
* @selected_volume: (type Gio.Volume) (nullable): #GVolume if the selected item is a volume, or #NULL if it is a file.
|
||||||
*
|
*
|
||||||
* The places sidebar emits this signal when the user invokes a contextual
|
* The places sidebar emits this signal when the user invokes a contextual
|
||||||
* menu on one of its items. In the signal handler, the application may
|
* popup on one of its items. In the signal handler, the application may
|
||||||
* add extra items to the menu as appropriate. For example, a file manager
|
* add extra items to the menu as appropriate. For example, a file manager
|
||||||
* may want to add a "Properties" command to the menu.
|
* may want to add a "Properties" command to the menu.
|
||||||
*
|
*
|
||||||
* It is not necessary to store the @selected_item for each menu item;
|
* It is not necessary to store the @selected_item for each menu item;
|
||||||
* during their GtkMenuItem::activate callbacks, the application can use
|
* during their callbacks, the application can use gtk_places_sidebar_get_location()
|
||||||
* gtk_places_sidebar_get_location() to get the file to which the item
|
* to get the file to which the item refers.
|
||||||
* refers.
|
|
||||||
*
|
*
|
||||||
* The @selected_item argument may be #NULL in case the selection refers to
|
* The @selected_item argument may be %NULL in case the selection refers to
|
||||||
* a volume. In this case, @selected_volume will be non-NULL. In this case,
|
* a volume. In this case, @selected_volume will be non-%NULL. In this case,
|
||||||
* the calling application will have to g_object_ref() the @selected_volume and
|
* the calling application will have to g_object_ref() the @selected_volume and
|
||||||
* keep it around for the purposes of its menu item's "activate" callback.
|
* keep it around to use it in the callback.
|
||||||
*
|
*
|
||||||
* The @menu and all its menu items are destroyed after the user
|
* The @container and all its contents are destroyed after the user
|
||||||
* dismisses the menu. The menu is re-created (and thus, this signal is
|
* dismisses the popup. The popup is re-created (and thus, this signal is
|
||||||
* emitted) every time the user activates the contextual menu.
|
* emitted) every time the user activates the contextual menu.
|
||||||
*
|
*
|
||||||
|
* Before 3.18, the @container always was a #GtkMenu, and you were expected
|
||||||
|
* to add your items as #GtkMenuItems. Since 3.18, the popup may be implemented
|
||||||
|
* as a #GtkPopover, in which case @container will be something else, e.g. a
|
||||||
|
* #GtkBox, to which you may add #GtkModelButtons or other widgets, such as
|
||||||
|
* #GtkEntries, #GtkSpinButtons, etc. If your application can deal with this
|
||||||
|
* situation, you can set #GtkPlacesSidebar::populate-all to %TRUE to request
|
||||||
|
* that this signal is emitted for populating popovers as well.
|
||||||
|
*
|
||||||
* Since: 3.10
|
* Since: 3.10
|
||||||
*/
|
*/
|
||||||
places_sidebar_signals [POPULATE_POPUP] =
|
places_sidebar_signals [POPULATE_POPUP] =
|
||||||
@ -4099,9 +4135,9 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
|
|||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
_gtk_marshal_VOID__OBJECT_OBJECT_OBJECT,
|
_gtk_marshal_VOID__OBJECT_OBJECT_OBJECT,
|
||||||
G_TYPE_NONE, 3,
|
G_TYPE_NONE, 3,
|
||||||
G_TYPE_OBJECT,
|
GTK_TYPE_WIDGET,
|
||||||
G_TYPE_OBJECT,
|
G_TYPE_FILE,
|
||||||
G_TYPE_OBJECT);
|
G_TYPE_VOLUME);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GtkPlacesSidebar::show-error-message:
|
* GtkPlacesSidebar::show-error-message:
|
||||||
@ -4335,6 +4371,21 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
|
|||||||
FALSE,
|
FALSE,
|
||||||
G_PARAM_READWRITE);
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkPlacesSidebar:populate-all:
|
||||||
|
*
|
||||||
|
* If :populate-all is %TRUE, the #GtkPlacesSidebar::populate-popup signal
|
||||||
|
* is also emitted for popovers.
|
||||||
|
*
|
||||||
|
* Since: 3.18
|
||||||
|
*/
|
||||||
|
properties[PROP_POPULATE_ALL] =
|
||||||
|
g_param_spec_boolean ("populate-all",
|
||||||
|
P_("Show 'Other locations'"),
|
||||||
|
P_("Whether the sidebar includes an item to show external locations"),
|
||||||
|
FALSE,
|
||||||
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
|
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user