From c6f0ddfa3dc5325fe0510fa435876756fec92762 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 10 Jan 2021 07:21:13 +0100 Subject: [PATCH] #3250: Move ResourceTreeViewToolbar implementation to .cpp file --- libs/wxutil/CMakeLists.txt | 1 + .../dataview/ResourceTreeViewToolbar.cpp | 140 ++++++++++++++++++ .../wxutil/dataview/ResourceTreeViewToolbar.h | 136 ++--------------- tools/msvc/wxutillib.vcxproj | 1 + tools/msvc/wxutillib.vcxproj.filters | 3 + 5 files changed, 154 insertions(+), 127 deletions(-) create mode 100644 libs/wxutil/dataview/ResourceTreeViewToolbar.cpp diff --git a/libs/wxutil/CMakeLists.txt b/libs/wxutil/CMakeLists.txt index bd141c48fa..27b462dbe4 100644 --- a/libs/wxutil/CMakeLists.txt +++ b/libs/wxutil/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(wxutil ConsoleView.cpp dataview/KeyValueTable.cpp dataview/ResourceTreeView.cpp + dataview/ResourceTreeViewToolbar.cpp dataview/ThreadedResourceTreePopulator.cpp dataview/TreeModel.cpp dataview/TreeModelFilter.cpp diff --git a/libs/wxutil/dataview/ResourceTreeViewToolbar.cpp b/libs/wxutil/dataview/ResourceTreeViewToolbar.cpp new file mode 100644 index 0000000000..c865d6c79f --- /dev/null +++ b/libs/wxutil/dataview/ResourceTreeViewToolbar.cpp @@ -0,0 +1,140 @@ +#include "ResourceTreeViewToolbar.h" + +#include "i18n.h" +#include "iuimanager.h" + +#include +#include +#include +#include + +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); +} + +} diff --git a/libs/wxutil/dataview/ResourceTreeViewToolbar.h b/libs/wxutil/dataview/ResourceTreeViewToolbar.h index 2e097f0b86..0f46f8a8e4 100644 --- a/libs/wxutil/dataview/ResourceTreeViewToolbar.h +++ b/libs/wxutil/dataview/ResourceTreeViewToolbar.h @@ -1,13 +1,9 @@ #pragma once -#include "i18n.h" -#include "iuimanager.h" #include -#include #include -#include -#include -#include +#include + #include "ResourceTreeView.h" namespace wxutil @@ -29,132 +25,18 @@ class ResourceTreeViewToolbar : wxBitmapButton* _findNextButton; public: - ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView = nullptr) : - 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); + ResourceTreeViewToolbar(wxWindow* parent, ResourceTreeView* treeView = nullptr); - _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 AssociateToTreeView(ResourceTreeView* treeView) - { - _treeView = treeView; - UpdateFromTreeView(); - } + void AssociateToTreeView(ResourceTreeView* treeView); private: - void jumpToNextFilterMatch() - { - if (_treeView != nullptr) - { - _treeView->JumpToNextFilterMatch(); - } - } - - void jumpToPrevFilterMatch() - { - if (_treeView != nullptr) - { - _treeView->JumpToPrevFilterMatch(); - } - } - - void _onEntryChar(wxKeyEvent& ev) - { - if (ev.GetKeyCode() == WXK_UP) - { - jumpToPrevFilterMatch(); - } - else if (ev.GetKeyCode() == WXK_DOWN) - { - jumpToNextFilterMatch(); - } - else - { - ev.Skip(); - } - } + void JumpToNextFilterMatch(); + void JumpToPrevFilterMatch(); - void _onFilterButtonToggled(wxCommandEvent& ev) - { - if (_treeView == nullptr) return; - - _treeView->SetTreeMode(_showAll->GetValue() ? - ResourceTreeView::TreeMode::ShowAll : - ResourceTreeView::TreeMode::ShowFavourites); - } + void _onEntryChar(wxKeyEvent& ev); + void _onFilterButtonToggled(wxCommandEvent& ev); - void UpdateFromTreeView() - { - if (_treeView == nullptr) return; - - auto mode = _treeView->GetTreeMode(); - _showAll->SetValue(mode == ResourceTreeView::TreeMode::ShowAll); - _showFavourites->SetValue(mode == ResourceTreeView::TreeMode::ShowFavourites); - } + void UpdateFromTreeView(); }; } diff --git a/tools/msvc/wxutillib.vcxproj b/tools/msvc/wxutillib.vcxproj index 6527c2b56d..005f5a6600 100644 --- a/tools/msvc/wxutillib.vcxproj +++ b/tools/msvc/wxutillib.vcxproj @@ -199,6 +199,7 @@ + diff --git a/tools/msvc/wxutillib.vcxproj.filters b/tools/msvc/wxutillib.vcxproj.filters index c8d3cd75a0..d5382cb151 100644 --- a/tools/msvc/wxutillib.vcxproj.filters +++ b/tools/msvc/wxutillib.vcxproj.filters @@ -218,5 +218,8 @@ dataview + + dataview + \ No newline at end of file