mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 06:10:21 +00:00
filechooser: Trigger the location popup via bindings
Simplifies code quite a bit.
This commit is contained in:
parent
bb4fbe3d8f
commit
43c0ea676d
@ -1190,125 +1190,22 @@ places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
should_trigger_location_entry (GtkFileChooserWidget *impl,
|
trigger_location_entry (GtkWidget *widget,
|
||||||
guint keyval,
|
GVariant *arguments,
|
||||||
GdkModifierType state,
|
gpointer unused)
|
||||||
const char **string)
|
|
||||||
{
|
{
|
||||||
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
||||||
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
|
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
|
||||||
GdkModifierType no_text_input_mask;
|
|
||||||
|
|
||||||
if (priv->operation_mode == OPERATION_MODE_SEARCH)
|
if (priv->operation_mode == OPERATION_MODE_SEARCH)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
no_text_input_mask =
|
if (priv->action != GTK_FILE_CHOOSER_ACTION_OPEN &&
|
||||||
gtk_widget_get_modifier_mask (GTK_WIDGET (impl), GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
|
priv->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||||
|
|
||||||
if (state & no_text_input_mask)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
switch (keyval)
|
location_popup_handler (impl, g_variant_get_string (arguments, NULL));
|
||||||
{
|
return TRUE;
|
||||||
case GDK_KEY_slash:
|
|
||||||
case GDK_KEY_KP_Divide:
|
|
||||||
*string = "/";
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case GDK_KEY_period:
|
|
||||||
*string = ".";
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case GDK_KEY_asciitilde:
|
|
||||||
*string = "~";
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handles key press events on the file list, so that we can trap Enter to
|
|
||||||
* activate the default button on our own. Also, checks to see if “/” has been
|
|
||||||
* pressed.
|
|
||||||
*/
|
|
||||||
static gboolean
|
|
||||||
treeview_key_press_cb (GtkEventControllerKey *controller,
|
|
||||||
guint keyval,
|
|
||||||
guint keycode,
|
|
||||||
GdkModifierType state,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data;
|
|
||||||
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
|
|
||||||
const char *string;
|
|
||||||
|
|
||||||
if (should_trigger_location_entry (impl, keyval, state, &string) &&
|
|
||||||
(priv->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
||||||
priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
|
|
||||||
{
|
|
||||||
location_popup_handler (impl, string);
|
|
||||||
return GDK_EVENT_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((keyval == GDK_KEY_Return ||
|
|
||||||
keyval == GDK_KEY_ISO_Enter ||
|
|
||||||
keyval == GDK_KEY_KP_Enter ||
|
|
||||||
keyval == GDK_KEY_space ||
|
|
||||||
keyval == GDK_KEY_KP_Space) &&
|
|
||||||
!(state & gtk_accelerator_get_default_mod_mask ()) &&
|
|
||||||
priv->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
||||||
{
|
|
||||||
gtk_widget_activate_default (GTK_WIDGET (impl));
|
|
||||||
return GDK_EVENT_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyval == GDK_KEY_Escape &&
|
|
||||||
priv->operation_mode == OPERATION_MODE_SEARCH)
|
|
||||||
{
|
|
||||||
return gtk_event_controller_key_forward (controller,
|
|
||||||
GTK_WIDGET (gtk_search_entry_get_text_widget (GTK_SEARCH_ENTRY (priv->search_entry))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return GDK_EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
widget_key_press_cb (GtkEventControllerKey *controller,
|
|
||||||
guint keyval,
|
|
||||||
guint keycode,
|
|
||||||
GdkModifierType state,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data;
|
|
||||||
GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
|
|
||||||
gboolean handled = FALSE;
|
|
||||||
const char *string;
|
|
||||||
|
|
||||||
if (should_trigger_location_entry (impl, keyval, state, &string))
|
|
||||||
{
|
|
||||||
if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
||||||
priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
||||||
{
|
|
||||||
location_popup_handler (impl, string);
|
|
||||||
handled = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
priv->starting_search = TRUE;
|
|
||||||
if (gtk_event_controller_key_forward (controller, priv->search_entry))
|
|
||||||
{
|
|
||||||
gtk_widget_grab_focus (priv->search_entry);
|
|
||||||
|
|
||||||
if (priv->operation_mode != OPERATION_MODE_SEARCH &&
|
|
||||||
priv->starting_search)
|
|
||||||
operation_mode_set (impl, OPERATION_MODE_SEARCH);
|
|
||||||
|
|
||||||
handled = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return handled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback used from gtk_tree_selection_selected_foreach(); adds a bookmark for
|
/* Callback used from gtk_tree_selection_selected_foreach(); adds a bookmark for
|
||||||
@ -7834,6 +7731,22 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
|
|||||||
GDK_KEY_p, GDK_MOD1_MASK,
|
GDK_KEY_p, GDK_MOD1_MASK,
|
||||||
"places-shortcut",
|
"places-shortcut",
|
||||||
NULL);
|
NULL);
|
||||||
|
gtk_widget_class_add_binding (widget_class,
|
||||||
|
GDK_KEY_slash, 0,
|
||||||
|
trigger_location_entry,
|
||||||
|
"s", "/");
|
||||||
|
gtk_widget_class_add_binding (widget_class,
|
||||||
|
GDK_KEY_KP_Divide, 0,
|
||||||
|
trigger_location_entry,
|
||||||
|
"s", "/");
|
||||||
|
gtk_widget_class_add_binding (widget_class,
|
||||||
|
GDK_KEY_period, 0,
|
||||||
|
trigger_location_entry,
|
||||||
|
"s", ".");
|
||||||
|
gtk_widget_class_add_binding (widget_class,
|
||||||
|
GDK_KEY_asciitilde, 0,
|
||||||
|
trigger_location_entry,
|
||||||
|
"s", "~");
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (quick_bookmark_keyvals); i++)
|
for (i = 0; i < G_N_ELEMENTS (quick_bookmark_keyvals); i++)
|
||||||
gtk_widget_class_add_binding_signal (widget_class,
|
gtk_widget_class_add_binding_signal (widget_class,
|
||||||
@ -7923,8 +7836,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
|
|||||||
gtk_widget_class_bind_template_callback (widget_class, rename_file_end);
|
gtk_widget_class_bind_template_callback (widget_class, rename_file_end);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, click_cb);
|
gtk_widget_class_bind_template_callback (widget_class, click_cb);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, long_press_cb);
|
gtk_widget_class_bind_template_callback (widget_class, long_press_cb);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, treeview_key_press_cb);
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, widget_key_press_cb);
|
|
||||||
|
|
||||||
gtk_widget_class_set_css_name (widget_class, I_("filechooser"));
|
gtk_widget_class_set_css_name (widget_class, I_("filechooser"));
|
||||||
|
|
||||||
|
@ -159,11 +159,6 @@
|
|||||||
<signal name="pressed" handler="click_cb" swapped="no"/>
|
<signal name="pressed" handler="click_cb" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkEventControllerKey">
|
|
||||||
<signal name="key-pressed" handler="treeview_key_press_cb" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<signal name="query-tooltip" handler="file_list_query_tooltip_cb" swapped="no"/>
|
<signal name="query-tooltip" handler="file_list_query_tooltip_cb" swapped="no"/>
|
||||||
<signal name="row-activated" handler="list_row_activated" swapped="no"/>
|
<signal name="row-activated" handler="list_row_activated" swapped="no"/>
|
||||||
<signal name="keynav-failed" handler="browse_files_tree_view_keynav_failed_cb"/>
|
<signal name="keynav-failed" handler="browse_files_tree_view_keynav_failed_cb"/>
|
||||||
@ -366,11 +361,6 @@
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkEventControllerKey">
|
|
||||||
<signal name="key-pressed" handler="widget_key_press_cb" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</template>
|
</template>
|
||||||
<object class="GtkSizeGroup" id="browse_path_bar_size_group">
|
<object class="GtkSizeGroup" id="browse_path_bar_size_group">
|
||||||
<property name="mode">vertical</property>
|
<property name="mode">vertical</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user