2004-12-15 14:58:39 +00:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
/* GTK+: gtkfilechooserbutton.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 James M. Cape <jcape@ignore-your.tv>
|
|
|
|
*
|
|
|
|
* 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/>.
|
2004-12-15 14:58:39 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2004-12-15 14:58:39 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2004-08-17 16:06:39 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static const char *backend = "gtk+";
|
2004-12-15 14:58:39 +00:00
|
|
|
static gboolean rtl = FALSE;
|
|
|
|
static GOptionEntry entries[] = {
|
|
|
|
{ "backend", 'b', 0, G_OPTION_ARG_STRING, &backend, "The filesystem backend to use.", "gtk+" },
|
|
|
|
{ "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &rtl, "Force right-to-left layout.", NULL },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *gtk_src_dir = NULL;
|
|
|
|
|
2004-08-17 16:06:39 +00:00
|
|
|
static void
|
2004-11-30 21:06:48 +00:00
|
|
|
print_selected_path_clicked_cb (GtkWidget *button,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *folder, *filename;
|
|
|
|
char *folder_uri, *filename_uri;
|
2004-11-30 21:06:48 +00:00
|
|
|
|
|
|
|
folder = gtk_file_chooser_get_current_folder (user_data);
|
2020-02-21 15:11:15 +00:00
|
|
|
filename = gtk_file_chooser_get_file (user_data);
|
|
|
|
|
|
|
|
folder_uri = g_file_get_uri (folder);
|
|
|
|
filename_uri = g_file_get_uri (filename);
|
2004-11-30 21:06:48 +00:00
|
|
|
g_message ("Currently Selected:\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
|
2020-02-21 15:11:15 +00:00
|
|
|
folder_uri, filename_uri);
|
|
|
|
g_free (folder_uri);
|
|
|
|
g_free (filename_uri);
|
|
|
|
|
|
|
|
g_object_unref (folder);
|
|
|
|
g_object_unref (filename);
|
2004-11-30 21:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-12-15 14:58:39 +00:00
|
|
|
add_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *path = g_file_new_for_path (gtk_src_dir);
|
2004-12-15 14:58:39 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
if (!gtk_file_chooser_add_shortcut_folder (user_data, path, &err))
|
2004-12-15 14:58:39 +00:00
|
|
|
{
|
|
|
|
g_message ("Couldn't add `%s' as shortcut folder: %s", gtk_src_dir,
|
|
|
|
err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_message ("Added `%s' as shortcut folder.", gtk_src_dir);
|
|
|
|
}
|
2020-02-21 15:11:15 +00:00
|
|
|
|
|
|
|
g_object_unref (path);
|
2004-12-15 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
del_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *path = g_file_new_for_path (gtk_src_dir);
|
2004-12-15 14:58:39 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
if (!gtk_file_chooser_remove_shortcut_folder (user_data, path, &err))
|
2004-12-15 14:58:39 +00:00
|
|
|
{
|
|
|
|
g_message ("Couldn't remove `%s' as shortcut folder: %s", gtk_src_dir,
|
|
|
|
err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_message ("Removed `%s' as shortcut folder.", gtk_src_dir);
|
|
|
|
}
|
2020-02-21 15:11:15 +00:00
|
|
|
|
|
|
|
g_object_unref (path);
|
2004-12-15 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 05:19:23 +00:00
|
|
|
static void
|
|
|
|
unselect_all_clicked_cb (GtkWidget *button,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gtk_file_chooser_unselect_all (user_data);
|
|
|
|
}
|
|
|
|
|
2004-12-15 14:58:39 +00:00
|
|
|
static void
|
|
|
|
tests_button_clicked_cb (GtkButton *real_button,
|
2004-11-30 21:06:48 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *tests;
|
|
|
|
|
|
|
|
tests = g_object_get_data (user_data, "tests-dialog");
|
|
|
|
|
|
|
|
if (tests == NULL)
|
|
|
|
{
|
2004-12-15 14:58:39 +00:00
|
|
|
GtkWidget *box, *button;
|
2004-11-30 21:06:48 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
tests = gtk_window_new ();
|
2017-12-31 17:52:54 +00:00
|
|
|
gtk_window_set_hide_on_close (GTK_WINDOW (tests), TRUE);
|
2004-11-30 21:06:48 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (tests),
|
|
|
|
"Tests - TestFileChooserButton");
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (tests),
|
2019-05-20 04:47:50 +00:00
|
|
|
GTK_WINDOW (gtk_widget_get_root (user_data)));
|
2004-11-30 21:06:48 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2004-11-30 21:06:48 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (tests), box);
|
|
|
|
|
2004-12-15 14:58:39 +00:00
|
|
|
button = gtk_button_new_with_label ("Print Selected Path");
|
|
|
|
g_signal_connect (button, "clicked",
|
2004-11-30 21:06:48 +00:00
|
|
|
G_CALLBACK (print_selected_path_clicked_cb), user_data);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
2004-12-15 14:58:39 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Add $PWD's Parent as Shortcut");
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (add_pwds_parent_as_shortcut_clicked_cb), user_data);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
2004-12-15 14:58:39 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Remove $PWD's Parent as Shortcut");
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (del_pwds_parent_as_shortcut_clicked_cb), user_data);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
2004-11-30 21:06:48 +00:00
|
|
|
|
2008-07-15 05:19:23 +00:00
|
|
|
button = gtk_button_new_with_label ("Unselect all");
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (unselect_all_clicked_cb), user_data);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
2008-07-15 05:19:23 +00:00
|
|
|
|
2004-11-30 21:06:48 +00:00
|
|
|
g_object_set_data (user_data, "tests-dialog", tests);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (tests));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chooser_current_folder_changed_cb (GtkFileChooser *chooser,
|
|
|
|
gpointer user_data)
|
2004-08-17 16:06:39 +00:00
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *folder, *filename;
|
|
|
|
char *folder_uri, *filename_uri;
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
folder = gtk_file_chooser_get_current_folder (chooser);
|
|
|
|
filename = gtk_file_chooser_get_file (chooser);
|
|
|
|
|
|
|
|
folder_uri = g_file_get_uri (folder);
|
|
|
|
filename_uri = g_file_get_uri (filename);
|
Rework of GtkFileChooserButton, some cleanups. Fixes #154388, #154390,
2004-10-25 James M. Cape <jcape@ignore-your.tv>
Rework of GtkFileChooserButton, some cleanups. Fixes #154388,
#154390, #154390, #156272.
* docs/reference/gtk/gtk-docs.sgml: Moved GtkFileChooserButton
below GtkFileChooser.
* docs/reference/gtk/gtk-sections.txt: Added
gtk_file_chooser_button_get_width_chars(),
gtk_file_chooser_button_set_width_chars(),
gtk_label_set_width_chars(), gtk_label_get_width_chars().
* docs/reference/gtk/gtk.types: Added
gtk_cell_renderer_combo_get_type,
gtk_cell_view_get_type,
gtk_text_iter_get_type.
* docs/reference/gtk/tmpl/gtkaboutdialog.sgml: Add
"logo-icon-name" property.
* docs/reference/gtk/tmpl/gtkcellview.sgml: Updates for
properties
(b/c of get_type() inclusion above).
* docs/reference/gtk/tmpl/gtkfilechooserbutton.sgml:
* docs/reference/gtk/tmpl/gtklabel.sgml: Add "width-chars"
property,
getters/setters.
* docs/reference/gtk/tmpl/gtkcellrenderercombo.sgml: Added.
* gtk/gtkentrycompletion.c:
(_gtk_entry_completion_popdown): Don't show if the entry isn't
mapped.
* gtk/gtkfilechooserbutton.[c,h]: (*): About 45%
rewritten, adds "width-chars" property, icons, working save
modes, volume/Home/Desktop friendly-naming support.
* gtk/gtklabel.[c,h]:
(gtk_label_class_init), (gtk_label_init),
(gtk_label_get_property), (gtk_label_set_property),
(gtk_label_get_width_chars), (gtk_label_set_width_chars),
(gtk_label_size_request): Add "width-chars" property.
* tests/testfilechooserbutton.c: Update, use 4 different buttons
for the different ACTIONs.
* gtk/.cvsignore: Ignore gtk-update-icon-cache.
* tests/.cvsignore: Ignore testimage.
2004-10-26 04:29:56 +00:00
|
|
|
g_message ("%s::current-folder-changed\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
|
2020-02-21 15:11:15 +00:00
|
|
|
G_OBJECT_TYPE_NAME (chooser), folder_uri, filename_uri);
|
|
|
|
g_free (folder_uri);
|
|
|
|
g_free (filename_uri);
|
|
|
|
|
|
|
|
g_object_unref (folder);
|
|
|
|
g_object_unref (filename);
|
2004-08-17 16:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-30 21:06:48 +00:00
|
|
|
chooser_selection_changed_cb (GtkFileChooser *chooser,
|
|
|
|
gpointer user_data)
|
2004-08-17 16:06:39 +00:00
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *filename;
|
|
|
|
char *uri;
|
|
|
|
|
|
|
|
filename = gtk_file_chooser_get_file (chooser);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
uri = g_file_get_uri (filename);
|
Rework of GtkFileChooserButton, some cleanups. Fixes #154388, #154390,
2004-10-25 James M. Cape <jcape@ignore-your.tv>
Rework of GtkFileChooserButton, some cleanups. Fixes #154388,
#154390, #154390, #156272.
* docs/reference/gtk/gtk-docs.sgml: Moved GtkFileChooserButton
below GtkFileChooser.
* docs/reference/gtk/gtk-sections.txt: Added
gtk_file_chooser_button_get_width_chars(),
gtk_file_chooser_button_set_width_chars(),
gtk_label_set_width_chars(), gtk_label_get_width_chars().
* docs/reference/gtk/gtk.types: Added
gtk_cell_renderer_combo_get_type,
gtk_cell_view_get_type,
gtk_text_iter_get_type.
* docs/reference/gtk/tmpl/gtkaboutdialog.sgml: Add
"logo-icon-name" property.
* docs/reference/gtk/tmpl/gtkcellview.sgml: Updates for
properties
(b/c of get_type() inclusion above).
* docs/reference/gtk/tmpl/gtkfilechooserbutton.sgml:
* docs/reference/gtk/tmpl/gtklabel.sgml: Add "width-chars"
property,
getters/setters.
* docs/reference/gtk/tmpl/gtkcellrenderercombo.sgml: Added.
* gtk/gtkentrycompletion.c:
(_gtk_entry_completion_popdown): Don't show if the entry isn't
mapped.
* gtk/gtkfilechooserbutton.[c,h]: (*): About 45%
rewritten, adds "width-chars" property, icons, working save
modes, volume/Home/Desktop friendly-naming support.
* gtk/gtklabel.[c,h]:
(gtk_label_class_init), (gtk_label_init),
(gtk_label_get_property), (gtk_label_set_property),
(gtk_label_get_width_chars), (gtk_label_set_width_chars),
(gtk_label_size_request): Add "width-chars" property.
* tests/testfilechooserbutton.c: Update, use 4 different buttons
for the different ACTIONs.
* gtk/.cvsignore: Ignore gtk-update-icon-cache.
* tests/.cvsignore: Ignore testimage.
2004-10-26 04:29:56 +00:00
|
|
|
g_message ("%s::selection-changed\n\tSelection:`%s'\nDone.\n",
|
2020-02-21 15:11:15 +00:00
|
|
|
G_OBJECT_TYPE_NAME (chooser), uri);
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
g_object_unref (filename);
|
2004-08-17 16:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-30 21:06:48 +00:00
|
|
|
chooser_file_activated_cb (GtkFileChooser *chooser,
|
|
|
|
gpointer user_data)
|
2004-08-17 16:06:39 +00:00
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *folder, *filename;
|
|
|
|
char *folder_uri, *filename_uri;
|
|
|
|
|
|
|
|
folder = gtk_file_chooser_get_current_folder (chooser);
|
|
|
|
filename = gtk_file_chooser_get_file (chooser);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
folder_uri = g_file_get_uri (folder);
|
|
|
|
filename_uri = g_file_get_uri (filename);
|
Rework of GtkFileChooserButton, some cleanups. Fixes #154388, #154390,
2004-10-25 James M. Cape <jcape@ignore-your.tv>
Rework of GtkFileChooserButton, some cleanups. Fixes #154388,
#154390, #154390, #156272.
* docs/reference/gtk/gtk-docs.sgml: Moved GtkFileChooserButton
below GtkFileChooser.
* docs/reference/gtk/gtk-sections.txt: Added
gtk_file_chooser_button_get_width_chars(),
gtk_file_chooser_button_set_width_chars(),
gtk_label_set_width_chars(), gtk_label_get_width_chars().
* docs/reference/gtk/gtk.types: Added
gtk_cell_renderer_combo_get_type,
gtk_cell_view_get_type,
gtk_text_iter_get_type.
* docs/reference/gtk/tmpl/gtkaboutdialog.sgml: Add
"logo-icon-name" property.
* docs/reference/gtk/tmpl/gtkcellview.sgml: Updates for
properties
(b/c of get_type() inclusion above).
* docs/reference/gtk/tmpl/gtkfilechooserbutton.sgml:
* docs/reference/gtk/tmpl/gtklabel.sgml: Add "width-chars"
property,
getters/setters.
* docs/reference/gtk/tmpl/gtkcellrenderercombo.sgml: Added.
* gtk/gtkentrycompletion.c:
(_gtk_entry_completion_popdown): Don't show if the entry isn't
mapped.
* gtk/gtkfilechooserbutton.[c,h]: (*): About 45%
rewritten, adds "width-chars" property, icons, working save
modes, volume/Home/Desktop friendly-naming support.
* gtk/gtklabel.[c,h]:
(gtk_label_class_init), (gtk_label_init),
(gtk_label_get_property), (gtk_label_set_property),
(gtk_label_get_width_chars), (gtk_label_set_width_chars),
(gtk_label_size_request): Add "width-chars" property.
* tests/testfilechooserbutton.c: Update, use 4 different buttons
for the different ACTIONs.
* gtk/.cvsignore: Ignore gtk-update-icon-cache.
* tests/.cvsignore: Ignore testimage.
2004-10-26 04:29:56 +00:00
|
|
|
g_message ("%s::file-activated\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
|
2020-02-21 15:11:15 +00:00
|
|
|
G_OBJECT_TYPE_NAME (chooser), folder_uri, filename_uri);
|
|
|
|
g_free (folder_uri);
|
|
|
|
g_free (filename_uri);
|
|
|
|
|
|
|
|
g_object_unref (folder);
|
|
|
|
g_object_unref (filename);
|
2004-08-17 16:06:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 12:27:46 +00:00
|
|
|
static void
|
|
|
|
add_new_filechooser_button (const gchar *mnemonic,
|
|
|
|
const gchar *chooser_title,
|
|
|
|
GtkFileChooserAction action,
|
|
|
|
GtkWidget *group_box,
|
|
|
|
GtkSizeGroup *label_group)
|
|
|
|
{
|
|
|
|
GtkWidget *hbox, *label, *chooser, *button;
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *path;
|
2018-09-17 12:27:46 +00:00
|
|
|
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (group_box), hbox);
|
2018-09-17 12:27:46 +00:00
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (mnemonic);
|
|
|
|
gtk_size_group_add_widget (GTK_SIZE_GROUP (label_group), label);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), label);
|
2018-09-17 12:27:46 +00:00
|
|
|
|
|
|
|
chooser = gtk_file_chooser_button_new (g_strconcat(chooser_title,
|
|
|
|
" - testfilechooserbutton", NULL),
|
|
|
|
action);
|
|
|
|
gtk_widget_set_hexpand (chooser, TRUE);
|
2020-02-21 15:11:15 +00:00
|
|
|
|
|
|
|
path = g_file_new_for_path (gtk_src_dir);
|
|
|
|
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), path, NULL);
|
|
|
|
gtk_file_chooser_remove_shortcut_folder (GTK_FILE_CHOOSER (chooser), path, NULL);
|
|
|
|
g_object_unref (path);
|
|
|
|
|
2018-09-17 12:27:46 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), chooser);
|
|
|
|
g_signal_connect (chooser, "current-folder-changed",
|
|
|
|
G_CALLBACK (chooser_current_folder_changed_cb), NULL);
|
|
|
|
g_signal_connect (chooser, "selection-changed", G_CALLBACK (chooser_selection_changed_cb), NULL);
|
|
|
|
g_signal_connect (chooser, "file-activated", G_CALLBACK (chooser_file_activated_cb), NULL);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), chooser);
|
2018-09-17 12:27:46 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Tests");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (tests_button_clicked_cb), chooser);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
2018-09-17 12:27:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
2004-11-30 21:06:48 +00:00
|
|
|
|
2004-08-17 16:06:39 +00:00
|
|
|
int
|
2004-11-30 21:06:48 +00:00
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
2004-08-17 16:06:39 +00:00
|
|
|
{
|
2014-05-24 00:42:47 +00:00
|
|
|
GtkWidget *win, *vbox, *frame, *group_box;
|
2004-08-17 16:06:39 +00:00
|
|
|
GtkSizeGroup *label_group;
|
2004-12-15 14:58:39 +00:00
|
|
|
GOptionContext *context;
|
2009-10-20 02:01:52 +00:00
|
|
|
gchar *cwd;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2004-12-15 14:58:39 +00:00
|
|
|
|
|
|
|
context = g_option_context_new ("- test GtkFileChooserButton widget");
|
|
|
|
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
|
|
|
g_option_context_parse (context, &argc, &argv, NULL);
|
|
|
|
g_option_context_free (context);
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2004-12-15 14:58:39 +00:00
|
|
|
/* to test rtl layout, use "--right-to-left" */
|
|
|
|
if (rtl)
|
2004-08-17 16:52:04 +00:00
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
|
|
|
|
2009-10-20 02:01:52 +00:00
|
|
|
cwd = g_get_current_dir();
|
2004-12-15 14:58:39 +00:00
|
|
|
gtk_src_dir = g_path_get_dirname (cwd);
|
2009-10-20 02:01:52 +00:00
|
|
|
g_free (cwd);
|
2004-12-15 14:58:39 +00:00
|
|
|
|
2010-09-02 13:31:54 +00:00
|
|
|
win = gtk_dialog_new_with_buttons ("TestFileChooserButton", NULL, 0,
|
2013-06-24 21:31:22 +00:00
|
|
|
"_Quit", GTK_RESPONSE_CLOSE, NULL);
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (win, "response", G_CALLBACK (quit_cb), &done);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (vbox, 6);
|
|
|
|
gtk_widget_set_margin_end (vbox, 6);
|
|
|
|
gtk_widget_set_margin_top (vbox, 6);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 6);
|
2010-06-03 07:36:39 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (win))), vbox);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
|
|
|
frame = gtk_frame_new ("<b>GtkFileChooserButton</b>");
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (gtk_frame_get_label_widget (GTK_FRAME (frame))), TRUE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), frame);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2014-05-24 00:42:47 +00:00
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_set_valign (frame, GTK_ALIGN_FILL);
|
|
|
|
g_object_set (frame, "margin-top", 6, "margin-start", 12, NULL);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2004-08-17 16:06:39 +00:00
|
|
|
label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
group_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), group_box);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
2004-12-15 14:58:39 +00:00
|
|
|
/* OPEN */
|
2018-09-17 12:27:46 +00:00
|
|
|
add_new_filechooser_button ("_Open:", "Select A File",
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
group_box, label_group);
|
2004-11-30 21:06:48 +00:00
|
|
|
|
2004-12-15 14:58:39 +00:00
|
|
|
/* SELECT_FOLDER */
|
2018-09-17 12:27:46 +00:00
|
|
|
add_new_filechooser_button ("Select _Folder:", "Select A Folder",
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
|
|
|
group_box, label_group);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
|
|
|
g_object_unref (label_group);
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (win);
|
2004-08-17 16:06:39 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (win));
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2004-08-17 16:06:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|