2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* gtkrecentchooserdefault.c
|
|
|
|
|
* Copyright (C) 2005-2006, Emmanuele Bassi
|
2011-08-28 05:40:10 +00:00
|
|
|
|
*
|
2006-03-29 20:16:44 +00:00
|
|
|
|
* 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>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
|
#include "gtksettings.h"
|
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
|
#include "gtkliststore.h"
|
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
|
#include "gtkcellrendererpixbuf.h"
|
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
|
#include "gtkcheckmenuitem.h"
|
|
|
|
|
#include "gtkclipboard.h"
|
2010-10-02 16:19:46 +00:00
|
|
|
|
#include "gtkcomboboxtext.h"
|
2015-12-02 02:18:26 +00:00
|
|
|
|
#include "gtkcssiconthemevalueprivate.h"
|
2015-11-22 04:26:08 +00:00
|
|
|
|
#include "gtkdragsource.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtkentry.h"
|
|
|
|
|
#include "gtkexpander.h"
|
|
|
|
|
#include "gtkframe.h"
|
2011-06-08 01:16:00 +00:00
|
|
|
|
#include "gtkbox.h"
|
|
|
|
|
#include "gtkpaned.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtkimage.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkmenuitem.h"
|
|
|
|
|
#include "gtkmessagedialog.h"
|
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
|
#include "gtkseparatormenuitem.h"
|
|
|
|
|
#include "gtksizegroup.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
|
#include "gtksizerequest.h"
|
2015-12-02 02:18:26 +00:00
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtktreemodelsort.h"
|
|
|
|
|
#include "gtktreemodelfilter.h"
|
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
|
#include "gtktreestore.h"
|
2007-07-23 16:44:07 +00:00
|
|
|
|
#include "gtktooltip.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
#include "gtktypebuiltins.h"
|
2011-06-07 22:35:46 +00:00
|
|
|
|
#include "gtkorientable.h"
|
2014-06-04 10:18:03 +00:00
|
|
|
|
#include "gtkwindowgroup.h"
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkrecentmanager.h"
|
|
|
|
|
#include "gtkrecentfilter.h"
|
|
|
|
|
#include "gtkrecentchooser.h"
|
|
|
|
|
#include "gtkrecentchooserprivate.h"
|
|
|
|
|
#include "gtkrecentchooserutils.h"
|
|
|
|
|
#include "gtkrecentchooserdefault.h"
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
typedef struct
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentManager *manager;
|
|
|
|
|
gulong manager_changed_id;
|
|
|
|
|
guint local_manager : 1;
|
2011-06-07 22:35:46 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* RecentChooser properties */
|
2011-06-07 22:35:46 +00:00
|
|
|
|
gint limit;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GtkRecentSortType sort_type;
|
|
|
|
|
guint show_private : 1;
|
|
|
|
|
guint show_not_found : 1;
|
|
|
|
|
guint select_multiple : 1;
|
|
|
|
|
guint show_tips : 1;
|
|
|
|
|
guint show_icons : 1;
|
|
|
|
|
guint local_only : 1;
|
2007-07-20 10:39:03 +00:00
|
|
|
|
|
|
|
|
|
guint limit_set : 1;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
GSList *filters;
|
|
|
|
|
GtkRecentFilter *current_filter;
|
|
|
|
|
GtkWidget *filter_combo_hbox;
|
|
|
|
|
GtkWidget *filter_combo;
|
|
|
|
|
|
|
|
|
|
GtkRecentSortFunc sort_func;
|
|
|
|
|
gpointer sort_data;
|
|
|
|
|
GDestroyNotify sort_data_destroy;
|
|
|
|
|
|
|
|
|
|
GtkWidget *recent_view;
|
|
|
|
|
GtkListStore *recent_store;
|
|
|
|
|
GtkTreeViewColumn *icon_column;
|
|
|
|
|
GtkTreeViewColumn *meta_column;
|
2013-03-26 12:50:28 +00:00
|
|
|
|
GtkCellRenderer *icon_renderer;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GtkCellRenderer *meta_renderer;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
GtkWidget *recent_popup_menu;
|
|
|
|
|
GtkWidget *recent_popup_menu_copy_item;
|
|
|
|
|
GtkWidget *recent_popup_menu_remove_item;
|
|
|
|
|
GtkWidget *recent_popup_menu_clear_item;
|
|
|
|
|
GtkWidget *recent_popup_menu_show_private_item;
|
|
|
|
|
|
|
|
|
|
guint load_id;
|
|
|
|
|
GList *recent_items;
|
|
|
|
|
gint n_recent_items;
|
|
|
|
|
gint loaded_items;
|
|
|
|
|
guint load_state;
|
2013-03-26 12:50:28 +00:00
|
|
|
|
} GtkRecentChooserDefaultPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GtkRecentChooserDefault
|
|
|
|
|
{
|
|
|
|
|
GtkBox parent_instance;
|
|
|
|
|
|
|
|
|
|
GtkRecentChooserDefaultPrivate *priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct _GtkRecentChooserDefaultClass
|
|
|
|
|
{
|
2011-06-07 22:35:46 +00:00
|
|
|
|
GtkBoxClass parent_class;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
} GtkRecentChooserDefaultClass;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
/* Keep inline with GtkTreeStore defined in gtkrecentchooserdefault.ui */
|
2006-03-29 20:16:44 +00:00
|
|
|
|
enum {
|
|
|
|
|
RECENT_URI_COLUMN,
|
|
|
|
|
RECENT_DISPLAY_NAME_COLUMN,
|
|
|
|
|
RECENT_INFO_COLUMN,
|
|
|
|
|
N_RECENT_COLUMNS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
LOAD_EMPTY, /* initial state: the model is empty */
|
|
|
|
|
LOAD_PRELOAD, /* the model is loading and not inserted in the tree yet */
|
|
|
|
|
LOAD_LOADING, /* the model is fully loaded but not inserted */
|
|
|
|
|
LOAD_FINISHED /* the model is fully loaded and inserted */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define FALLBACK_ITEM_LIMIT 20
|
|
|
|
|
|
|
|
|
|
#define NUM_CHARS 40
|
|
|
|
|
#define NUM_LINES 9
|
|
|
|
|
|
2013-07-08 20:42:44 +00:00
|
|
|
|
#define DEFAULT_RECENT_FILES_LIMIT 50
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GObject */
|
|
|
|
|
static void gtk_recent_chooser_default_finalize (GObject *object);
|
2007-03-14 10:33:36 +00:00
|
|
|
|
static void gtk_recent_chooser_default_dispose (GObject *object);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void gtk_recent_chooser_default_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gtk_recent_chooser_default_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
/* GtkRecentChooserIface */
|
|
|
|
|
static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
|
|
|
|
|
static gboolean gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error);
|
|
|
|
|
static gchar * gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser);
|
|
|
|
|
static gboolean gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error);
|
|
|
|
|
static void gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri);
|
|
|
|
|
static void gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser);
|
|
|
|
|
static void gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser);
|
|
|
|
|
static GList * gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser);
|
|
|
|
|
static GtkRecentManager *gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser);
|
|
|
|
|
static void gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentSortFunc sort_func,
|
|
|
|
|
gpointer sort_data,
|
|
|
|
|
GDestroyNotify data_destroy);
|
|
|
|
|
static void gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter);
|
|
|
|
|
static void gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter);
|
|
|
|
|
static GSList * gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void gtk_recent_chooser_default_map (GtkWidget *widget);
|
|
|
|
|
|
|
|
|
|
static void set_current_filter (GtkRecentChooserDefault *impl,
|
|
|
|
|
GtkRecentFilter *filter);
|
|
|
|
|
|
|
|
|
|
static void reload_recent_items (GtkRecentChooserDefault *impl);
|
|
|
|
|
static void chooser_set_model (GtkRecentChooserDefault *impl);
|
|
|
|
|
|
|
|
|
|
static void set_recent_manager (GtkRecentChooserDefault *impl,
|
|
|
|
|
GtkRecentManager *manager);
|
|
|
|
|
|
|
|
|
|
static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
|
|
|
|
|
GtkRecentSortType sort_type);
|
|
|
|
|
|
|
|
|
|
static void recent_manager_changed_cb (GtkRecentManager *manager,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void recent_icon_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void recent_meta_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
static void selection_changed_cb (GtkTreeSelection *z,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void row_activated_cb (GtkTreeView *tree_view,
|
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
|
GtkTreeViewColumn *tree_column,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void filter_combo_changed_cb (GtkComboBox *combo_box,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
static void remove_all_activated_cb (GtkMenuItem *menu_item,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void remove_item_activated_cb (GtkMenuItem *menu_item,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void show_private_toggled_cb (GtkCheckMenuItem *menu_item,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
static gboolean recent_view_popup_menu_cb (GtkWidget *widget,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static gboolean recent_view_button_press_cb (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
static void recent_view_drag_begin_cb (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void recent_view_drag_data_get_cb (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
|
guint info,
|
|
|
|
|
guint32 time_,
|
|
|
|
|
gpointer data);
|
2007-07-23 16:44:07 +00:00
|
|
|
|
static gboolean recent_view_query_tooltip_cb (GtkWidget *widget,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gboolean keyboard_tip,
|
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
|
2006-05-04 13:36:30 +00:00
|
|
|
|
_gtk_recent_chooser_default,
|
2011-06-07 22:35:46 +00:00
|
|
|
|
GTK_TYPE_BOX,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkRecentChooserDefault)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
|
2016-10-16 16:26:00 +00:00
|
|
|
|
gtk_recent_chooser_iface_init))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
|
|
|
|
|
iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
|
|
|
|
|
iface->select_uri = gtk_recent_chooser_default_select_uri;
|
|
|
|
|
iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
|
|
|
|
|
iface->select_all = gtk_recent_chooser_default_select_all;
|
|
|
|
|
iface->unselect_all = gtk_recent_chooser_default_unselect_all;
|
|
|
|
|
iface->get_items = gtk_recent_chooser_default_get_items;
|
|
|
|
|
iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
|
|
|
|
|
iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
|
|
|
|
|
iface->add_filter = gtk_recent_chooser_default_add_filter;
|
|
|
|
|
iface->remove_filter = gtk_recent_chooser_default_remove_filter;
|
|
|
|
|
iface->list_filters = gtk_recent_chooser_default_list_filters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-04 13:36:30 +00:00
|
|
|
|
_gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
gobject_class->set_property = gtk_recent_chooser_default_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_recent_chooser_default_get_property;
|
2007-03-14 10:33:36 +00:00
|
|
|
|
gobject_class->dispose = gtk_recent_chooser_default_dispose;
|
|
|
|
|
gobject_class->finalize = gtk_recent_chooser_default_finalize;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
widget_class->map = gtk_recent_chooser_default_map;
|
|
|
|
|
|
|
|
|
|
_gtk_recent_chooser_install_properties (gobject_class);
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
/* Bind class to template
|
|
|
|
|
*/
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2014-01-23 23:59:20 +00:00
|
|
|
|
"/org/gtk/libgtk/ui/gtkrecentchooserdefault.ui");
|
2013-03-26 12:50:28 +00:00
|
|
|
|
|
2013-07-26 20:29:12 +00:00
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, filter_combo_hbox);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, filter_combo);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, recent_view);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, recent_store);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, icon_column);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, meta_column);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, icon_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, meta_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, selection);
|
2013-07-26 17:49:49 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, selection_changed_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, recent_view_popup_menu_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, recent_view_button_press_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, recent_view_drag_begin_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, recent_view_drag_data_get_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, recent_view_query_tooltip_cb);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-05-04 13:36:30 +00:00
|
|
|
|
_gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
GtkRecentChooserDefaultPrivate *priv;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
impl->priv = priv = _gtk_recent_chooser_default_get_instance_private (impl);
|
2011-06-07 22:35:46 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* by default, we use the global manager */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
priv->local_manager = FALSE;
|
2011-06-07 22:35:46 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
priv->limit = FALLBACK_ITEM_LIMIT;
|
|
|
|
|
priv->sort_type = GTK_RECENT_SORT_NONE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
priv->show_icons = TRUE;
|
|
|
|
|
priv->show_private = FALSE;
|
|
|
|
|
priv->show_not_found = TRUE;
|
|
|
|
|
priv->show_tips = FALSE;
|
|
|
|
|
priv->select_multiple = FALSE;
|
|
|
|
|
priv->local_only = TRUE;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
priv->current_filter = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
priv->recent_items = NULL;
|
|
|
|
|
priv->n_recent_items = 0;
|
|
|
|
|
priv->loaded_items = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
priv->load_state = LOAD_EMPTY;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (impl));
|
|
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (priv->recent_view),
|
2007-03-14 10:33:36 +00:00
|
|
|
|
"GtkRecentChooserDefault", impl);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_cell_data_func (priv->icon_column,
|
|
|
|
|
priv->icon_renderer,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
recent_icon_data_func,
|
|
|
|
|
impl,
|
|
|
|
|
NULL);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_view_column_set_cell_data_func (priv->meta_column,
|
|
|
|
|
priv->meta_renderer,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
recent_meta_data_func,
|
|
|
|
|
impl,
|
|
|
|
|
NULL);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_drag_source_set (priv->recent_view,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GDK_BUTTON1_MASK,
|
2017-11-14 21:32:23 +00:00
|
|
|
|
NULL,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GDK_ACTION_COPY);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_drag_source_add_uri_targets (priv->recent_view);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
|
|
|
|
|
set_recent_manager (impl, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
|
2014-06-09 12:56:10 +00:00
|
|
|
|
if (impl->priv->show_private != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->show_private = g_value_get_boolean (value);
|
|
|
|
|
if (impl->priv->recent_popup_menu_show_private_item)
|
|
|
|
|
{
|
|
|
|
|
GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->priv->recent_popup_menu_show_private_item);
|
|
|
|
|
g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
|
|
|
|
|
gtk_check_menu_item_set_active (item, impl->priv->show_private);
|
|
|
|
|
g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
|
|
|
|
|
}
|
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
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 12:56:10 +00:00
|
|
|
|
if (impl->priv->show_not_found != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->show_not_found = g_value_get_boolean (value);
|
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
|
2014-06-09 12:56:10 +00:00
|
|
|
|
if (impl->priv->show_tips != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->show_tips = 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_ICONS:
|
2014-06-09 12:56:10 +00:00
|
|
|
|
if (impl->priv->show_icons != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->show_icons = g_value_get_boolean (value);
|
|
|
|
|
gtk_tree_view_column_set_visible (impl->priv->icon_column, impl->priv->show_icons);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
|
2014-06-09 12:56:10 +00:00
|
|
|
|
if (impl->priv->select_multiple != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->select_multiple = g_value_get_boolean (value);
|
|
|
|
|
if (impl->priv->select_multiple)
|
|
|
|
|
gtk_tree_selection_set_mode (impl->priv->selection, GTK_SELECTION_MULTIPLE);
|
|
|
|
|
else
|
|
|
|
|
gtk_tree_selection_set_mode (impl->priv->selection, GTK_SELECTION_SINGLE);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
|
2014-06-09 12:56:10 +00:00
|
|
|
|
if (impl->priv->local_only != g_value_get_boolean (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->local_only = g_value_get_boolean (value);
|
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
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 12:56:10 +00:00
|
|
|
|
if (impl->priv->limit != g_value_get_int (value))
|
|
|
|
|
{
|
|
|
|
|
impl->priv->limit = g_value_get_int (value);
|
|
|
|
|
impl->priv->limit_set = TRUE;
|
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
g_object_notify_by_pspec (object, pspec);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
|
|
|
|
|
chooser_set_sort_type (impl, g_value_get_enum (value));
|
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_FILTER:
|
|
|
|
|
set_current_filter (impl, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LIMIT:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_int (value, impl->priv->limit);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_enum (value, impl->priv->sort_type);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_boolean (value, impl->priv->show_private);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_boolean (value, impl->priv->show_icons);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_boolean (value, impl->priv->show_not_found);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_boolean (value, impl->priv->show_tips);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_boolean (value, impl->priv->local_only);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_boolean (value, impl->priv->select_multiple);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_RECENT_CHOOSER_PROP_FILTER:
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_value_set_object (value, impl->priv->current_filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-03-14 10:33:36 +00:00
|
|
|
|
gtk_recent_chooser_default_dispose (GObject *object)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->load_id)
|
2007-03-14 10:33:36 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_source_remove (impl->priv->load_id);
|
|
|
|
|
impl->priv->load_state = LOAD_EMPTY;
|
|
|
|
|
impl->priv->load_id = 0;
|
2007-03-14 10:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_list_free_full (impl->priv->recent_items, (GDestroyNotify) gtk_recent_info_unref);
|
|
|
|
|
impl->priv->recent_items = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->manager && impl->priv->manager_changed_id)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_signal_handler_disconnect (impl->priv->manager, impl->priv->manager_changed_id);
|
|
|
|
|
impl->priv->manager_changed_id = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->filters)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2015-07-31 21:57:04 +00:00
|
|
|
|
g_slist_free_full (impl->priv->filters, g_object_unref);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->filters = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->current_filter)
|
2007-03-14 10:33:36 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_object_unref (impl->priv->current_filter);
|
|
|
|
|
impl->priv->current_filter = NULL;
|
2007-03-14 10:33:36 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2007-03-14 10:33:36 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->manager = NULL;
|
2007-03-14 10:33:36 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->sort_data_destroy)
|
2007-03-14 10:33:36 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->sort_data_destroy (impl->priv->sort_data);
|
|
|
|
|
impl->priv->sort_data_destroy = NULL;
|
2007-03-14 10:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->sort_data = NULL;
|
|
|
|
|
impl->priv->sort_func = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2006-05-04 13:36:30 +00:00
|
|
|
|
G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows an error dialog set as transient for the specified window */
|
|
|
|
|
static void
|
|
|
|
|
error_message_with_parent (GtkWindow *parent,
|
|
|
|
|
const gchar *msg,
|
|
|
|
|
const gchar *detail)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (parent,
|
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
|
"%s",
|
|
|
|
|
msg);
|
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
|
"%s", detail);
|
|
|
|
|
|
2010-08-24 14:10:38 +00:00
|
|
|
|
if (gtk_window_has_group (parent))
|
|
|
|
|
gtk_window_group_add_window (gtk_window_get_group (parent),
|
|
|
|
|
GTK_WINDOW (dialog));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns a toplevel GtkWindow, or NULL if none */
|
|
|
|
|
static GtkWindow *
|
|
|
|
|
get_toplevel (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (widget);
|
2010-01-04 06:49:26 +00:00
|
|
|
|
if (!gtk_widget_is_toplevel (toplevel))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
else
|
|
|
|
|
return GTK_WINDOW (toplevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows an error dialog for the file chooser */
|
|
|
|
|
static void
|
|
|
|
|
error_message (GtkRecentChooserDefault *impl,
|
|
|
|
|
const gchar *msg,
|
|
|
|
|
const gchar *detail)
|
|
|
|
|
{
|
|
|
|
|
error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_busy_cursor (GtkRecentChooserDefault *impl,
|
2015-05-08 02:36:00 +00:00
|
|
|
|
gboolean busy)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWindow *toplevel;
|
|
|
|
|
|
|
|
|
|
toplevel = get_toplevel (GTK_WIDGET (impl));
|
2010-03-02 06:16:02 +00:00
|
|
|
|
if (!toplevel || !gtk_widget_get_realized (GTK_WIDGET (toplevel)))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
2015-05-08 02:36:00 +00:00
|
|
|
|
|
|
|
|
|
if (busy)
|
2017-11-04 00:37:03 +00:00
|
|
|
|
gtk_widget_set_cursor_from_name (GTK_WIDGET (toplevel), "progress");
|
2015-05-08 02:36:00 +00:00
|
|
|
|
else
|
2017-11-04 00:37:03 +00:00
|
|
|
|
gtk_widget_set_cursor (GTK_WIDGET (toplevel), NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
chooser_set_model (GtkRecentChooserDefault *impl)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_assert (impl->priv->recent_store != NULL);
|
|
|
|
|
g_assert (impl->priv->load_state == LOAD_LOADING);
|
2007-03-15 10:05:34 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->priv->recent_view),
|
|
|
|
|
GTK_TREE_MODEL (impl->priv->recent_store));
|
|
|
|
|
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->priv->recent_view));
|
|
|
|
|
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->priv->recent_view), TRUE);
|
|
|
|
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->priv->recent_view),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
RECENT_DISPLAY_NAME_COLUMN);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->load_state = LOAD_FINISHED;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
load_recent_items (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
const gchar *uri, *name;
|
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
|
|
impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
|
|
|
|
|
(impl->priv->load_state == LOAD_PRELOAD));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* store the items for multiple runs */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->recent_items)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
|
|
|
|
|
if (!impl->priv->recent_items)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->load_state = LOAD_FINISHED;
|
2014-06-09 12:56:10 +00:00
|
|
|
|
impl->priv->load_id = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->n_recent_items = g_list_length (impl->priv->recent_items);
|
|
|
|
|
impl->priv->loaded_items = 0;
|
|
|
|
|
impl->priv->load_state = LOAD_PRELOAD;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
info = (GtkRecentInfo *) g_list_nth_data (impl->priv->recent_items,
|
|
|
|
|
impl->priv->loaded_items);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_assert (info);
|
|
|
|
|
|
|
|
|
|
uri = gtk_recent_info_get_uri (info);
|
|
|
|
|
name = gtk_recent_info_get_display_name (info);
|
|
|
|
|
|
|
|
|
|
/* at this point, everything goes inside the model; operations on the
|
|
|
|
|
* visualization of items inside the model are done in the cell data
|
|
|
|
|
* funcs (remember that there are two of those: one for the icon and
|
|
|
|
|
* one for the text), while the filtering is done only when a filter
|
|
|
|
|
* is actually loaded. */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_list_store_append (impl->priv->recent_store, &iter);
|
|
|
|
|
gtk_list_store_set (impl->priv->recent_store, &iter,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
RECENT_URI_COLUMN, uri, /* uri */
|
|
|
|
|
RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
|
|
|
|
|
RECENT_INFO_COLUMN, info, /* info */
|
|
|
|
|
-1);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->loaded_items += 1;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->loaded_items == impl->priv->n_recent_items)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
/* we have finished loading, so we remove the items cache */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->load_state = LOAD_LOADING;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_list_free_full (impl->priv->recent_items, (GDestroyNotify) gtk_recent_info_unref);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_items = NULL;
|
|
|
|
|
impl->priv->n_recent_items = 0;
|
|
|
|
|
impl->priv->loaded_items = 0;
|
2007-03-15 10:05:34 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
/* load the filled up model */
|
|
|
|
|
chooser_set_model (impl);
|
|
|
|
|
|
|
|
|
|
retval = FALSE;
|
2013-12-04 20:08:25 +00:00
|
|
|
|
impl->priv->load_id = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* we did not finish, so continue loading */
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
cleanup_after_load (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
|
|
|
|
|
impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->load_id != 0)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
|
|
|
|
|
(impl->priv->load_state == LOAD_PRELOAD) ||
|
|
|
|
|
(impl->priv->load_state == LOAD_LOADING) ||
|
|
|
|
|
(impl->priv->load_state == LOAD_FINISHED));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* we have officialy finished loading all the items,
|
|
|
|
|
* so we can reset the state machine
|
|
|
|
|
*/
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->load_id = 0;
|
|
|
|
|
impl->priv->load_state = LOAD_EMPTY;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
|
|
|
|
|
(impl->priv->load_state == LOAD_LOADING) ||
|
|
|
|
|
(impl->priv->load_state == LOAD_FINISHED));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* clears the current model and reloads the recently used resources */
|
|
|
|
|
static void
|
|
|
|
|
reload_recent_items (GtkRecentChooserDefault *impl)
|
|
|
|
|
{
|
|
|
|
|
/* reload is already in progress - do not disturb */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->load_id)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
2007-07-20 10:39:03 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->priv->recent_view), NULL);
|
|
|
|
|
gtk_list_store_clear (impl->priv->recent_store);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->limit_set)
|
2013-07-08 20:42:44 +00:00
|
|
|
|
impl->priv->limit = DEFAULT_RECENT_FILES_LIMIT;
|
2007-07-20 10:39:03 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->load_state = LOAD_EMPTY;
|
|
|
|
|
impl->priv->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
|
2007-03-14 10:33:36 +00:00
|
|
|
|
load_recent_items,
|
|
|
|
|
impl,
|
|
|
|
|
cleanup_after_load);
|
2014-03-22 11:44:01 +00:00
|
|
|
|
g_source_set_name_by_id (impl->priv->load_id, "[gtk+] load_recent_items");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* taken form gtkfilechooserdialog.c */
|
|
|
|
|
static void
|
|
|
|
|
set_default_size (GtkRecentChooserDefault *impl)
|
|
|
|
|
{
|
2011-04-27 17:59:02 +00:00
|
|
|
|
GtkScrolledWindow *scrollw;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
gint width, height;
|
2012-12-06 01:53:43 +00:00
|
|
|
|
double font_size;
|
2016-04-11 03:01:10 +00:00
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GdkMonitor *monitor;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
GtkRequisition req;
|
2016-04-11 03:01:10 +00:00
|
|
|
|
GdkRectangle workarea;
|
2011-01-04 01:11:12 +00:00
|
|
|
|
GtkStyleContext *context;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (impl);
|
2011-01-04 01:11:12 +00:00
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* Size based on characters and the icon size */
|
2016-10-08 03:07:23 +00:00
|
|
|
|
gtk_style_context_get (context, "font-size", &font_size, NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2017-11-15 02:14:47 +00:00
|
|
|
|
width = 16 + font_size * NUM_CHARS + 0.5;
|
|
|
|
|
height = (16 + font_size) * NUM_LINES + 0.5;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* Use at least the requisition size... */
|
2010-09-21 14:35:17 +00:00
|
|
|
|
gtk_widget_get_preferred_size (widget, &req, NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
width = MAX (width, req.width);
|
|
|
|
|
height = MAX (height, req.height);
|
|
|
|
|
|
|
|
|
|
/* ... but no larger than the monitor */
|
2016-04-11 03:01:10 +00:00
|
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
|
monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (widget));
|
|
|
|
|
gdk_monitor_get_workarea (monitor, &workarea);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2016-04-11 03:01:10 +00:00
|
|
|
|
width = MIN (width, workarea.width * 3 / 4);
|
|
|
|
|
height = MIN (height, workarea.height * 3 / 4);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* Set size */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
scrollw = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (impl->priv->recent_view));
|
2011-04-27 17:59:02 +00:00
|
|
|
|
gtk_scrolled_window_set_min_content_width (scrollw, width);
|
|
|
|
|
gtk_scrolled_window_set_min_content_height (scrollw, height);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_map (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
|
2008-08-12 09:44:32 +00:00
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* reloads everything */
|
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
|
|
|
|
|
set_default_size (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_icon_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info = NULL;
|
2010-04-29 13:23:44 +00:00
|
|
|
|
GIcon *icon;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, RECENT_INFO_COLUMN, &info, -1);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_assert (info != NULL);
|
2010-04-29 13:23:44 +00:00
|
|
|
|
|
|
|
|
|
icon = gtk_recent_info_get_gicon (info);
|
|
|
|
|
g_object_set (cell, "gicon", icon, NULL);
|
|
|
|
|
|
|
|
|
|
if (icon != NULL)
|
|
|
|
|
g_object_unref (icon);
|
2007-07-23 16:44:07 +00:00
|
|
|
|
|
|
|
|
|
gtk_recent_info_unref (info);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_meta_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info = NULL;
|
2007-07-23 16:44:07 +00:00
|
|
|
|
gchar *name;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
RECENT_DISPLAY_NAME_COLUMN, &name,
|
|
|
|
|
RECENT_INFO_COLUMN, &info,
|
|
|
|
|
-1);
|
|
|
|
|
g_assert (info != NULL);
|
|
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
|
name = gtk_recent_info_get_short_name (info);
|
2007-05-18 15:48:43 +00:00
|
|
|
|
|
2007-07-23 16:44:07 +00:00
|
|
|
|
g_object_set (cell, "text", name, NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
gtk_recent_info_unref (info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
|
gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_assert (impl->priv->selection != NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->select_multiple)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gchar *uri = NULL;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!gtk_tree_selection_get_selected (impl->priv->selection, &model, &iter))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
|
|
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
guint found : 1;
|
|
|
|
|
guint do_select : 1;
|
|
|
|
|
guint do_activate : 1;
|
|
|
|
|
|
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
} SelectURIData;
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
scan_for_uri_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
SelectURIData *select_data = (SelectURIData *) user_data;
|
2006-07-10 16:49:16 +00:00
|
|
|
|
gchar *uri = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (!select_data)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (select_data->found)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
|
2006-07-10 16:49:16 +00:00
|
|
|
|
if (!uri)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (strcmp (uri, select_data->uri) == 0)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
select_data->found = TRUE;
|
|
|
|
|
|
|
|
|
|
if (select_data->do_activate)
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->priv->recent_view),
|
2006-07-10 16:49:16 +00:00
|
|
|
|
path,
|
2013-03-26 12:50:28 +00:00
|
|
|
|
select_data->impl->priv->meta_column);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (select_data->do_select)
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_selection_select_path (select_data->impl->priv->selection, path);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_selection_unselect_path (select_data->impl->priv->selection, path);
|
2006-07-10 16:49:16 +00:00
|
|
|
|
|
|
|
|
|
g_free (uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2006-07-10 16:49:16 +00:00
|
|
|
|
|
|
|
|
|
g_free (uri);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
SelectURIData *data;
|
|
|
|
|
|
|
|
|
|
data = g_new0 (SelectURIData, 1);
|
|
|
|
|
data->uri = g_strdup (uri);
|
|
|
|
|
data->impl = impl;
|
|
|
|
|
data->found = FALSE;
|
|
|
|
|
data->do_activate = TRUE;
|
|
|
|
|
data->do_select = TRUE;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
scan_for_uri_cb,
|
|
|
|
|
data);
|
|
|
|
|
|
|
|
|
|
if (!data->found)
|
|
|
|
|
{
|
|
|
|
|
g_free (data->uri);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
|
|
g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
|
|
|
|
|
GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("No item for URI “%s” found"),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (data->uri);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
SelectURIData *data;
|
|
|
|
|
|
|
|
|
|
data = g_new0 (SelectURIData, 1);
|
|
|
|
|
data->uri = g_strdup (uri);
|
|
|
|
|
data->impl = impl;
|
|
|
|
|
data->found = FALSE;
|
|
|
|
|
data->do_activate = FALSE;
|
|
|
|
|
data->do_select = TRUE;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
scan_for_uri_cb,
|
|
|
|
|
data);
|
|
|
|
|
|
|
|
|
|
if (!data->found)
|
|
|
|
|
{
|
|
|
|
|
g_free (data->uri);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
|
|
g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
|
|
|
|
|
GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
|
2016-10-03 16:20:03 +00:00
|
|
|
|
_("No item for URI “%s” found"),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (data->uri);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
|
|
|
|
|
const gchar *uri)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
SelectURIData *data;
|
|
|
|
|
|
|
|
|
|
data = g_new0 (SelectURIData, 1);
|
|
|
|
|
data->uri = g_strdup (uri);
|
|
|
|
|
data->impl = impl;
|
|
|
|
|
data->found = FALSE;
|
|
|
|
|
data->do_activate = FALSE;
|
|
|
|
|
data->do_select = FALSE;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
scan_for_uri_cb,
|
|
|
|
|
data);
|
|
|
|
|
|
|
|
|
|
g_free (data->uri);
|
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->select_multiple)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_selection_select_all (impl->priv->selection);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_selection_unselect_all (impl->priv->selection);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentSortFunc sort_func,
|
|
|
|
|
gpointer sort_data,
|
|
|
|
|
GDestroyNotify data_destroy)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->sort_data_destroy)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->sort_data_destroy (impl->priv->sort_data);
|
|
|
|
|
impl->priv->sort_data_destroy = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
2007-03-14 10:33:36 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->sort_func = NULL;
|
|
|
|
|
impl->priv->sort_data = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (sort_func)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->sort_func = sort_func;
|
|
|
|
|
impl->priv->sort_data = sort_data;
|
|
|
|
|
impl->priv->sort_data_destroy = data_destroy;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
|
gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
|
2007-03-14 10:33:36 +00:00
|
|
|
|
impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2007-03-14 10:33:36 +00:00
|
|
|
|
return _gtk_recent_chooser_get_items (chooser,
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->current_filter,
|
|
|
|
|
impl->priv->sort_func,
|
|
|
|
|
impl->priv->sort_data);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkRecentManager *
|
|
|
|
|
gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
return GTK_RECENT_CHOOSER_DEFAULT (chooser)->priv->manager;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_filters (GtkRecentChooserDefault *impl,
|
|
|
|
|
gboolean show)
|
|
|
|
|
{
|
|
|
|
|
if (show)
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_widget_show (impl->priv->filter_combo_hbox);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_widget_hide (impl->priv->filter_combo_hbox);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
|
|
impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (g_slist_find (impl->priv->filters, filter))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("gtk_recent_chooser_add_filter() called on filter already in list");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_ref_sink (filter);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->filters = g_slist_append (impl->priv->filters, filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
/* display new filter */
|
|
|
|
|
name = gtk_recent_filter_get_name (filter);
|
|
|
|
|
if (!name)
|
2007-07-13 16:34:05 +00:00
|
|
|
|
name = _("Untitled filter");
|
2010-10-02 16:19:46 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (impl->priv->filter_combo), name);
|
2010-10-02 16:19:46 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!g_slist_find (impl->priv->filters, impl->priv->current_filter))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
set_current_filter (impl, filter);
|
|
|
|
|
|
|
|
|
|
show_filters (impl, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
|
|
|
|
|
GtkRecentFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gint filter_idx;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
filter_idx = g_slist_index (impl->priv->filters, filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (filter_idx < 0)
|
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list");
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->filters = g_slist_remove (impl->priv->filters, filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (filter == impl->priv->current_filter)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->filters)
|
|
|
|
|
set_current_filter (impl, impl->priv->filters->data);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
|
|
|
|
set_current_filter (impl, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->priv->filter_combo));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
|
|
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
|
|
|
|
|
|
|
|
|
g_object_unref (filter);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->filters)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
show_filters (impl, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
|
gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
return g_slist_copy (impl->priv->filters);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_current_filter (GtkRecentChooserDefault *impl,
|
|
|
|
|
GtkRecentFilter *filter)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->current_filter != filter)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
gint filter_idx;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
filter_idx = g_slist_index (impl->priv->filters, filter);
|
|
|
|
|
if (impl->priv->filters && filter && filter_idx < 0)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->current_filter)
|
|
|
|
|
g_object_unref (impl->priv->current_filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->current_filter = filter;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->current_filter)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_object_ref_sink (impl->priv->current_filter);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->filters)
|
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->priv->filter_combo),
|
2006-03-29 20:16:44 +00:00
|
|
|
|
filter_idx);
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->recent_store)
|
2007-03-15 10:05:34 +00:00
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "filter");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-14 10:33:36 +00:00
|
|
|
|
static void
|
|
|
|
|
chooser_set_sort_type (GtkRecentChooserDefault *impl,
|
|
|
|
|
GtkRecentSortType sort_type)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->sort_type != sort_type)
|
2007-03-15 10:05:34 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->sort_type = sort_type;
|
2007-03-15 10:05:34 +00:00
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
g_object_notify (G_OBJECT (impl), "sort-type");
|
|
|
|
|
}
|
2007-03-14 10:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
static void
|
|
|
|
|
recent_manager_changed_cb (GtkRecentManager *manager,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
|
|
|
|
|
reload_recent_items (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
selection_changed_cb (GtkTreeSelection *selection,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
_gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
row_activated_cb (GtkTreeView *tree_view,
|
|
|
|
|
GtkTreePath *tree_path,
|
|
|
|
|
GtkTreeViewColumn *tree_column,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
_gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
filter_combo_changed_cb (GtkComboBox *combo_box,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
gint new_index;
|
|
|
|
|
GtkRecentFilter *filter;
|
|
|
|
|
|
|
|
|
|
impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
|
|
|
|
|
new_index = gtk_combo_box_get_active (combo_box);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
filter = g_slist_nth_data (impl->priv->filters, new_index);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
set_current_filter (impl, filter);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 03:38:10 +00:00
|
|
|
|
static GIcon *
|
|
|
|
|
get_drag_icon (GtkRecentChooserDefault *impl)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info;
|
2017-11-15 03:38:10 +00:00
|
|
|
|
GIcon *gicon = NULL;
|
2017-10-22 20:21:21 +00:00
|
|
|
|
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
|
|
|
|
|
|
|
|
|
|
info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
|
2017-11-15 03:38:10 +00:00
|
|
|
|
if (info != NULL)
|
|
|
|
|
{
|
|
|
|
|
gicon = gtk_recent_info_get_gicon (info);
|
|
|
|
|
gtk_recent_info_unref (info);
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2017-11-15 03:38:10 +00:00
|
|
|
|
return gicon;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_view_drag_begin_cb (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
2017-11-15 03:38:10 +00:00
|
|
|
|
GIcon *icon;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2017-11-15 03:38:10 +00:00
|
|
|
|
icon = get_drag_icon (impl);
|
|
|
|
|
if (icon)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2017-11-15 03:38:10 +00:00
|
|
|
|
gtk_drag_set_icon_gicon (context, icon, 0, 0);
|
|
|
|
|
g_object_unref (icon);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_drag_set_icon_default (context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
gchar **uri_list;
|
|
|
|
|
gsize next_pos;
|
|
|
|
|
} DragData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
append_uri_to_urilist (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
DragData *drag_data = (DragData *) user_data;
|
|
|
|
|
gchar *uri = NULL;
|
|
|
|
|
gsize pos;
|
|
|
|
|
|
2014-09-06 01:02:00 +00:00
|
|
|
|
gtk_tree_model_get (model, iter,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
RECENT_URI_COLUMN, &uri,
|
|
|
|
|
-1);
|
|
|
|
|
g_assert (uri != NULL);
|
|
|
|
|
|
|
|
|
|
pos = drag_data->next_pos;
|
|
|
|
|
drag_data->uri_list[pos] = g_strdup (uri);
|
|
|
|
|
drag_data->next_pos = pos + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_view_drag_data_get_cb (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
|
guint info,
|
|
|
|
|
guint32 time_,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
|
2008-02-16 02:31:33 +00:00
|
|
|
|
DragData drag_data;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gsize n_uris;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
n_uris = gtk_tree_selection_count_selected_rows (impl->priv->selection);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (n_uris == 0)
|
2008-02-16 02:31:33 +00:00
|
|
|
|
return;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2008-02-16 02:31:33 +00:00
|
|
|
|
drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
|
|
|
|
|
drag_data.next_pos = 0;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (impl->priv->selection,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
append_uri_to_urilist,
|
2008-02-16 02:31:33 +00:00
|
|
|
|
&drag_data);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2008-02-16 02:31:33 +00:00
|
|
|
|
gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2008-02-16 02:31:33 +00:00
|
|
|
|
g_strfreev (drag_data.uri_list);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-23 16:44:07 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
recent_view_query_tooltip_cb (GtkWidget *widget,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gboolean keyboard_tip,
|
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = user_data;
|
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
GtkRecentInfo *info = NULL;
|
|
|
|
|
gchar *uri_display;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->show_tips)
|
2007-07-23 16:44:07 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
tree_view = GTK_TREE_VIEW (impl->priv->recent_view);
|
2007-07-23 16:44:07 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_view_get_tooltip_context (tree_view,
|
|
|
|
|
&x, &y,
|
|
|
|
|
keyboard_tip,
|
|
|
|
|
NULL, &path, NULL);
|
|
|
|
|
if (!path)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->priv->recent_store), &iter, path))
|
2007-07-23 16:44:07 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->priv->recent_store), &iter,
|
2007-07-23 16:44:07 +00:00
|
|
|
|
RECENT_INFO_COLUMN, &info,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
uri_display = gtk_recent_info_get_uri_display (info);
|
|
|
|
|
|
|
|
|
|
gtk_tooltip_set_text (tooltip, uri_display);
|
|
|
|
|
gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
|
|
|
|
|
|
|
|
|
|
g_free (uri_display);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
gtk_recent_info_unref (info);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_selected_from_list (GtkRecentChooserDefault *impl)
|
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
|
|
|
|
GError *err;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->select_multiple)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
|
|
|
|
|
if (!uri)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
err = NULL;
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!gtk_recent_manager_remove_item (impl->priv->manager, uri, &err))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *msg;
|
|
|
|
|
|
2008-10-24 04:21:25 +00:00
|
|
|
|
msg = g_strdup (_("Could not remove item"));
|
2006-03-29 20:16:44 +00:00
|
|
|
|
error_message (impl, msg, err->message);
|
|
|
|
|
|
|
|
|
|
g_free (msg);
|
|
|
|
|
g_error_free (err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
copy_activated_cb (GtkMenuItem *menu_item,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
GtkRecentInfo *info;
|
|
|
|
|
gchar *utf8_uri;
|
|
|
|
|
|
|
|
|
|
info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
|
|
|
|
|
if (!info)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
utf8_uri = gtk_recent_info_get_uri_display (info);
|
|
|
|
|
|
|
|
|
|
gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
|
|
|
|
|
GDK_SELECTION_CLIPBOARD),
|
|
|
|
|
utf8_uri, -1);
|
|
|
|
|
|
2009-02-28 00:22:15 +00:00
|
|
|
|
gtk_recent_info_unref (info);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_free (utf8_uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_all_activated_cb (GtkMenuItem *menu_item,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_recent_manager_purge_items (impl->priv->manager, &err);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
gchar *msg;
|
|
|
|
|
|
|
|
|
|
msg = g_strdup (_("Could not clear list"));
|
|
|
|
|
|
|
|
|
|
error_message (impl, msg, err->message);
|
|
|
|
|
|
|
|
|
|
g_free (msg);
|
|
|
|
|
g_error_free (err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_item_activated_cb (GtkMenuItem *menu_item,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
|
|
|
|
|
remove_selected_from_list (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_private_toggled_cb (GtkCheckMenuItem *menu_item,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
|
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (impl),
|
|
|
|
|
"show-private", gtk_check_menu_item_get_active (menu_item),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_popup_menu_detach_cb (GtkWidget *attach_widget,
|
|
|
|
|
GtkMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl;
|
|
|
|
|
|
|
|
|
|
impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
|
|
|
|
|
g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_popup_menu = NULL;
|
|
|
|
|
impl->priv->recent_popup_menu_remove_item = NULL;
|
|
|
|
|
impl->priv->recent_popup_menu_copy_item = NULL;
|
|
|
|
|
impl->priv->recent_popup_menu_clear_item = NULL;
|
|
|
|
|
impl->priv->recent_popup_menu_show_private_item = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
|
|
|
|
|
{
|
|
|
|
|
gint count;
|
|
|
|
|
|
|
|
|
|
g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_assert (impl->priv->recent_popup_menu != NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (!impl->priv->manager)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
count = 0;
|
|
|
|
|
else
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_object_get (G_OBJECT (impl->priv->manager), "size", &count, NULL);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->priv->recent_popup_menu_remove_item, FALSE);
|
|
|
|
|
gtk_widget_set_sensitive (impl->priv->recent_popup_menu_copy_item, FALSE);
|
|
|
|
|
gtk_widget_set_sensitive (impl->priv->recent_popup_menu_clear_item, FALSE);
|
|
|
|
|
gtk_widget_set_sensitive (impl->priv->recent_popup_menu_show_private_item, FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_view_menu_build (GtkRecentChooserDefault *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->recent_popup_menu)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
recent_view_menu_ensure_state (impl);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_popup_menu = gtk_menu_new ();
|
|
|
|
|
gtk_menu_attach_to_widget (GTK_MENU (impl->priv->recent_popup_menu),
|
|
|
|
|
impl->priv->recent_view,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
recent_popup_menu_detach_cb);
|
|
|
|
|
|
2013-06-24 23:28:53 +00:00
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("Copy _Location"));
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_popup_menu_copy_item = item;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (copy_activated_cb), impl);
|
|
|
|
|
gtk_widget_show (item);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_widget_show (item);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-06-24 23:28:53 +00:00
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Remove From List"));
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_popup_menu_remove_item = item;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (remove_item_activated_cb), impl);
|
|
|
|
|
gtk_widget_show (item);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-06-24 23:28:53 +00:00
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Clear List"));
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_popup_menu_clear_item = item;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (remove_all_activated_cb), impl);
|
|
|
|
|
|
|
|
|
|
gtk_widget_show (item);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_widget_show (item);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->recent_popup_menu_show_private_item = item;
|
|
|
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->priv->show_private);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
g_signal_connect (item, "toggled",
|
|
|
|
|
G_CALLBACK (show_private_toggled_cb), impl);
|
|
|
|
|
gtk_widget_show (item);
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
|
|
|
|
recent_view_menu_ensure_state (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
recent_view_menu_popup (GtkRecentChooserDefault *impl,
|
|
|
|
|
GdkEventButton *event)
|
|
|
|
|
{
|
|
|
|
|
recent_view_menu_build (impl);
|
|
|
|
|
|
2016-07-12 18:08:36 +00:00
|
|
|
|
if (event && gdk_event_triggers_context_menu ((GdkEvent *) event))
|
|
|
|
|
gtk_menu_popup_at_pointer (GTK_MENU (impl->priv->recent_popup_menu), (GdkEvent *) event);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-07-12 18:08:36 +00:00
|
|
|
|
gtk_menu_popup_at_widget (GTK_MENU (impl->priv->recent_popup_menu),
|
|
|
|
|
impl->priv->recent_view,
|
|
|
|
|
GDK_GRAVITY_CENTER,
|
|
|
|
|
GDK_GRAVITY_CENTER,
|
|
|
|
|
(GdkEvent *) event);
|
|
|
|
|
|
|
|
|
|
gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->priv->recent_popup_menu), FALSE);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
recent_view_popup_menu_cb (GtkWidget *widget,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
recent_view_button_press_cb (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
|
2017-08-25 14:54:11 +00:00
|
|
|
|
gdouble x, y;
|
2011-09-18 22:32:52 +00:00
|
|
|
|
|
2017-08-25 14:54:11 +00:00
|
|
|
|
if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
|
|
|
|
|
gdk_event_get_coords ((GdkEvent *) event, &x, &y))
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->priv->recent_view),
|
2017-08-25 14:54:11 +00:00
|
|
|
|
x, y, &path,
|
2006-03-29 20:16:44 +00:00
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
if (!res)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* select the path before creating the popup menu */
|
2013-03-26 12:50:28 +00:00
|
|
|
|
gtk_tree_selection_select_path (impl->priv->selection, path);
|
2006-03-29 20:16:44 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
recent_view_menu_popup (impl, event);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_recent_manager (GtkRecentChooserDefault *impl,
|
|
|
|
|
GtkRecentManager *manager)
|
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->manager)
|
2006-03-29 20:16:44 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->manager_changed_id)
|
2007-06-19 10:29:55 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
g_signal_handler_disconnect (impl, impl->priv->manager_changed_id);
|
|
|
|
|
impl->priv->manager_changed_id = 0;
|
2007-06-19 10:29:55 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->manager = NULL;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manager)
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->manager = manager;
|
2006-03-29 20:16:44 +00:00
|
|
|
|
else
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->manager = gtk_recent_manager_get_default ();
|
2006-03-29 20:16:44 +00:00
|
|
|
|
|
2013-03-26 12:50:28 +00:00
|
|
|
|
if (impl->priv->manager)
|
2007-06-19 10:29:55 +00:00
|
|
|
|
{
|
2013-03-26 12:50:28 +00:00
|
|
|
|
impl->priv->manager_changed_id = g_signal_connect (impl->priv->manager, "changed",
|
|
|
|
|
G_CALLBACK (recent_manager_changed_cb),
|
|
|
|
|
impl);
|
2007-06-19 10:29:55 +00:00
|
|
|
|
}
|
2006-03-29 20:16:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
|
_gtk_recent_chooser_default_new (GtkRecentManager *manager)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
|
|
|
|
|
"recent-manager", manager,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|