-/* GTK - The GTK+ Toolkit
+/* GTK - The GIMP Toolkit
* Recent chooser action for GtkUIManager
*
* Copyright (C) 2007, Emmanuele Bassi
#include "gtkrecentchooserutils.h"
#include "gtkrecentchooserprivate.h"
#include "gtkprivate.h"
-#include "gtkalias.h"
+
+/**
+ * SECTION:gtkrecentaction
+ * @Short_description: An action of which represents a list of recently used files
+ * @Title: GtkRecentAction
+ *
+ * A #GtkRecentAction represents a list of recently used files, which
+ * can be shown by widgets such as #GtkRecentChooserDialog or
+ * #GtkRecentChooserMenu.
+ *
+ * To construct a submenu showing recently used files, use a #GtkRecentAction
+ * as the action for a <menuitem>. To construct a menu toolbutton showing
+ * the recently used files in the popup menu, use a #GtkRecentAction as the
+ * action for a <toolitem> element.
+ */
+
#define FALLBACK_ITEM_LIMIT 10
-#define GTK_RECENT_ACTION_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- GTK_TYPE_RECENT_ACTION, \
- GtkRecentActionPrivate))
struct _GtkRecentActionPrivate
{
GtkRecentManager *manager;
- guint manager_changed_id;
guint show_numbers : 1;
GtkRecentSortType sort_type;
GtkRecentSortFunc sort_func;
- gpointer sort_data;
- GDestroyNotify data_destroy;
+ gpointer sort_data;
+ GDestroyNotify data_destroy;
GtkRecentFilter *current_filter;
static GtkRecentManager *
gtk_recent_action_get_recent_manager (GtkRecentChooser *chooser)
{
- return GTK_RECENT_ACTION_GET_PRIVATE (chooser)->manager;
+ return GTK_RECENT_ACTION (chooser)->priv->manager;
}
static void
for (l = priv->choosers; l; l = l->next)
{
GtkRecentChooser *chooser_menu = l->data;
-
+
gtk_recent_chooser_set_sort_func (chooser_menu, priv->sort_func,
priv->sort_data,
priv->data_destroy);
GtkRecentFilter *filter)
{
GtkRecentActionPrivate *priv = action->priv;
- GSList *l;
g_object_ref (action);
if (priv->current_filter)
g_object_ref_sink (priv->current_filter);
- for (l = priv->choosers; l; l = l->next)
- {
- GtkRecentChooser *chooser = l->data;
-
- gtk_recent_chooser_set_filter (chooser, priv->current_filter);
- }
-
g_object_notify (G_OBJECT (action), "filter");
g_object_unref (action);
gtk_recent_action_add_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
- GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
+ GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
+ GtkRecentActionPrivate *priv = action->priv;
if (priv->current_filter != filter)
set_current_filter (GTK_RECENT_ACTION (chooser), filter);
gtk_recent_action_remove_filter (GtkRecentChooser *chooser,
GtkRecentFilter *filter)
{
- GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
+ GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
+ GtkRecentActionPrivate *priv = action->priv;
if (priv->current_filter == filter)
set_current_filter (GTK_RECENT_ACTION (chooser), NULL);
static GSList *
gtk_recent_action_list_filters (GtkRecentChooser *chooser)
{
+ GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
+ GtkRecentActionPrivate *priv = action->priv;
GSList *retval = NULL;
GtkRecentFilter *current_filter;
- current_filter = GTK_RECENT_ACTION_GET_PRIVATE (chooser)->current_filter;
+ current_filter = priv->current_filter;
retval = g_slist_prepend (retval, current_filter);
return retval;
static void
gtk_recent_action_activate (GtkAction *action)
{
+ GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
+ GtkRecentActionPrivate *priv = recent_action->priv;
+
/* we have probably been invoked by a menu tool button or by a
* direct call of gtk_action_activate(); since no item has been
* selected, we must unset the current recent chooser pointer
*/
- GTK_RECENT_ACTION_GET_PRIVATE (action)->current_chooser = NULL;
+ priv->current_chooser = NULL;
}
static void
GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
GtkRecentActionPrivate *priv = recent_action->priv;
+ /* it can only be a recent chooser implementor anyway... */
if (GTK_IS_RECENT_CHOOSER (widget) &&
!g_slist_find (priv->choosers, widget))
{
- g_object_set (G_OBJECT (widget),
- "show-private", priv->show_private,
- "show-not-found", priv->show_not_found,
- "show-tips", priv->show_tips,
- "show-icons", priv->show_icons,
- "show-numbers", priv->show_numbers,
- "limit", priv->limit,
- "sort-type", priv->sort_type,
- "filter", priv->current_filter,
- "local-only", priv->local_only,
- NULL);
-
if (priv->sort_func)
{
gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
action);
}
- GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
+ if (GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy)
+ GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
}
static void
if (g_slist_find (priv->choosers, widget))
priv->choosers = g_slist_remove (priv->choosers, widget);
- GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy (action, widget);
+ if (GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy)
+ GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy (action, widget);
}
static GtkWidget *
return toolitem;
}
-static void
-manager_changed_cb (GtkRecentManager *manager,
- gpointer user_data)
-{
- /* do we need to propagate the signal to all the proxies? guess not */
-}
-
static void
set_recent_manager (GtkRecentAction *action,
GtkRecentManager *manager)
{
GtkRecentActionPrivate *priv = action->priv;
- if (priv->manager)
- {
- if (priv->manager_changed_id)
- {
- g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
- priv->manager_changed_id = 0;
- }
-
- priv->manager = NULL;
- }
-
if (manager)
priv->manager = NULL;
else
priv->manager = gtk_recent_manager_get_default ();
-
- if (priv->manager)
- priv->manager_changed_id = g_signal_connect (priv->manager, "changed",
- G_CALLBACK (manager_changed_cb),
- action);
}
static void
GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
GtkRecentActionPrivate *priv = action->priv;
- if (priv->manager_changed_id)
- {
- if (priv->manager)
- g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
-
- priv->manager_changed_id = 0;
- }
-
if (priv->current_filter)
{
g_object_unref (priv->current_filter);
{
GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
GtkRecentActionPrivate *priv = action->priv;
- GSList *l;
switch (prop_id)
{
priv->sort_type = g_value_get_enum (value);
break;
case GTK_RECENT_CHOOSER_PROP_FILTER:
- /* this already iterates over the choosers list */
set_current_filter (action, g_value_get_object (value));
- return;
+ 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 (gobject));
return;
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
- /* this is a construct-only property; we set the recent-manager
- * of the choosers with this value when we create them, so there's
- * no need to iterate later.
- */
set_recent_manager (action, g_value_get_object (value));
- return;
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
return;
}
-
- /* propagate the properties to the proxies we have created */
- for (l = priv->choosers; l != NULL; l = l->next)
- {
- GObject *proxy = l->data;
-
- g_object_set_property (proxy, pspec->name, value);
- }
}
static void
GValue *value,
GParamSpec *pspec)
{
- GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (gobject);
+ GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
+ GtkRecentActionPrivate *priv = action->priv;
switch (prop_id)
{
{
GtkRecentActionPrivate *priv;
- action->priv = priv = GTK_RECENT_ACTION_GET_PRIVATE (action);
+ action->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (action,
+ GTK_TYPE_RECENT_ACTION,
+ GtkRecentActionPrivate);
priv->show_numbers = FALSE;
priv->show_icons = TRUE;
priv->current_filter = NULL;
priv->manager = NULL;
- priv->manager_changed_id = 0;
}
/**
* gtk_recent_action_new:
* @name: a unique name for the action
- * @label: the label displayed in menu items and on buttons, or %NULL
- * @tooltip: a tooltip for the action, or %NULL
+ * @label: (allow-none): the label displayed in menu items and on buttons, or %NULL
+ * @tooltip: (allow-none): a tooltip for the action, or %NULL
* @stock_id: the stock icon to display in widgets representing the
* action, or %NULL
*
/**
* gtk_recent_action_new_for_manager:
* @name: a unique name for the action
- * @label: the label displayed in menu items and on buttons, or %NULL
- * @tooltip: a tooltip for the action, or %NULL
+ * @label: (allow-none): the label displayed in menu items and on buttons, or %NULL
+ * @tooltip: (allow-none): a tooltip for the action, or %NULL
* @stock_id: the stock icon to display in widgets representing the
* action, or %NULL
- * @manager: a #GtkRecentManager, or %NULL for using the default
+ * @manager: (allow-none): a #GtkRecentManager, or %NULL for using the default
* #GtkRecentManager
*
* Creates a new #GtkRecentAction object. To add the action to
g_object_unref (action);
}
}
-
-#define __GTK_RECENT_ACTION_C__
-#include "gtkaliasdef.c"