Procházet zdrojové kódy

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

Andreas Kling před 5 roky
rodič
revize
990ca1a7a5
2 změnil soubory, kde provedl 17 přidání a 4 odebrání
  1. 15 4
      DevTools/HackStudio/Locator.cpp
  2. 2 0
      DevTools/HackStudio/Locator.h

+ 15 - 4
DevTools/HackStudio/Locator.cpp

@@ -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);

+ 2 - 0
DevTools/HackStudio/Locator.h

@@ -3,6 +3,7 @@
 #include <LibGUI/GWidget.h>
 
 class LocatorTextBox;
+class GModelIndex;
 class GTableView;
 
 class Locator final : public GWidget {
@@ -17,6 +18,7 @@ private:
     virtual void keydown_event(GKeyEvent&) override;
 
     void update_suggestions();
+    void open_suggestion(const GModelIndex&);
 
     explicit Locator(GWidget* parent);