Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3250: Move ResourceTreeViewToolbar implementation to .cpp file
- Loading branch information
1 parent
3af5798
commit c6f0ddf
Showing
5 changed files
with
154 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include "ResourceTreeViewToolbar.h" | ||
|
||
#include "i18n.h" | ||
#include "iuimanager.h" | ||
|
||
#include <wx/artprov.h> | ||
#include <wx/sizer.h> | ||
#include <wx/statbmp.h> | ||
#include <wx/textctrl.h> | ||
|
||
namespace wxutil | ||
{ | ||
|
||
ResourceTreeViewToolbar::ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView) : | ||
wxPanel(parent, wxID_ANY), | ||
_treeView(nullptr), | ||
_showAll(nullptr), | ||
_showFavourites(nullptr) | ||
{ | ||
auto* grid = new wxFlexGridSizer(2); | ||
grid->AddGrowableCol(1); | ||
|
||
SetSizer(grid); | ||
|
||
// Hbox for the favourites selection widgets | ||
auto* favourites = new wxBoxSizer(wxHORIZONTAL); | ||
_showAll = new wxRadioButton(this, wxID_ANY, _("Show All"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); | ||
_showFavourites = new wxRadioButton(this, wxID_ANY, _("Show Favourites")); | ||
|
||
_showAll->Bind(wxEVT_RADIOBUTTON, &ResourceTreeViewToolbar::_onFilterButtonToggled, this); | ||
_showFavourites->Bind(wxEVT_RADIOBUTTON, &ResourceTreeViewToolbar::_onFilterButtonToggled, this); | ||
|
||
favourites->Add(_showAll, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0); | ||
favourites->Add(_showFavourites, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 6); | ||
|
||
// Filter text entry box | ||
auto* filterBox = new wxBoxSizer(wxHORIZONTAL); | ||
|
||
auto* filterImage = new wxStaticBitmap(this, wxID_ANY, wxArtProvider::GetBitmap(wxART_FIND, wxART_TOOLBAR, wxSize(16, 16))); | ||
|
||
auto* filterEntry = new wxTextCtrl(this, wxID_ANY); | ||
filterEntry->SetMinSize(wxSize(100, -1)); | ||
filterEntry->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev) | ||
{ | ||
if (_treeView != nullptr) | ||
{ | ||
_treeView->SetFilterText(ev.GetString().ToStdString()); | ||
} | ||
}); | ||
filterEntry->Bind(wxEVT_CHAR, &ResourceTreeViewToolbar::_onEntryChar, this); | ||
|
||
auto nextImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_down.png"); | ||
_findNextButton = new wxBitmapButton(this, wxID_ANY, nextImg); | ||
|
||
auto prevImg = wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "arrow_up.png"); | ||
_findPrevButton = new wxBitmapButton(this, wxID_ANY, prevImg); | ||
|
||
_findNextButton->SetSize(wxSize(16, 16)); | ||
_findPrevButton->SetSize(wxSize(16, 16)); | ||
|
||
_findNextButton->SetToolTip(_("Go to next match")); | ||
_findPrevButton->SetToolTip(_("Go to previous match")); | ||
|
||
_findNextButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) | ||
{ | ||
JumpToNextFilterMatch(); | ||
}); | ||
_findPrevButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) | ||
{ | ||
JumpToPrevFilterMatch(); | ||
}); | ||
|
||
filterBox->Add(filterImage, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6); | ||
filterBox->Add(filterEntry, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 6); | ||
filterBox->Add(_findPrevButton, 0, wxEXPAND | wxRIGHT, 3); | ||
filterBox->Add(_findNextButton, 0, wxEXPAND, 6); | ||
|
||
grid->Add(favourites, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxRIGHT, 6); | ||
grid->Add(filterBox, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT, 6); | ||
|
||
AssociateToTreeView(treeView); | ||
} | ||
|
||
void ResourceTreeViewToolbar::AssociateToTreeView(ResourceTreeView* treeView) | ||
{ | ||
_treeView = treeView; | ||
UpdateFromTreeView(); | ||
} | ||
|
||
void ResourceTreeViewToolbar::JumpToNextFilterMatch() | ||
{ | ||
if (_treeView != nullptr) | ||
{ | ||
_treeView->JumpToNextFilterMatch(); | ||
} | ||
} | ||
|
||
void ResourceTreeViewToolbar::JumpToPrevFilterMatch() | ||
{ | ||
if (_treeView != nullptr) | ||
{ | ||
_treeView->JumpToPrevFilterMatch(); | ||
} | ||
} | ||
|
||
void ResourceTreeViewToolbar::_onEntryChar(wxKeyEvent& ev) | ||
{ | ||
if (ev.GetKeyCode() == WXK_UP) | ||
{ | ||
JumpToPrevFilterMatch(); | ||
} | ||
else if (ev.GetKeyCode() == WXK_DOWN) | ||
{ | ||
JumpToNextFilterMatch(); | ||
} | ||
else | ||
{ | ||
ev.Skip(); | ||
} | ||
} | ||
|
||
void ResourceTreeViewToolbar::_onFilterButtonToggled(wxCommandEvent& ev) | ||
{ | ||
if (_treeView == nullptr) return; | ||
|
||
_treeView->SetTreeMode(_showAll->GetValue() ? | ||
ResourceTreeView::TreeMode::ShowAll : | ||
ResourceTreeView::TreeMode::ShowFavourites); | ||
} | ||
|
||
void ResourceTreeViewToolbar::UpdateFromTreeView() | ||
{ | ||
if (_treeView == nullptr) return; | ||
|
||
auto mode = _treeView->GetTreeMode(); | ||
_showAll->SetValue(mode == ResourceTreeView::TreeMode::ShowAll); | ||
_showFavourites->SetValue(mode == ResourceTreeView::TreeMode::ShowFavourites); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters