summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2003-09-11 00:33:28 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2003-09-11 00:33:28 +0000
commitaa22566e6c98745e38b777b2c099bdc799857f59 (patch)
treef8b1a77adfa66d7e0e471c6c705a05ea5f739fa2
parente23ed607821328952000268ff8227cf36cddefc9 (diff)
downloadgtk+-aa22566e6c98745e38b777b2c099bdc799857f59.tar.gz
Connect to "row_activated" on the file list. (list_row_activated): New
2003-09-10 Federico Mena Quintero <federico@ximian.com> * gtkfilechooserimpldefault.c (create_file_list): Connect to "row_activated" on the file list. (list_row_activated): New function. Changes to folders or emits the "file-activated" signal depending on what type of row was activated. (create_folder_tree): Renamed from create_directory_tree(), since "folder" is the new politically-correct name. * gtkfilechooserprivate.h (struct _GtkFileChooserIface): Added a file-activated signal. * gtkfilechooser.c (gtk_file_chooser_class_init): Register the signal. * gtkfilechooserutils.c (_gtk_file_chooser_set_delegate): Connect to "file-activated" on the delegate. (delegate_file_activated): New function. * TODO: Added an API item about Clipart-like folders provided by applications.
-rw-r--r--gtk/gtkfilechooser.c7
-rw-r--r--gtk/gtkfilechooserdefault.c51
-rw-r--r--gtk/gtkfilechooserprivate.h1
-rw-r--r--gtk/gtkfilechooserutils.c11
4 files changed, 65 insertions, 5 deletions
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index 45e233646b..f3046e75ec 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -80,6 +80,13 @@ gtk_file_chooser_class_init (gpointer g_iface)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ g_signal_new ("file-activated",
+ iface_type,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkFileChooserIface, file_activated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
g_object_interface_install_property (g_iface,
g_param_spec_enum ("action",
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 03d7f88362..a1884b6a21 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -141,6 +141,10 @@ static void tree_selection_changed (GtkTreeSelection *tree_selectio
GtkFileChooserImplDefault *impl);
static void list_selection_changed (GtkTreeSelection *tree_selection,
GtkFileChooserImplDefault *impl);
+static void list_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ GtkFileChooserImplDefault *impl);
static void entry_activate (GtkEntry *entry,
GtkFileChooserImplDefault *impl);
@@ -333,9 +337,9 @@ create_filter (GtkFileChooserImplDefault *impl)
return impl->filter_alignment;
}
-/* Creates the widgets for the directory tree */
+/* Creates the widgets for the folder tree */
static GtkWidget *
-create_directory_tree (GtkFileChooserImplDefault *impl)
+create_folder_tree (GtkFileChooserImplDefault *impl)
{
GtkTreeSelection *selection;
@@ -381,7 +385,7 @@ create_directory_tree (GtkFileChooserImplDefault *impl)
return impl->tree_scrollwin;
}
-/* Creates the widgets for the directory tree */
+/* Creates the widgets for the folder tree */
static GtkWidget *
create_file_list (GtkFileChooserImplDefault *impl)
{
@@ -403,6 +407,8 @@ create_file_list (GtkFileChooserImplDefault *impl)
impl->list = gtk_tree_view_new ();
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->list), TRUE);
gtk_container_add (GTK_CONTAINER (impl->list_scrollwin), impl->list);
+ g_signal_connect (impl->list, "row_activated",
+ G_CALLBACK (list_row_activated), impl);
gtk_widget_show (impl->list);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
@@ -531,9 +537,9 @@ gtk_file_chooser_impl_default_constructor (GType type,
gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
gtk_widget_show (hpaned);
- /* Directory tree */
+ /* Folder tree */
- widget = create_directory_tree (impl);
+ widget = create_folder_tree (impl);
gtk_paned_add1 (GTK_PANED (hpaned), widget);
/* File list */
@@ -1395,6 +1401,41 @@ list_selection_changed (GtkTreeSelection *selection,
g_signal_emit_by_name (impl, "selection-changed", 0);
}
+/* Callback used when a row in the file list is activated */
+static void
+list_row_activated (GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ GtkFileChooserImplDefault *impl)
+{
+ GtkTreeIter iter, child_iter;
+ const GtkFileInfo *info;
+
+ if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
+ return;
+
+ gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
+
+ info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
+
+ if (gtk_file_info_get_is_folder (info))
+ {
+ const GtkFilePath *file_path;
+ char *uri;
+
+ file_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
+ uri = gtk_file_system_path_to_uri (impl->file_system, file_path);
+
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (impl), uri);
+
+ g_free (uri);
+
+ return;
+ }
+
+ g_signal_emit_by_name (impl, "file-activated");
+}
+
static void
entry_activate (GtkEntry *entry,
GtkFileChooserImplDefault *impl)
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 17343854ac..aeb79ee89d 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -62,6 +62,7 @@ struct _GtkFileChooserIface
void (*current_folder_changed) (GtkFileChooser *chooser);
void (*selection_changed) (GtkFileChooser *chooser);
void (*update_preview) (GtkFileChooser *chooser);
+ void (*file_activated) (GtkFileChooser *chooser);
};
GtkFileSystem *_gtk_file_chooser_get_file_system (GtkFileChooser *chooser);
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index 687cf44714..593a7ab567 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -52,6 +52,8 @@ static void delegate_selection_changed (GtkFileChooser *choose
gpointer data);
static void delegate_update_preview (GtkFileChooser *chooser,
gpointer data);
+static void delegate_file_activated (GtkFileChooser *chooser,
+ gpointer data);
/**
* _gtk_file_chooser_install_properties:
@@ -156,6 +158,8 @@ _gtk_file_chooser_set_delegate (GtkFileChooser *receiver,
G_CALLBACK (delegate_selection_changed), receiver);
g_signal_connect (delegate, "update-preview",
G_CALLBACK (delegate_update_preview), receiver);
+ g_signal_connect (delegate, "file-activated",
+ G_CALLBACK (delegate_file_activated), receiver);
}
static GtkFileChooser *
@@ -280,3 +284,10 @@ delegate_update_preview (GtkFileChooser *chooser,
{
g_signal_emit_by_name (data, "update-preview");
}
+
+static void
+delegate_file_activated (GtkFileChooser *chooser,
+ gpointer data)
+{
+ g_signal_emit_by_name (data, "file-activated");
+}