Fix strange multi-selection behaviour on Linux (#2269).
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Jun 2022 20:29:13 +0000 (22:29 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 9 Jun 2022 07:34:57 +0000 (09:34 +0200)
It seems that all of a sudden the behaviour of wxListCtrl's selection
is strange (on Linux at least).  If a list item is selected by
some other action (e.g. selection in the timeline) and then you click
another directly in the list, both are selected.

This "fix" seems to work on Linux at least - also setting
wxLIST_STATE_FOCUSED as well as wxLIST_STATE_SELECTED.  I don't know
why this works.

src/wx/content_panel.cc
src/wx/content_panel.h

index 69dd724266abfc35a780f141833587c2853bd13a..a7c9a445482ce486c30eea5b722464479c538631 100644 (file)
@@ -677,11 +677,7 @@ ContentPanel::set_selection (weak_ptr<Content> wc)
 {
        auto content = _film->content ();
        for (size_t i = 0; i < content.size(); ++i) {
-               if (content[i] == wc.lock ()) {
-                       _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
-               } else {
-                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
-               }
+               set_selected_state(i, content[i] == wc.lock());
        }
 }
 
@@ -693,11 +689,7 @@ ContentPanel::set_selection (ContentList cl)
 
        auto content = _film->content ();
        for (size_t i = 0; i < content.size(); ++i) {
-               if (find(cl.begin(), cl.end(), content[i]) != cl.end()) {
-                       _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
-               } else {
-                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
-               }
+               set_selected_state(i, find(cl.begin(), cl.end(), content[i]) != cl.end());
        }
 
        _no_check_selection = false;
@@ -783,7 +775,7 @@ ContentPanel::setup ()
                _content->InsertItem (item);
 
                if (i.get() == selected_content) {
-                       _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+                       set_selected_state(t, true);
                }
 
                if (!valid || needs_kdm || needs_assets) {
@@ -793,7 +785,7 @@ ContentPanel::setup ()
 
        if (!selected_content && !content.empty ()) {
                /* Select the item of content if none was selected before */
-               _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+               set_selected_state(0, true);
        }
 
        setup_sensitivity ();
@@ -861,6 +853,14 @@ ContentPanel::panels () const
 }
 
 
+void
+ContentPanel::set_selected_state(int item, bool state)
+{
+       _content->SetItemState(item, state ? wxLIST_STATE_SELECTED : 0, wxLIST_STATE_SELECTED);
+       _content->SetItemState(item, state ? wxLIST_STATE_FOCUSED : 0, wxLIST_STATE_FOCUSED);
+}
+
+
 LimitedSplitter::LimitedSplitter (wxWindow* parent)
        : wxSplitterWindow (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_3DSASH | wxSP_LIVE_UPDATE)
        , _first_shown (false)
index d6c81a8d2a794b5cf1fa9867f24c3bce379402d2..a886b021726ec00de2ce7d189d2b709c46ce7d54 100644 (file)
@@ -128,6 +128,7 @@ private:
 
        void setup ();
        void setup_sensitivity ();
+       void set_selected_state(int item, bool state);
 
        void add_files (std::vector<boost::filesystem::path>);
        std::list<ContentSubPanel *> panels () const;