Skip to content

Commit

Permalink
Working towards resolving #5095: the search popup box needs to react …
Browse files Browse the repository at this point in the history
…to certain events affecting the parent tree view's visibility as well as its position.
  • Loading branch information
codereader committed Jan 4, 2020
1 parent 09a069d commit afcc211
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions libs/wxutil/TreeView.cpp
Expand Up @@ -40,6 +40,8 @@ class TreeView::Search :
void HighlightNextMatch();
void HighlightPrevMatch();

void Close();

private:
void HighlightMatch(const wxDataViewItem& item);
};
Expand All @@ -55,7 +57,7 @@ TreeView::TreeView(wxWindow* parent, TreeModel::Ptr model, long style) :
}

Bind(wxEVT_CHAR, std::bind(&TreeView::_onChar, this, std::placeholders::_1));
Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, std::bind(&TreeView::_onItemActivated, this, std::placeholders::_1));
Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, std::bind(&TreeView::_onItemActivated, this, std::placeholders::_1));
}

TreeView* TreeView::Create(wxWindow* parent, long style)
Expand Down Expand Up @@ -242,9 +244,20 @@ class TreeView::SearchPopupWindow :
Layout();
Fit();

// Position this control in the bottom right corner
wxPoint popupPos = GetParent()->GetScreenPosition() + GetParent()->GetSize() - GetSize();
Position(popupPos, wxSize(0, 0));
Reposition();

// Subscribe to the parent window's visibility and iconise events to avoid
// the popup from lingering around long after the tree is gone (#5095)
wxWindow* parentWindow = wxGetTopLevelParent(treeView);

if (parentWindow != nullptr)
{
parentWindow->Bind(wxEVT_SHOW, &SearchPopupWindow::_onParentVisibilityChanged, this);
parentWindow->Bind(wxEVT_ICONIZE, &SearchPopupWindow::_onParentMinimized, this);

// Detect parent window movements to reposition ourselves
parentWindow->Bind(wxEVT_MOVE, &SearchPopupWindow::_onParentMoved, this);
}
}

wxString GetSearchString()
Expand All @@ -256,6 +269,34 @@ class TreeView::SearchPopupWindow :
{
_entry->SetValue(str);
}

private:
void Reposition()
{
// Position this control in the bottom right corner
wxPoint popupPos = GetParent()->GetScreenPosition() + GetParent()->GetSize() - GetSize();
Position(popupPos, wxSize(0, 0));
}

void _onParentMoved(wxMoveEvent&)
{
Reposition();
}

void _onParentMinimized(wxIconizeEvent&)
{
// Close any searches when the parent window is minimized
_owner.Close();
}

void _onParentVisibilityChanged(wxShowEvent& ev)
{
if (!ev.IsShown())
{
// Close any searches when the parent window is hidden
_owner.Close();
}
}
};

TreeView::Search::Search(TreeView& treeView) :
Expand Down Expand Up @@ -377,6 +418,11 @@ void TreeView::Search::HighlightPrevMatch()
HighlightMatch(model->FindPrevString(_popup->GetSearchString(), _treeView._colsToSearch, _curSearchMatch));
}

void TreeView::Search::Close()
{
_treeView.CloseSearch();
}

void TreeView::CloseSearch()
{
_search.reset();
Expand Down

0 comments on commit afcc211

Please sign in to comment.