summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2004-04-02 00:35:07 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2004-04-02 00:35:07 +0000
commit8e661364c6019e986f88dfbb7edb84b7deaf6f1c (patch)
treee9aac7791f5253cd7c96c7e07d8b2297836e7e61 /gtk
parent3d76be337dcec986c8624f863d322e9eb46e12fd (diff)
downloadgtk+-8e661364c6019e986f88dfbb7edb84b7deaf6f1c.tar.gz
Fix #136077.
2004-04-01 Federico Mena Quintero <federico@ximian.com> Fix #136077. * gtk/gtkpathbar.h (struct _GtkPathBarClass): Add a "child_is_hidden" boolean argument to the "path-clicked" signal. * gtk/gtkpathbar.c (struct _ButtonData): Added a file_is_hidden field. (make_directory_button): Take a file_is_hidden argument; put it in the ButtonData. (_gtk_path_bar_set_path): See whether each path component path is a hidden file. (gtk_path_bar_class_init): Add the file_is_hidden argument to the "path-clicked" signal. (button_clicked_cb): See if the downwards button represents a hidden file for the file_is_hidden argument in the signal emission. * gtk/gtkmarshalers.list: Added a signal type VOID:POINTER,BOOLEAN. * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_select_path): If we fail to switch folders, don't try to select the path in the file system model. Also, return the result from _gtk_file_system_model_path_do(). (gtk_file_chooser_default_select_path): Turn on show_hidden in the file system model if we are asked to select a hidden file. (path_bar_clicked): Show hidden files based on whether the immediate downwards folder in the path bar is a hidden file itself. (struct _GtkFileChooserDefault): Added fields browse_files_popup_menu and browse_files_popup_menu_hidden_files_item. (create_file_list): Set an object data key of "GtkFileChooserDefault" on the tree view so that we can find the impl from the popup menu callbacks. Also, hook up to the "button-press-event" and "popup-menu" signals in the file list to bring up a popup menu. (list_popup_menu_cb): New callback. (list_button_press_event_cb): New callback. Fix #138763: * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_new): Oops, connect_object to "finished-loading".
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkfilechooserdefault.c169
-rw-r--r--gtk/gtkfilesystemmodel.c4
-rw-r--r--gtk/gtkmarshalers.list1
-rw-r--r--gtk/gtkpathbar.c43
-rw-r--r--gtk/gtkpathbar.h3
5 files changed, 198 insertions, 22 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index ed559d75eb..9443feeb86 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -27,6 +27,7 @@
#include "gtkcellrendererpixbuf.h"
#include "gtkcellrendererseptext.h"
#include "gtkcellrenderertext.h"
+#include "gtkcheckmenuitem.h"
#include "gtkcombobox.h"
#include "gtkentry.h"
#include "gtkexpander.h"
@@ -106,6 +107,8 @@ struct _GtkFileChooserDefault
GtkWidget *browse_shortcuts_add_button;
GtkWidget *browse_shortcuts_remove_button;
GtkWidget *browse_files_tree_view;
+ GtkWidget *browse_files_popup_menu;
+ GtkWidget *browse_files_popup_menu_hidden_files_item;
GtkWidget *browse_new_folder_button;
GtkWidget *browse_path_bar;
GtkWidget *browse_extra_align;
@@ -347,6 +350,7 @@ static void list_row_activated (GtkTreeView *tree_view,
static void path_bar_clicked (GtkPathBar *path_bar,
GtkFilePath *file_path,
+ gboolean child_is_hidden,
GtkFileChooserDefault *impl);
static void add_bookmark_button_clicked_cb (GtkButton *button,
@@ -1676,7 +1680,7 @@ add_bookmark_foreach_cb (GtkTreeModel *model,
fs_model = impl->browse_files_model;
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, iter);
- file_path = _gtk_file_system_model_get_path (GTK_FILE_SYSTEM_MODEL (fs_model), &child_iter);
+ file_path = _gtk_file_system_model_get_path (fs_model, &child_iter);
shortcuts_add_bookmark_from_path (impl, file_path, -1);
}
@@ -2546,6 +2550,9 @@ shortcuts_pane_create (GtkFileChooserDefault *impl,
return vbox;
}
+/* Handles key press events on the file list, so that we can trap Enter to
+ * activate the default button on our own.
+ */
static gboolean
trap_activate_cb (GtkWidget *widget,
GdkEventKey *event,
@@ -2574,6 +2581,106 @@ trap_activate_cb (GtkWidget *widget,
return FALSE;
}
+/* Callback used when the file list's popup menu is detached */
+static void
+popup_menu_detach_cb (GtkWidget *attach_widget,
+ GtkMenu *menu)
+{
+ GtkFileChooserDefault *impl;
+
+ impl = g_object_get_data (G_OBJECT (attach_widget), "GtkFileChooserDefault");
+ g_assert (GTK_IS_FILE_CHOOSER_DEFAULT (impl));
+
+ impl->browse_files_popup_menu = NULL;
+ impl->browse_files_popup_menu_hidden_files_item = NULL;
+}
+
+/* Callback used when the "Show Hidden Files" menu item is toggled */
+static void
+show_hidden_toggled_cb (GtkCheckMenuItem *item,
+ GtkFileChooserDefault *impl)
+{
+ g_object_set (impl,
+ "show-hidden", gtk_check_menu_item_get_active (item),
+ NULL);
+}
+
+/* Constructs the popup menu for the file list if needed */
+static void
+file_list_build_popup_menu (GtkFileChooserDefault *impl)
+{
+ if (!impl->browse_files_popup_menu)
+ {
+ impl->browse_files_popup_menu = gtk_menu_new ();
+ gtk_menu_attach_to_widget (GTK_MENU (impl->browse_files_popup_menu),
+ impl->browse_files_tree_view,
+ popup_menu_detach_cb);
+
+ impl->browse_files_popup_menu_hidden_files_item =
+ gtk_check_menu_item_new_with_mnemonic (_("Show _Hidden Files"));
+ g_signal_connect (impl->browse_files_popup_menu_hidden_files_item, "toggled",
+ G_CALLBACK (show_hidden_toggled_cb), impl);
+
+ gtk_widget_show (impl->browse_files_popup_menu_hidden_files_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu),
+ impl->browse_files_popup_menu_hidden_files_item);
+ }
+
+ g_signal_handlers_block_by_func (impl->browse_files_popup_menu_hidden_files_item,
+ G_CALLBACK (show_hidden_toggled_cb), impl);
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (impl->browse_files_popup_menu_hidden_files_item),
+ impl->show_hidden);
+ g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_hidden_files_item,
+ G_CALLBACK (show_hidden_toggled_cb), impl);
+}
+
+static void
+file_list_popup_menu (GtkFileChooserDefault *impl,
+ GdkEventButton *event)
+{
+ int button;
+ guint32 timestamp;
+
+ if (event)
+ {
+ button = event->button;
+ timestamp = event->time;
+ }
+ else
+ {
+ button = 0;
+ timestamp = GDK_CURRENT_TIME;
+ }
+
+ file_list_build_popup_menu (impl);
+ gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
+ NULL, NULL, NULL, NULL,
+ button, timestamp);
+}
+
+/* Callback used for the GtkWidget::popup-menu signal of the file list */
+static gboolean
+list_popup_menu_cb (GtkWidget *widget,
+ GtkFileChooserDefault *impl)
+{
+ file_list_popup_menu (impl, NULL);
+ return TRUE;
+}
+
+/* Callback used when a button is pressed on the file list. We trap button 3 to
+ * bring up a popup menu.
+ */
+static gboolean
+list_button_press_event_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ GtkFileChooserDefault *impl)
+{
+ if (event->button != 3)
+ return FALSE;
+
+ file_list_popup_menu (impl, event);
+ return TRUE;
+}
/* Creates the widgets for the file list */
static GtkWidget *
@@ -2595,12 +2702,18 @@ create_file_list (GtkFileChooserDefault *impl)
/* Tree/list view */
impl->browse_files_tree_view = gtk_tree_view_new ();
+ g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "GtkFileChooserDefault", impl);
+
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE);
gtk_container_add (GTK_CONTAINER (swin), impl->browse_files_tree_view);
g_signal_connect (impl->browse_files_tree_view, "row-activated",
G_CALLBACK (list_row_activated), impl);
g_signal_connect (impl->browse_files_tree_view, "key-press-event",
G_CALLBACK (trap_activate_cb), impl);
+ g_signal_connect (impl->browse_files_tree_view, "popup-menu",
+ G_CALLBACK (list_popup_menu_cb), impl);
+ g_signal_connect (impl->browse_files_tree_view, "button-press-event",
+ G_CALLBACK (list_button_press_event_cb), impl);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view),
@@ -3272,8 +3385,7 @@ gtk_file_chooser_default_set_property (GObject *object,
if (show_hidden != impl->show_hidden)
{
impl->show_hidden = show_hidden;
- _gtk_file_system_model_set_show_hidden (GTK_FILE_SYSTEM_MODEL (impl->browse_files_model),
- show_hidden);
+ _gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden);
}
}
break;
@@ -3825,11 +3937,43 @@ gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
else
{
gboolean result;
+ GtkFileFolder *folder;
+ GtkFileInfo *info;
+ gboolean is_hidden;
result = _gtk_file_chooser_set_current_folder_path (chooser, parent_path, error);
+
+ if (!result)
+ {
+ gtk_file_path_free (parent_path);
+ return result;
+ }
+
+ folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_HIDDEN, error);
gtk_file_path_free (parent_path);
- _gtk_file_system_model_path_do (impl->browse_files_model, path,
- select_func, impl);
+
+ if (!folder)
+ return FALSE;
+
+ info = gtk_file_folder_get_info (folder, path, error);
+ g_object_unref (folder);
+
+ if (!info)
+ return FALSE;
+
+ is_hidden = gtk_file_info_get_is_hidden (info);
+ gtk_file_info_free (info);
+
+ if (is_hidden)
+ g_object_set (impl, "show-hidden", TRUE, NULL);
+
+ result = _gtk_file_system_model_path_do (impl->browse_files_model, path,
+ select_func, impl);
+ if (!result)
+ g_set_error (error,
+ GTK_FILE_CHOOSER_ERROR,
+ GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
+ _("Could not find the path"));
return result;
}
@@ -3861,7 +4005,7 @@ gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
_gtk_file_system_model_path_do (impl->browse_files_model, path,
- unselect_func, impl);
+ unselect_func, impl);
}
static void
@@ -3943,7 +4087,7 @@ get_paths_foreach (GtkTreeModel *model,
fs_model = info->impl->browse_files_model;
gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
- file_path = _gtk_file_system_model_get_path (GTK_FILE_SYSTEM_MODEL (fs_model), &sel_iter);
+ file_path = _gtk_file_system_model_get_path (fs_model, &sel_iter);
if (!file_path)
return; /* We are on the editable row */
@@ -4731,9 +4875,18 @@ list_row_activated (GtkTreeView *tree_view,
static void
path_bar_clicked (GtkPathBar *path_bar,
GtkFilePath *file_path,
+ gboolean child_is_hidden,
GtkFileChooserDefault *impl)
{
- change_folder_and_display_error (impl, file_path);
+ if (!change_folder_and_display_error (impl, file_path))
+ return;
+
+ /* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
+ * show hidden files so that ".baz" appears in the file list, as it will still
+ * be shown in the path bar: "/foo/[bar]/.baz"
+ */
+ if (child_is_hidden)
+ g_object_set (impl, "show-hidden", TRUE, NULL);
}
static const GtkFileInfo *
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 4032f7a09d..3a63681917 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -770,8 +770,8 @@ _gtk_file_system_model_new (GtkFileSystem *file_system,
if (gtk_file_folder_is_finished_loading (model->root_folder))
queue_finished_loading (model); /* done in an idle because we are being created */
else
- g_signal_connect (model->root_folder, "finished-loading",
- G_CALLBACK (root_folder_finished_loading_cb), model);
+ g_signal_connect_object (model->root_folder, "finished-loading",
+ G_CALLBACK (root_folder_finished_loading_cb), model, 0);
g_signal_connect_object (model->root_folder, "deleted",
G_CALLBACK (root_deleted_callback), model, 0);
diff --git a/gtk/gtkmarshalers.list b/gtk/gtkmarshalers.list
index 9d5bc9be66..fd65235793 100644
--- a/gtk/gtkmarshalers.list
+++ b/gtk/gtkmarshalers.list
@@ -82,6 +82,7 @@ VOID:OBJECT,UINT
VOID:OBJECT,UINT,FLAGS
VOID:POINTER
VOID:POINTER,INT
+VOID:POINTER,BOOLEAN
VOID:POINTER,POINTER,POINTER
VOID:POINTER,UINT
VOID:STRING
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 3009ed7f43..4a04dbacda 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -61,6 +61,7 @@ struct _ButtonData
GtkWidget *image;
GtkWidget *label;
gboolean ignore_changes;
+ gboolean file_is_hidden;
};
G_DEFINE_TYPE (GtkPathBar,
@@ -155,14 +156,15 @@ gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
/* container_class->child_type = gtk_path_bar_child_type;*/
path_bar_signals [PATH_CLICKED] =
- g_signal_new ("path_clicked",
+ g_signal_new ("path-clicked",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
NULL, NULL,
- _gtk_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
+ _gtk_marshal_VOID__POINTER_BOOLEAN,
+ G_TYPE_NONE, 2,
+ G_TYPE_POINTER,
+ G_TYPE_BOOLEAN);
}
@@ -744,17 +746,32 @@ button_clicked_cb (GtkWidget *button,
gpointer data)
{
ButtonData *button_data;
- GtkWidget *path_bar;
+ GtkPathBar *path_bar;
+ GList *button_list;
+ gboolean child_is_hidden;
button_data = BUTTON_DATA (data);
if (button_data->ignore_changes)
return;
- path_bar = button->parent;
- g_assert (GTK_IS_PATH_BAR (path_bar));
+ path_bar = GTK_PATH_BAR (button->parent);
+
+ button_list = g_list_find (path_bar->button_list, button_data);
+ g_assert (button_list != NULL);
+
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0, button_data->path);
+ if (button_list->prev)
+ {
+ ButtonData *child_data;
+
+ child_data = BUTTON_DATA (button_list->prev->data);
+ child_is_hidden = child_data->file_is_hidden;
+ }
+ else
+ child_is_hidden = FALSE;
+
+ g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0, button_data->path, child_is_hidden);
}
static GdkPixbuf *
@@ -880,7 +897,8 @@ static ButtonData *
make_directory_button (GtkPathBar *path_bar,
const char *dir_name,
GtkFilePath *path,
- gboolean current_dir)
+ gboolean current_dir,
+ gboolean file_is_hidden)
{
GtkWidget *child = NULL;
ButtonData *button_data;
@@ -915,6 +933,7 @@ make_directory_button (GtkPathBar *path_bar,
button_data->dir_name = g_strdup (dir_name);
button_data->path = gtk_file_path_new_dup (gtk_file_path_get_string (path));
+ button_data->file_is_hidden = file_is_hidden;
gtk_container_add (GTK_CONTAINER (button_data->button), child);
gtk_widget_show_all (button_data->button);
@@ -993,6 +1012,7 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar,
GtkFilePath *parent_path = NULL;
ButtonData *button_data;
const gchar *display_name;
+ gboolean is_hidden;
GtkFileFolder *file_folder;
GtkFileInfo *file_info;
gboolean valid;
@@ -1010,7 +1030,7 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar,
file_folder = gtk_file_system_get_folder (path_bar->file_system,
parent_path ? parent_path : path,
- GTK_FILE_INFO_DISPLAY_NAME,
+ GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN,
NULL);
if (!file_folder)
{
@@ -1032,8 +1052,9 @@ _gtk_path_bar_set_path (GtkPathBar *path_bar,
}
display_name = gtk_file_info_get_display_name (file_info);
+ is_hidden = gtk_file_info_get_is_hidden (file_info);
- button_data = make_directory_button (path_bar, display_name, path, first_directory);
+ button_data = make_directory_button (path_bar, display_name, path, first_directory, is_hidden);
gtk_file_info_free (file_info);
gtk_file_path_free (path);
diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h
index d34fc7aa5e..285da9ec4c 100644
--- a/gtk/gtkpathbar.h
+++ b/gtk/gtkpathbar.h
@@ -66,7 +66,8 @@ struct _GtkPathBarClass
GtkContainerClass parent_class;
void (* path_clicked) (GtkPathBar *path_bar,
- GtkFilePath *file_path);
+ GtkFilePath *file_path,
+ gboolean child_is_hidden);
};
GType gtk_path_bar_get_type (void) G_GNUC_CONST;