#include <string.h>
-#include <gdk/gdkscreen.h>
-
#include "gtkrecentmanager.h"
#include "gtkrecentfilter.h"
#include "gtkrecentchooser.h"
#include "gtkmenu.h"
#include "gtkimage.h"
#include "gtklabel.h"
-#include "gtkobject.h"
-#include "gtktooltips.h"
+#include "gtktooltip.h"
+#include "gtkactivatable.h"
#include "gtktypebuiltins.h"
+#include "gtkprivate.h"
#include "gtkalias.h"
struct _GtkRecentChooserMenuPrivate
gulong manager_changed_id;
gulong populate_id;
-
- /* tooltips for our bookmark items*/
- GtkTooltips *tooltips;
};
enum {
PROP_0,
+ PROP_SHOW_NUMBERS,
- PROP_SHOW_NUMBERS
+ /* activatable properties */
+ PROP_ACTIVATABLE_RELATED_ACTION,
+ PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
};
+
#define FALLBACK_ICON_SIZE 32
#define FALLBACK_ITEM_LIMIT 10
#define DEFAULT_LABEL_WIDTH 30
static void manager_changed_cb (GtkRecentManager *manager,
gpointer user_data);
+static void gtk_recent_chooser_activatable_iface_init (GtkActivatableIface *iface);
+static void gtk_recent_chooser_update (GtkActivatable *activatable,
+ GtkAction *action,
+ const gchar *property_name);
+static void gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
+ GtkAction *action);
+
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserMenu,
gtk_recent_chooser_menu,
GTK_TYPE_MENU,
G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
- gtk_recent_chooser_iface_init))
+ gtk_recent_chooser_iface_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
+ gtk_recent_chooser_activatable_iface_init))
static void
iface->list_filters = gtk_recent_chooser_menu_list_filters;
}
+static void
+gtk_recent_chooser_activatable_iface_init (GtkActivatableIface *iface)
+{
+ iface->update = gtk_recent_chooser_update;
+ iface->sync_action_properties = gtk_recent_chooser_sync_action_properties;
+}
+
static void
gtk_recent_chooser_menu_class_init (GtkRecentChooserMenuClass *klass)
{
P_("Show Numbers"),
P_("Whether the items should be displayed with a number"),
FALSE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
+
+ g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
+ g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
+
g_type_class_add_private (klass, sizeof (GtkRecentChooserMenuPrivate));
}
priv->local_only = TRUE;
priv->limit = FALLBACK_ITEM_LIMIT;
-
priv->sort_type = GTK_RECENT_SORT_NONE;
-
priv->icon_size = FALLBACK_ICON_SIZE;
-
priv->label_width = DEFAULT_LABEL_WIDTH;
priv->first_recent_item_pos = -1;
priv->placeholder = NULL;
priv->current_filter = NULL;
-
- priv->tooltips = gtk_tooltips_new ();
- g_object_ref_sink (priv->tooltips);
}
static void
priv->populate_id = 0;
}
- if (priv->tooltips)
- {
- g_object_unref (priv->tooltips);
- priv->tooltips = NULL;
- }
-
if (priv->current_filter)
{
g_object_unref (priv->current_filter);
GINT_TO_POINTER (TRUE));
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), priv->placeholder, 0);
+ gtk_widget_set_no_show_all (priv->placeholder, TRUE);
gtk_widget_show (priv->placeholder);
/* (re)populate the menu */
GParamSpec *pspec)
{
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
switch (prop_id)
{
case PROP_SHOW_NUMBERS:
- menu->priv->show_numbers = g_value_get_boolean (value);
+ priv->show_numbers = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
set_recent_manager (menu, g_value_get_object (value));
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- menu->priv->show_private = g_value_get_boolean (value);
+ priv->show_private = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- menu->priv->show_not_found = g_value_get_boolean (value);
+ priv->show_not_found = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
gtk_recent_chooser_menu_set_show_tips (menu, g_value_get_boolean (value));
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- menu->priv->show_icons = g_value_get_boolean (value);
+ priv->show_icons = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
G_OBJECT_TYPE_NAME (object));
break;
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- menu->priv->local_only = g_value_get_boolean (value);
+ priv->local_only = g_value_get_boolean (value);
break;
case GTK_RECENT_CHOOSER_PROP_LIMIT:
- menu->priv->limit = g_value_get_int (value);
+ priv->limit = g_value_get_int (value);
break;
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
chooser_set_sort_type (menu, g_value_get_enum (value));
case GTK_RECENT_CHOOSER_PROP_FILTER:
gtk_recent_chooser_menu_set_current_filter (menu, g_value_get_object (value));
break;
+ case PROP_ACTIVATABLE_RELATED_ACTION:
+ _gtk_recent_chooser_set_related_action (GTK_RECENT_CHOOSER (menu), g_value_get_object (value));
+ break;
+ case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
+ _gtk_recent_chooser_set_use_action_appearance (GTK_RECENT_CHOOSER (menu), g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
GParamSpec *pspec)
{
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
switch (prop_id)
{
case PROP_SHOW_NUMBERS:
- g_value_set_boolean (value, menu->priv->show_numbers);
+ g_value_set_boolean (value, priv->show_numbers);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
- g_value_set_boolean (value, menu->priv->show_tips);
+ g_value_set_boolean (value, priv->show_tips);
break;
case GTK_RECENT_CHOOSER_PROP_LIMIT:
- g_value_set_int (value, menu->priv->limit);
+ g_value_set_int (value, priv->limit);
break;
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- g_value_set_boolean (value, menu->priv->local_only);
+ g_value_set_boolean (value, priv->local_only);
break;
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
- g_value_set_enum (value, menu->priv->sort_type);
+ g_value_set_enum (value, priv->sort_type);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- g_value_set_boolean (value, menu->priv->show_private);
+ g_value_set_boolean (value, priv->show_private);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- g_value_set_boolean (value, menu->priv->show_not_found);
+ g_value_set_boolean (value, priv->show_not_found);
break;
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- g_value_set_boolean (value, menu->priv->show_icons);
+ g_value_set_boolean (value, priv->show_icons);
break;
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
- g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
- G_STRFUNC,
- G_OBJECT_TYPE_NAME (object));
+ g_value_set_boolean (value, FALSE);
break;
case GTK_RECENT_CHOOSER_PROP_FILTER:
- g_value_set_object (value, menu->priv->current_filter);
+ g_value_set_object (value, priv->current_filter);
+ break;
+ case PROP_ACTIVATABLE_RELATED_ACTION:
+ g_value_set_object (value, _gtk_recent_chooser_get_related_action (GTK_RECENT_CHOOSER (menu)));
+ break;
+ case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
+ g_value_set_boolean (value, _gtk_recent_chooser_get_use_action_appearance (GTK_RECENT_CHOOSER (menu)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
gboolean found = FALSE;
children = gtk_container_get_children (GTK_CONTAINER (menu));
+
for (l = children; l != NULL; l = l->next)
{
GtkRecentInfo *info;
if (priv->sort_data_destroy)
{
priv->sort_data_destroy (priv->sort_data);
-
- priv->sort_func = NULL;
- priv->sort_data = NULL;
priv->sort_data_destroy = NULL;
}
+
+ priv->sort_func = NULL;
+ priv->sort_data = NULL;
+ priv->sort_data_destroy = NULL;
if (sort_func)
{
}
}
-static gint
-sort_recent_items_mru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return (gtk_recent_info_get_modified (a) < gtk_recent_info_get_modified (b));
-}
-
-static gint
-sort_recent_items_lru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return (gtk_recent_info_get_modified (a) > gtk_recent_info_get_modified (b));
-}
-
-/* our proxy sorting function */
-static gint
-sort_recent_items_proxy (gpointer *a,
- gpointer *b,
- gpointer user_data)
-{
- GtkRecentInfo *info_a = (GtkRecentInfo *) a;
- GtkRecentInfo *info_b = (GtkRecentInfo *) b;
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (user_data);
-
- if (menu->priv->sort_func)
- return (* menu->priv->sort_func) (info_a,
- info_b,
- menu->priv->sort_data);
-
- /* fallback */
- return 0;
-}
-
static void
chooser_set_sort_type (GtkRecentChooserMenu *menu,
GtkRecentSortType sort_type)
gtk_recent_chooser_menu_get_items (GtkRecentChooser *chooser)
{
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GtkRecentChooserMenuPrivate *priv;
- gint limit;
- GtkRecentSortType sort_type;
- GList *items;
- GCompareDataFunc compare_func;
- gint length;
-
- priv = menu->priv;
-
- if (!priv->manager)
- return NULL;
-
- limit = gtk_recent_chooser_get_limit (chooser);
- if (limit == 0)
- return NULL;
-
- sort_type = gtk_recent_chooser_get_sort_type (chooser);
- switch (sort_type)
- {
- case GTK_RECENT_SORT_NONE:
- compare_func = NULL;
- break;
- case GTK_RECENT_SORT_MRU:
- compare_func = (GCompareDataFunc) sort_recent_items_mru;
- break;
- case GTK_RECENT_SORT_LRU:
- compare_func = (GCompareDataFunc) sort_recent_items_lru;
- break;
- case GTK_RECENT_SORT_CUSTOM:
- compare_func = (GCompareDataFunc) sort_recent_items_proxy;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- items = gtk_recent_manager_get_items (priv->manager);
- if (!items)
- return NULL;
-
- if (compare_func)
- items = g_list_sort_with_data (items, compare_func, menu);
-
- length = g_list_length (items);
- if ((limit != -1) && (length > limit))
- {
- GList *clamp, *l;
-
- clamp = g_list_nth (items, limit - 1);
- if (!clamp)
- return items;
-
- l = clamp->next;
- clamp->next = NULL;
-
- g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
- g_list_free (l);
- }
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
- return items;
+ return _gtk_recent_chooser_get_items (chooser,
+ priv->current_filter,
+ priv->sort_func,
+ priv->sort_data);
}
static GtkRecentManager *
priv->current_filter = filter;
g_object_ref_sink (priv->current_filter);
}
-
- g_object_notify (G_OBJECT (menu), "filter");
-}
-
-static gboolean
-get_is_recent_filtered (GtkRecentChooserMenu *menu,
- GtkRecentInfo *info)
-{
- GtkRecentChooserMenuPrivate *priv;
- GtkRecentFilter *current_filter;
- GtkRecentFilterInfo filter_info;
- GtkRecentFilterFlags needed;
- gboolean retval;
-
- g_assert (info != NULL);
-
- priv = menu->priv;
-
- if (!priv->current_filter)
- return FALSE;
-
- current_filter = priv->current_filter;
- needed = gtk_recent_filter_get_needed (current_filter);
-
- filter_info.contains = GTK_RECENT_FILTER_URI | GTK_RECENT_FILTER_MIME_TYPE;
-
- filter_info.uri = gtk_recent_info_get_uri (info);
- filter_info.mime_type = gtk_recent_info_get_mime_type (info);
-
- if (needed & GTK_RECENT_FILTER_DISPLAY_NAME)
- {
- filter_info.display_name = gtk_recent_info_get_display_name (info);
- filter_info.contains |= GTK_RECENT_FILTER_DISPLAY_NAME;
- }
- else
- filter_info.uri = NULL;
-
- if (needed & GTK_RECENT_FILTER_APPLICATION)
- {
- filter_info.applications = (const gchar **) gtk_recent_info_get_applications (info, NULL);
- filter_info.contains |= GTK_RECENT_FILTER_APPLICATION;
- }
- else
- filter_info.applications = NULL;
- if (needed & GTK_RECENT_FILTER_GROUP)
- {
- filter_info.groups = (const gchar **) gtk_recent_info_get_groups (info, NULL);
- filter_info.contains |= GTK_RECENT_FILTER_GROUP;
- }
- else
- filter_info.groups = NULL;
-
- if (needed & GTK_RECENT_FILTER_AGE)
- {
- filter_info.age = gtk_recent_info_get_age (info);
- filter_info.contains |= GTK_RECENT_FILTER_AGE;
- }
- else
- filter_info.age = -1;
-
- retval = gtk_recent_filter_filter (current_filter, &filter_info);
-
- /* this we own */
- if (filter_info.applications)
- g_strfreev ((gchar **) filter_info.applications);
- if (filter_info.groups)
- g_strfreev ((gchar **) filter_info.groups);
+ gtk_recent_chooser_menu_populate (menu);
- return !retval;
+ g_object_notify (G_OBJECT (menu), "filter");
}
/* taken from libeel/eel-strings.c */
GtkWidget *item)
{
GtkRecentChooserMenuPrivate *priv;
- gchar *path, *tip_text;
+ gchar *path;
g_assert (info != NULL);
g_assert (item != NULL);
priv = menu->priv;
- if (!priv->tooltips)
- return;
-
path = gtk_recent_info_get_uri_display (info);
if (path)
{
- tip_text = g_strdup_printf (_("Open '%s'"), path);
+ gchar *tip_text = g_strdup_printf (_("Open '%s'"), path);
- gtk_tooltips_set_tip (priv->tooltips,
- item,
- tip_text,
- NULL);
+ gtk_widget_set_tooltip_text (item, tip_text);
+ gtk_widget_set_has_tooltip (item, priv->show_tips);
g_free (path);
g_free (tip_text);
/* avoid clashing mnemonics */
if (count <= 10)
- text = g_strdup_printf ("_%d. %s", count, escaped);
+ /* This is the label format that is used for the first 10 items
+ * in a recent files menu. The %d is the number of the item,
+ * the %s is the name of the item. Please keep the _ in front
+ * of the number to give these menu items a mnemonic.
+ */
+ text = g_strdup_printf (C_("recent menu label", "_%d. %s"), count, escaped);
else
- text = g_strdup_printf ("%d. %s", count, escaped);
+ /* This is the format that is used for items in a recent files menu.
+ * The %d is the number of the item, the %s is the name of the item.
+ */
+ text = g_strdup_printf (C_("recent menu label", "%d. %s"), count, escaped);
item = gtk_image_menu_item_new_with_mnemonic (text);
g_free (text);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item),
+ TRUE);
+
/* ellipsize the menu item label, in case the recent document
* display name is huge.
*/
label = GTK_BIN (item)->child;
- if (label)
+ if (GTK_IS_LABEL (label))
{
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_label_set_max_width_chars (GTK_LABEL (label), priv->label_width);
gint loaded_items;
gint displayed_items;
GtkRecentChooserMenu *menu;
+ GtkWidget *placeholder;
} MenuPopulateData;
static gboolean
pdata = (MenuPopulateData *) data;
priv = pdata->menu->priv;
- priv->populate_id = 0;
-
if (!pdata->items)
{
pdata->items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (pdata->menu));
if (!pdata->items)
{
/* show the placeholder here */
- gtk_widget_show (priv->placeholder);
+ gtk_widget_show (pdata->placeholder);
pdata->displayed_items = 1;
-
- GDK_THREADS_LEAVE ();
+ priv->populate_id = 0;
return FALSE;
}
+ else
+ gtk_widget_hide (pdata->placeholder);
pdata->n_items = g_list_length (pdata->items);
pdata->loaded_items = 0;
}
info = g_list_nth_data (pdata->items, pdata->loaded_items);
-
- /* skip non-local items on request */
- if (priv->local_only &&
- !gtk_recent_info_is_local (info))
- {
- goto check_and_return;
- }
-
- /* skip private items on request */
- if (!priv->show_private &&
- gtk_recent_info_get_private_hint (info))
- {
- goto check_and_return;
- }
-
- /* skip non-existing items on request */
- if (!priv->show_not_found &&
- !gtk_recent_info_exists (info))
- {
- goto check_and_return;
- }
- /* filter items based on the currently set filter object */
- if (get_is_recent_filtered (pdata->menu, info))
- {
- goto check_and_return;
- }
-
item = gtk_recent_chooser_menu_create_item (pdata->menu,
info,
pdata->displayed_items);
g_list_foreach (pdata->items, (GFunc) gtk_recent_info_unref, NULL);
g_list_free (pdata->items);
+ priv->populate_id = 0;
+
retval = FALSE;
}
else
idle_populate_clean_up (gpointer data)
{
MenuPopulateData *pdata = data;
- GtkRecentChooserMenuPrivate *priv = pdata->menu->priv;
-
- /* show the placeholder in case no item survived
- * the filtering process in the idle loop
- */
- if (!pdata->displayed_items)
- gtk_widget_show (priv->placeholder);
- g_slice_free (MenuPopulateData, data);
+ if (pdata->menu->priv->populate_id == 0)
+ {
+ /* show the placeholder in case no item survived
+ * the filtering process in the idle loop
+ */
+ if (!pdata->displayed_items)
+ gtk_widget_show (pdata->placeholder);
+ g_object_unref (pdata->placeholder);
+
+ g_slice_free (MenuPopulateData, data);
+ }
}
static void
pdata->loaded_items = 0;
pdata->displayed_items = 0;
pdata->menu = menu;
+ pdata->placeholder = g_object_ref (priv->placeholder);
priv->icon_size = get_icon_size_for_widget (GTK_WIDGET (menu));
- /* remove our menu items first and hide the placeholder */
+ /* remove our menu items first */
gtk_recent_chooser_menu_dispose_items (menu);
- gtk_widget_hide (priv->placeholder);
priv->populate_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
idle_populate_func,
return FALLBACK_ICON_SIZE;
}
+static void
+foreach_set_shot_tips (GtkWidget *widget,
+ gpointer user_data)
+{
+ GtkRecentChooserMenu *menu = user_data;
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
+ gboolean has_mark;
+
+ /* toggle the tooltip only on the items we create */
+ has_mark =
+ GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "gtk-recent-menu-mark"));
+
+ if (has_mark)
+ gtk_widget_set_has_tooltip (widget, priv->show_tips);
+}
+
static void
gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
gboolean show_tips)
{
- if (menu->priv->show_tips == show_tips)
+ GtkRecentChooserMenuPrivate *priv = menu->priv;
+
+ if (priv->show_tips == show_tips)
return;
- g_assert (menu->priv->tooltips != NULL);
-
- if (show_tips)
- gtk_tooltips_enable (menu->priv->tooltips);
- else
- gtk_tooltips_disable (menu->priv->tooltips);
-
- menu->priv->show_tips = show_tips;
+ priv->show_tips = show_tips;
+ gtk_container_foreach (GTK_CONTAINER (menu), foreach_set_shot_tips, menu);
+}
+
+static void
+gtk_recent_chooser_update (GtkActivatable *activatable,
+ GtkAction *action,
+ const gchar *property_name)
+{
+ if (strcmp (property_name, "sensitive") == 0)
+ gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
+
+ _gtk_recent_chooser_update (activatable, action, property_name);
+}
+
+static void
+gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
+ GtkAction *action)
+{
+ gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
+
+ _gtk_recent_chooser_sync_action_properties (activatable, action);
}
+
/*
* Public API
*/
*
* Sets whether a number should be added to the items of @menu. The
* numbers are shown to provide a unique character for a mnemonic to
- * be used inside the menu item's label. Only the first the items
+ * be used inside ten menu item's label. Only the first the items
* get a number to avoid clashes.
*
* Since: 2.10