Browse Source

LibGUI+FileManager: Add GAbstractView::on_selection_change hook

This hook will be called whenever the view's selection changes somehow.
Use this in the FileManager to keep the left and right views in sync.
Andreas Kling 5 years ago
parent
commit
6dec328af7

+ 2 - 2
Applications/FileManager/main.cpp

@@ -77,8 +77,8 @@ int main(int argc, char** argv)
         directory_view->open(location_textbox->text());
     };
 
-    file_system_model->on_selection_changed = [&](auto& index) {
-        auto path = file_system_model->path(index);
+    tree_view->on_selection_change = [&] {
+        auto path = file_system_model->path(tree_view->selection().first());
         if (directory_view->path() == path)
             return;
         directory_view->open(path);

+ 3 - 0
Libraries/LibGUI/GAbstractView.cpp

@@ -100,5 +100,8 @@ void GAbstractView::activate(const GModelIndex& index)
 
 void GAbstractView::notify_selection_changed(Badge<GModelSelection>)
 {
+    did_update_selection();
+    if (on_selection_change)
+        on_selection_change();
     update();
 }

+ 1 - 0
Libraries/LibGUI/GAbstractView.h

@@ -36,6 +36,7 @@ public:
     void set_activates_on_selection(bool b) { m_activates_on_selection = b; }
     bool activates_on_selection() const { return m_activates_on_selection; }
 
+    Function<void()> on_selection_change;
     Function<void(const GModelIndex&)> on_activation;
     Function<void(const GModelIndex&)> on_selection;
     Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;