mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +00:00
Remove filename/URI API from GtkFileChooser
GtkFileChooser's API predates GIO by a few years, so it started off with filenames and URI as character arrays. After introducing GIO as a dependency, the API included GFile-based entry points. It's much more appropriate to use GFile everywhere, as we want to encourage people to use GIO instead of passing random bytes to low level POSIX API. See: #2455
This commit is contained in:
parent
b002572824
commit
5f070ff233
@ -221,9 +221,12 @@ open_cb (GtkWidget *button,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
"_Load",
|
||||
"_Cancel");
|
||||
|
||||
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
|
||||
|
||||
GFile *cwd = g_file_new_for_path (".");
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
|
||||
g_object_unref (cwd);
|
||||
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), self);
|
||||
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
|
||||
}
|
||||
@ -290,14 +293,20 @@ save_response_cb (GtkNativeDialog *dialog,
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
GListModel *model;
|
||||
char *text, *filename;
|
||||
GFile *file;
|
||||
char *text;
|
||||
GError *error = NULL;
|
||||
|
||||
model = constraint_view_get_model (CONSTRAINT_VIEW (self->view));
|
||||
text = serialize_model (model);
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
if (!g_file_set_contents (filename, text, -1, &error))
|
||||
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
g_file_replace_contents (file, text, -1,
|
||||
NULL, FALSE,
|
||||
G_FILE_CREATE_NONE,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
if (error != NULL)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
@ -312,7 +321,9 @@ save_response_cb (GtkNativeDialog *dialog,
|
||||
gtk_widget_show (dialog);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_free (filename);
|
||||
|
||||
g_free (text);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
gtk_native_dialog_destroy (dialog);
|
||||
@ -329,9 +340,12 @@ save_cb (GtkWidget *button,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
"_Save",
|
||||
"_Cancel");
|
||||
|
||||
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
|
||||
|
||||
GFile *cwd = g_file_new_for_path (".");
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
|
||||
g_object_unref (cwd);
|
||||
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (save_response_cb), self);
|
||||
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
|
||||
}
|
||||
|
@ -385,7 +385,11 @@ show_open_filechooser (NodeEditorWindow *self)
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
|
||||
|
||||
GFile *cwd = g_file_new_for_path (".");
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
|
||||
g_object_unref (cwd);
|
||||
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), self);
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
@ -406,13 +410,20 @@ save_response_cb (GtkWidget *dialog,
|
||||
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char *text, *filename;
|
||||
GFile *file;
|
||||
char *text;
|
||||
GError *error = NULL;
|
||||
|
||||
text = get_current_text (self->text_buffer);
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
if (!g_file_set_contents (filename, text, -1, &error))
|
||||
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
g_file_replace_contents (file, text, -1,
|
||||
NULL, FALSE,
|
||||
G_FILE_CREATE_NONE,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
if (error != NULL)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
@ -427,7 +438,9 @@ save_response_cb (GtkWidget *dialog,
|
||||
gtk_widget_show (dialog);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_free (filename);
|
||||
|
||||
g_free (text);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
@ -449,7 +462,11 @@ save_cb (GtkWidget *button,
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), ".");
|
||||
|
||||
GFile *cwd = g_file_new_for_path (".");
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
|
||||
g_object_unref (cwd);
|
||||
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (save_response_cb), self);
|
||||
gtk_widget_show (dialog);
|
||||
}
|
||||
@ -523,10 +540,10 @@ export_image_response_cb (GtkWidget *dialog,
|
||||
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char *filename;
|
||||
GFile *file;
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
if (!gdk_texture_save_to_png (texture, filename))
|
||||
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
if (!gdk_texture_save_to_png (texture, g_file_peek_path (file)))
|
||||
{
|
||||
GtkWidget *message_dialog;
|
||||
|
||||
@ -538,7 +555,8 @@ export_image_response_cb (GtkWidget *dialog,
|
||||
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
gtk_widget_show (message_dialog);
|
||||
}
|
||||
g_free (filename);
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
@ -1140,51 +1140,37 @@ gtk_file_chooser_set_create_folders
|
||||
gtk_file_chooser_get_create_folders
|
||||
gtk_file_chooser_set_current_name
|
||||
gtk_file_chooser_get_current_name
|
||||
gtk_file_chooser_get_filename
|
||||
gtk_file_chooser_set_filename
|
||||
gtk_file_chooser_select_filename
|
||||
gtk_file_chooser_unselect_filename
|
||||
<SUBSECTION>
|
||||
gtk_file_chooser_get_file
|
||||
gtk_file_chooser_set_file
|
||||
gtk_file_chooser_select_file
|
||||
gtk_file_chooser_unselect_file
|
||||
gtk_file_chooser_select_all
|
||||
gtk_file_chooser_unselect_all
|
||||
gtk_file_chooser_get_filenames
|
||||
gtk_file_chooser_get_files
|
||||
gtk_file_chooser_set_current_folder
|
||||
gtk_file_chooser_get_current_folder
|
||||
gtk_file_chooser_get_uri
|
||||
gtk_file_chooser_set_uri
|
||||
gtk_file_chooser_select_uri
|
||||
gtk_file_chooser_unselect_uri
|
||||
gtk_file_chooser_get_uris
|
||||
gtk_file_chooser_set_current_folder_uri
|
||||
gtk_file_chooser_get_current_folder_uri
|
||||
<SUBSECTION>
|
||||
gtk_file_chooser_set_preview_widget
|
||||
gtk_file_chooser_get_preview_widget
|
||||
gtk_file_chooser_set_preview_widget_active
|
||||
gtk_file_chooser_get_preview_widget_active
|
||||
gtk_file_chooser_set_use_preview_label
|
||||
gtk_file_chooser_get_use_preview_label
|
||||
gtk_file_chooser_get_preview_filename
|
||||
gtk_file_chooser_get_preview_uri
|
||||
gtk_file_chooser_get_preview_file
|
||||
gtk_file_chooser_set_extra_widget
|
||||
gtk_file_chooser_get_extra_widget
|
||||
<SUBSECTION>
|
||||
gtk_file_chooser_add_filter
|
||||
gtk_file_chooser_remove_filter
|
||||
gtk_file_chooser_list_filters
|
||||
gtk_file_chooser_set_filter
|
||||
gtk_file_chooser_get_filter
|
||||
<SUBSECTION>
|
||||
gtk_file_chooser_add_shortcut_folder
|
||||
gtk_file_chooser_remove_shortcut_folder
|
||||
gtk_file_chooser_list_shortcut_folders
|
||||
gtk_file_chooser_add_shortcut_folder_uri
|
||||
gtk_file_chooser_remove_shortcut_folder_uri
|
||||
gtk_file_chooser_list_shortcut_folder_uris
|
||||
gtk_file_chooser_get_current_folder_file
|
||||
gtk_file_chooser_get_file
|
||||
gtk_file_chooser_get_files
|
||||
gtk_file_chooser_get_preview_file
|
||||
gtk_file_chooser_select_file
|
||||
gtk_file_chooser_set_current_folder_file
|
||||
gtk_file_chooser_set_file
|
||||
gtk_file_chooser_unselect_file
|
||||
<SUBSECTION>
|
||||
gtk_file_chooser_add_choice
|
||||
gtk_file_chooser_remove_choice
|
||||
gtk_file_chooser_set_choice
|
||||
|
1127
gtk/gtkfilechooser.c
1127
gtk/gtkfilechooser.c
File diff suppressed because it is too large
Load Diff
@ -156,52 +156,10 @@ void gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gchar *gtk_file_chooser_get_current_name (GtkFileChooser *chooser);
|
||||
|
||||
/* Filename manipulation
|
||||
*/
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gchar * gtk_file_chooser_get_filename (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_set_filename (GtkFileChooser *chooser,
|
||||
const char *filename);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_select_filename (GtkFileChooser *chooser,
|
||||
const char *filename);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_unselect_filename (GtkFileChooser *chooser,
|
||||
const char *filename);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_select_all (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_unselect_all (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList * gtk_file_chooser_get_filenames (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
|
||||
const gchar *filename);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gchar * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser);
|
||||
|
||||
|
||||
/* URI manipulation
|
||||
*/
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gchar * gtk_file_chooser_get_uri (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_set_uri (GtkFileChooser *chooser,
|
||||
const char *uri);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_select_uri (GtkFileChooser *chooser,
|
||||
const char *uri);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_unselect_uri (GtkFileChooser *chooser,
|
||||
const char *uri);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList * gtk_file_chooser_get_uris (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_set_current_folder_uri (GtkFileChooser *chooser,
|
||||
const gchar *uri);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gchar * gtk_file_chooser_get_current_folder_uri (GtkFileChooser *chooser);
|
||||
|
||||
/* GFile manipulation */
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
@ -220,11 +178,11 @@ void gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList * gtk_file_chooser_get_files (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_set_current_folder_file (GtkFileChooser *chooser,
|
||||
gboolean gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GFile * gtk_file_chooser_get_current_folder_file (GtkFileChooser *chooser);
|
||||
GFile * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser);
|
||||
|
||||
/* Preview widget
|
||||
*/
|
||||
@ -244,10 +202,6 @@ void gtk_file_chooser_set_use_preview_label (GtkFileChooser *chooser,
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
char *gtk_file_chooser_get_preview_filename (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
char *gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GFile *gtk_file_chooser_get_preview_file (GtkFileChooser *chooser);
|
||||
|
||||
@ -274,7 +228,7 @@ GSList *gtk_file_chooser_list_filters (GtkFileChooser *chooser);
|
||||
*/
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_set_filter (GtkFileChooser *chooser,
|
||||
GtkFileFilter *filter);
|
||||
GtkFileFilter *filter);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkFileFilter *gtk_file_chooser_get_filter (GtkFileChooser *chooser);
|
||||
|
||||
@ -282,26 +236,15 @@ GtkFileFilter *gtk_file_chooser_get_filter (GtkFileChooser *chooser);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
|
||||
const char *folder,
|
||||
GFile *folder,
|
||||
GError **error);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||
const char *folder,
|
||||
GFile *folder,
|
||||
GError **error);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList *gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_add_shortcut_folder_uri (GtkFileChooser *chooser,
|
||||
const char *uri,
|
||||
GError **error);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
|
||||
const char *uri,
|
||||
GError **error);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GSList *gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_add_choice (GtkFileChooser *chooser,
|
||||
const char *id,
|
||||
|
@ -80,11 +80,12 @@
|
||||
* |[<!-- language="C" -->
|
||||
* {
|
||||
* GtkWidget *button;
|
||||
* GFile *cwd = g_file_new_for_path ("/etc");
|
||||
*
|
||||
* button = gtk_file_chooser_button_new (_("Select a file"),
|
||||
* GTK_FILE_CHOOSER_ACTION_OPEN);
|
||||
* gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button),
|
||||
* "/etc");
|
||||
* gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), cwd);
|
||||
* g_object_unref (cwd);
|
||||
* }
|
||||
* ]|
|
||||
*
|
||||
@ -556,7 +557,7 @@ gtk_file_chooser_button_set_current_folder (GtkFileChooser *chooser,
|
||||
g_signal_emit_by_name (button, "current-folder-changed");
|
||||
|
||||
if (priv->active)
|
||||
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->chooser), file, NULL);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->chooser), file, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -688,7 +689,7 @@ gtk_file_chooser_button_add_shortcut_folder (GtkFileChooser *chooser,
|
||||
|
||||
delegate = g_object_get_qdata (G_OBJECT (chooser),
|
||||
GTK_FILE_CHOOSER_DELEGATE_QUARK);
|
||||
retval = _gtk_file_chooser_add_shortcut_folder (delegate, file, error);
|
||||
retval = gtk_file_chooser_add_shortcut_folder (delegate, file, error);
|
||||
|
||||
if (retval)
|
||||
{
|
||||
@ -728,7 +729,7 @@ gtk_file_chooser_button_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||
delegate = g_object_get_qdata (G_OBJECT (chooser),
|
||||
GTK_FILE_CHOOSER_DELEGATE_QUARK);
|
||||
|
||||
retval = _gtk_file_chooser_remove_shortcut_folder (delegate, file, error);
|
||||
retval = gtk_file_chooser_remove_shortcut_folder (delegate, file, error);
|
||||
|
||||
if (retval)
|
||||
{
|
||||
@ -2550,7 +2551,7 @@ save_inactive_state (GtkFileChooserButton *button)
|
||||
if (priv->selection_while_inactive)
|
||||
g_object_unref (priv->selection_while_inactive);
|
||||
|
||||
priv->current_folder_while_inactive = gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER (priv->chooser));
|
||||
priv->current_folder_while_inactive = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (priv->chooser));
|
||||
priv->selection_while_inactive = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->chooser));
|
||||
}
|
||||
|
||||
@ -2560,7 +2561,7 @@ restore_inactive_state (GtkFileChooserButton *button)
|
||||
GtkFileChooserButtonPrivate *priv = gtk_file_chooser_button_get_instance_private (button);
|
||||
|
||||
if (priv->current_folder_while_inactive)
|
||||
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (priv->chooser), priv->current_folder_while_inactive, NULL);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->chooser), priv->current_folder_while_inactive, NULL);
|
||||
|
||||
if (priv->selection_while_inactive)
|
||||
gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->chooser), priv->selection_while_inactive, NULL);
|
||||
|
@ -85,11 +85,9 @@
|
||||
* res = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
* if (res == GTK_RESPONSE_ACCEPT)
|
||||
* {
|
||||
* char *filename;
|
||||
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
|
||||
* filename = gtk_file_chooser_get_filename (chooser);
|
||||
* open_file (filename);
|
||||
* g_free (filename);
|
||||
* g_autoptr(GFile) filen = gtk_file_chooser_get_file (chooser);
|
||||
* open_file (file);
|
||||
* }
|
||||
*
|
||||
* gtk_widget_destroy (dialog);
|
||||
@ -116,20 +114,15 @@
|
||||
* gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
|
||||
*
|
||||
* if (user_edited_a_new_document)
|
||||
* gtk_file_chooser_set_current_name (chooser,
|
||||
* _("Untitled document"));
|
||||
* gtk_file_chooser_set_current_name (chooser, _("Untitled document"));
|
||||
* else
|
||||
* gtk_file_chooser_set_filename (chooser,
|
||||
* existing_filename);
|
||||
* gtk_file_chooser_set_file (chooser, existing_filename);
|
||||
*
|
||||
* res = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
* if (res == GTK_RESPONSE_ACCEPT)
|
||||
* {
|
||||
* char *filename;
|
||||
*
|
||||
* filename = gtk_file_chooser_get_filename (chooser);
|
||||
* save_to_file (filename);
|
||||
* g_free (filename);
|
||||
* g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);
|
||||
* save_to_file (file);
|
||||
* }
|
||||
*
|
||||
* gtk_widget_destroy (dialog);
|
||||
@ -145,7 +138,7 @@
|
||||
* and suggest a name such as “Untitled” with gtk_file_chooser_set_current_name().
|
||||
*
|
||||
* - To save a file under a different name. Use #GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
* and set the existing filename with gtk_file_chooser_set_filename().
|
||||
* and set the existing file with gtk_file_chooser_set_file().
|
||||
*
|
||||
* - To choose a folder instead of a file. Use #GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
|
||||
*
|
||||
@ -156,7 +149,7 @@
|
||||
* considered to be a good policy, as now the file chooser is
|
||||
* able to make good suggestions on its own. In general, you
|
||||
* should only cause the file chooser to show a specific folder
|
||||
* when it is appropriate to use gtk_file_chooser_set_filename(),
|
||||
* when it is appropriate to use gtk_file_chooser_set_file(),
|
||||
* i.e. when you are doing a Save As command and you already
|
||||
* have a file saved somewhere.
|
||||
|
||||
@ -362,18 +355,18 @@ file_chooser_widget_selection_changed (GtkWidget *widget,
|
||||
{
|
||||
GtkFileChooserDialogPrivate *priv = gtk_file_chooser_dialog_get_instance_private (dialog);
|
||||
GtkWidget *button;
|
||||
GSList *uris;
|
||||
GSList *files;
|
||||
gboolean sensitive;
|
||||
|
||||
button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
|
||||
if (button == NULL)
|
||||
return;
|
||||
|
||||
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (priv->widget));
|
||||
sensitive = (uris != NULL);
|
||||
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->widget));
|
||||
sensitive = (files != NULL);
|
||||
gtk_widget_set_sensitive (button, sensitive);
|
||||
|
||||
g_slist_free_full (uris, g_free);
|
||||
g_slist_free_full (files, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -644,8 +644,8 @@ gtk_file_chooser_native_set_current_folder (GtkFileChooser *chooser,
|
||||
GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);
|
||||
gboolean res;
|
||||
|
||||
res = gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (self->dialog),
|
||||
file, error);
|
||||
res = gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (self->dialog),
|
||||
file, error);
|
||||
|
||||
|
||||
if (res)
|
||||
|
@ -69,7 +69,7 @@ typedef struct {
|
||||
char *cancel_label;
|
||||
char *title;
|
||||
|
||||
GSList *shortcut_uris;
|
||||
GSList *shortcut_files;
|
||||
GArray *choices_selections;
|
||||
|
||||
GFile *current_folder;
|
||||
@ -331,7 +331,7 @@ filechooser_win32_thread_data_free (FilechooserWin32ThreadData *data)
|
||||
g_array_free (data->choices_selections, TRUE);
|
||||
data->choices_selections = NULL;
|
||||
}
|
||||
g_slist_free_full (data->shortcut_uris, g_free);
|
||||
g_slist_free_full (data->shortcut_files, g_object_unref);
|
||||
g_slist_free_full (data->files, g_object_unref);
|
||||
if (data->self)
|
||||
g_object_unref (data->self);
|
||||
@ -538,9 +538,9 @@ filechooser_win32_thread (gpointer _data)
|
||||
g_free (label);
|
||||
}
|
||||
|
||||
for (l = data->shortcut_uris; l != NULL; l = l->next)
|
||||
for (l = data->shortcut_files; l != NULL; l = l->next)
|
||||
{
|
||||
IShellItem *item = get_shell_item_for_uri (l->data);
|
||||
IShellItem *item = get_shell_item_for_file (l->data);
|
||||
if (item)
|
||||
{
|
||||
hr = IFileDialog_AddPlace (pfd, item, FDAP_BOTTOM);
|
||||
@ -911,8 +911,8 @@ gtk_file_chooser_native_win32_show (GtkFileChooserNative *self)
|
||||
self->mode_data = data;
|
||||
data->self = g_object_ref (self);
|
||||
|
||||
data->shortcut_uris =
|
||||
gtk_file_chooser_list_shortcut_folder_uris (GTK_FILE_CHOOSER (self->dialog));
|
||||
data->shortcut_files =
|
||||
gtk_file_chooser_list_shortcut_folders (GTK_FILE_CHOOSER (self->dialog));
|
||||
|
||||
data->accept_label = translate_mnemonics (self->accept_label);
|
||||
data->cancel_label = translate_mnemonics (self->cancel_label);
|
||||
|
@ -112,14 +112,6 @@ struct _GtkFileChooserIface
|
||||
};
|
||||
|
||||
GtkFileSystem *_gtk_file_chooser_get_file_system (GtkFileChooser *chooser);
|
||||
gboolean _gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
|
||||
GFile *folder,
|
||||
GError **error);
|
||||
gboolean _gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||
GFile *folder,
|
||||
GError **error);
|
||||
GSList * _gtk_file_chooser_list_shortcut_folder_files (GtkFileChooser *chooser);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -289,7 +289,7 @@ delegate_add_shortcut_folder (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
return _gtk_file_chooser_add_shortcut_folder (get_delegate (chooser), file, error);
|
||||
return gtk_file_chooser_add_shortcut_folder (get_delegate (chooser), file, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -297,13 +297,13 @@ delegate_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
return _gtk_file_chooser_remove_shortcut_folder (get_delegate (chooser), file, error);
|
||||
return gtk_file_chooser_remove_shortcut_folder (get_delegate (chooser), file, error);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
delegate_list_shortcut_folders (GtkFileChooser *chooser)
|
||||
{
|
||||
return _gtk_file_chooser_list_shortcut_folder_files (get_delegate (chooser));
|
||||
return gtk_file_chooser_list_shortcut_folders (get_delegate (chooser));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -311,13 +311,13 @@ delegate_set_current_folder (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
return gtk_file_chooser_set_current_folder_file (get_delegate (chooser), file, error);
|
||||
return gtk_file_chooser_set_current_folder (get_delegate (chooser), file, error);
|
||||
}
|
||||
|
||||
static GFile *
|
||||
delegate_get_current_folder (GtkFileChooser *chooser)
|
||||
{
|
||||
return gtk_file_chooser_get_current_folder_file (get_delegate (chooser));
|
||||
return gtk_file_chooser_get_current_folder (get_delegate (chooser));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -913,7 +913,7 @@ change_folder_and_display_error (GtkFileChooserWidget *impl,
|
||||
* list_row_activated()
|
||||
* fetches path from model; path belongs to the model (*)
|
||||
* calls change_folder_and_display_error()
|
||||
* calls gtk_file_chooser_set_current_folder_file()
|
||||
* calls gtk_file_chooser_set_current_folder()
|
||||
* changing folders fails, sets model to NULL, thus freeing the path in (*)
|
||||
*/
|
||||
|
||||
@ -2832,7 +2832,7 @@ switch_to_home_dir (GtkFileChooserWidget *impl)
|
||||
|
||||
home_file = g_file_new_for_path (home);
|
||||
|
||||
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (impl), home_file, NULL); /* NULL-GError */
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), home_file, NULL); /* NULL-GError */
|
||||
|
||||
g_object_unref (home_file);
|
||||
}
|
||||
@ -3734,10 +3734,12 @@ settings_save (GtkFileChooserWidget *impl)
|
||||
static void
|
||||
switch_to_cwd (GtkFileChooserWidget *impl)
|
||||
{
|
||||
char *current_working_dir;
|
||||
char *current_working_dir = g_get_current_dir ();
|
||||
GFile *cwd = g_file_new_for_path (current_working_dir);
|
||||
|
||||
current_working_dir = g_get_current_dir ();
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), cwd, NULL);
|
||||
|
||||
g_object_unref (cwd);
|
||||
g_free (current_working_dir);
|
||||
}
|
||||
|
||||
@ -5599,7 +5601,7 @@ gtk_file_chooser_widget_select_file (GtkFileChooser *chooser,
|
||||
parent_file = g_file_get_parent (file);
|
||||
|
||||
if (!parent_file)
|
||||
return gtk_file_chooser_set_current_folder_file (chooser, file, error);
|
||||
return gtk_file_chooser_set_current_folder (chooser, file, error);
|
||||
|
||||
fsmodel = GTK_FILE_SYSTEM_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->browse_files_tree_view)));
|
||||
|
||||
@ -5639,7 +5641,7 @@ gtk_file_chooser_widget_select_file (GtkFileChooser *chooser,
|
||||
{
|
||||
gboolean result;
|
||||
|
||||
result = gtk_file_chooser_set_current_folder_file (chooser, parent_file, error);
|
||||
result = gtk_file_chooser_set_current_folder (chooser, parent_file, error);
|
||||
g_object_unref (parent_file);
|
||||
return result;
|
||||
}
|
||||
@ -5948,7 +5950,7 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser)
|
||||
{
|
||||
GFile *current_folder;
|
||||
|
||||
current_folder = gtk_file_chooser_get_current_folder_file (chooser);
|
||||
current_folder = gtk_file_chooser_get_current_folder (chooser);
|
||||
|
||||
if (current_folder)
|
||||
info.result = g_slist_prepend (info.result, current_folder);
|
||||
@ -7801,6 +7803,7 @@ static void
|
||||
desktop_folder_handler (GtkFileChooserWidget *impl)
|
||||
{
|
||||
const char *name;
|
||||
GFile *file;
|
||||
|
||||
/* "To disable a directory, point it to the homedir."
|
||||
* See http://freedesktop.org/wiki/Software/xdg-user-dirs
|
||||
@ -7809,7 +7812,9 @@ desktop_folder_handler (GtkFileChooserWidget *impl)
|
||||
if (!g_strcmp0 (name, g_get_home_dir ()))
|
||||
return;
|
||||
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), name);
|
||||
file = g_file_new_for_path (name);
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), file, NULL);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
/* Handler for the "search-shortcut" keybinding signal */
|
||||
|
@ -68,7 +68,7 @@ struct GtkPrinterOptionWidgetPrivate
|
||||
GtkWidget *button;
|
||||
|
||||
/* the last location for save to file, that the user selected */
|
||||
gchar *last_location;
|
||||
GFile *last_location;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -485,42 +485,49 @@ dialog_response_callback (GtkDialog *dialog,
|
||||
GtkPrinterOptionWidget *widget)
|
||||
{
|
||||
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
||||
gchar *uri = NULL;
|
||||
gchar *new_location = NULL;
|
||||
GFile *new_location = NULL;
|
||||
char *uri = NULL;
|
||||
|
||||
if (response_id == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
gchar *filename;
|
||||
gchar *filename_utf8;
|
||||
gchar *filename_short;
|
||||
GFileInfo *info;
|
||||
|
||||
new_location = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
|
||||
new_location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
info = g_file_query_info (new_location,
|
||||
"standard::display-name",
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
if (info != NULL)
|
||||
{
|
||||
const char *filename_utf8 = g_file_info_get_display_name (info);
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
||||
filename_short = trim_long_filename (filename_utf8);
|
||||
gtk_button_set_label (GTK_BUTTON (priv->button), filename_short);
|
||||
g_free (filename_short);
|
||||
g_free (filename_utf8);
|
||||
g_free (filename);
|
||||
char *filename_short = trim_long_filename (filename_utf8);
|
||||
gtk_button_set_label (GTK_BUTTON (priv->button), filename_short);
|
||||
|
||||
g_free (filename_short);
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
g_object_unref (new_location);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
|
||||
if (new_location)
|
||||
uri = new_location;
|
||||
uri = g_file_get_uri (new_location);
|
||||
else
|
||||
uri = priv->last_location;
|
||||
uri = g_file_get_uri (priv->last_location);
|
||||
|
||||
if (uri)
|
||||
if (uri != NULL)
|
||||
{
|
||||
gtk_printer_option_set (priv->source, uri);
|
||||
emit_changed (widget);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
g_free (new_location);
|
||||
g_free (priv->last_location);
|
||||
priv->last_location = NULL;
|
||||
g_object_unref (new_location);
|
||||
g_clear_object (&priv->last_location);
|
||||
|
||||
/* unblock the handler which was blocked in the filesave_choose_cb function */
|
||||
g_signal_handler_unblock (priv->source, priv->source_changed_handler);
|
||||
@ -531,7 +538,6 @@ filesave_choose_cb (GtkWidget *button,
|
||||
GtkPrinterOptionWidget *widget)
|
||||
{
|
||||
GtkPrinterOptionWidgetPrivate *priv = widget->priv;
|
||||
gchar *last_location = NULL;
|
||||
GtkWidget *dialog;
|
||||
GtkWindow *toplevel;
|
||||
|
||||
@ -550,23 +556,21 @@ filesave_choose_cb (GtkWidget *button,
|
||||
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), FALSE);
|
||||
|
||||
/* select the current filename in the dialog */
|
||||
if (priv->source != NULL)
|
||||
if (priv->source != NULL && priv->source->value != NULL)
|
||||
{
|
||||
priv->last_location = last_location = g_strdup (priv->source->value);
|
||||
if (last_location)
|
||||
priv->last_location = g_file_new_for_uri (priv->source->value);
|
||||
if (priv->last_location)
|
||||
{
|
||||
GFile *file;
|
||||
gchar *basename;
|
||||
gchar *basename_utf8;
|
||||
char *basename;
|
||||
char *basename_utf8;
|
||||
|
||||
gtk_file_chooser_select_uri (GTK_FILE_CHOOSER (dialog), last_location);
|
||||
file = g_file_new_for_uri (last_location);
|
||||
basename = g_file_get_basename (file);
|
||||
gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->last_location, NULL);
|
||||
|
||||
basename = g_file_get_basename (priv->last_location);
|
||||
basename_utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename_utf8);
|
||||
g_free (basename_utf8);
|
||||
g_free (basename);
|
||||
g_object_unref (file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,14 +185,22 @@ get_current_text (GtkTextBuffer *buffer)
|
||||
|
||||
static void
|
||||
save_to_file (GtkInspectorCssEditor *ce,
|
||||
const gchar *filename)
|
||||
GFile *file)
|
||||
{
|
||||
gchar *text;
|
||||
GError *error = NULL;
|
||||
char *text;
|
||||
|
||||
text = get_current_text (ce->priv->text);
|
||||
|
||||
if (!g_file_set_contents (filename, text, -1, &error))
|
||||
g_file_replace_contents (file, text, -1,
|
||||
NULL,
|
||||
FALSE,
|
||||
G_FILE_CREATE_NONE,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
@ -220,11 +228,9 @@ save_response (GtkWidget *dialog,
|
||||
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
gchar *filename;
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
save_to_file (ce, filename);
|
||||
g_free (filename);
|
||||
GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
save_to_file (ce, file);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static GtkWidget *main_window;
|
||||
static char *filename = NULL;
|
||||
static GFile *filename = NULL;
|
||||
static GtkPageSetup *page_setup = NULL;
|
||||
static GtkPrintSettings *settings = NULL;
|
||||
static gboolean file_changed = FALSE;
|
||||
@ -20,7 +20,7 @@ update_title (GtkWindow *window)
|
||||
if (filename == NULL)
|
||||
basename = g_strdup ("Untitled");
|
||||
else
|
||||
basename = g_path_get_basename (filename);
|
||||
basename = g_file_get_basename (filename);
|
||||
|
||||
title = g_strdup_printf ("Simple Editor with printing - %s", basename);
|
||||
g_free (basename);
|
||||
@ -81,7 +81,8 @@ get_text (void)
|
||||
}
|
||||
|
||||
static void
|
||||
set_text (const char *text, gsize len)
|
||||
set_text (const char *text,
|
||||
gsize len)
|
||||
{
|
||||
gtk_text_buffer_set_text (buffer, text, len);
|
||||
file_changed = FALSE;
|
||||
@ -89,7 +90,7 @@ set_text (const char *text, gsize len)
|
||||
}
|
||||
|
||||
static void
|
||||
load_file (const char *open_filename)
|
||||
load_file (GFile *open_filename)
|
||||
{
|
||||
GtkWidget *error_dialog;
|
||||
char *contents;
|
||||
@ -98,37 +99,45 @@ load_file (const char *open_filename)
|
||||
|
||||
error_dialog = NULL;
|
||||
error = NULL;
|
||||
if (g_file_get_contents (open_filename, &contents, &len, &error))
|
||||
g_file_load_contents (open_filename, NULL, &contents, &len, NULL, &error);
|
||||
if (error == NULL)
|
||||
{
|
||||
if (g_utf8_validate (contents, len, NULL))
|
||||
{
|
||||
filename = g_strdup (open_filename);
|
||||
g_clear_object (&filename);
|
||||
filename = g_object_ref (open_filename);
|
||||
set_text (contents, len);
|
||||
g_free (contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
GFileInfo *info = g_file_query_info (open_filename, "standard::display-name", 0, NULL, &error);
|
||||
const char *display_name = g_file_info_get_display_name (info);
|
||||
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Error loading file %s:\n%s",
|
||||
open_filename,
|
||||
display_name,
|
||||
"Not valid utf8");
|
||||
g_object_unref (info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GFileInfo *info = g_file_query_info (open_filename, "standard::display-name", 0, NULL, &error);
|
||||
const char *display_name = g_file_info_get_display_name (info);
|
||||
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Error loading file %s:\n%s",
|
||||
open_filename,
|
||||
display_name,
|
||||
error->message);
|
||||
|
||||
g_object_unref (info);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
if (error_dialog)
|
||||
{
|
||||
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
@ -138,38 +147,49 @@ load_file (const char *open_filename)
|
||||
|
||||
|
||||
static void
|
||||
save_file (const char *save_filename)
|
||||
save_file (GFile *save_filename)
|
||||
{
|
||||
char *text = get_text ();
|
||||
GtkWidget *error_dialog;
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
if (g_file_set_contents (save_filename,
|
||||
text, -1, &error))
|
||||
g_file_replace_contents (save_filename,
|
||||
text, -1,
|
||||
NULL, FALSE,
|
||||
G_FILE_CREATE_NONE,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
if (save_filename != filename)
|
||||
{
|
||||
g_free (filename);
|
||||
filename = g_strdup (save_filename);
|
||||
g_clear_object (&filename);
|
||||
filename = g_object_ref (save_filename);
|
||||
}
|
||||
file_changed = FALSE;
|
||||
update_ui ();
|
||||
}
|
||||
else
|
||||
{
|
||||
GFileInfo *info = g_file_query_info (save_filename, "standard::display-name", 0, NULL, NULL);
|
||||
const char *display_name = g_file_info_get_display_name (info);
|
||||
|
||||
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Error saving to file %s:\n%s",
|
||||
filename,
|
||||
display_name,
|
||||
error->message);
|
||||
|
||||
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
gtk_widget_show (error_dialog);
|
||||
|
||||
g_error_free (error);
|
||||
g_object_unref (info);
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +501,6 @@ activate_save_as (GSimpleAction *action,
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
gint response;
|
||||
char *save_filename;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new ("Select file",
|
||||
GTK_WINDOW (main_window),
|
||||
@ -494,9 +513,9 @@ activate_save_as (GSimpleAction *action,
|
||||
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
{
|
||||
save_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
GFile *save_filename = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
save_file (save_filename);
|
||||
g_free (save_filename);
|
||||
g_object_unref (save_filename);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
@ -520,7 +539,6 @@ activate_open (GSimpleAction *action,
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
gint response;
|
||||
char *open_filename;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new ("Select file",
|
||||
GTK_WINDOW (main_window),
|
||||
@ -533,9 +551,9 @@ activate_open (GSimpleAction *action,
|
||||
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
{
|
||||
open_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
GFile *open_filename = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
load_file (open_filename);
|
||||
g_free (open_filename);
|
||||
g_object_unref (open_filename);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
@ -689,7 +707,11 @@ command_line (GApplication *application,
|
||||
argv = g_application_command_line_get_arguments (command_line, &argc);
|
||||
|
||||
if (argc == 2)
|
||||
load_file (argv[1]);
|
||||
{
|
||||
GFile *file = g_file_new_for_commandline_arg (argv[1]);
|
||||
load_file (file);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,28 +44,38 @@ static GtkFileChooserAction action;
|
||||
static void
|
||||
print_current_folder (GtkFileChooser *chooser)
|
||||
{
|
||||
gchar *uri;
|
||||
GFile *cwd;
|
||||
|
||||
uri = gtk_file_chooser_get_current_folder_uri (chooser);
|
||||
g_print ("Current folder changed :\n %s\n", uri ? uri : "(null)");
|
||||
g_free (uri);
|
||||
cwd = gtk_file_chooser_get_current_folder (chooser);
|
||||
if (cwd != NULL)
|
||||
{
|
||||
char *uri = g_file_get_uri (cwd);
|
||||
g_print ("Current folder changed :\n %s\n", uri ? uri : "(null)");
|
||||
g_free (uri);
|
||||
g_object_unref (cwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print ("Current folder changed :\n none\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_selected (GtkFileChooser *chooser)
|
||||
{
|
||||
GSList *uris = gtk_file_chooser_get_uris (chooser);
|
||||
GSList *uris = gtk_file_chooser_get_files (chooser);
|
||||
GSList *tmp_list;
|
||||
|
||||
g_print ("Selection changed :\n");
|
||||
for (tmp_list = uris; tmp_list; tmp_list = tmp_list->next)
|
||||
{
|
||||
gchar *uri = tmp_list->data;
|
||||
g_print (" %s\n", uri);
|
||||
GFile *file = tmp_list->data;
|
||||
char *uri = g_file_get_uri (file);
|
||||
g_print (" %s\n", uri ? uri : "(null)");
|
||||
g_free (uri);
|
||||
}
|
||||
g_print ("\n");
|
||||
g_slist_free (uris);
|
||||
g_slist_free_full (uris, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -79,7 +89,7 @@ response_cb (GtkDialog *dialog,
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
list = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
|
||||
list = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
|
||||
|
||||
if (list)
|
||||
{
|
||||
@ -89,11 +99,13 @@ response_cb (GtkDialog *dialog,
|
||||
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
g_print ("%s\n", (char *) l->data);
|
||||
g_free (l->data);
|
||||
GFile *file = l->data;
|
||||
char *uri = g_file_get_uri (file);
|
||||
g_print (" %s\n", uri ? uri : "(null)");
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
g_slist_free (list);
|
||||
g_slist_free_full (list, g_object_unref);
|
||||
}
|
||||
else
|
||||
g_print ("No selected files\n");
|
||||
@ -341,7 +353,8 @@ static void
|
||||
set_current_folder (GtkFileChooser *chooser,
|
||||
const char *name)
|
||||
{
|
||||
if (!gtk_file_chooser_set_current_folder (chooser, name))
|
||||
GFile *file = g_file_new_for_path (name);
|
||||
if (!gtk_file_chooser_set_current_folder (chooser, file, NULL))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
@ -354,6 +367,7 @@ set_current_folder (GtkFileChooser *chooser,
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -374,7 +388,8 @@ static void
|
||||
set_filename (GtkFileChooser *chooser,
|
||||
const char *name)
|
||||
{
|
||||
if (!gtk_file_chooser_set_filename (chooser, name))
|
||||
GFile *file = g_file_new_for_path (name);
|
||||
if (!gtk_file_chooser_set_file (chooser, file, NULL))
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
@ -387,6 +402,7 @@ set_filename (GtkFileChooser *chooser,
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -409,7 +425,7 @@ get_selection_cb (GtkButton *button,
|
||||
{
|
||||
GSList *selection;
|
||||
|
||||
selection = gtk_file_chooser_get_uris (chooser);
|
||||
selection = gtk_file_chooser_get_files (chooser);
|
||||
|
||||
g_print ("Selection: ");
|
||||
|
||||
@ -421,16 +437,19 @@ get_selection_cb (GtkButton *button,
|
||||
|
||||
for (l = selection; l; l = l->next)
|
||||
{
|
||||
char *uri = l->data;
|
||||
GFile *file = l->data;
|
||||
char *uri = g_file_get_uri (file);
|
||||
|
||||
g_print ("%s\n", uri);
|
||||
|
||||
g_free (uri);
|
||||
|
||||
if (l->next)
|
||||
g_print (" ");
|
||||
}
|
||||
}
|
||||
|
||||
g_slist_free_full (selection, g_free);
|
||||
g_slist_free_full (selection, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -534,6 +553,7 @@ main (int argc, char **argv)
|
||||
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" },
|
||||
@ -680,7 +700,7 @@ main (int argc, char **argv)
|
||||
G_CALLBACK (update_preview_cb), NULL);
|
||||
#endif
|
||||
|
||||
/* Extra widget */
|
||||
/* Choices */
|
||||
|
||||
gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (dialog), "choice1",
|
||||
"Choose one:",
|
||||
@ -690,12 +710,13 @@ main (int argc, char **argv)
|
||||
|
||||
/* Shortcuts */
|
||||
|
||||
gtk_file_chooser_add_shortcut_folder_uri (GTK_FILE_CHOOSER (dialog),
|
||||
"file:///usr/share/pixmaps",
|
||||
NULL);
|
||||
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
|
||||
g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
|
||||
NULL);
|
||||
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);
|
||||
|
||||
/* Initial filename or folder */
|
||||
|
||||
|
@ -45,23 +45,31 @@ static void
|
||||
print_selected_path_clicked_cb (GtkWidget *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
gchar *folder, *filename;
|
||||
GFile *folder, *filename;
|
||||
char *folder_uri, *filename_uri;
|
||||
|
||||
folder = gtk_file_chooser_get_current_folder (user_data);
|
||||
filename = gtk_file_chooser_get_filename (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, filename);
|
||||
g_free (folder);
|
||||
g_free (filename);
|
||||
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, gtk_src_dir, &err))
|
||||
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);
|
||||
@ -71,15 +79,18 @@ add_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
|
||||
{
|
||||
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, gtk_src_dir, &err))
|
||||
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);
|
||||
@ -89,6 +100,8 @@ del_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
|
||||
{
|
||||
g_message ("Removed `%s' as shortcut folder.", gtk_src_dir);
|
||||
}
|
||||
|
||||
g_object_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -155,54 +168,76 @@ static void
|
||||
chooser_current_folder_changed_cb (GtkFileChooser *chooser,
|
||||
gpointer user_data)
|
||||
{
|
||||
gchar *folder, *filename;
|
||||
GFile *folder, *filename;
|
||||
char *folder_uri, *filename_uri;
|
||||
|
||||
folder = gtk_file_chooser_get_current_folder_uri (chooser);
|
||||
filename = gtk_file_chooser_get_uri (chooser);
|
||||
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);
|
||||
g_message ("%s::current-folder-changed\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
|
||||
G_OBJECT_TYPE_NAME (chooser), folder, filename);
|
||||
g_free (folder);
|
||||
g_free (filename);
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
chooser_selection_changed_cb (GtkFileChooser *chooser,
|
||||
gpointer user_data)
|
||||
{
|
||||
gchar *filename;
|
||||
GFile *filename;
|
||||
char *uri;
|
||||
|
||||
filename = gtk_file_chooser_get_uri (chooser);
|
||||
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), filename);
|
||||
g_free (filename);
|
||||
G_OBJECT_TYPE_NAME (chooser), uri);
|
||||
g_free (uri);
|
||||
|
||||
g_object_unref (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
chooser_file_activated_cb (GtkFileChooser *chooser,
|
||||
gpointer user_data)
|
||||
{
|
||||
gchar *folder, *filename;
|
||||
GFile *folder, *filename;
|
||||
char *folder_uri, *filename_uri;
|
||||
|
||||
folder = gtk_file_chooser_get_current_folder_uri (chooser);
|
||||
filename = gtk_file_chooser_get_uri (chooser);
|
||||
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);
|
||||
g_message ("%s::file-activated\n\tFolder: `%s'\n\tFilename: `%s'\nDone.\n",
|
||||
G_OBJECT_TYPE_NAME (chooser), folder, filename);
|
||||
g_free (folder);
|
||||
g_free (filename);
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
chooser_update_preview_cb (GtkFileChooser *chooser,
|
||||
gpointer user_data)
|
||||
{
|
||||
gchar *filename;
|
||||
GFile *filename;
|
||||
|
||||
filename = gtk_file_chooser_get_preview_uri (chooser);
|
||||
filename = gtk_file_chooser_get_preview_file (chooser);
|
||||
if (filename != NULL)
|
||||
{
|
||||
char *uri = g_file_get_uri (filename);
|
||||
g_message ("%s::update-preview\n\tPreview Filename: `%s'\nDone.\n",
|
||||
G_OBJECT_TYPE_NAME (chooser), filename);
|
||||
g_free (filename);
|
||||
G_OBJECT_TYPE_NAME (chooser), uri);
|
||||
g_free (uri);
|
||||
|
||||
g_object_unref (filename);
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,6 +249,7 @@ add_new_filechooser_button (const gchar *mnemonic,
|
||||
GtkSizeGroup *label_group)
|
||||
{
|
||||
GtkWidget *hbox, *label, *chooser, *button;
|
||||
GFile *path;
|
||||
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
||||
gtk_container_add (GTK_CONTAINER (group_box), hbox);
|
||||
@ -227,8 +263,12 @@ add_new_filechooser_button (const gchar *mnemonic,
|
||||
" - testfilechooserbutton", NULL),
|
||||
action);
|
||||
gtk_widget_set_hexpand (chooser, TRUE);
|
||||
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
|
||||
gtk_file_chooser_remove_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
|
||||
|
||||
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);
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), chooser);
|
||||
g_signal_connect (chooser, "current-folder-changed",
|
||||
G_CALLBACK (chooser_current_folder_changed_cb), NULL);
|
||||
|
@ -5709,14 +5709,17 @@ native_response (GtkNativeDialog *self,
|
||||
char *response;
|
||||
GtkFileFilter *filter;
|
||||
|
||||
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (self));
|
||||
uris = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (self));
|
||||
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self));
|
||||
s = g_string_new ("");
|
||||
for (l = uris; l != NULL; l = l->next)
|
||||
{
|
||||
g_string_prepend (s, l->data);
|
||||
char *uri = g_file_get_uri (l->data);
|
||||
g_string_prepend (s, uri);
|
||||
g_string_prepend (s, "\n");
|
||||
g_free (uri);
|
||||
}
|
||||
g_slist_free_full (uris, g_object_unref);
|
||||
|
||||
switch (response_id)
|
||||
{
|
||||
@ -5826,12 +5829,12 @@ native_visible_notify_hide (GObject *object,
|
||||
gtk_widget_set_sensitive (hide_button, visible);
|
||||
}
|
||||
|
||||
static char *
|
||||
static GFile *
|
||||
get_some_file (void)
|
||||
{
|
||||
GFile *dir = g_file_new_for_path (g_get_current_dir ());
|
||||
GFileEnumerator *e;
|
||||
char *res = NULL;
|
||||
GFile *res = NULL;
|
||||
|
||||
e = g_file_enumerate_children (dir, "*", 0, NULL, NULL);
|
||||
if (e)
|
||||
@ -5846,8 +5849,7 @@ get_some_file (void)
|
||||
if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
GFile *child = g_file_enumerator_get_child (e, info);
|
||||
res = g_file_get_path (child);
|
||||
g_object_unref (child);
|
||||
res = g_steal_pointer (&child);
|
||||
}
|
||||
g_object_unref (info);
|
||||
}
|
||||
@ -5882,9 +5884,8 @@ native_action_changed (GtkWidget *combo,
|
||||
{
|
||||
if (save_as)
|
||||
{
|
||||
char *file = get_some_file ();
|
||||
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (native), file);
|
||||
g_free (file);
|
||||
GFile *file = get_some_file ();
|
||||
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (native), file, NULL);
|
||||
}
|
||||
else
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (native), "newname.txt");
|
||||
@ -5962,6 +5963,8 @@ create_native_dialogs (GtkWidget *widget)
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GFile *path;
|
||||
|
||||
window = gtk_window_new ();
|
||||
gtk_window_set_display (GTK_WINDOW (window),
|
||||
gtk_widget_get_display (widget));
|
||||
@ -5974,9 +5977,9 @@ create_native_dialogs (GtkWidget *widget)
|
||||
|
||||
g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (destroy_native), native);
|
||||
|
||||
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native),
|
||||
g_get_current_dir (),
|
||||
NULL);
|
||||
path = g_file_new_for_path (g_get_current_dir ());
|
||||
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native), path, NULL);
|
||||
g_object_unref (path);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW(window), "Native dialog parent");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user