From e8b729fb6b1606a231a0ce819f2823cfd4d06d73 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 11 May 2007 17:20:26 +0100 Subject: [PATCH] Subclass GtkTreeModelSort for the recent files model In order to add a path to the shortcuts from the recent files model via drag and drop we have to override the GtkTreeDragSourceIface implementation of the GtkTreeModelSort. This is done by subclassing GtkTreeModelSort into RecentModelSort. This patch creates the subclass. The actual override functions are in the next commit. --- gtk/gtkfilechooserdefault.c | 93 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 92 insertions(+), 1 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 159a062..549be48 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -261,6 +261,13 @@ static const GtkTargetEntry file_list_dest_targets[] = { static const int num_file_list_dest_targets = G_N_ELEMENTS (file_list_dest_targets); +/* Target types for dragging from the recent files list */ +static const GtkTargetEntry recent_list_source_targets[] = { + { "text/uri-list", 0, TEXT_URI_LIST } +}; + +static const int num_recent_list_source_targets = G_N_ELEMENTS (recent_list_source_targets); + static gboolean search_is_possible (GtkFileChooserDefault *impl) { @@ -526,6 +533,30 @@ static GtkTreeModel *shortcuts_pane_model_filter_new (GtkFileChooserDefault *imp GtkTreePath *root); +typedef struct { + GtkTreeModelSort parent; + + GtkFileChooserDefault *impl; +} RecentModelSort; + +typedef struct { + GtkTreeModelSortClass parent_class; +} RecentModelSortClass; + +#define RECENT_MODEL_SORT_TYPE (_recent_model_sort_get_type ()) +#define RECENT_MODEL_SORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RECENT_MODEL_SORT_TYPE, RecentModelSort)) + +static void recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface); + +G_DEFINE_TYPE_WITH_CODE (RecentModelSort, + _recent_model_sort, + GTK_TYPE_TREE_MODEL_SORT, + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE, + recent_model_sort_drag_source_iface_init)); + +static GtkTreeModel *recent_model_sort_new (GtkFileChooserDefault *impl, + GtkTreeModel *child_model); + G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDefault, _gtk_file_chooser_default, GTK_TYPE_VBOX, G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER, @@ -9553,7 +9584,7 @@ recent_setup_model (GtkFileChooserDefault *impl) * real data inside the model. */ impl->recent_model_sort = - GTK_TREE_MODEL_SORT (gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->recent_model_filter))); + GTK_TREE_MODEL_SORT (recent_model_sort_new (impl, GTK_TREE_MODEL (impl->recent_model_filter))); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->recent_model_sort), RECENT_MODEL_COL_INFO, recent_column_mtime_sort_func, @@ -11148,3 +11179,63 @@ shortcuts_pane_model_filter_new (GtkFileChooserDefault *impl, return GTK_TREE_MODEL (model); } + + + +static gboolean +recent_model_sort_row_draggable (GtkTreeDragSource *drag_source, + GtkTreePath *path) +{ + RecentModelSort *model; + + model = RECENT_MODEL_SORT (drag_source); + + return TRUE; +} + +static gboolean +recent_model_sort_drag_data_get (GtkTreeDragSource *drag_source, + GtkTreePath *path, + GtkSelectionData *selection_data) +{ + RecentModelSort *model; + + model = RECENT_MODEL_SORT (drag_source); + + /* FIXME */ + + return FALSE; +} + +static void +recent_model_sort_drag_source_iface_init (GtkTreeDragSourceIface *iface) +{ + iface->row_draggable = recent_model_sort_row_draggable; + iface->drag_data_get = recent_model_sort_drag_data_get; +} + +static void +_recent_model_sort_class_init (RecentModelSortClass *klass) +{ + +} + +static void +_recent_model_sort_init (RecentModelSort *model) +{ + model->impl = NULL; +} + +static GtkTreeModel * +recent_model_sort_new (GtkFileChooserDefault *impl, + GtkTreeModel *child_model) +{ + RecentModelSort *model; + + model = g_object_new (RECENT_MODEL_SORT_TYPE, + "model", child_model, + NULL); + model->impl = impl; + + return GTK_TREE_MODEL (model); +} -- 1.4.4.2