mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 05:31:07 +00:00
filechooser: Add gtk_file_chooser_get_current_name()
Currently you can only set the current filename, but not get it. It's useful to be able to get it in save dialogs, where the user has typed the desired filename and you are not in a real directory (recent used, for example). https://bugzilla.gnome.org/show_bug.cgi?id=702497
This commit is contained in:
parent
159cccfe7b
commit
84b4910b39
@ -1316,6 +1316,7 @@ gtk_file_chooser_get_do_overwrite_confirmation
|
||||
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
|
||||
|
@ -1352,6 +1352,34 @@ gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
|
||||
GTK_FILE_CHOOSER_GET_IFACE (chooser)->set_current_name (chooser, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_file_chooser_get_current_name:
|
||||
* @chooser: a #GtkFileChooser
|
||||
*
|
||||
* Gets the current name in the file selector, as entered by the user in the
|
||||
* text entry for "Name".
|
||||
*
|
||||
* This is meant to be used in save dialogs, to get the currently typed filename
|
||||
* when the file itself does not exist yet. For example, an application that
|
||||
* adds a custom extra widget to the file chooser for "file format" may want to
|
||||
* change the extension of the typed filename based on the chosen format, say,
|
||||
* from ".jpg" to ".png".
|
||||
*
|
||||
* Returns: The raw text from the file chooser's "Name" entry. Free this with
|
||||
* g_free(). Note that this string is not a full pathname or URI; it is
|
||||
* whatever the contents of the entry are. Note also that this string is in
|
||||
* UTF-8 encoding, which is not necessarily the system's encoding for filenames.
|
||||
*
|
||||
* Since: 3.10
|
||||
**/
|
||||
gchar *
|
||||
gtk_file_chooser_get_current_name (GtkFileChooser *chooser)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
|
||||
|
||||
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_current_name (chooser);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_file_chooser_get_uri:
|
||||
* @chooser: a #GtkFileChooser
|
||||
|
@ -153,8 +153,10 @@ gboolean gtk_file_chooser_get_create_folders (GtkFileChooser *choose
|
||||
/* Suggested name for the Save-type actions
|
||||
*/
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
|
||||
const gchar *name);
|
||||
void gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
|
||||
const gchar *name);
|
||||
GDK_AVAILABLE_IN_3_10
|
||||
gchar *gtk_file_chooser_get_current_name (GtkFileChooser *chooser);
|
||||
|
||||
/* Filename manipulation
|
||||
*/
|
||||
|
@ -436,6 +436,7 @@ static gboolean gtk_file_chooser_default_update_current_folder (GtkFil
|
||||
static GFile * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
|
||||
static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
|
||||
const gchar *name);
|
||||
static gchar * gtk_file_chooser_default_get_current_name (GtkFileChooser *chooser);
|
||||
static gboolean gtk_file_chooser_default_select_file (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error);
|
||||
@ -563,6 +564,7 @@ gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
|
||||
iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
|
||||
iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
|
||||
iface->set_current_name = gtk_file_chooser_default_set_current_name;
|
||||
iface->get_current_name = gtk_file_chooser_default_get_current_name;
|
||||
iface->add_filter = gtk_file_chooser_default_add_filter;
|
||||
iface->remove_filter = gtk_file_chooser_default_remove_filter;
|
||||
iface->list_filters = gtk_file_chooser_default_list_filters;
|
||||
@ -4755,6 +4757,19 @@ gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->location_entry), name);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gtk_file_chooser_default_get_current_name (GtkFileChooser *chooser)
|
||||
{
|
||||
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
||||
GtkFileChooserDefaultPrivate *priv = impl->priv;
|
||||
|
||||
g_return_val_if_fail (priv->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
|
||||
priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER,
|
||||
NULL);
|
||||
|
||||
return g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->location_entry)));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_file_chooser_default_select_file (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
|
@ -61,6 +61,7 @@ struct _GtkFileChooserIface
|
||||
GFile * (*get_current_folder) (GtkFileChooser *chooser);
|
||||
void (*set_current_name) (GtkFileChooser *chooser,
|
||||
const gchar *name);
|
||||
gchar * (*get_current_name) (GtkFileChooser *chooser);
|
||||
gboolean (*select_file) (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error);
|
||||
|
@ -31,6 +31,7 @@ static gboolean delegate_set_current_folder (GtkFileChooser *choose
|
||||
static GFile * delegate_get_current_folder (GtkFileChooser *chooser);
|
||||
static void delegate_set_current_name (GtkFileChooser *chooser,
|
||||
const gchar *name);
|
||||
static gchar * delegate_get_current_name (GtkFileChooser *chooser);
|
||||
static gboolean delegate_select_file (GtkFileChooser *chooser,
|
||||
GFile *file,
|
||||
GError **error);
|
||||
@ -134,6 +135,7 @@ _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface)
|
||||
iface->set_current_folder = delegate_set_current_folder;
|
||||
iface->get_current_folder = delegate_get_current_folder;
|
||||
iface->set_current_name = delegate_set_current_name;
|
||||
iface->get_current_name = delegate_get_current_name;
|
||||
iface->select_file = delegate_select_file;
|
||||
iface->unselect_file = delegate_unselect_file;
|
||||
iface->select_all = delegate_select_all;
|
||||
@ -308,6 +310,12 @@ delegate_set_current_name (GtkFileChooser *chooser,
|
||||
gtk_file_chooser_set_current_name (get_delegate (chooser), name);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
delegate_get_current_name (GtkFileChooser *chooser)
|
||||
{
|
||||
return gtk_file_chooser_get_current_name (get_delegate (chooser));
|
||||
}
|
||||
|
||||
static void
|
||||
delegate_notify (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
|
Loading…
Reference in New Issue
Block a user