gtk/tests/testfilechooser.c

452 lines
13 KiB
C
Raw Normal View History

2005-07-13 05:44:22 +00:00
/* testfilechooser.c
* Copyright (C) 2003 Red Hat, Inc.
* Author: Owen Taylor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
2012-02-27 13:01:10 +00:00
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
2005-07-13 05:44:22 +00:00
*/
#include "config.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
2003-03-21 20:34:02 +00:00
#include <gtk/gtk.h>
#ifdef G_OS_WIN32
# include <io.h>
# define localtime_r(t,b) *(b) = *localtime (t)
# ifndef S_ISREG
# define S_ISREG(m) ((m) & _S_IFREG)
# endif
#endif
#if 0
static GtkWidget *preview_label;
static GtkWidget *preview_image;
#endif
static GtkFileChooserAction action;
2003-03-21 20:34:02 +00:00
static void
print_selected (GtkFileChooser *chooser)
{
GListModel *files = gtk_file_chooser_get_files (chooser);
guint i, n;
2003-03-21 20:34:02 +00:00
g_print ("Selection changed :\n");
n = g_list_model_get_n_items (files);
for (i = 0; i < n; i++)
2003-03-21 20:34:02 +00:00
{
GFile *file = g_list_model_get_item (files, i);
char *uri = g_file_get_uri (file);
g_print (" %s\n", uri ? uri : "(null)");
2003-03-21 20:34:02 +00:00
g_free (uri);
g_object_unref (files);
2003-03-21 20:34:02 +00:00
}
g_print ("\n");
g_object_unref (files);
2003-03-21 20:34:02 +00:00
}
static void
response_cb (GtkDialog *dialog,
2020-07-24 13:54:49 +00:00
int response_id,
gpointer data)
{
gboolean *done = data;
if (response_id == GTK_RESPONSE_OK)
{
GListModel *files;
guint i, n;
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
n = g_list_model_get_n_items (files);
g_print ("Selected files:\n");
for (i = 0; i < n; i++)
{
GFile *file = g_list_model_get_item (files, i);
char *uri = g_file_get_uri (file);
g_print (" %s\n", uri ? uri : "(null)");
g_free (uri);
g_object_unref (file);
}
g_object_unref (files);
}
else
g_print ("Dialog was closed\n");
*done = TRUE;
g_main_context_wakeup (NULL);
}
static void
filter_changed (GtkFileChooserDialog *dialog,
gpointer data)
{
g_print ("file filter changed\n");
}
#include <stdio.h>
#include <errno.h>
#define _(s) (s)
static void
set_current_folder (GtkFileChooser *chooser,
const char *name)
{
GFile *file = g_file_new_for_path (name);
if (!gtk_file_chooser_set_current_folder (chooser, file, NULL))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (chooser),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not set the folder to %s",
name);
gtk_widget_show (dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy),
NULL);
}
g_object_unref (file);
}
static void
set_folder_nonexistent_cb (GtkButton *button,
GtkFileChooser *chooser)
{
set_current_folder (chooser, "/nonexistent");
}
static void
set_folder_existing_nonexistent_cb (GtkButton *button,
GtkFileChooser *chooser)
{
set_current_folder (chooser, "/usr/nonexistent");
}
static void
set_filename (GtkFileChooser *chooser,
const char *name)
{
GFile *file = g_file_new_for_path (name);
if (!gtk_file_chooser_set_file (chooser, file, NULL))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (chooser),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not select %s",
name);
gtk_widget_show (dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy),
NULL);
}
g_object_unref (file);
}
static void
set_filename_nonexistent_cb (GtkButton *button,
GtkFileChooser *chooser)
{
set_filename (chooser, "/nonexistent");
}
static void
set_filename_existing_nonexistent_cb (GtkButton *button,
GtkFileChooser *chooser)
{
set_filename (chooser, "/usr/nonexistent");
}
static void
get_selection_cb (GtkButton *button,
GtkFileChooser *chooser)
{
GListModel *selection;
guint i, n;
selection = gtk_file_chooser_get_files (chooser);
n = g_list_model_get_n_items (selection);
g_print ("Selection: ");
for (i = 0; i < n; i++)
{
GFile *file = g_list_model_get_item (selection, i);
char *uri = g_file_get_uri (file);
g_print ("%s\n", uri);
g_free (uri);
g_object_unref (file);
}
g_object_unref (selection);
}
static void
get_current_name_cb (GtkButton *button,
GtkFileChooser *chooser)
{
char *name;
name = gtk_file_chooser_get_current_name (chooser);
g_print ("Current name: %s\n", name ? name : "NULL");
g_free (name);
}
Merged from gtk-2-6: 2005-01-24 Federico Mena Quintero <federico@ximian.com> Merged from gtk-2-6: Fix #147785 and clean up the loading code: * gtk/gtkfilechooserdefault.c (LoadState): Make the set of states be EMPTY, PRELOAD, LOADING, FINISHED. (gtk_file_chooser_default_init): Start in the LOAD_EMPTY state. (struct _GtkFileChooserDefault): Added a pending_select_paths field. (load_remove_timer): Add the new states. (load_setup_timer): Likewise. (load_timeout_cb): Likewise. Switch to the LOAD_LOADING state. (browse_files_model_finished_loading_cb): Switch to the LOAD_FINISHED state. (enum PendingOp): Removed. (struct _GtkFileChooserDefault): Removed the pending_op and pending_select_path fields. (pending_select_paths_free): New utility function. (pending_select_paths_add): New utility function. (gtk_file_chooser_default_finalize): Call pending_select_paths_free(). (pending_op_queue): Removed. (pending_op_process): Removed. (pending_select_paths_process): New function. (browse_files_model_finished_loading_cb): Call pending_select_paths_process(). (center_selected_row_foreach_cb): Handle multiple selection by only centering the first row. (get_is_file_filtered): Constify. (gtk_file_chooser_default_select_path): Queue into a list of paths to select if we are not finished loading. (show_and_select_paths): New utility function. (up_folder_handler): Use pending_select_paths_add(). (gtk_file_chooser_default_should_respond): Do not call pending_op_queue(); free the pending_selected_paths instead. (gtk_file_chooser_default_initial_focus): Don't queue a pending operation, and don't select the first row unconditionally --- this will happen when the folder is done loading. (shortcuts_row_activated_cb): Free the pending_select_paths. (pending_select_paths_store_selection): New utility function. (gtk_file_chooser_default_map): Call pending_select_paths_store_selection() to save the selection before reloading the folder. (select_func): Umm? Call gtk_tree_selection_select_iter(). Don't move the cursor here; it will be done when processing the pending paths. * tests/testfilechooser.c (main): Add a button to the command window to unmap and remap the file chooser.
2005-01-25 01:35:09 +00:00
static void
unmap_and_remap_cb (GtkButton *button,
GtkFileChooser *chooser)
{
gtk_widget_hide (GTK_WIDGET (chooser));
gtk_widget_show (GTK_WIDGET (chooser));
}
static void
2010-09-18 23:57:32 +00:00
kill_dependent (GtkWindow *win, GtkWidget *dep)
{
gtk_window_destroy (GTK_WINDOW (dep));
}
2003-03-21 20:34:02 +00:00
int
main (int argc, char **argv)
{
GtkWidget *control_window;
GtkWidget *vbbox;
GtkWidget *button;
GtkWidget *dialog;
GtkFileFilter *filter;
gboolean force_rtl = FALSE;
gboolean multiple = FALSE;
char *action_arg = NULL;
char *initial_filename = NULL;
char *initial_folder = NULL;
GFile *file;
GError *error = NULL;
GOptionEntry options[] = {
{ "action", 'a', 0, G_OPTION_ARG_STRING, &action_arg, "Filechooser action", "ACTION" },
{ "multiple", 'm', 0, G_OPTION_ARG_NONE, &multiple, "Select multiple", NULL },
{ "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
{ "initial-filename", 'f', 0, G_OPTION_ARG_FILENAME, &initial_filename, "Initial filename to select", "FILENAME" },
{ "initial-folder", 'F', 0, G_OPTION_ARG_FILENAME, &initial_folder, "Initial folder to show", "FILENAME" },
{ NULL }
};
GOptionContext *context;
gboolean done = FALSE;
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_print ("Failed to parse args: %s\n", error->message);
g_error_free (error);
return 1;
}
g_option_context_free (context);
gtk_init ();
if (initial_filename && initial_folder)
{
g_print ("Only one of --initial-filename and --initial-folder may be specified");
return 1;
}
if (force_rtl)
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
action = GTK_FILE_CHOOSER_ACTION_OPEN;
if (action_arg != NULL)
{
if (! strcmp ("open", action_arg))
action = GTK_FILE_CHOOSER_ACTION_OPEN;
else if (! strcmp ("save", action_arg))
action = GTK_FILE_CHOOSER_ACTION_SAVE;
else if (! strcmp ("select_folder", action_arg))
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
else
{
g_print ("--action must be one of \"open\", \"save\", \"select_folder\"\n");
return 1;
}
g_free (action_arg);
}
dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
"action", action,
"select-multiple", multiple,
NULL);
switch (action)
{
case GTK_FILE_CHOOSER_ACTION_OPEN:
case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
gtk_window_set_title (GTK_WINDOW (dialog), "Select a file");
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_OK,
NULL);
break;
case GTK_FILE_CHOOSER_ACTION_SAVE:
gtk_window_set_title (GTK_WINDOW (dialog), "Save a file");
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_OK,
NULL);
break;
default:
g_assert_not_reached ();
}
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
g_signal_connect (dialog, "selection-changed",
2003-03-21 20:34:02 +00:00
G_CALLBACK (print_selected), NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (response_cb), &done);
/* Filters */
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "All Files");
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
/* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
g_object_unref (filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "Starts with D");
gtk_file_filter_add_pattern (filter, "D*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_object_unref (filter);
g_signal_connect (dialog, "notify::filter",
G_CALLBACK (filter_changed), NULL);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "PNG and JPEG");
gtk_file_filter_add_mime_type (filter, "image/jpeg");
gtk_file_filter_add_mime_type (filter, "image/png");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_object_unref (filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "Images");
gtk_file_filter_add_pixbuf_formats (filter);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_object_unref (filter);
/* Choices */
2019-12-22 01:57:28 +00:00
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (dialog), "choice1",
"Choose one:",
(const char *[]){"one", "two", "three", NULL},
(const char *[]){"One", "Two", "Three", NULL});
gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (dialog), "choice1", "two");
Removed. (gtk_file_system_gnome_vfs_set_bookmarks): Removed. 2003-10-17 Federico Mena Quintero <federico@ximian.com> * gtkfilesystemgnomevfs.c (gtk_file_system_gnome_vfs_get_supports_bookmarks): Removed. (gtk_file_system_gnome_vfs_set_bookmarks): Removed. (gtk_file_system_gnome_vfs_add_bookmark): Implement. (gtk_file_system_gnome_vfs_remove_bookmark): Implement. * gtkfilechooserprivate.h (struct _GtkFileChooserIface): Replaced the ::set_shortcut_folders() method with :;add_shortcut_folder() and ::remove_shortcut_folder(). * gtkfilechooserutils.c (delegate_add_shortcut_folder): New function. (delegate_remove_shortcut_folder): New function. (delegate_list_shortcut_folders): New function. * gtkfilechooserimpldefault.c (create_shortcuts_model): Insert the Desktop directory as well. (shortcuts_insert_path): Renamed from shortcuts_append_path; now takes a position index instead of a parent node iter. Also takes a GError argument. (struct _GtkFileChooserImplDefault): Removed the shortcuts_folder list. It is all kept in the model now. (shortcuts_append_home): Save whether adding a shortcut for the home directory was successful. (shortcuts_append_desktop): Likewise for the desktop. (shortcuts_append_file_system_roots): Count and save the number of roots added. (shortcuts_append_shortcut_folders): Removed. (gtk_file_chooser_impl_default_add_shortcut_folder): Implement. (shortcuts_append_bookmarks): Now that we don't have a bookmarks parent node, don't expand the tree. (add_bookmark_button_clicked_cb): Use gtk_file_system_add_bookmark(). (remove_bookmark_button_clicked_cb): Use gtk_file_system_remove_bookmark(). (gtk_file_chooser_impl_default_list_shortcut_folders): Get the folders from the shortcuts model; we no longer keep a separate list. * gtkfilesystem.h (struct _GtkFileSystemIface): Oops, there shouldn't be shortcuts-related virtual methods here. * gtkfilechooser.c (file_paths_to_strings): New helper function. (gtk_file_chooser_get_filenames): Use file_paths_to_strings(). (gtk_file_chooser_get_uris): Likewise. (gtk_file_chooser_set_shortcut_folders): Removed. (gtk_file_chooser_list_shortcut_folders): Return a list of strings, not of GtkFilePath*. (gtk_file_chooser_list_shortcut_folder_uris): New function. (gtk_file_chooser_add_shortcut_folder): New function. (gtk_file_chooser_remove_shortcut_folder): New function. (gtk_file_chooser_add_shortcut_folder_uri): New function. (gtk_file_chooser_remove_shortcut_folder_uri): New function. (_gtk_file_chooser_add_shortcut_folder): New function. (_gtk_file_chooser_remove_shortcut_folder): New function. * gtkfilechooser.h: New enum. * gtkfilechooser.c (gtk_file_chooser_error_quark): New function. * gtkfilesystem.c (gtk_file_system_get_supports_bookmarks): Removed. (gtk_file_system_set_bookmarks): Removed. (gtk_file_system_add_bookmark): New function. (gtk_file_system_remove_bookmark): New function. * gtkfilesystemunix.c (gtk_file_system_unix_get_supports_bookmarks): Removed. (gtk_file_system_unix_set_bookmarks): Removed. (gtk_file_system_unix_add_bookmark): Just a stub for now. (gtk_file_system_unix_remove_bookmark): Likewise. * testfilechooser.c (main): Add a shortcut for testing purposes.
2003-10-18 04:29:40 +00:00
/* Shortcuts */
file = g_file_new_for_uri ("file:///usr/share/pixmaps");
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), file, NULL);
g_object_unref (file);
file = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_MUSIC));
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), file, NULL);
g_object_unref (file);
Removed. (gtk_file_system_gnome_vfs_set_bookmarks): Removed. 2003-10-17 Federico Mena Quintero <federico@ximian.com> * gtkfilesystemgnomevfs.c (gtk_file_system_gnome_vfs_get_supports_bookmarks): Removed. (gtk_file_system_gnome_vfs_set_bookmarks): Removed. (gtk_file_system_gnome_vfs_add_bookmark): Implement. (gtk_file_system_gnome_vfs_remove_bookmark): Implement. * gtkfilechooserprivate.h (struct _GtkFileChooserIface): Replaced the ::set_shortcut_folders() method with :;add_shortcut_folder() and ::remove_shortcut_folder(). * gtkfilechooserutils.c (delegate_add_shortcut_folder): New function. (delegate_remove_shortcut_folder): New function. (delegate_list_shortcut_folders): New function. * gtkfilechooserimpldefault.c (create_shortcuts_model): Insert the Desktop directory as well. (shortcuts_insert_path): Renamed from shortcuts_append_path; now takes a position index instead of a parent node iter. Also takes a GError argument. (struct _GtkFileChooserImplDefault): Removed the shortcuts_folder list. It is all kept in the model now. (shortcuts_append_home): Save whether adding a shortcut for the home directory was successful. (shortcuts_append_desktop): Likewise for the desktop. (shortcuts_append_file_system_roots): Count and save the number of roots added. (shortcuts_append_shortcut_folders): Removed. (gtk_file_chooser_impl_default_add_shortcut_folder): Implement. (shortcuts_append_bookmarks): Now that we don't have a bookmarks parent node, don't expand the tree. (add_bookmark_button_clicked_cb): Use gtk_file_system_add_bookmark(). (remove_bookmark_button_clicked_cb): Use gtk_file_system_remove_bookmark(). (gtk_file_chooser_impl_default_list_shortcut_folders): Get the folders from the shortcuts model; we no longer keep a separate list. * gtkfilesystem.h (struct _GtkFileSystemIface): Oops, there shouldn't be shortcuts-related virtual methods here. * gtkfilechooser.c (file_paths_to_strings): New helper function. (gtk_file_chooser_get_filenames): Use file_paths_to_strings(). (gtk_file_chooser_get_uris): Likewise. (gtk_file_chooser_set_shortcut_folders): Removed. (gtk_file_chooser_list_shortcut_folders): Return a list of strings, not of GtkFilePath*. (gtk_file_chooser_list_shortcut_folder_uris): New function. (gtk_file_chooser_add_shortcut_folder): New function. (gtk_file_chooser_remove_shortcut_folder): New function. (gtk_file_chooser_add_shortcut_folder_uri): New function. (gtk_file_chooser_remove_shortcut_folder_uri): New function. (_gtk_file_chooser_add_shortcut_folder): New function. (_gtk_file_chooser_remove_shortcut_folder): New function. * gtkfilechooser.h: New enum. * gtkfilechooser.c (gtk_file_chooser_error_quark): New function. * gtkfilesystem.c (gtk_file_system_get_supports_bookmarks): Removed. (gtk_file_system_set_bookmarks): Removed. (gtk_file_system_add_bookmark): New function. (gtk_file_system_remove_bookmark): New function. * gtkfilesystemunix.c (gtk_file_system_unix_get_supports_bookmarks): Removed. (gtk_file_system_unix_set_bookmarks): Removed. (gtk_file_system_unix_add_bookmark): Just a stub for now. (gtk_file_system_unix_remove_bookmark): Likewise. * testfilechooser.c (main): Add a shortcut for testing purposes.
2003-10-18 04:29:40 +00:00
/* Initial filename or folder */
if (initial_filename)
set_filename (GTK_FILE_CHOOSER (dialog), initial_filename);
if (initial_folder)
set_current_folder (GTK_FILE_CHOOSER (dialog), initial_folder);
/* show_all() to reveal bugs in composite widget handling */
2017-01-19 09:02:04 +00:00
gtk_widget_show (dialog);
2003-03-21 20:34:02 +00:00
/* Extra controls for manipulating the test environment
*/
2003-03-21 20:34:02 +00:00
control_window = gtk_window_new ();
vbbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (control_window), vbbox);
2003-03-21 20:34:02 +00:00
button = gtk_button_new_with_label ("set_current_folder (\"/nonexistent\")");
gtk_box_append (GTK_BOX (vbbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (set_folder_nonexistent_cb), dialog);
button = gtk_button_new_with_label ("set_current_folder (\"/usr/nonexistent\")");
gtk_box_append (GTK_BOX (vbbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (set_folder_existing_nonexistent_cb), dialog);
button = gtk_button_new_with_label ("set_filename (\"/nonexistent\")");
gtk_box_append (GTK_BOX (vbbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (set_filename_nonexistent_cb), dialog);
button = gtk_button_new_with_label ("set_filename (\"/usr/nonexistent\")");
gtk_box_append (GTK_BOX (vbbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (set_filename_existing_nonexistent_cb), dialog);
button = gtk_button_new_with_label ("Get selection");
gtk_box_append (GTK_BOX (vbbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (get_selection_cb), dialog);
button = gtk_button_new_with_label ("Get current name");
gtk_box_append (GTK_BOX (vbbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (get_current_name_cb), dialog);
Merged from gtk-2-6: 2005-01-24 Federico Mena Quintero <federico@ximian.com> Merged from gtk-2-6: Fix #147785 and clean up the loading code: * gtk/gtkfilechooserdefault.c (LoadState): Make the set of states be EMPTY, PRELOAD, LOADING, FINISHED. (gtk_file_chooser_default_init): Start in the LOAD_EMPTY state. (struct _GtkFileChooserDefault): Added a pending_select_paths field. (load_remove_timer): Add the new states. (load_setup_timer): Likewise. (load_timeout_cb): Likewise. Switch to the LOAD_LOADING state. (browse_files_model_finished_loading_cb): Switch to the LOAD_FINISHED state. (enum PendingOp): Removed. (struct _GtkFileChooserDefault): Removed the pending_op and pending_select_path fields. (pending_select_paths_free): New utility function. (pending_select_paths_add): New utility function. (gtk_file_chooser_default_finalize): Call pending_select_paths_free(). (pending_op_queue): Removed. (pending_op_process): Removed. (pending_select_paths_process): New function. (browse_files_model_finished_loading_cb): Call pending_select_paths_process(). (center_selected_row_foreach_cb): Handle multiple selection by only centering the first row. (get_is_file_filtered): Constify. (gtk_file_chooser_default_select_path): Queue into a list of paths to select if we are not finished loading. (show_and_select_paths): New utility function. (up_folder_handler): Use pending_select_paths_add(). (gtk_file_chooser_default_should_respond): Do not call pending_op_queue(); free the pending_selected_paths instead. (gtk_file_chooser_default_initial_focus): Don't queue a pending operation, and don't select the first row unconditionally --- this will happen when the folder is done loading. (shortcuts_row_activated_cb): Free the pending_select_paths. (pending_select_paths_store_selection): New utility function. (gtk_file_chooser_default_map): Call pending_select_paths_store_selection() to save the selection before reloading the folder. (select_func): Umm? Call gtk_tree_selection_select_iter(). Don't move the cursor here; it will be done when processing the pending paths. * tests/testfilechooser.c (main): Add a button to the command window to unmap and remap the file chooser.
2005-01-25 01:35:09 +00:00
button = gtk_button_new_with_label ("Unmap and remap");
gtk_box_append (GTK_BOX (vbbox), button);
Merged from gtk-2-6: 2005-01-24 Federico Mena Quintero <federico@ximian.com> Merged from gtk-2-6: Fix #147785 and clean up the loading code: * gtk/gtkfilechooserdefault.c (LoadState): Make the set of states be EMPTY, PRELOAD, LOADING, FINISHED. (gtk_file_chooser_default_init): Start in the LOAD_EMPTY state. (struct _GtkFileChooserDefault): Added a pending_select_paths field. (load_remove_timer): Add the new states. (load_setup_timer): Likewise. (load_timeout_cb): Likewise. Switch to the LOAD_LOADING state. (browse_files_model_finished_loading_cb): Switch to the LOAD_FINISHED state. (enum PendingOp): Removed. (struct _GtkFileChooserDefault): Removed the pending_op and pending_select_path fields. (pending_select_paths_free): New utility function. (pending_select_paths_add): New utility function. (gtk_file_chooser_default_finalize): Call pending_select_paths_free(). (pending_op_queue): Removed. (pending_op_process): Removed. (pending_select_paths_process): New function. (browse_files_model_finished_loading_cb): Call pending_select_paths_process(). (center_selected_row_foreach_cb): Handle multiple selection by only centering the first row. (get_is_file_filtered): Constify. (gtk_file_chooser_default_select_path): Queue into a list of paths to select if we are not finished loading. (show_and_select_paths): New utility function. (up_folder_handler): Use pending_select_paths_add(). (gtk_file_chooser_default_should_respond): Do not call pending_op_queue(); free the pending_selected_paths instead. (gtk_file_chooser_default_initial_focus): Don't queue a pending operation, and don't select the first row unconditionally --- this will happen when the folder is done loading. (shortcuts_row_activated_cb): Free the pending_select_paths. (pending_select_paths_store_selection): New utility function. (gtk_file_chooser_default_map): Call pending_select_paths_store_selection() to save the selection before reloading the folder. (select_func): Umm? Call gtk_tree_selection_select_iter(). Don't move the cursor here; it will be done when processing the pending paths. * tests/testfilechooser.c (main): Add a button to the command window to unmap and remap the file chooser.
2005-01-25 01:35:09 +00:00
g_signal_connect (button, "clicked",
G_CALLBACK (unmap_and_remap_cb), dialog);
2017-01-19 09:02:04 +00:00
gtk_widget_show (control_window);
g_signal_connect (dialog, "destroy",
G_CALLBACK (kill_dependent), control_window);
/* We need to hold a ref until we have destroyed the widgets, just in case
* someone else destroys them. We explicitly destroy windows to catch leaks.
*/
g_object_ref (dialog);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_destroy (GTK_WINDOW (dialog));
g_object_unref (dialog);
2003-03-21 20:34:02 +00:00
return 0;
}