2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* gtkrecentchoosermenu.c - Recently used items menu widget
|
|
|
|
|
* Copyright (C) 2005, Emmanuele Bassi
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2006-03-29 21:01:36 +00:00
|
|
|
|
#include "gtkrecentmanager.h"
|
|
|
|
|
#include "gtkrecentfilter.h"
|
|
|
|
|
#include "gtkrecentchooser.h"
|
|
|
|
|
#include "gtkrecentchooserutils.h"
|
|
|
|
|
#include "gtkrecentchooserprivate.h"
|
|
|
|
|
#include "gtkrecentchoosermenu.h"
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtksettings.h"
|
|
|
|
|
#include "gtkmenushell.h"
|
|
|
|
|
#include "gtkmenuitem.h"
|
2013-07-20 00:29:11 +00:00
|
|
|
|
#include "deprecated/gtkimagemenuitem.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtkseparatormenuitem.h"
|
|
|
|
|
#include "gtkmenu.h"
|
|
|
|
|
#include "gtkimage.h"
|
2007-01-15 12:44:28 +00:00
|
|
|
|
#include "gtklabel.h"
|
2007-07-23 16:44:07 +00:00
|
|
|
|
#include "gtktooltip.h"
|
2013-07-20 00:29:11 +00:00
|
|
|
|
#include "deprecated/gtkactivatable.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtktypebuiltins.h"
|
2007-03-14 10:33:36 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2010-05-21 01:19:02 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkrecentchoosermenu
|
|
|
|
|
* @Short_description: Displays recently used files in a menu
|
|
|
|
|
* @Title: GtkRecentChooserMenu
|
|
|
|
|
* @See_also:#GtkRecentChooser
|
|
|
|
|
*
|
|
|
|
|
* #GtkRecentChooserMenu is a widget suitable for displaying recently used files
|
|
|
|
|
* inside a menu. It can be used to set a sub-menu of a #GtkMenuItem using
|
|
|
|
|
* gtk_menu_item_set_submenu(), or as the menu of a #GtkMenuToolButton.
|
|
|
|
|
*
|
|
|
|
|
* Note that #GtkRecentChooserMenu does not have any methods of its own. Instead,
|
|
|
|
|
* you should use the functions that work on a #GtkRecentChooser.
|
|
|
|
|
*
|
|
|
|
|
* Note also that #GtkRecentChooserMenu does not support multiple filters, as it
|
|
|
|
|
* has no way to let the user choose between them as the #GtkRecentChooserWidget
|
|
|
|
|
* and #GtkRecentChooserDialog widgets do. Thus using gtk_recent_chooser_add_filter()
|
|
|
|
|
* on a #GtkRecentChooserMenu widget will yield the same effects as using
|
|
|
|
|
* gtk_recent_chooser_set_filter(), replacing any currently set filter
|
|
|
|
|
* with the supplied filter; gtk_recent_chooser_remove_filter() will remove
|
|
|
|
|
* any currently set #GtkRecentFilter object and will unset the current filter;
|
|
|
|
|
* gtk_recent_chooser_list_filters() will return a list containing a single
|
|
|
|
|
* #GtkRecentFilter object.
|
|
|
|
|
*
|
|
|
|
|
* Recently used files are supported since GTK+ 2.10.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
struct _GtkRecentChooserMenuPrivate
|
|
|
|
|
{
|
|
|
|
|
/* the recent manager object */
|
|
|
|
|
GtkRecentManager *manager;
|
|
|
|
|
|
2007-01-15 12:44:28 +00:00
|
|
|
|
/* max size of the menu item label */
|
|
|
|
|
gint label_width;
|
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
gint first_recent_item_pos;
|
|
|
|
|
GtkWidget *placeholder;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* RecentChooser properties */
|
|
|
|
|
gint limit;
|
|
|
|
|
guint show_private : 1;
|
|
|
|
|
guint show_not_found : 1;
|
|
|
|
|
guint show_tips : 1;
|
|
|
|
|
guint show_icons : 1;
|
|
|
|
|
guint local_only : 1;
|
|
|
|
|
|
|
|
|
|
guint show_numbers : 1;
|
|
|
|
|
|
|
|
|
|
GtkRecentSortType sort_type;
|
|
|
|
|
GtkRecentSortFunc sort_func;
|
|
|
|
|
gpointer sort_data;
|
|
|
|
|
GDestroyNotify sort_data_destroy;
|
|
|
|
|
|
|
|
|
|
GSList *filters;
|
|
|
|
|
GtkRecentFilter *current_filter;
|
|
|
|
|
|
|
|
|
|
guint local_manager : 1;
|
|
|
|
|
gulong manager_changed_id;
|
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
gulong populate_id;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
2009-01-23 15:15:28 +00:00
|
|
|
|
PROP_SHOW_NUMBERS,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
/* activatable properties */
|
|
|
|
|
PROP_ACTIVATABLE_RELATED_ACTION,
|
|
|
|
|
PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
|
2006-03-29 20:16:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#define FALLBACK_ITEM_LIMIT 10
|
2007-01-15 12:44:28 +00:00
|
|
|
|
#define DEFAULT_LABEL_WIDTH 30
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void gtk_recent_chooser_menu_finalize (GObject *object);
|
2006-12-31 16:35:00 +00:00
|
|
|
|
static void gtk_recent_chooser_menu_dispose (GObject *object);
|
2014-06-26 22:22:42 +00:00
|
|
|
|
static void gtk_recent_chooser_menu_constructed (GObject *object);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
|
|
|
|
|
|
|
|
|
|
static void gtk_recent_chooser_menu_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gtk_recent_chooser_menu_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
static gboolean gtk_recent_chooser_menu_set_current_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error);
|
|
|
|
|
static gchar * gtk_recent_chooser_menu_get_current_uri (GtkRecentChooser *chooser);
|
|
|
|
|
static gboolean gtk_recent_chooser_menu_select_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error);
|
|
|
|
|
static void gtk_recent_chooser_menu_unselect_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri);
|
|
|
|
|
static void gtk_recent_chooser_menu_select_all (GtkRecentChooser *chooser);
|
|
|
|
|
static void gtk_recent_chooser_menu_unselect_all (GtkRecentChooser *chooser);
|
|
|
|
|
static GList * gtk_recent_chooser_menu_get_items (GtkRecentChooser *chooser);
|
|
|
|
|
static GtkRecentManager *gtk_recent_chooser_menu_get_recent_manager (GtkRecentChooser *chooser);
|
|
|
|
|
static void gtk_recent_chooser_menu_set_sort_func (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentSortFunc sort_func,
|
|
|
|
|
gpointer sort_data,
|
|
|
|
|
GDestroyNotify data_destroy);
|
|
|
|
|
static void gtk_recent_chooser_menu_add_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter);
|
|
|
|
|
static void gtk_recent_chooser_menu_remove_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter);
|
|
|
|
|
static GSList * gtk_recent_chooser_menu_list_filters (GtkRecentChooser *chooser);
|
|
|
|
|
static void gtk_recent_chooser_menu_set_current_filter (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkRecentFilter *filter);
|
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
static void gtk_recent_chooser_menu_populate (GtkRecentChooserMenu *menu);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
|
|
|
|
|
gboolean show_tips);
|
|
|
|
|
|
|
|
|
|
static void set_recent_manager (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkRecentManager *manager);
|
|
|
|
|
|
|
|
|
|
static void item_activate_cb (GtkWidget *widget,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void manager_changed_cb (GtkRecentManager *manager,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
static void gtk_recent_chooser_activatable_iface_init (GtkActivatableIface *iface);
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void gtk_recent_chooser_update (GtkActivatable *activatable,
|
2009-01-23 15:15:28 +00:00
|
|
|
|
GtkAction *action,
|
|
|
|
|
const gchar *property_name);
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
|
2009-01-23 15:15:28 +00:00
|
|
|
|
GtkAction *action);
|
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserMenu,
|
|
|
|
|
gtk_recent_chooser_menu,
|
|
|
|
|
GTK_TYPE_MENU,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkRecentChooserMenu)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
|
2009-01-23 15:15:28 +00:00
|
|
|
|
gtk_recent_chooser_iface_init)
|
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
|
|
|
|
|
gtk_recent_chooser_activatable_iface_init))
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->set_current_uri = gtk_recent_chooser_menu_set_current_uri;
|
|
|
|
|
iface->get_current_uri = gtk_recent_chooser_menu_get_current_uri;
|
|
|
|
|
iface->select_uri = gtk_recent_chooser_menu_select_uri;
|
|
|
|
|
iface->unselect_uri = gtk_recent_chooser_menu_unselect_uri;
|
|
|
|
|
iface->select_all = gtk_recent_chooser_menu_select_all;
|
|
|
|
|
iface->unselect_all = gtk_recent_chooser_menu_unselect_all;
|
|
|
|
|
iface->get_items = gtk_recent_chooser_menu_get_items;
|
|
|
|
|
iface->get_recent_manager = gtk_recent_chooser_menu_get_recent_manager;
|
|
|
|
|
iface->set_sort_func = gtk_recent_chooser_menu_set_sort_func;
|
|
|
|
|
iface->add_filter = gtk_recent_chooser_menu_add_filter;
|
|
|
|
|
iface->remove_filter = gtk_recent_chooser_menu_remove_filter;
|
|
|
|
|
iface->list_filters = gtk_recent_chooser_menu_list_filters;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
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;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_class_init (GtkRecentChooserMenuClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2006-08-03 20:26:31 +00:00
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
gobject_class->constructed = gtk_recent_chooser_menu_constructed;
|
2006-12-31 16:35:00 +00:00
|
|
|
|
gobject_class->dispose = gtk_recent_chooser_menu_dispose;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gobject_class->finalize = gtk_recent_chooser_menu_finalize;
|
|
|
|
|
gobject_class->set_property = gtk_recent_chooser_menu_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_recent_chooser_menu_get_property;
|
|
|
|
|
|
|
|
|
|
_gtk_recent_chooser_install_properties (gobject_class);
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
|
* GtkRecentChooserMenu:show-numbers:
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Whether the first ten items in the menu should be prepended by
|
|
|
|
|
* a number acting as a unique mnemonic.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.10
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SHOW_NUMBERS,
|
|
|
|
|
g_param_spec_boolean ("show-numbers",
|
|
|
|
|
P_("Show Numbers"),
|
|
|
|
|
P_("Whether the items should be displayed with a number"),
|
|
|
|
|
FALSE,
|
2014-06-09 13:21:28 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
|
|
|
|
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");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_init (GtkRecentChooserMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv;
|
2010-07-07 23:56:13 +00:00
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
menu->priv = gtk_recent_chooser_menu_get_instance_private (menu);
|
2010-07-07 23:56:13 +00:00
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv->show_icons= TRUE;
|
|
|
|
|
priv->show_numbers = FALSE;
|
|
|
|
|
priv->show_tips = FALSE;
|
2006-08-06 23:44:46 +00:00
|
|
|
|
priv->show_not_found = TRUE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv->show_private = FALSE;
|
|
|
|
|
priv->local_only = TRUE;
|
|
|
|
|
|
|
|
|
|
priv->limit = FALLBACK_ITEM_LIMIT;
|
|
|
|
|
priv->sort_type = GTK_RECENT_SORT_NONE;
|
2007-01-15 12:44:28 +00:00
|
|
|
|
priv->label_width = DEFAULT_LABEL_WIDTH;
|
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
priv->first_recent_item_pos = -1;
|
|
|
|
|
priv->placeholder = NULL;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
priv->current_filter = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
priv->manager = NULL;
|
|
|
|
|
|
|
|
|
|
if (priv->sort_data_destroy)
|
|
|
|
|
{
|
|
|
|
|
priv->sort_data_destroy (priv->sort_data);
|
|
|
|
|
priv->sort_data_destroy = NULL;
|
|
|
|
|
}
|
2006-12-31 16:35:00 +00:00
|
|
|
|
|
|
|
|
|
priv->sort_data = NULL;
|
|
|
|
|
priv->sort_func = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-12-31 16:35:00 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->manager_changed_id)
|
|
|
|
|
{
|
2006-12-31 16:54:56 +00:00
|
|
|
|
if (priv->manager)
|
|
|
|
|
g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
|
|
|
|
|
|
2006-12-31 16:35:00 +00:00
|
|
|
|
priv->manager_changed_id = 0;
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-12-31 16:35:00 +00:00
|
|
|
|
if (priv->populate_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (priv->populate_id);
|
|
|
|
|
priv->populate_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (priv->current_filter)
|
2006-12-31 16:35:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_object_unref (priv->current_filter);
|
|
|
|
|
priv->current_filter = NULL;
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-12-31 16:35:00 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->dispose (object);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_constructed (GObject *object)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2014-06-26 22:22:42 +00:00
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->constructed (object);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
g_assert (priv->manager);
|
|
|
|
|
|
2007-02-10 12:14:39 +00:00
|
|
|
|
/* we create a placeholder menuitem, to be used in case
|
|
|
|
|
* the menu is empty. this placeholder will stay around
|
2007-02-09 14:24:19 +00:00
|
|
|
|
* for the entire lifetime of the menu, and we just hide it
|
|
|
|
|
* when it's not used. we have to do this, and do it here,
|
|
|
|
|
* because we need a marker for the beginning of the recent
|
|
|
|
|
* items list, so that we can insert the new items at the
|
2007-02-10 12:14:39 +00:00
|
|
|
|
* right place when idly populating the menu in case the
|
|
|
|
|
* user appended or prepended custom menu items to the
|
|
|
|
|
* recent chooser menu widget.
|
2007-02-09 14:24:19 +00:00
|
|
|
|
*/
|
|
|
|
|
priv->placeholder = gtk_menu_item_new_with_label (_("No items found"));
|
|
|
|
|
gtk_widget_set_sensitive (priv->placeholder, FALSE);
|
|
|
|
|
g_object_set_data (G_OBJECT (priv->placeholder),
|
|
|
|
|
"gtk-recent-menu-placeholder",
|
|
|
|
|
GINT_TO_POINTER (TRUE));
|
|
|
|
|
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), priv->placeholder, 0);
|
2008-02-11 09:54:09 +00:00
|
|
|
|
gtk_widget_set_no_show_all (priv->placeholder, TRUE);
|
2007-02-09 14:24:19 +00:00
|
|
|
|
gtk_widget_show (priv->placeholder);
|
|
|
|
|
|
|
|
|
|
/* (re)populate the menu */
|
|
|
|
|
gtk_recent_chooser_menu_populate (menu);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
|
2007-03-14 10:33:36 +00:00
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SHOW_NUMBERS:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->show_numbers != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
priv->show_numbers = g_value_get_boolean (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
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:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->show_private != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
priv->show_private = g_value_get_boolean (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->show_not_found != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
priv->show_not_found = g_value_get_boolean (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
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:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->show_icons != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
priv->show_icons = g_value_get_boolean (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
|
2006-07-06 05:14:03 +00:00
|
|
|
|
g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
|
2006-03-29 20:16:44 +00:00
|
|
|
|
G_STRFUNC,
|
|
|
|
|
G_OBJECT_TYPE_NAME (object));
|
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->local_only != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
priv->local_only = g_value_get_boolean (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LIMIT:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->limit != g_value_get_int (value))
|
|
|
|
|
{
|
|
|
|
|
priv->limit = g_value_get_int (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
|
2014-06-09 13:21:28 +00:00
|
|
|
|
if (priv->sort_type != g_value_get_enum (value))
|
|
|
|
|
{
|
|
|
|
|
priv->sort_type = g_value_get_enum (value);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_FILTER:
|
|
|
|
|
gtk_recent_chooser_menu_set_current_filter (menu, g_value_get_object (value));
|
|
|
|
|
break;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
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;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
|
2007-03-14 10:33:36 +00:00
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SHOW_NUMBERS:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_boolean (value, priv->show_numbers);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_boolean (value, priv->show_tips);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LIMIT:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_int (value, priv->limit);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_boolean (value, priv->local_only);
|
2006-04-01 00:28:27 +00:00
|
|
|
|
break;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_enum (value, priv->sort_type);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_boolean (value, priv->show_private);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_boolean (value, priv->show_not_found);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_boolean (value, priv->show_icons);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
|
2007-09-14 09:51:34 +00:00
|
|
|
|
g_value_set_boolean (value, FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_FILTER:
|
2007-03-14 10:33:36 +00:00
|
|
|
|
g_value_set_object (value, priv->current_filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
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;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_recent_chooser_menu_set_current_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
GtkWidget *menu_item = NULL;
|
|
|
|
|
gboolean found = FALSE;
|
2014-04-28 17:46:48 +00:00
|
|
|
|
gint i = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
2007-03-14 10:33:36 +00:00
|
|
|
|
|
2014-04-28 17:46:48 +00:00
|
|
|
|
for (l = children; l != NULL; l = l->next, i++)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
|
|
|
|
|
menu_item = GTK_WIDGET (l->data);
|
|
|
|
|
|
|
|
|
|
info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
|
|
|
|
|
if (!info)
|
|
|
|
|
continue;
|
|
|
|
|
|
2006-08-29 18:38:59 +00:00
|
|
|
|
if (strcmp (uri, gtk_recent_info_get_uri (info)) == 0)
|
|
|
|
|
{
|
2014-04-28 17:46:48 +00:00
|
|
|
|
gtk_menu_set_active (GTK_MENU (menu), i);
|
2006-08-29 18:38:59 +00:00
|
|
|
|
found = TRUE;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
|
|
|
|
|
GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
|
2014-08-22 15:08:52 +00:00
|
|
|
|
_("No recently used resource found with URI '%s'"),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
uri);
|
|
|
|
|
}
|
2006-08-29 18:38:59 +00:00
|
|
|
|
|
|
|
|
|
return found;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
|
gtk_recent_chooser_menu_get_current_uri (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
GtkWidget *menu_item;
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
|
|
|
|
|
menu_item = gtk_menu_get_active (GTK_MENU (menu));
|
|
|
|
|
if (!menu_item)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
|
|
|
|
|
if (!info)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return g_strdup (gtk_recent_info_get_uri (info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_recent_chooser_menu_select_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
GtkWidget *menu_item = NULL;
|
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
for (l = children; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
|
|
|
|
|
menu_item = GTK_WIDGET (l->data);
|
|
|
|
|
|
|
|
|
|
info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
|
|
|
|
|
if (!info)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (0 == strcmp (uri, gtk_recent_info_get_uri (info)))
|
|
|
|
|
found = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
|
|
|
|
|
GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
|
2014-08-22 15:08:52 +00:00
|
|
|
|
_("No recently used resource found with URI '%s'"),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_menu_shell_select_item (GTK_MENU_SHELL (menu), menu_item);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_unselect_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
|
|
|
|
|
gtk_menu_shell_deselect (GTK_MENU_SHELL (menu));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_select_all (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
2011-04-29 14:32:56 +00:00
|
|
|
|
g_warning ("This function is not implemented for "
|
|
|
|
|
"widgets of class '%s'",
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_type_name (G_OBJECT_TYPE (chooser)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_unselect_all (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
2011-04-29 14:32:56 +00:00
|
|
|
|
g_warning ("This function is not implemented for "
|
|
|
|
|
"widgets of class '%s'",
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_type_name (G_OBJECT_TYPE (chooser)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_set_sort_func (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentSortFunc sort_func,
|
|
|
|
|
gpointer sort_data,
|
|
|
|
|
GDestroyNotify data_destroy)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->sort_data_destroy)
|
|
|
|
|
{
|
|
|
|
|
priv->sort_data_destroy (priv->sort_data);
|
|
|
|
|
priv->sort_data_destroy = NULL;
|
|
|
|
|
}
|
2007-03-14 10:33:36 +00:00
|
|
|
|
|
|
|
|
|
priv->sort_func = NULL;
|
|
|
|
|
priv->sort_data = NULL;
|
|
|
|
|
priv->sort_data_destroy = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (sort_func)
|
|
|
|
|
{
|
|
|
|
|
priv->sort_func = sort_func;
|
|
|
|
|
priv->sort_data = sort_data;
|
|
|
|
|
priv->sort_data_destroy = data_destroy;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
|
gtk_recent_chooser_menu_get_items (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
2007-03-14 10:33:36 +00:00
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
2006-08-06 23:44:46 +00:00
|
|
|
|
|
2007-03-14 10:33:36 +00:00
|
|
|
|
return _gtk_recent_chooser_get_items (chooser,
|
2007-03-15 10:05:34 +00:00
|
|
|
|
priv->current_filter,
|
2007-03-14 10:33:36 +00:00
|
|
|
|
priv->sort_func,
|
|
|
|
|
priv->sort_data);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkRecentManager *
|
|
|
|
|
gtk_recent_chooser_menu_get_recent_manager (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
priv = GTK_RECENT_CHOOSER_MENU (chooser)->priv;
|
|
|
|
|
|
|
|
|
|
return priv->manager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_add_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter)
|
|
|
|
|
{
|
2006-08-14 20:58:21 +00:00
|
|
|
|
GtkRecentChooserMenu *menu;
|
|
|
|
|
|
|
|
|
|
menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
|
|
|
|
|
gtk_recent_chooser_menu_set_current_filter (menu, filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_remove_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter)
|
|
|
|
|
{
|
2006-08-14 20:58:21 +00:00
|
|
|
|
GtkRecentChooserMenu *menu;
|
|
|
|
|
|
|
|
|
|
menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
|
|
|
|
|
if (filter == menu->priv->current_filter)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (menu->priv->current_filter);
|
|
|
|
|
menu->priv->current_filter = NULL;
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (menu), "filter");
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GSList *
|
2006-08-18 02:41:52 +00:00
|
|
|
|
gtk_recent_chooser_menu_list_filters (GtkRecentChooser *chooser)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2006-08-14 20:58:21 +00:00
|
|
|
|
GtkRecentChooserMenu *menu;
|
|
|
|
|
GSList *retval = NULL;
|
|
|
|
|
|
2006-08-18 02:41:52 +00:00
|
|
|
|
menu = GTK_RECENT_CHOOSER_MENU (chooser);
|
|
|
|
|
|
2006-08-14 20:58:21 +00:00
|
|
|
|
if (menu->priv->current_filter)
|
|
|
|
|
retval = g_slist_prepend (retval, menu->priv->current_filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-08-14 20:58:21 +00:00
|
|
|
|
return retval;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_set_current_filter (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkRecentFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv;
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->current_filter)
|
|
|
|
|
g_object_unref (G_OBJECT (priv->current_filter));
|
|
|
|
|
|
2011-02-04 15:58:40 +00:00
|
|
|
|
priv->current_filter = filter;
|
|
|
|
|
|
|
|
|
|
if (priv->current_filter)
|
|
|
|
|
g_object_ref_sink (priv->current_filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2007-03-15 10:05:34 +00:00
|
|
|
|
gtk_recent_chooser_menu_populate (menu);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2007-03-15 10:05:34 +00:00
|
|
|
|
g_object_notify (G_OBJECT (menu), "filter");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* taken from libeel/eel-strings.c */
|
|
|
|
|
static gchar *
|
|
|
|
|
escape_underscores (const gchar *string)
|
|
|
|
|
{
|
|
|
|
|
gint underscores;
|
|
|
|
|
const gchar *p;
|
|
|
|
|
gchar *q;
|
|
|
|
|
gchar *escaped;
|
|
|
|
|
|
|
|
|
|
if (!string)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
underscores = 0;
|
|
|
|
|
for (p = string; *p != '\0'; p++)
|
|
|
|
|
underscores += (*p == '_');
|
|
|
|
|
|
|
|
|
|
if (underscores == 0)
|
|
|
|
|
return g_strdup (string);
|
|
|
|
|
|
|
|
|
|
escaped = g_new (char, strlen (string) + underscores + 1);
|
|
|
|
|
for (p = string, q = escaped; *p != '\0'; p++, q++)
|
|
|
|
|
{
|
|
|
|
|
/* Add an extra underscore. */
|
|
|
|
|
if (*p == '_')
|
|
|
|
|
*q++ = '_';
|
|
|
|
|
|
|
|
|
|
*q = *p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*q = '\0';
|
|
|
|
|
|
|
|
|
|
return escaped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_add_tip (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkRecentInfo *info,
|
|
|
|
|
GtkWidget *item)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv;
|
2007-07-23 16:44:07 +00:00
|
|
|
|
gchar *path;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_assert (info != NULL);
|
|
|
|
|
g_assert (item != NULL);
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
path = gtk_recent_info_get_uri_display (info);
|
2006-11-16 10:10:44 +00:00
|
|
|
|
if (path)
|
|
|
|
|
{
|
2007-07-23 16:44:07 +00:00
|
|
|
|
gchar *tip_text = g_strdup_printf (_("Open '%s'"), path);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2007-07-23 16:44:07 +00:00
|
|
|
|
gtk_widget_set_tooltip_text (item, tip_text);
|
|
|
|
|
gtk_widget_set_has_tooltip (item, priv->show_tips);
|
2006-11-16 10:10:44 +00:00
|
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
g_free (tip_text);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
|
gtk_recent_chooser_menu_create_item (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkRecentInfo *info,
|
|
|
|
|
gint count)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv;
|
2007-01-15 12:44:28 +00:00
|
|
|
|
gchar *text;
|
|
|
|
|
GtkWidget *item, *image, *label;
|
2010-04-29 13:23:44 +00:00
|
|
|
|
GIcon *icon;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_assert (info != NULL);
|
|
|
|
|
|
|
|
|
|
priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->show_numbers)
|
|
|
|
|
{
|
|
|
|
|
gchar *name, *escaped;
|
|
|
|
|
|
|
|
|
|
name = g_strdup (gtk_recent_info_get_display_name (info));
|
|
|
|
|
if (!name)
|
|
|
|
|
name = g_strdup (_("Unknown item"));
|
|
|
|
|
|
|
|
|
|
escaped = escape_underscores (name);
|
|
|
|
|
|
|
|
|
|
/* avoid clashing mnemonics */
|
|
|
|
|
if (count <= 10)
|
2008-10-27 01:42:28 +00:00
|
|
|
|
/* This is the label format that is used for the first 10 items
|
2007-07-13 16:34:05 +00:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2008-10-27 01:42:28 +00:00
|
|
|
|
text = g_strdup_printf (C_("recent menu label", "_%d. %s"), count, escaped);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
2008-10-27 01:42:28 +00:00
|
|
|
|
/* 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.
|
2007-07-13 16:34:05 +00:00
|
|
|
|
*/
|
2008-10-27 01:42:28 +00:00
|
|
|
|
text = g_strdup_printf (C_("recent menu label", "%d. %s"), count, escaped);
|
2013-06-27 22:48:46 +00:00
|
|
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2007-01-15 12:44:28 +00:00
|
|
|
|
item = gtk_image_menu_item_new_with_mnemonic (text);
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_free (escaped);
|
|
|
|
|
g_free (name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-01-15 12:44:28 +00:00
|
|
|
|
text = g_strdup (gtk_recent_info_get_display_name (info));
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2007-01-15 12:44:28 +00:00
|
|
|
|
item = gtk_image_menu_item_new_with_label (text);
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2007-01-15 12:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
|
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2009-01-31 02:17:00 +00:00
|
|
|
|
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item),
|
|
|
|
|
TRUE);
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2009-01-31 02:17:00 +00:00
|
|
|
|
|
2007-01-15 12:44:28 +00:00
|
|
|
|
/* ellipsize the menu item label, in case the recent document
|
|
|
|
|
* display name is huge.
|
|
|
|
|
*/
|
2010-05-24 20:31:36 +00:00
|
|
|
|
label = gtk_bin_get_child (GTK_BIN (item));
|
2007-03-14 10:33:36 +00:00
|
|
|
|
if (GTK_IS_LABEL (label))
|
2007-01-15 12:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
|
|
|
|
gtk_label_set_max_width_chars (GTK_LABEL (label), priv->label_width);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (priv->show_icons)
|
|
|
|
|
{
|
2010-04-29 13:23:44 +00:00
|
|
|
|
icon = gtk_recent_info_get_gicon (info);
|
|
|
|
|
|
|
|
|
|
image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
|
2010-04-29 13:23:44 +00:00
|
|
|
|
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
|
2013-06-27 22:48:46 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-04-29 13:23:44 +00:00
|
|
|
|
if (icon)
|
|
|
|
|
g_object_unref (icon);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
2006-08-06 23:44:46 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (item_activate_cb),
|
|
|
|
|
menu);
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_insert_item (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkWidget *menuitem,
|
|
|
|
|
gint position)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
gint real_position;
|
|
|
|
|
|
|
|
|
|
if (priv->first_recent_item_pos == -1)
|
|
|
|
|
{
|
2007-02-10 12:14:39 +00:00
|
|
|
|
GList *children, *l;
|
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
2007-02-10 12:14:39 +00:00
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
for (real_position = 0, l = children;
|
|
|
|
|
l != NULL;
|
|
|
|
|
real_position += 1, l = l->next)
|
|
|
|
|
{
|
2007-02-10 12:14:39 +00:00
|
|
|
|
GObject *child = l->data;
|
|
|
|
|
gboolean is_placeholder = FALSE;
|
2007-02-09 14:24:19 +00:00
|
|
|
|
|
2007-02-10 12:14:39 +00:00
|
|
|
|
is_placeholder =
|
|
|
|
|
GPOINTER_TO_INT (g_object_get_data (child, "gtk-recent-menu-placeholder"));
|
|
|
|
|
|
|
|
|
|
if (is_placeholder)
|
2007-02-09 14:24:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-02-10 12:14:39 +00:00
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
g_list_free (children);
|
|
|
|
|
priv->first_recent_item_pos = real_position;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
real_position = priv->first_recent_item_pos;
|
|
|
|
|
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem,
|
|
|
|
|
real_position + position);
|
|
|
|
|
gtk_widget_show (menuitem);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* removes the items we own from the menu */
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_dispose_items (GtkRecentChooserMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GList *children, *l;
|
|
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (menu));
|
|
|
|
|
for (l = children; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *menu_item = GTK_WIDGET (l->data);
|
2007-02-10 12:14:39 +00:00
|
|
|
|
gboolean has_mark = FALSE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* check for our mark, in order to remove just the items we own */
|
2007-02-10 12:14:39 +00:00
|
|
|
|
has_mark =
|
|
|
|
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "gtk-recent-menu-mark"));
|
|
|
|
|
|
|
|
|
|
if (has_mark)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
|
|
|
|
|
/* destroy the attached RecentInfo struct, if found */
|
|
|
|
|
info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
|
|
|
|
|
if (info)
|
|
|
|
|
g_object_set_data_full (G_OBJECT (menu_item), "gtk-recent-info",
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* and finally remove the item from the menu */
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (menu), menu_item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
/* recalculate the position of the first recent item */
|
|
|
|
|
menu->priv->first_recent_item_pos = -1;
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_list_free (children);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
typedef struct
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2006-08-03 20:26:31 +00:00
|
|
|
|
GList *items;
|
|
|
|
|
gint n_items;
|
|
|
|
|
gint loaded_items;
|
2007-02-08 14:22:20 +00:00
|
|
|
|
gint displayed_items;
|
2006-08-03 20:26:31 +00:00
|
|
|
|
GtkRecentChooserMenu *menu;
|
2007-07-04 07:41:57 +00:00
|
|
|
|
GtkWidget *placeholder;
|
2006-08-03 20:26:31 +00:00
|
|
|
|
} MenuPopulateData;
|
|
|
|
|
|
2011-04-06 02:43:09 +00:00
|
|
|
|
static MenuPopulateData *
|
|
|
|
|
create_menu_populate_data (GtkRecentChooserMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
MenuPopulateData *pdata;
|
|
|
|
|
|
|
|
|
|
pdata = g_slice_new (MenuPopulateData);
|
|
|
|
|
pdata->items = NULL;
|
|
|
|
|
pdata->n_items = 0;
|
|
|
|
|
pdata->loaded_items = 0;
|
|
|
|
|
pdata->displayed_items = 0;
|
|
|
|
|
pdata->menu = menu;
|
|
|
|
|
pdata->placeholder = g_object_ref (menu->priv->placeholder);
|
|
|
|
|
|
|
|
|
|
return pdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_menu_populate_data (MenuPopulateData *pdata)
|
|
|
|
|
{
|
|
|
|
|
if (pdata->placeholder)
|
|
|
|
|
g_object_unref (pdata->placeholder);
|
|
|
|
|
g_slice_free (MenuPopulateData, pdata);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
idle_populate_func (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
MenuPopulateData *pdata;
|
|
|
|
|
GtkRecentChooserMenuPrivate *priv;
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
gboolean retval;
|
|
|
|
|
GtkWidget *item;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
pdata = (MenuPopulateData *) data;
|
2006-08-10 12:08:51 +00:00
|
|
|
|
priv = pdata->menu->priv;
|
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
if (!pdata->items)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2006-08-03 20:26:31 +00:00
|
|
|
|
pdata->items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (pdata->menu));
|
|
|
|
|
if (!pdata->items)
|
|
|
|
|
{
|
2007-02-09 14:24:19 +00:00
|
|
|
|
/* show the placeholder here */
|
2007-07-04 07:41:57 +00:00
|
|
|
|
gtk_widget_show (pdata->placeholder);
|
2007-02-08 14:22:20 +00:00
|
|
|
|
pdata->displayed_items = 1;
|
2008-01-10 14:27:54 +00:00
|
|
|
|
priv->populate_id = 0;
|
2007-02-08 14:22:20 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2009-01-26 03:01:01 +00:00
|
|
|
|
else
|
|
|
|
|
gtk_widget_hide (pdata->placeholder);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
pdata->n_items = g_list_length (pdata->items);
|
|
|
|
|
pdata->loaded_items = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = g_list_nth_data (pdata->items, pdata->loaded_items);
|
|
|
|
|
item = gtk_recent_chooser_menu_create_item (pdata->menu,
|
|
|
|
|
info,
|
2007-02-08 14:22:20 +00:00
|
|
|
|
pdata->displayed_items);
|
2006-08-03 20:26:31 +00:00
|
|
|
|
if (!item)
|
|
|
|
|
goto check_and_return;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
gtk_recent_chooser_menu_add_tip (pdata->menu, info, item);
|
2007-02-09 14:24:19 +00:00
|
|
|
|
gtk_recent_chooser_menu_insert_item (pdata->menu, item,
|
|
|
|
|
pdata->displayed_items);
|
|
|
|
|
|
2007-02-08 14:22:20 +00:00
|
|
|
|
pdata->displayed_items += 1;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
/* mark the menu item as one of our own */
|
2007-02-10 12:14:39 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (item),
|
|
|
|
|
"gtk-recent-menu-mark",
|
|
|
|
|
GINT_TO_POINTER (TRUE));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
/* attach the RecentInfo object to the menu item, and own a reference
|
|
|
|
|
* to it, so that it will be destroyed with the menu item when it's
|
|
|
|
|
* not needed anymore.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*/
|
2006-08-03 20:26:31 +00:00
|
|
|
|
g_object_set_data_full (G_OBJECT (item), "gtk-recent-info",
|
|
|
|
|
gtk_recent_info_ref (info),
|
|
|
|
|
(GDestroyNotify) gtk_recent_info_unref);
|
2006-08-06 23:44:46 +00:00
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
check_and_return:
|
|
|
|
|
pdata->loaded_items += 1;
|
|
|
|
|
|
|
|
|
|
if (pdata->loaded_items == pdata->n_items)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2012-01-02 03:20:59 +00:00
|
|
|
|
g_list_free_full (pdata->items, (GDestroyNotify) gtk_recent_info_unref);
|
2006-08-03 20:26:31 +00:00
|
|
|
|
|
2008-01-10 14:27:54 +00:00
|
|
|
|
priv->populate_id = 0;
|
|
|
|
|
|
2006-08-03 20:26:31 +00:00
|
|
|
|
retval = FALSE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
2006-08-03 20:26:31 +00:00
|
|
|
|
else
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
idle_populate_clean_up (gpointer data)
|
|
|
|
|
{
|
2007-02-08 14:22:20 +00:00
|
|
|
|
MenuPopulateData *pdata = data;
|
|
|
|
|
|
2008-01-10 14:27:54 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2011-04-06 02:43:09 +00:00
|
|
|
|
|
|
|
|
|
free_menu_populate_data (pdata);
|
2006-08-03 20:26:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_populate (GtkRecentChooserMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
MenuPopulateData *pdata;
|
2007-02-09 14:24:19 +00:00
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
2006-08-03 20:26:31 +00:00
|
|
|
|
|
2011-04-06 02:43:09 +00:00
|
|
|
|
if (priv->populate_id)
|
2006-08-03 20:26:31 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2011-04-06 02:43:09 +00:00
|
|
|
|
pdata = create_menu_populate_data (menu);
|
2006-08-03 20:26:31 +00:00
|
|
|
|
|
2009-01-26 03:01:01 +00:00
|
|
|
|
/* remove our menu items first */
|
2006-08-03 20:26:31 +00:00
|
|
|
|
gtk_recent_chooser_menu_dispose_items (menu);
|
2011-04-06 02:43:09 +00:00
|
|
|
|
|
2007-02-09 14:24:19 +00:00
|
|
|
|
priv->populate_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
|
|
|
|
|
idle_populate_func,
|
|
|
|
|
pdata,
|
|
|
|
|
idle_populate_clean_up);
|
2014-03-22 11:44:01 +00:00
|
|
|
|
g_source_set_name_by_id (priv->populate_id, "[gtk+] idle_populate_func");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* bounce activate signal from the recent menu item widget
|
|
|
|
|
* to the recent menu widget
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
item_activate_cb (GtkWidget *widget,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooser *chooser = GTK_RECENT_CHOOSER (user_data);
|
2014-04-28 17:46:48 +00:00
|
|
|
|
GtkRecentInfo *info = g_object_get_data (G_OBJECT (widget), "gtk-recent-info");
|
|
|
|
|
|
|
|
|
|
gtk_recent_chooser_menu_set_current_uri (chooser, gtk_recent_info_get_uri (info), NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
_gtk_recent_chooser_item_activated (chooser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we force a redraw if the manager changes when we are showing */
|
|
|
|
|
static void
|
|
|
|
|
manager_changed_cb (GtkRecentManager *manager,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2006-08-03 20:26:31 +00:00
|
|
|
|
GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (user_data);
|
|
|
|
|
|
|
|
|
|
gtk_recent_chooser_menu_populate (menu);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_recent_manager (GtkRecentChooserMenu *menu,
|
|
|
|
|
GtkRecentManager *manager)
|
|
|
|
|
{
|
2006-12-31 16:54:56 +00:00
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->manager)
|
2006-08-03 20:26:31 +00:00
|
|
|
|
{
|
2006-12-31 16:54:56 +00:00
|
|
|
|
if (priv->manager_changed_id)
|
2007-02-09 14:24:19 +00:00
|
|
|
|
{
|
|
|
|
|
g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
|
|
|
|
|
priv->manager_changed_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (priv->populate_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (priv->populate_id);
|
|
|
|
|
priv->populate_id = 0;
|
|
|
|
|
}
|
2006-12-31 16:54:56 +00:00
|
|
|
|
|
|
|
|
|
priv->manager = NULL;
|
2006-08-03 20:26:31 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (manager)
|
2006-12-31 16:54:56 +00:00
|
|
|
|
priv->manager = manager;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
2006-12-31 16:54:56 +00:00
|
|
|
|
priv->manager = gtk_recent_manager_get_default ();
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-12-31 16:54:56 +00:00
|
|
|
|
if (priv->manager)
|
|
|
|
|
priv->manager_changed_id = g_signal_connect (priv->manager, "changed",
|
|
|
|
|
G_CALLBACK (manager_changed_cb),
|
|
|
|
|
menu);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-23 16:44:07 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
|
|
|
|
|
gboolean show_tips)
|
|
|
|
|
{
|
2007-07-23 16:44:07 +00:00
|
|
|
|
GtkRecentChooserMenuPrivate *priv = menu->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->show_tips == show_tips)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2007-07-23 16:44:07 +00:00
|
|
|
|
priv->show_tips = show_tips;
|
|
|
|
|
gtk_container_foreach (GTK_CONTAINER (menu), foreach_set_shot_tips, menu);
|
2014-06-09 13:21:28 +00:00
|
|
|
|
g_object_notify (G_OBJECT (menu), "show-tips");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_update (GtkActivatable *activatable,
|
|
|
|
|
GtkAction *action,
|
|
|
|
|
const gchar *property_name)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
{
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
if (strcmp (property_name, "sensitive") == 0)
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
|
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
_gtk_recent_chooser_update (activatable, action, property_name);
|
2009-01-23 15:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
|
|
|
|
|
GtkAction *action)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
{
|
2013-04-06 09:42:19 +00:00
|
|
|
|
if (!action)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
|
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
_gtk_recent_chooser_sync_action_properties (activatable, action);
|
2009-01-23 15:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* Public API
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_chooser_menu_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkRecentChooserMenu widget.
|
|
|
|
|
*
|
|
|
|
|
* This kind of widget shows the list of recently used resources as
|
|
|
|
|
* a menu, each item as a menu item. Each item inside the menu might
|
|
|
|
|
* have an icon, representing its MIME type, and a number, for mnemonic
|
|
|
|
|
* access.
|
|
|
|
|
*
|
|
|
|
|
* This widget implements the #GtkRecentChooser interface.
|
|
|
|
|
*
|
|
|
|
|
* This widget creates its own #GtkRecentManager object. See the
|
|
|
|
|
* gtk_recent_chooser_menu_new_for_manager() function to know how to create
|
|
|
|
|
* a #GtkRecentChooserMenu widget bound to another #GtkRecentManager object.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: a new #GtkRecentChooserMenu
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.10
|
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_recent_chooser_menu_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
|
|
|
|
|
"recent-manager", NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_chooser_menu_new_for_manager:
|
|
|
|
|
* @manager: a #GtkRecentManager
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkRecentChooserMenu widget using @manager as
|
|
|
|
|
* the underlying recently used resources manager.
|
|
|
|
|
*
|
|
|
|
|
* This is useful if you have implemented your own recent manager,
|
|
|
|
|
* or if you have a customized instance of a #GtkRecentManager
|
|
|
|
|
* object or if you wish to share a common #GtkRecentManager object
|
|
|
|
|
* among multiple #GtkRecentChooser widgets.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: a new #GtkRecentChooserMenu, bound to @manager.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.10
|
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_recent_chooser_menu_new_for_manager (GtkRecentManager *manager)
|
|
|
|
|
{
|
2006-06-11 03:13:50 +00:00
|
|
|
|
g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
|
|
|
|
|
"recent-manager", manager,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_chooser_menu_get_show_numbers:
|
|
|
|
|
* @menu: a #GtkRecentChooserMenu
|
|
|
|
|
*
|
|
|
|
|
* Returns the value set by gtk_recent_chooser_menu_set_show_numbers().
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if numbers should be shown.
|
2006-03-29 20:16:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.10
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_recent_chooser_menu_get_show_numbers (GtkRecentChooserMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_RECENT_CHOOSER_MENU (menu), FALSE);
|
|
|
|
|
|
|
|
|
|
return menu->priv->show_numbers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_recent_chooser_menu_set_show_numbers:
|
|
|
|
|
* @menu: a #GtkRecentChooserMenu
|
|
|
|
|
* @show_numbers: whether to show numbers
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* be used inside ten menu item’s label. Only the first the items
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* get a number to avoid clashes.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.10
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_recent_chooser_menu_set_show_numbers (GtkRecentChooserMenu *menu,
|
|
|
|
|
gboolean show_numbers)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_RECENT_CHOOSER_MENU (menu));
|
|
|
|
|
|
|
|
|
|
if (menu->priv->show_numbers == show_numbers)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
menu->priv->show_numbers = show_numbers;
|
|
|
|
|
g_object_notify (G_OBJECT (menu), "show-numbers");
|
|
|
|
|
}
|