filechooser: Enter in the location entry of a file chooser in a window of the program's own opens the folder or chooses the file (file-activated), where no default button takes it (from Ardour's YTK)
This commit is contained in:
parent
b024119172
commit
d35ef12fda
1 changed files with 50 additions and 0 deletions
|
|
@ -6821,6 +6821,53 @@ file_pane_create (GtkFileChooserDefault *impl,
|
|||
return vbox;
|
||||
}
|
||||
|
||||
static void check_save_entry (GtkFileChooserDefault *impl,
|
||||
GFile **file_ret,
|
||||
gboolean *is_well_formed_ret,
|
||||
gboolean *is_empty_ret,
|
||||
gboolean *is_file_part_empty_ret,
|
||||
gboolean *is_folder);
|
||||
|
||||
/* Enter in the location entry where nothing takes it as the default:
|
||||
* a file chooser in a window of the program's own, not in a dialog.
|
||||
* A folder is opened, a file chosen ("file-activated"), as Ardour's
|
||||
* YTK does. */
|
||||
static void
|
||||
location_entry_activate_cb (GtkEntry *entry,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
|
||||
GFile *file;
|
||||
gboolean is_well_formed, is_empty, is_file_part_empty, is_folder;
|
||||
|
||||
if (GTK_IS_WINDOW (toplevel) && GTK_WINDOW (toplevel)->default_widget != NULL)
|
||||
return;
|
||||
if (impl->location_mode != LOCATION_MODE_FILENAME_ENTRY &&
|
||||
impl->action != GTK_FILE_CHOOSER_ACTION_SAVE &&
|
||||
impl->action != GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
|
||||
return;
|
||||
|
||||
check_save_entry (impl, &file, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
|
||||
if (!is_well_formed || is_empty || file == NULL)
|
||||
{
|
||||
if (file)
|
||||
g_object_unref (file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_folder)
|
||||
change_folder_and_display_error (impl, file, TRUE);
|
||||
else if (impl->action != GTK_FILE_CHOOSER_ACTION_OPEN ||
|
||||
!g_file_is_native (file) || g_file_query_exists (file, NULL))
|
||||
{
|
||||
/* to open, only what is there (a local file is quick to look at) */
|
||||
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
||||
gtk_file_chooser_select_file (GTK_FILE_CHOOSER (impl), file, NULL);
|
||||
g_signal_emit_by_name (impl, "file-activated");
|
||||
}
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
location_entry_create (GtkFileChooserDefault *impl)
|
||||
{
|
||||
|
|
@ -6831,6 +6878,9 @@ location_entry_create (GtkFileChooserDefault *impl)
|
|||
_gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
|
||||
gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
|
||||
g_signal_handlers_disconnect_by_func (impl->location_entry, location_entry_activate_cb, impl);
|
||||
g_signal_connect (impl->location_entry, "activate",
|
||||
G_CALLBACK (location_entry_activate_cb), impl);
|
||||
}
|
||||
|
||||
/* Creates the widgets specific to Save mode */
|
||||
|
|
|
|||
Loading…
Reference in a new issue