Commit eb9c2045 authored by Benjamin Otte's avatar Benjamin Otte
Browse files

gtk: Remove GtkFileChooserButton

... as discussed in the meeting.
parent a51f1199
Pipeline #235798 passed with stages
in 24 minutes and 42 seconds
......@@ -142,16 +142,42 @@ load_file (GtkStringList *list,
}
static void
file_selected_cb (GtkWidget *button,
open_response_cb (GtkWidget *dialog,
int response,
GtkStringList *stringlist)
{
GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (button));
gtk_widget_hide (dialog);
if (file)
if (response == GTK_RESPONSE_ACCEPT)
{
GFile *file;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
load_file (stringlist, file);
g_object_unref (file);
}
gtk_window_destroy (GTK_WINDOW (dialog));
}
static void
file_open_cb (GtkWidget *button,
GtkStringList *stringlist)
{
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new ("Open file",
GTK_WINDOW (gtk_widget_get_root (button)),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Load", GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), stringlist);
gtk_widget_show (dialog);
}
GtkWidget *
......@@ -189,8 +215,8 @@ do_listview_words (GtkWidget *do_widget)
header = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
open_button = gtk_file_chooser_button_new ("_Open", GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect (open_button, "file-set", G_CALLBACK (file_selected_cb), stringlist);
open_button = gtk_button_new_with_mnemonic ("_Open");
g_signal_connect (open_button, "clicked", G_CALLBACK (file_open_cb), stringlist);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), open_button);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
......
......@@ -13,19 +13,50 @@
static void
file_set (GtkFileChooserButton *button,
GtkWidget *picture)
open_response_cb (GtkWidget *dialog,
int response,
GtkPicture *picture)
{
GFile *file;
GdkPaintable *paintable;
gtk_widget_hide (dialog);
if (response == GTK_RESPONSE_ACCEPT)
{
GFile *file;
GdkPaintable *paintable;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
paintable = svg_paintable_new (file);
gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
g_object_unref (paintable);
g_object_unref (file);
}
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (button));
gtk_window_destroy (GTK_WINDOW (dialog));
}
paintable = svg_paintable_new (file);
gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
static void
show_file_open (GtkWidget *button,
GtkPicture *picture)
{
GtkFileFilter *filter;
GtkWidget *dialog;
g_object_unref (paintable);
g_object_unref (file);
dialog = gtk_file_chooser_dialog_new ("Open node file",
GTK_WINDOW (gtk_widget_get_root (button)),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Load", GTK_RESPONSE_ACCEPT,
NULL);
filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "image/svg+xml");
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), picture);
gtk_widget_show (dialog);
}
static GtkWidget *window;
......@@ -35,7 +66,6 @@ do_paintable_svg (GtkWidget *do_widget)
{
GtkWidget *header;
GtkWidget *picture;
GtkFileFilter *filter;
GtkWidget *button;
GFile *file;
GdkPaintable *paintable;
......@@ -49,17 +79,14 @@ do_paintable_svg (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "Paintable — SVG");
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
button = gtk_file_chooser_button_new ("Select an SVG file", GTK_FILE_CHOOSER_ACTION_OPEN);
filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "image/svg+xml");
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (button), filter);
button = gtk_button_new_with_mnemonic ("_Open");
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
picture = gtk_picture_new ();
gtk_picture_set_can_shrink (GTK_PICTURE (picture), TRUE);
gtk_widget_set_size_request (picture, 16, 16);
g_signal_connect (button, "file-set", G_CALLBACK (file_set), picture);
g_signal_connect (button, "clicked", G_CALLBACK (show_file_open), picture);
gtk_window_set_child (GTK_WINDOW (window), picture);
......
......@@ -63,9 +63,6 @@ do_pickers (GtkWidget *do_widget)
if (!window)
{
char *dir;
GFile *file;
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
......@@ -129,41 +126,6 @@ do_pickers (GtkWidget *do_widget)
gtk_widget_set_hexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
picker = gtk_file_chooser_button_new ("Pick a File",
GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_grid_attach (GTK_GRID (table), picker, 1, 2, 1, 1);
picker = gtk_file_chooser_button_new ("Pick a File",
GTK_FILE_CHOOSER_ACTION_OPEN);
dir = g_get_current_dir ();
file = g_file_new_for_path (dir);
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (picker), file, NULL);
g_object_unref (file);
g_free (dir);
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (picker),
"choice",
"Encoding",
(const char *[]) { "option1", "option2", NULL },
(const char *[]) { "UTF-8", "Other Encoding", NULL });
gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (picker), "choice", "option1");
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (picker),
"check",
"Read backwards",
NULL, NULL);
gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (picker), "check", "false");
gtk_grid_attach (GTK_GRID (table), picker, 2, 2, 1, 1);
label = gtk_label_new ("Folder:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
picker = gtk_file_chooser_button_new ("Pick a Folder",
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_grid_attach (GTK_GRID (table), label, 0, 3, 1, 1);
gtk_grid_attach (GTK_GRID (table), picker, 1, 3, 1, 1);
label = gtk_label_new ("Mail:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
......
......@@ -878,9 +878,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<property name="use-alpha">1</property>
</object>
</child>
<child>
<object class="GtkFileChooserButton" id="filechooserbutton1"/>
</child>
<child>
<object class="GtkLinkButton" id="linkbutton1">
<property name="label" translatable="yes">link button</property>
......
......@@ -283,7 +283,6 @@
<xi:include href="xml/gtkcolorchooserwidget.xml" />
<xi:include href="xml/gtkcolorchooserdialog.xml" />
<xi:include href="xml/gtkfilechooser.xml" />
<xi:include href="xml/gtkfilechooserbutton.xml" />
<xi:include href="xml/gtkfilechoosernative.xml" />
<xi:include href="xml/gtkfilechooserdialog.xml" />
<xi:include href="xml/gtkfilechooserwidget.xml" />
......
......@@ -1339,31 +1339,6 @@ gtk_file_chooser_widget_get_type
GtkFileChooserWidgetPrivate
</SECTION>
<SECTION>
<FILE>gtkfilechooserbutton</FILE>
<TITLE>GtkFileChooserButton</TITLE>
GtkFileChooserButton
gtk_file_chooser_button_new
gtk_file_chooser_button_new_with_dialog
gtk_file_chooser_button_get_title
gtk_file_chooser_button_set_title
gtk_file_chooser_button_get_width_chars
gtk_file_chooser_button_set_width_chars
gtk_file_chooser_button_get_modal
gtk_file_chooser_button_set_modal
<SUBSECTION Standard>
GTK_FILE_CHOOSER_BUTTON
GTK_IS_FILE_CHOOSER_BUTTON
GTK_TYPE_FILE_CHOOSER_BUTTON
GTK_FILE_CHOOSER_BUTTON_CLASS
GTK_IS_FILE_CHOOSER_BUTTON_CLASS
GTK_FILE_CHOOSER_BUTTON_GET_CLASS
<SUBSECTION Private>
gtk_file_chooser_button_get_type
GtkFileChooserButtonPrivate
</SECTION>
<SECTION>
<FILE>gtkfilefilter</FILE>
GtkFileFilter
......
......@@ -87,7 +87,6 @@ gtk_event_controller_motion_get_type
gtk_event_controller_scroll_get_type
gtk_every_filter_get_type
gtk_expander_get_type
gtk_file_chooser_button_get_type
gtk_file_chooser_dialog_get_type
gtk_file_chooser_get_type
gtk_file_chooser_native_get_type
......
......@@ -615,51 +615,6 @@ create_font_button (void)
return new_widget_info ("font-button", vbox, SMALL);
}
static WidgetInfo *
create_file_button (void)
{
GtkWidget *vbox;
GtkWidget *vbox2;
GtkWidget *picker;
char *path;
GFile *file;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
picker = gtk_file_chooser_button_new ("File Chooser Button",
GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_widget_set_size_request (picker, 150, -1);
gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox2), picker);
gtk_box_append (GTK_BOX (vbox2),
gtk_label_new ("File Button (Files)"));
gtk_box_append (GTK_BOX (vbox),
vbox2);
gtk_box_append (GTK_BOX (vbox),
gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
picker = gtk_file_chooser_button_new ("File Chooser Button",
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_widget_set_size_request (picker, 150, -1);
path = g_build_filename (g_get_home_dir (), "Documents", NULL);
file = g_file_new_for_path (path);
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (picker), file, NULL);
g_free (path);
g_object_unref (file);
gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox2), picker);
gtk_box_append (GTK_BOX (vbox2), gtk_label_new ("File Button (Select Folder)"));
gtk_box_append (GTK_BOX (vbox), vbox2);
add_margin (vbox);
return new_widget_info ("file-button", vbox, MEDIUM);
}
static WidgetInfo *
create_editable_label (void)
{
......@@ -2144,7 +2099,6 @@ get_all_widgets (void)
retval = g_list_prepend (retval, create_combo_box_entry ());
retval = g_list_prepend (retval, create_combo_box_text ());
retval = g_list_prepend (retval, create_entry ());
retval = g_list_prepend (retval, create_file_button ());
retval = g_list_prepend (retval, create_font_button ());
retval = g_list_prepend (retval, create_frame ());
retval = g_list_prepend (retval, create_icon_view ());
......
......@@ -66,7 +66,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkEntry, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkEntryCompletion, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkEventController, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkExpander, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFileChooserButton, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFileChooserDialog, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFileChooserWidget, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFileFilter, g_object_unref)
......
......@@ -119,7 +119,6 @@
#include <gtk/gtkfixed.h>
#include <gtk/gtkfixedlayout.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/gtkfilechooserbutton.h>
#include <gtk/gtkfilechooserdialog.h>
#include <gtk/gtkfilechoosernative.h>
#include <gtk/gtkfilechooserwidget.h>
......
......@@ -29,15 +29,14 @@
* SECTION:gtkfilechooser
* @Short_description: File chooser interface used by GtkFileChooserWidget and GtkFileChooserDialog
* @Title: GtkFileChooser
* @See_also: #GtkFileChooserDialog, #GtkFileChooserWidget, #GtkFileChooserButton
* @See_also: #GtkFileChooserDialog, #GtkFileChooserWidget
*
* #GtkFileChooser is an interface that can be implemented by file
* selection widgets. In GTK, the main objects that implement this
* interface are #GtkFileChooserWidget, #GtkFileChooserDialog, and
* #GtkFileChooserButton. You do not need to write an object that
* implements the #GtkFileChooser interface unless you are trying to
* adapt an existing file selector to expose a standard programming
* interface.
* interface are #GtkFileChooserWidget and #GtkFileChooserDialog. You do not
* need to write an object that implements the #GtkFileChooser interface
* unless you are trying to adapt an existing file selector to expose a
* standard programming interface.
*
* #GtkFileChooser allows for shortcuts to various places in the filesystem.
* In the default implementation these are displayed in the left pane. It
......
This diff is collapsed.
/* gtkfilechooserbutton.h
*
* 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_FILE_CHOOSER_BUTTON_H__
#define __GTK_FILE_CHOOSER_BUTTON_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkbox.h>
#include <gtk/gtkfilechooser.h>
G_BEGIN_DECLS
#define GTK_TYPE_FILE_CHOOSER_BUTTON (gtk_file_chooser_button_get_type ())
#define GTK_FILE_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_CHOOSER_BUTTON, GtkFileChooserButton))
#define GTK_IS_FILE_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_CHOOSER_BUTTON))
typedef struct _GtkFileChooserButton GtkFileChooserButton;
GDK_AVAILABLE_IN_ALL
GType gtk_file_chooser_button_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_file_chooser_button_new (const char *title,
GtkFileChooserAction action);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_file_chooser_button_new_with_dialog (GtkWidget *dialog);
GDK_AVAILABLE_IN_ALL
const char * gtk_file_chooser_button_get_title (GtkFileChooserButton *button);
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_button_set_title (GtkFileChooserButton *button,
const char *title);
GDK_AVAILABLE_IN_ALL
int gtk_file_chooser_button_get_width_chars (GtkFileChooserButton *button);
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_button_set_width_chars (GtkFileChooserButton *button,
int n_chars);
GDK_AVAILABLE_IN_ALL
gboolean gtk_file_chooser_button_get_modal (GtkFileChooserButton *button);
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_button_set_modal (GtkFileChooserButton *button,
gboolean modal);
G_END_DECLS
#endif /* !__GTK_FILE_CHOOSER_BUTTON_H__ */
......@@ -241,7 +241,6 @@ gtk_public_sources = files([
'gtkexpander.c',
'gtkexpression.c',
'gtkfilechooser.c',
'gtkfilechooserbutton.c',
'gtkfilechooserdialog.c',
'gtkfilechoosernative.c',
'gtkfilechooserwidget.c',
......@@ -529,7 +528,6 @@ gtk_public_headers = files([
'gtkexpander.h',
'gtkexpression.h',
'gtkfilechooser.h',
'gtkfilechooserbutton.h',
'gtkfilechooserdialog.h',
'gtkfilechoosernative.h',
'gtkfilechooserwidget.h',
......
......@@ -33,7 +33,6 @@ gtk_tests = [
['testentrycompletion'],
['testentryicons'],
['testfilechooser'],
['testfilechooserbutton'],
['testflowbox'],
['testfontoptions'],
['testframe'],
......
/* -*- 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <gtk/gtk.h>
static const char *backend = "gtk+";
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 char *gtk_src_dir = NULL;
static void
print_selected_path_clicked_cb (GtkWidget *button,
gpointer user_data)
{
GFile *folder, *filename;
char *folder_uri, *filename_uri;
folder = gtk_file_chooser_get_current_folder (user_data);
filename = gtk_file_chooser_get_file (user_data);
folder_uri = g_file_get_uri (folder);
filename_uri = g_file_get_uri (filename);
g_message ("Currently Selected:\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
folder_uri, filename_uri);
g_free (folder_uri);
g_free (filename_uri);
g_object_unref (folder);
g_object_unref (filename);
}
static void
add_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
gpointer user_data)
{
GFile *path = g_file_new_for_path (gtk_src_dir);
GError *err = NULL;
if (!gtk_file_chooser_add_shortcut_folder (user_data, path, &err))
{
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);
}
g_object_unref (path);
}
static void
del_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
gpointer user_data)
{
GFile *path = g_file_new_for_path (gtk_src_dir);
GError *err = NULL;
if (!gtk_file_chooser_remove_shortcut_folder (user_data, path, &err))
{
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);
}
g_object_unref (path);
}
static void
tests_button_clicked_cb (GtkButton *real_button,
gpointer user_data)
{
GtkWidget *tests;
tests = g_object_get_data (user_data, "tests-dialog");
if (tests == NULL)
{
GtkWidget *box, *button;
tests = gtk_window_new ();
gtk_window_set_hide_on_close (GTK_WINDOW (tests), TRUE);
gtk_window_set_title (GTK_WINDOW (tests),
"Tests - TestFileChooserButton");
gtk_window_set_transient_for (GTK_WINDOW (tests),
GTK_WINDOW (gtk_widget_get_root (user_data)));
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_box_append (GTK_BOX (tests), box);
button = gtk_button_new_with_label ("Print Selected Path");
g_signal_connect (button, "clicked",
G_CALLBACK (print_selected_path_clicked_cb), user_data);
gtk_box_append (GTK_BOX (box), button);
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);
gtk_box_append (GTK_BOX (box), button);
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);
gtk_box_append (GTK_BOX (box), button);
g_object_set_data (user_data, "tests-dialog", tests);
}
gtk_window_present (GTK_WINDOW (tests));
}
static void
chooser_selection_changed_cb (GtkFileChooser *chooser,
gpointer user_data)
{
GFile *filename;
char *uri;
filename = gtk_file_chooser_get_file (chooser);
uri = g_file_get_uri (filename);
g_message ("%s::selection-changed\n\tSelection:`%s'\nDone.\n",
G_OBJECT_TYPE_NAME (chooser), uri);
g_free (uri);
g_object_unref (filename);