mirror of
https://github.com/GNOME/gedit
synced 2024-07-08 00:30:44 +00:00
file-browser: expand/collapse item on right/left keypress
When an item is selected in the file browser: - when the left key is pressed: - if it can be collapsed, collapse it; - if its parent exists, go to the parent; - otherwise, do nothing; - when the right key is pressed: - if it can be expanded, expand it; - otherwise, do nothing. This mirrors the behaviour of Nautilus (before the tree view has been temporarily removed). See https://gitlab.gnome.org/GNOME/gedit/-/merge_requests/141
This commit is contained in:
parent
f61231dc0f
commit
7e1c744182
|
@ -406,6 +406,30 @@ activate_selected_items (GeditFileBrowserView *view)
|
|||
activate_selected_bookmark (view);
|
||||
}
|
||||
|
||||
static void
|
||||
expand_or_collapse_selected_item (GeditFileBrowserView *view, gboolean collapse)
|
||||
{
|
||||
GtkTreeView *tree_view = GTK_TREE_VIEW (view);
|
||||
g_autoptr (GtkTreePath) path = NULL;
|
||||
|
||||
gtk_tree_view_get_cursor (tree_view, &path, NULL);
|
||||
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
if (collapse)
|
||||
{
|
||||
if (!gtk_tree_view_collapse_row (tree_view, path) &&
|
||||
gtk_tree_path_get_depth (path) > 1 &&
|
||||
gtk_tree_path_up (path))
|
||||
gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_tree_view_expand_row (tree_view, path, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
row_activated (GtkTreeView *tree_view,
|
||||
GtkTreePath *path,
|
||||
|
@ -687,8 +711,18 @@ key_press_event (GtkWidget *widget,
|
|||
{
|
||||
toggle_hidden_filter (view);
|
||||
handled = TRUE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_KEY_Left:
|
||||
expand_or_collapse_selected_item (view, TRUE);
|
||||
handled = TRUE;
|
||||
break;
|
||||
|
||||
case GDK_KEY_Right:
|
||||
expand_or_collapse_selected_item (view, FALSE);
|
||||
handled = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
handled = FALSE;
|
||||
|
|
Loading…
Reference in New Issue
Block a user