2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2006-03-29 20:16:44 +00:00
|
|
|
* gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
|
|
|
|
* Copyright (C) 2006 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
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
#include "gtkrecentchooserwidget.h"
|
|
|
|
#include "gtkrecentchooserdefault.h"
|
|
|
|
#include "gtkrecentchooserutils.h"
|
2011-06-07 22:35:28 +00:00
|
|
|
#include "gtkorientable.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
2010-05-15 23:58:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkrecentchooserwidget
|
|
|
|
* @Short_description: Displays recently used files
|
|
|
|
* @Title: GtkRecentChooserWidget
|
|
|
|
* @See_also:#GtkRecentChooser, #GtkRecentChooserDialog
|
|
|
|
*
|
|
|
|
* #GtkRecentChooserWidget is a widget suitable for selecting recently used
|
|
|
|
* files. It is the main building block of a #GtkRecentChooserDialog. Most
|
|
|
|
* applications will only need to use the latter; you can use
|
|
|
|
* #GtkRecentChooserWidget as part of a larger window if you have special needs.
|
|
|
|
*
|
|
|
|
* Note that #GtkRecentChooserWidget does not have any methods of its own.
|
|
|
|
* Instead, you should use the functions that work on a #GtkRecentChooser.
|
|
|
|
*
|
|
|
|
* Recently used files are supported since GTK+ 2.10.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
struct _GtkRecentChooserWidgetPrivate
|
|
|
|
{
|
|
|
|
GtkRecentManager *manager;
|
|
|
|
|
|
|
|
GtkWidget *chooser;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gtk_recent_chooser_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_recent_chooser_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_recent_chooser_widget_finalize (GObject *object);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
|
|
|
|
gtk_recent_chooser_widget,
|
2011-06-07 22:35:28 +00:00
|
|
|
GTK_TYPE_BOX,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkRecentChooserWidget)
|
2006-03-29 20:16:44 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
|
2006-05-14 04:25:34 +00:00
|
|
|
_gtk_recent_chooser_delegate_iface_init))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
static void
|
2013-06-27 19:02:52 +00:00
|
|
|
gtk_recent_chooser_widget_constructed (GObject *gobject)
|
2006-03-29 20:16:44 +00:00
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (gobject);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
self->priv->chooser = _gtk_recent_chooser_default_new (self->priv->manager);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (self), self->priv->chooser);
|
|
|
|
gtk_widget_show (self->priv->chooser);
|
|
|
|
_gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (self),
|
|
|
|
GTK_RECENT_CHOOSER (self->priv->chooser));
|
2006-03-29 20:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_recent_chooser_widget_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkRecentChooserWidgetPrivate *priv;
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
priv = gtk_recent_chooser_widget_get_instance_private (GTK_RECENT_CHOOSER_WIDGET (object));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
|
|
|
|
priv->manager = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_recent_chooser_widget_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkRecentChooserWidgetPrivate *priv;
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
priv = gtk_recent_chooser_widget_get_instance_private (GTK_RECENT_CHOOSER_WIDGET (object));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_recent_chooser_widget_finalize (GObject *object)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (object);
|
|
|
|
|
|
|
|
self->priv->manager = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
static void
|
|
|
|
gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->constructed = gtk_recent_chooser_widget_constructed;
|
|
|
|
gobject_class->set_property = gtk_recent_chooser_widget_set_property;
|
|
|
|
gobject_class->get_property = gtk_recent_chooser_widget_get_property;
|
|
|
|
gobject_class->finalize = gtk_recent_chooser_widget_finalize;
|
|
|
|
|
|
|
|
_gtk_recent_chooser_install_properties (gobject_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
|
|
|
|
{
|
|
|
|
widget->priv = gtk_recent_chooser_widget_get_instance_private (widget);
|
|
|
|
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (widget),
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
}
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
/*
|
|
|
|
* Public API
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_recent_chooser_widget_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkRecentChooserWidget object. This is an embeddable widget
|
|
|
|
* used to access the recently used resources list.
|
|
|
|
*
|
|
|
|
* Return value: a new #GtkRecentChooserWidget
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_recent_chooser_widget_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_recent_chooser_widget_new_for_manager:
|
|
|
|
* @manager: a #GtkRecentManager
|
|
|
|
*
|
|
|
|
* Creates a new #GtkRecentChooserWidget with a specified recent manager.
|
|
|
|
*
|
|
|
|
* This is useful if you have implemented your own recent manager, or if you
|
|
|
|
* have a customized instance of a #GtkRecentManager object.
|
|
|
|
*
|
|
|
|
* Return value: a new #GtkRecentChooserWidget
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_recent_chooser_widget_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_WIDGET,
|
|
|
|
"recent-manager", manager,
|
|
|
|
NULL);
|
|
|
|
}
|