mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-12 21:40:19 +00:00
Fix bug #321560, based on a patch by Bogdan Nicula (bogdanni@hotmail.com):
2005-11-28 Federico Mena Quintero <federico@ximian.com> Fix bug #321560, based on a patch by Bogdan Nicula (bogdanni@hotmail.com): * gtk/gtkfilechooserdefault.c (up_folder_handler): Don't add the current_folder to the pending select paths here; the path bar will give it to us now. (path_bar_clicked): Add the child_path to the pending select paths here. (show_and_select_paths): Don't filter out folders. (show_and_select_paths): Don't take separate arguments for only_one_path and multiple paths. * tests/autotestfilechooser.c (test_folder_switch_and_filters): New test about preserving the filters when we change folders.
This commit is contained in:
parent
5eb2aac947
commit
4ac1632f10
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
2005-11-28 Federico Mena Quintero <federico@ximian.com>
|
||||||
|
|
||||||
|
Fix bug #321560, based on a patch by Bogdan Nicula (bogdanni@hotmail.com):
|
||||||
|
|
||||||
|
* gtk/gtkfilechooserdefault.c (up_folder_handler): Don't add the
|
||||||
|
current_folder to the pending select paths here; the path bar will
|
||||||
|
give it to us now.
|
||||||
|
(path_bar_clicked): Add the child_path to the pending select paths
|
||||||
|
here.
|
||||||
|
(show_and_select_paths): Don't filter out folders.
|
||||||
|
(show_and_select_paths): Don't take separate arguments for
|
||||||
|
only_one_path and multiple paths.
|
||||||
|
|
||||||
|
* tests/autotestfilechooser.c (test_folder_switch_and_filters):
|
||||||
|
New test about preserving the filters when we change folders.
|
||||||
|
|
||||||
2005-11-28 Matthias Clasen <mclasen@redhat.com>
|
2005-11-28 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkscale.c (_gtk_scale_format_value): Insert an LRM, to prevent
|
* gtk/gtkscale.c (_gtk_scale_format_value): Insert an LRM, to prevent
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
2005-11-28 Federico Mena Quintero <federico@ximian.com>
|
||||||
|
|
||||||
|
Fix bug #321560, based on a patch by Bogdan Nicula (bogdanni@hotmail.com):
|
||||||
|
|
||||||
|
* gtk/gtkfilechooserdefault.c (up_folder_handler): Don't add the
|
||||||
|
current_folder to the pending select paths here; the path bar will
|
||||||
|
give it to us now.
|
||||||
|
(path_bar_clicked): Add the child_path to the pending select paths
|
||||||
|
here.
|
||||||
|
(show_and_select_paths): Don't filter out folders.
|
||||||
|
(show_and_select_paths): Don't take separate arguments for
|
||||||
|
only_one_path and multiple paths.
|
||||||
|
|
||||||
|
* tests/autotestfilechooser.c (test_folder_switch_and_filters):
|
||||||
|
New test about preserving the filters when we change folders.
|
||||||
|
|
||||||
2005-11-28 Matthias Clasen <mclasen@redhat.com>
|
2005-11-28 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkscale.c (_gtk_scale_format_value): Insert an LRM, to prevent
|
* gtk/gtkscale.c (_gtk_scale_format_value): Insert an LRM, to prevent
|
||||||
|
@ -5044,51 +5044,32 @@ browse_files_center_selected_row (GtkFileChooserDefault *impl)
|
|||||||
static gboolean
|
static gboolean
|
||||||
show_and_select_paths (GtkFileChooserDefault *impl,
|
show_and_select_paths (GtkFileChooserDefault *impl,
|
||||||
const GtkFilePath *parent_path,
|
const GtkFilePath *parent_path,
|
||||||
const GtkFilePath *only_one_path,
|
|
||||||
GSList *paths,
|
GSList *paths,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GtkFileFolder *folder;
|
GtkFileFolder *folder;
|
||||||
gboolean success;
|
|
||||||
gboolean have_hidden;
|
gboolean have_hidden;
|
||||||
gboolean have_filtered;
|
gboolean have_filtered;
|
||||||
|
GSList *l;
|
||||||
|
|
||||||
profile_start ("start", NULL);
|
profile_start ("start", NULL);
|
||||||
|
|
||||||
if (!only_one_path && !paths)
|
if (!paths)
|
||||||
{
|
{
|
||||||
profile_end ("end", NULL);
|
profile_end ("end", NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_HIDDEN, error);
|
folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_IS_HIDDEN, error);
|
||||||
if (!folder)
|
if (!folder)
|
||||||
{
|
{
|
||||||
profile_end ("end", NULL);
|
profile_end ("end", NULL);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
success = FALSE;
|
|
||||||
have_hidden = FALSE;
|
have_hidden = FALSE;
|
||||||
have_filtered = FALSE;
|
have_filtered = FALSE;
|
||||||
|
|
||||||
if (only_one_path)
|
|
||||||
{
|
|
||||||
GtkFileInfo *info;
|
|
||||||
|
|
||||||
info = gtk_file_folder_get_info (folder, only_one_path, error);
|
|
||||||
if (info)
|
|
||||||
{
|
|
||||||
success = TRUE;
|
|
||||||
have_hidden = gtk_file_info_get_is_hidden (info);
|
|
||||||
have_filtered = get_is_file_filtered (impl, only_one_path, info);
|
|
||||||
gtk_file_info_free (info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GSList *l;
|
|
||||||
|
|
||||||
for (l = paths; l; l = l->next)
|
for (l = paths; l; l = l->next)
|
||||||
{
|
{
|
||||||
const GtkFilePath *path;
|
const GtkFilePath *path;
|
||||||
@ -5104,7 +5085,7 @@ show_and_select_paths (GtkFileChooserDefault *impl,
|
|||||||
have_hidden = gtk_file_info_get_is_hidden (info);
|
have_hidden = gtk_file_info_get_is_hidden (info);
|
||||||
|
|
||||||
if (!have_filtered)
|
if (!have_filtered)
|
||||||
have_filtered = get_is_file_filtered (impl, path, info);
|
have_filtered = !gtk_file_info_get_is_folder (info) && get_is_file_filtered (impl, path, info);
|
||||||
|
|
||||||
gtk_file_info_free (info);
|
gtk_file_info_free (info);
|
||||||
|
|
||||||
@ -5113,29 +5094,14 @@ show_and_select_paths (GtkFileChooserDefault *impl,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
success = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref (folder);
|
g_object_unref (folder);
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
profile_end ("end", NULL);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (have_hidden)
|
if (have_hidden)
|
||||||
g_object_set (impl, "show-hidden", TRUE, NULL);
|
g_object_set (impl, "show-hidden", TRUE, NULL);
|
||||||
|
|
||||||
if (have_filtered)
|
if (have_filtered)
|
||||||
set_current_filter (impl, NULL);
|
set_current_filter (impl, NULL);
|
||||||
|
|
||||||
if (only_one_path)
|
|
||||||
_gtk_file_system_model_path_do (impl->browse_files_model, only_one_path, select_func, impl);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GSList *l;
|
|
||||||
|
|
||||||
for (l = paths; l; l = l->next)
|
for (l = paths; l; l = l->next)
|
||||||
{
|
{
|
||||||
const GtkFilePath *path;
|
const GtkFilePath *path;
|
||||||
@ -5143,7 +5109,6 @@ show_and_select_paths (GtkFileChooserDefault *impl,
|
|||||||
path = l->data;
|
path = l->data;
|
||||||
_gtk_file_system_model_path_do (impl->browse_files_model, path, select_func, impl);
|
_gtk_file_system_model_path_do (impl->browse_files_model, path, select_func, impl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
profile_end ("end", NULL);
|
profile_end ("end", NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -5160,7 +5125,7 @@ pending_select_paths_process (GtkFileChooserDefault *impl)
|
|||||||
if (impl->pending_select_paths)
|
if (impl->pending_select_paths)
|
||||||
{
|
{
|
||||||
/* NULL GError */
|
/* NULL GError */
|
||||||
show_and_select_paths (impl, impl->current_folder, NULL, impl->pending_select_paths, NULL);
|
show_and_select_paths (impl, impl->current_folder, impl->pending_select_paths, NULL);
|
||||||
pending_select_paths_free (impl);
|
pending_select_paths_free (impl);
|
||||||
browse_files_center_selected_row (impl);
|
browse_files_center_selected_row (impl);
|
||||||
}
|
}
|
||||||
@ -5492,8 +5457,12 @@ gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
|
|||||||
if (same_path && impl->load_state == LOAD_FINISHED)
|
if (same_path && impl->load_state == LOAD_FINISHED)
|
||||||
{
|
{
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
GSList paths;
|
||||||
|
|
||||||
result = show_and_select_paths (impl, parent_path, path, NULL, error);
|
paths.data = (gpointer) path;
|
||||||
|
paths.next = NULL;
|
||||||
|
|
||||||
|
result = show_and_select_paths (impl, parent_path, &paths, error);
|
||||||
gtk_file_path_free (parent_path);
|
gtk_file_path_free (parent_path);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -6913,6 +6882,9 @@ path_bar_clicked (GtkPathBar *path_bar,
|
|||||||
gboolean child_is_hidden,
|
gboolean child_is_hidden,
|
||||||
GtkFileChooserDefault *impl)
|
GtkFileChooserDefault *impl)
|
||||||
{
|
{
|
||||||
|
if (child_path)
|
||||||
|
pending_select_paths_add (impl, child_path);
|
||||||
|
|
||||||
if (!change_folder_and_display_error (impl, file_path))
|
if (!change_folder_and_display_error (impl, file_path))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -6922,18 +6894,6 @@ path_bar_clicked (GtkPathBar *path_bar,
|
|||||||
*/
|
*/
|
||||||
if (child_is_hidden)
|
if (child_is_hidden)
|
||||||
g_object_set (impl, "show-hidden", TRUE, NULL);
|
g_object_set (impl, "show-hidden", TRUE, NULL);
|
||||||
|
|
||||||
/* Say we have "/foo/bar/baz" and the user clicks on "bar". We should then
|
|
||||||
* focus the "baz" entry in the files list - the reason for this is that
|
|
||||||
* if user furst changed to /foo/bar/baz from /foo/bar unintentionally
|
|
||||||
* instead of /foo/bar/baz1, it will take quite some time to scroll to baz1
|
|
||||||
* in the file list, especially if this directory contains lots of folders
|
|
||||||
*/
|
|
||||||
if (child_path != NULL)
|
|
||||||
{
|
|
||||||
gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (impl), child_path, NULL);
|
|
||||||
browse_files_center_selected_row (impl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GtkFileInfo *
|
static const GtkFileInfo *
|
||||||
@ -7407,7 +7367,6 @@ location_popup_handler (GtkFileChooserDefault *impl,
|
|||||||
static void
|
static void
|
||||||
up_folder_handler (GtkFileChooserDefault *impl)
|
up_folder_handler (GtkFileChooserDefault *impl)
|
||||||
{
|
{
|
||||||
pending_select_paths_add (impl, impl->current_folder);
|
|
||||||
_gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
|
_gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,6 +568,106 @@ test_button_folder_states (void)
|
|||||||
return passed;
|
return passed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sleep_timeout_cb (gpointer data)
|
||||||
|
{
|
||||||
|
gtk_main_quit ();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sleep_in_main_loop (int milliseconds)
|
||||||
|
{
|
||||||
|
g_timeout_add (milliseconds, sleep_timeout_cb, NULL);
|
||||||
|
gtk_main ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
test_folder_switch_and_filters (void)
|
||||||
|
{
|
||||||
|
gboolean passed;
|
||||||
|
char *cwd;
|
||||||
|
char *base_dir;
|
||||||
|
GtkFilePath *cwd_path;
|
||||||
|
GtkFilePath *base_dir_path;
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GtkFileFilter *all_filter;
|
||||||
|
GtkFileFilter *txt_filter;
|
||||||
|
GtkFileChooserDefault *impl;
|
||||||
|
|
||||||
|
passed = TRUE;
|
||||||
|
|
||||||
|
cwd = g_get_current_dir ();
|
||||||
|
base_dir = g_build_filename (cwd, "file-chooser-test-dir", NULL);
|
||||||
|
|
||||||
|
dialog = gtk_file_chooser_dialog_new ("Test", NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
|
||||||
|
NULL);
|
||||||
|
impl = get_impl_from_dialog (dialog);
|
||||||
|
|
||||||
|
cwd_path = gtk_file_system_filename_to_path (impl->file_system, cwd);
|
||||||
|
base_dir_path = gtk_file_system_filename_to_path (impl->file_system, base_dir);
|
||||||
|
|
||||||
|
passed = passed && gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
|
||||||
|
if (!passed)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* All files filter */
|
||||||
|
|
||||||
|
all_filter = gtk_file_filter_new ();
|
||||||
|
gtk_file_filter_set_name (all_filter, "All files");
|
||||||
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all_filter);
|
||||||
|
|
||||||
|
/* *.txt filter */
|
||||||
|
|
||||||
|
txt_filter = gtk_file_filter_new ();
|
||||||
|
gtk_file_filter_set_name (all_filter, "*.txt");
|
||||||
|
gtk_file_filter_add_pattern (txt_filter, "*.txt");
|
||||||
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), txt_filter);
|
||||||
|
|
||||||
|
/* Test filter set */
|
||||||
|
|
||||||
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), all_filter);
|
||||||
|
passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == all_filter);
|
||||||
|
|
||||||
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), txt_filter);
|
||||||
|
passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
|
||||||
|
|
||||||
|
log_test (passed, "test_folder_switch_and_filters(): set and get filter");
|
||||||
|
|
||||||
|
gtk_widget_show (dialog);
|
||||||
|
|
||||||
|
/* Test that filter is unchanged when we switch folders */
|
||||||
|
|
||||||
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd);
|
||||||
|
sleep_in_main_loop (1000);
|
||||||
|
passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
|
||||||
|
|
||||||
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
|
||||||
|
sleep_in_main_loop (500);
|
||||||
|
|
||||||
|
g_signal_emit_by_name (impl->browse_path_bar, "path-clicked",
|
||||||
|
(GtkFilePath *) cwd_path,
|
||||||
|
(GtkFilePath *) base_dir_path,
|
||||||
|
FALSE);
|
||||||
|
sleep_in_main_loop (500);
|
||||||
|
passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
|
||||||
|
|
||||||
|
log_test (passed, "test_folder_switch_and_filters(): filter after changing folder");
|
||||||
|
|
||||||
|
out:
|
||||||
|
g_free (cwd);
|
||||||
|
g_free (base_dir);
|
||||||
|
gtk_file_path_free (cwd_path);
|
||||||
|
gtk_file_path_free (base_dir_path);
|
||||||
|
|
||||||
|
gtk_widget_destroy (dialog);
|
||||||
|
|
||||||
|
log_test (passed, "test_folder_switch_and_filters(): all filter tests");
|
||||||
|
return passed;
|
||||||
|
}
|
||||||
|
|
||||||
static GLogFunc default_log_handler;
|
static GLogFunc default_log_handler;
|
||||||
static int num_warnings;
|
static int num_warnings;
|
||||||
static int num_errors;
|
static int num_errors;
|
||||||
@ -605,10 +705,10 @@ main (int argc, char **argv)
|
|||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
/* Start tests */
|
/* Start tests */
|
||||||
|
|
||||||
passed = passed && test_action_widgets ();
|
passed = passed && test_action_widgets ();
|
||||||
passed = passed && test_reload ();
|
passed = passed && test_reload ();
|
||||||
passed = passed && test_button_folder_states ();
|
passed = passed && test_button_folder_states ();
|
||||||
|
passed = passed && test_folder_switch_and_filters ();
|
||||||
log_test (passed, "main(): main tests");
|
log_test (passed, "main(): main tests");
|
||||||
|
|
||||||
/* Warnings and errors */
|
/* Warnings and errors */
|
||||||
|
0
tests/file-chooser-test-dir/empty
Normal file
0
tests/file-chooser-test-dir/empty
Normal file
1
tests/file-chooser-test-dir/text.txt
Normal file
1
tests/file-chooser-test-dir/text.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello world!
|
Loading…
Reference in New Issue
Block a user