1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

HackStudio: Allow opening a Locator suggestion by double-clicking it

This commit is contained in:
Andreas Kling 2019-10-28 18:54:37 +01:00
parent 29ac3e1477
commit 990ca1a7a5
2 changed files with 17 additions and 4 deletions

View file

@ -106,14 +106,12 @@ Locator::Locator(GWidget* parent)
m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical);
}
};
m_textbox->on_return_pressed = [this] {
auto selected_index = m_suggestion_view->selection().first();
if (!selected_index.is_valid())
return;
auto filename_index = m_suggestion_view->model()->index(selected_index.row(), LocatorSuggestionModel::Column::Name);
auto filename = m_suggestion_view->model()->data(filename_index, GModel::Role::Display).to_string();
open_file(filename);
close();
open_suggestion(selected_index);
};
m_popup_window = GWindow::construct();
@ -125,12 +123,25 @@ Locator::Locator(GWidget* parent)
m_suggestion_view->set_size_columns_to_fit_content(true);
m_suggestion_view->set_headers_visible(false);
m_popup_window->set_main_widget(m_suggestion_view);
m_suggestion_view->on_activation = [this](auto& index) {
open_suggestion(index);
};
}
Locator::~Locator()
{
}
void Locator::open_suggestion(const GModelIndex& index)
{
auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name);
auto filename = m_suggestion_view->model()->data(filename_index, GModel::Role::Display).to_string();
open_file(filename);
close();
}
void Locator::open()
{
m_textbox->set_focus(true);