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
|
|
|
*/
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2003-11-15 20:35:55 +00:00
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
#include <string.h>
|
2003-07-23 22:30:32 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2003-11-15 20:35:55 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2003-07-23 22:30:32 +00:00
|
|
|
#include <unistd.h>
|
2003-11-15 20:35:55 +00:00
|
|
|
#endif
|
2003-03-21 20:34:02 +00:00
|
|
|
#include <gtk/gtk.h>
|
2003-11-15 20:35:55 +00:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
# include <io.h>
|
2004-03-08 00:55:21 +00:00
|
|
|
# define localtime_r(t,b) *(b) = *localtime (t)
|
2003-11-15 20:35:55 +00:00
|
|
|
# ifndef S_ISREG
|
|
|
|
# define S_ISREG(m) ((m) & _S_IFREG)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2022-10-29 14:36:29 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2015-07-16 04:25:46 +00:00
|
|
|
#if 0
|
2003-07-23 22:30:32 +00:00
|
|
|
static GtkWidget *preview_label;
|
|
|
|
static GtkWidget *preview_image;
|
2015-07-16 04:25:46 +00:00
|
|
|
#endif
|
2004-03-02 19:38:54 +00:00
|
|
|
static GtkFileChooserAction action;
|
2003-07-23 22:30:32 +00:00
|
|
|
|
2003-03-25 00:11:06 +00:00
|
|
|
static void
|
|
|
|
response_cb (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2020-02-10 03:24:47 +00:00
|
|
|
gpointer data)
|
2003-03-25 00:11:06 +00:00
|
|
|
{
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean *done = data;
|
|
|
|
|
2003-09-11 00:56:46 +00:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2020-07-09 05:29:20 +00:00
|
|
|
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);
|
|
|
|
}
|
2003-09-11 00:56:46 +00:00
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
g_object_unref (files);
|
2003-09-11 00:56:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_print ("Dialog was closed\n");
|
2004-03-02 17:03:04 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
2003-03-25 00:11:06 +00:00
|
|
|
}
|
|
|
|
|
2004-11-07 05:42:01 +00:00
|
|
|
static void
|
|
|
|
filter_changed (GtkFileChooserDialog *dialog,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_print ("file filter changed\n");
|
|
|
|
}
|
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#define _(s) (s)
|
|
|
|
|
|
|
|
|
2004-03-06 03:38:59 +00:00
|
|
|
static void
|
|
|
|
set_current_folder (GtkFileChooser *chooser,
|
|
|
|
const char *name)
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *file = g_file_new_for_path (name);
|
|
|
|
if (!gtk_file_chooser_set_current_folder (chooser, file, NULL))
|
2004-03-06 03:38:59 +00:00
|
|
|
{
|
|
|
|
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);
|
2020-04-30 14:32:38 +00:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gtk_window_destroy),
|
|
|
|
NULL);
|
2004-03-06 03:38:59 +00:00
|
|
|
}
|
2020-02-21 15:11:15 +00:00
|
|
|
g_object_unref (file);
|
2004-03-06 03:38:59 +00:00
|
|
|
}
|
|
|
|
|
2004-03-02 20:05:08 +00:00
|
|
|
static void
|
2004-03-02 21:55:01 +00:00
|
|
|
set_folder_nonexistent_cb (GtkButton *button,
|
2004-03-02 20:05:08 +00:00
|
|
|
GtkFileChooser *chooser)
|
|
|
|
{
|
2004-03-06 03:38:59 +00:00
|
|
|
set_current_folder (chooser, "/nonexistent");
|
2004-03-02 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-02 21:55:01 +00:00
|
|
|
set_folder_existing_nonexistent_cb (GtkButton *button,
|
2004-03-02 20:05:08 +00:00
|
|
|
GtkFileChooser *chooser)
|
|
|
|
{
|
2004-03-06 03:38:59 +00:00
|
|
|
set_current_folder (chooser, "/usr/nonexistent");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_filename (GtkFileChooser *chooser,
|
|
|
|
const char *name)
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *file = g_file_new_for_path (name);
|
|
|
|
if (!gtk_file_chooser_set_file (chooser, file, NULL))
|
2004-03-06 03:38:59 +00:00
|
|
|
{
|
|
|
|
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);
|
2020-04-30 14:32:38 +00:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gtk_window_destroy),
|
|
|
|
NULL);
|
2004-03-06 03:38:59 +00:00
|
|
|
}
|
2020-02-21 15:11:15 +00:00
|
|
|
g_object_unref (file);
|
2004-03-02 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-02 21:55:01 +00:00
|
|
|
set_filename_nonexistent_cb (GtkButton *button,
|
2004-03-02 20:05:08 +00:00
|
|
|
GtkFileChooser *chooser)
|
|
|
|
{
|
2004-03-06 03:38:59 +00:00
|
|
|
set_filename (chooser, "/nonexistent");
|
2004-03-02 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-02 21:55:01 +00:00
|
|
|
set_filename_existing_nonexistent_cb (GtkButton *button,
|
2004-03-02 20:05:08 +00:00
|
|
|
GtkFileChooser *chooser)
|
|
|
|
{
|
2004-03-06 03:38:59 +00:00
|
|
|
set_filename (chooser, "/usr/nonexistent");
|
2004-03-02 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:37:40 +00:00
|
|
|
static void
|
|
|
|
get_selection_cb (GtkButton *button,
|
|
|
|
GtkFileChooser *chooser)
|
|
|
|
{
|
2020-07-09 05:29:20 +00:00
|
|
|
GListModel *selection;
|
|
|
|
guint i, n;
|
2013-06-19 18:37:40 +00:00
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
selection = gtk_file_chooser_get_files (chooser);
|
2020-07-09 05:29:20 +00:00
|
|
|
n = g_list_model_get_n_items (selection);
|
2013-06-19 18:37:40 +00:00
|
|
|
|
|
|
|
g_print ("Selection: ");
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2013-06-19 18:37:40 +00:00
|
|
|
{
|
2020-07-09 05:29:20 +00:00
|
|
|
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);
|
2013-06-19 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
g_object_unref (selection);
|
2013-06-19 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2004-03-17 19:01:00 +00:00
|
|
|
static void
|
2010-09-18 23:57:32 +00:00
|
|
|
kill_dependent (GtkWindow *win, GtkWidget *dep)
|
2004-03-17 19:01:00 +00:00
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dep));
|
2004-03-17 19:01:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *control_window;
|
|
|
|
GtkWidget *vbbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *dialog;
|
2003-07-23 15:31:10 +00:00
|
|
|
GtkFileFilter *filter;
|
2008-02-16 01:23:18 +00:00
|
|
|
gboolean force_rtl = FALSE;
|
2004-03-10 14:56:28 +00:00
|
|
|
gboolean multiple = FALSE;
|
2008-02-16 01:23:18 +00:00
|
|
|
char *action_arg = NULL;
|
2009-06-12 19:02:37 +00:00
|
|
|
char *initial_filename = NULL;
|
2009-06-12 19:09:47 +00:00
|
|
|
char *initial_folder = NULL;
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *file;
|
2008-02-16 01:23:18 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GOptionEntry options[] = {
|
2008-10-13 15:15:23 +00:00
|
|
|
{ "action", 'a', 0, G_OPTION_ARG_STRING, &action_arg, "Filechooser action", "ACTION" },
|
2015-07-03 16:51:38 +00:00
|
|
|
{ "multiple", 'm', 0, G_OPTION_ARG_NONE, &multiple, "Select multiple", NULL },
|
2008-02-16 01:23:18 +00:00
|
|
|
{ "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
|
2009-06-12 19:02:37 +00:00
|
|
|
{ "initial-filename", 'f', 0, G_OPTION_ARG_FILENAME, &initial_filename, "Initial filename to select", "FILENAME" },
|
2009-06-12 19:09:47 +00:00
|
|
|
{ "initial-folder", 'F', 0, G_OPTION_ARG_FILENAME, &initial_folder, "Initial folder to show", "FILENAME" },
|
2008-02-16 01:23:18 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
2016-12-28 13:53:22 +00:00
|
|
|
GOptionContext *context;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2008-02-16 01:23:18 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
context = g_option_context_new ("");
|
|
|
|
g_option_context_add_main_entries (context, options, NULL);
|
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error))
|
2008-02-16 01:23:18 +00:00
|
|
|
{
|
|
|
|
g_print ("Failed to parse args: %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-12-28 13:53:22 +00:00
|
|
|
g_option_context_free (context);
|
|
|
|
|
|
|
|
gtk_init ();
|
2005-07-15 06:07:13 +00:00
|
|
|
|
2009-06-12 19:09:47 +00:00
|
|
|
if (initial_filename && initial_folder)
|
|
|
|
{
|
|
|
|
g_print ("Only one of --initial-filename and --initial-folder may be specified");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-16 01:23:18 +00:00
|
|
|
if (force_rtl)
|
2004-11-07 05:42:01 +00:00
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
2005-07-15 06:07:13 +00:00
|
|
|
|
2004-03-02 19:38:54 +00:00
|
|
|
action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
|
|
|
|
2008-02-16 01:23:18 +00:00
|
|
|
if (action_arg != NULL)
|
2004-03-02 19:38:54 +00:00
|
|
|
{
|
2008-02-16 01:23:18 +00:00
|
|
|
if (! strcmp ("open", action_arg))
|
2004-03-02 19:38:54 +00:00
|
|
|
action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
2008-02-16 01:23:18 +00:00
|
|
|
else if (! strcmp ("save", action_arg))
|
2004-03-02 19:38:54 +00:00
|
|
|
action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
2008-02-16 01:23:18 +00:00
|
|
|
else if (! strcmp ("select_folder", action_arg))
|
2004-03-02 19:38:54 +00:00
|
|
|
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
2013-06-21 15:19:54 +00:00
|
|
|
else
|
|
|
|
{
|
2020-02-22 14:54:48 +00:00
|
|
|
g_print ("--action must be one of \"open\", \"save\", \"select_folder\"\n");
|
2013-06-21 15:19:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-02-16 01:23:18 +00:00
|
|
|
|
|
|
|
g_free (action_arg);
|
2004-03-02 19:38:54 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 17:09:26 +00:00
|
|
|
dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
|
2004-03-02 19:38:54 +00:00
|
|
|
"action", action,
|
2004-03-10 14:56:28 +00:00
|
|
|
"select-multiple", multiple,
|
2003-03-26 17:09:26 +00:00
|
|
|
NULL);
|
2008-02-16 01:23:18 +00:00
|
|
|
|
2004-03-02 19:38:54 +00:00
|
|
|
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),
|
2013-06-24 21:31:22 +00:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Open"), GTK_RESPONSE_OK,
|
2004-03-02 19:38:54 +00:00
|
|
|
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),
|
2013-06-24 21:31:22 +00:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
2015-07-31 11:12:35 +00:00
|
|
|
_("_Save"), GTK_RESPONSE_OK,
|
2004-03-02 19:38:54 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
2020-03-06 17:05:43 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2004-03-02 19:38:54 +00:00
|
|
|
}
|
2003-03-25 00:11:06 +00:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2005-07-15 06:07:13 +00:00
|
|
|
|
2003-03-25 00:11:06 +00:00
|
|
|
g_signal_connect (dialog, "response",
|
2020-02-10 03:24:47 +00:00
|
|
|
G_CALLBACK (response_cb), &done);
|
2003-07-23 15:31:10 +00:00
|
|
|
|
|
|
|
/* 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);
|
2005-07-15 06:07:13 +00:00
|
|
|
|
2015-04-06 02:09:22 +00:00
|
|
|
/* Make this filter the default */
|
|
|
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
|
2020-07-03 17:40:58 +00:00
|
|
|
g_object_unref (filter);
|
2015-04-06 02:09:22 +00:00
|
|
|
|
2012-07-15 01:16:39 +00:00
|
|
|
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);
|
2020-07-03 17:40:58 +00:00
|
|
|
g_object_unref (filter);
|
2012-07-15 01:16:39 +00:00
|
|
|
|
2005-07-15 06:07:13 +00:00
|
|
|
g_signal_connect (dialog, "notify::filter",
|
2004-11-07 05:42:01 +00:00
|
|
|
G_CALLBACK (filter_changed), NULL);
|
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
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);
|
2020-07-03 17:40:58 +00:00
|
|
|
g_object_unref (filter);
|
2003-07-23 15:31:10 +00:00
|
|
|
|
2004-11-07 05:42:01 +00:00
|
|
|
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);
|
2020-07-03 17:40:58 +00:00
|
|
|
g_object_unref (filter);
|
2005-07-15 06:07:13 +00:00
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
/* Choices */
|
2004-03-02 20:05:08 +00:00
|
|
|
|
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");
|
2003-10-18 04:29:40 +00:00
|
|
|
|
|
|
|
/* Shortcuts */
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
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);
|
2003-10-18 04:29:40 +00:00
|
|
|
|
2009-06-12 19:09:47 +00:00
|
|
|
/* Initial filename or folder */
|
2009-06-12 19:02:37 +00:00
|
|
|
|
|
|
|
if (initial_filename)
|
|
|
|
set_filename (GTK_FILE_CHOOSER (dialog), initial_filename);
|
|
|
|
|
2009-06-12 19:09:47 +00:00
|
|
|
if (initial_folder)
|
|
|
|
set_current_folder (GTK_FILE_CHOOSER (dialog), initial_folder);
|
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
/* 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
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
/* Extra controls for manipulating the test environment
|
|
|
|
*/
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
control_window = gtk_window_new ();
|
2005-07-15 06:07:13 +00:00
|
|
|
|
2019-02-04 17:44:55 +00:00
|
|
|
vbbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-10 23:47:26 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (control_window), vbbox);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2004-03-02 21:55:01 +00:00
|
|
|
button = gtk_button_new_with_label ("set_current_folder (\"/nonexistent\")");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
2004-03-02 21:55:01 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (set_folder_nonexistent_cb), dialog);
|
|
|
|
|
2004-09-14 19:37:48 +00:00
|
|
|
button = gtk_button_new_with_label ("set_current_folder (\"/usr/nonexistent\")");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
2004-03-02 21:55:01 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (set_folder_existing_nonexistent_cb), dialog);
|
|
|
|
|
2004-09-14 19:37:48 +00:00
|
|
|
button = gtk_button_new_with_label ("set_filename (\"/nonexistent\")");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
2004-03-02 21:55:01 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (set_filename_nonexistent_cb), dialog);
|
|
|
|
|
2004-09-14 19:37:48 +00:00
|
|
|
button = gtk_button_new_with_label ("set_filename (\"/usr/nonexistent\")");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
2004-03-02 21:55:01 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (set_filename_existing_nonexistent_cb), dialog);
|
|
|
|
|
2013-06-19 18:37:40 +00:00
|
|
|
button = gtk_button_new_with_label ("Get selection");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
2013-06-19 18:37:40 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (get_selection_cb), dialog);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Get current name");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
2013-06-19 18:37:40 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (get_current_name_cb), dialog);
|
|
|
|
|
2005-01-25 01:35:09 +00:00
|
|
|
button = gtk_button_new_with_label ("Unmap and remap");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbbox), button);
|
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);
|
2004-03-17 19:01:00 +00:00
|
|
|
|
2004-11-19 23:30:47 +00:00
|
|
|
g_signal_connect (dialog, "destroy",
|
2004-03-17 19:01:00 +00:00
|
|
|
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);
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2004-03-17 19:01:00 +00:00
|
|
|
g_object_unref (dialog);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|