Skip to content

Commit

Permalink
#6166: Invoke EnsureVisible() in idle processing after an item has be…
Browse files Browse the repository at this point in the history
…en selected
  • Loading branch information
codereader committed Nov 17, 2022
1 parent a14c7ab commit 9b5eb96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions radiant/ui/entitylist/EntityList.cpp
Expand Up @@ -64,6 +64,9 @@ void EntityList::onPanelDeactivated()
// Unselect everything when hiding the dialog
util::ScopedBoolLock lock(_callbackActive);
_treeView->UnselectAll();

cancelCallbacks();
_itemToScrollToWhenIdle.Unset();
}

void EntityList::connectListeners()
Expand Down Expand Up @@ -216,6 +219,15 @@ void EntityList::expandRootNode()
}
}

void EntityList::onIdle()
{
if (_itemToScrollToWhenIdle.IsOk())
{
_treeView->EnsureVisible(_itemToScrollToWhenIdle);
_itemToScrollToWhenIdle.Unset();
}
}

void EntityList::onTreeViewSelection(const wxDataViewItem& item, bool selected)
{
if (selected)
Expand All @@ -226,8 +238,9 @@ void EntityList::onTreeViewSelection(const wxDataViewItem& item, bool selected)
// Remember this item
_selection.insert(item);

// Scroll to the row
_treeView->EnsureVisible(item);
// Scroll to the row, but don't do this immediately (can be expensive)
_itemToScrollToWhenIdle = item;
requestIdleCallback();
}
else
{
Expand Down
8 changes: 7 additions & 1 deletion radiant/ui/entitylist/EntityList.h
Expand Up @@ -6,6 +6,7 @@
#include <sigc++/connection.h>

#include "wxutil/DockablePanel.h"
#include "wxutil/event/SingleIdleCallback.h"

namespace wxutil
{
Expand All @@ -19,7 +20,8 @@ namespace ui

class EntityList :
public wxutil::DockablePanel,
public selection::SelectionSystem::Observer
public selection::SelectionSystem::Observer,
public wxutil::SingleIdleCallback
{
private:
// The GraphTreeModel instance
Expand All @@ -44,6 +46,8 @@ class EntityList :

std::set<wxDataViewItem, DataViewItemLess> _selection;

wxDataViewItem _itemToScrollToWhenIdle;

public:
EntityList(wxWindow* parent);
~EntityList() override;
Expand All @@ -52,6 +56,8 @@ class EntityList :
void onPanelActivated() override;
void onPanelDeactivated() override;

void onIdle() override;

private:
void connectListeners();
void disconnectListeners();
Expand Down

0 comments on commit 9b5eb96

Please sign in to comment.