Commit 9a4356d9 authored by Graeme Gott's avatar Graeme Gott

Fix icon view skipping first item when pressing arrow key.

parent 353371a6
......@@ -68,22 +68,31 @@ void Page::reset_selection()
{
m_view->collapse_all();
// Set keyboard focus on first item
// Set keyboard focus on first item and scroll to top
select_first();
// Clear selection
m_view->clear_selection();
}
//-----------------------------------------------------------------------------
void Page::select_first()
{
// Select and set keyboard focus on first item
GtkTreeModel* model = m_view->get_model();
GtkTreeIter iter;
if (model && gtk_tree_model_get_iter_first(model, &iter))
{
GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
m_view->set_cursor(path);
m_view->select_path(path);
gtk_tree_path_free(path);
}
// Scroll to top
GtkAdjustment* adjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(m_view->get_widget()));
gtk_adjustment_set_value(adjustment, gtk_adjustment_get_lower(adjustment));
// Clear selection
m_view->clear_selection();
}
//-----------------------------------------------------------------------------
......
......@@ -50,6 +50,7 @@ public:
}
void reset_selection();
void select_first();
void update_view();
protected:
......
......@@ -141,18 +141,7 @@ void SearchPage::set_filter(const gchar* filter)
g_object_unref(store);
// Find first result
GtkTreeIter iter;
GtkTreePath* path = gtk_tree_path_new_first();
bool found = gtk_tree_model_get_iter(get_view()->get_model(), &iter, path);
// Scroll to and select first result
if (found)
{
get_view()->set_cursor(path);
get_view()->select_path(path);
get_view()->scroll_to_path(path);
}
gtk_tree_path_free(path);
select_first();
}
//-----------------------------------------------------------------------------
......
......@@ -714,6 +714,19 @@ gboolean WhiskerMenu::Window::on_key_press_event(GtkWidget* widget, GdkEvent* ev
{
gtk_widget_grab_focus(view);
}
if (gtk_window_get_focus(m_window) == view)
{
GtkTreePath* path = page->get_view()->get_selected_path();
if (path)
{
gtk_tree_path_free(path);
}
else
{
page->select_first();
return true;
}
}
}
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment