From 2864d595e7c531f4f03ce6a9fef6123e169f7ba9 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 27 Dec 2020 19:15:38 +0100 Subject: [PATCH] #5127: Move common tree view item formatting code to wxutil. Remove wxutil namespace specifies from EntityClassChooser, it's part of wxutil --- libs/wxutil/EntityClassChooser.cpp | 56 +++++++++--------------- libs/wxutil/EntityClassChooser.h | 28 ++++++------ libs/wxutil/TreeViewItemStyle.h | 27 ++++++++++++ radiant/ui/mediabrowser/MediaBrowser.cpp | 22 ++-------- tools/msvc/wxutillib.vcxproj | 1 + tools/msvc/wxutillib.vcxproj.filters | 1 + 6 files changed, 66 insertions(+), 69 deletions(-) create mode 100644 libs/wxutil/TreeViewItemStyle.h diff --git a/libs/wxutil/EntityClassChooser.cpp b/libs/wxutil/EntityClassChooser.cpp index 87b5324e6f..965d6d0fba 100644 --- a/libs/wxutil/EntityClassChooser.cpp +++ b/libs/wxutil/EntityClassChooser.cpp @@ -9,11 +9,12 @@ #include "gamelib.h" #include - #include #include #include +#include "TreeViewItemStyle.h" + #include "string/string.h" #include "eclass.h" @@ -32,23 +33,6 @@ namespace // Registry XPath to lookup key that specifies the display folder const char* const FOLDER_KEY_PATH = "/entityChooser/displayFolderKey"; - - // Get the item format for favourites / non-favourites - inline wxDataViewItemAttr getItemFormat(bool isFavourite) - { - if (isFavourite) - { - wxDataViewItemAttr blueBold; - blueBold.SetColour(wxColor(0, 0, 255)); - blueBold.SetBold(true); - - return blueBold; - } - else - { - return wxDataViewItemAttr(); - } - } } /* @@ -56,14 +40,14 @@ namespace * taking account of display folders and mod names. */ class EntityClassTreePopulator: - public wxutil::VFSTreePopulator, + public VFSTreePopulator, public EntityClassVisitor { // TreeStore to populate - wxutil::TreeModel::Ptr _store; + TreeModel::Ptr _store; // Column definition - const wxutil::EntityClassChooser::TreeColumns& _columns; + const EntityClassChooser::TreeColumns& _columns; // Key that specifies the display folder std::string _folderKey; @@ -76,9 +60,9 @@ class EntityClassTreePopulator: public: // Constructor - EntityClassTreePopulator(wxutil::TreeModel::Ptr store, + EntityClassTreePopulator(TreeModel::Ptr store, const EntityClassChooser::TreeColumns& columns) - : wxutil::VFSTreePopulator(store), + : VFSTreePopulator(store), _store(store), _columns(columns), _folderKey(game::current::getValue(FOLDER_KEY_PATH)) @@ -104,7 +88,7 @@ class EntityClassTreePopulator: // of the DISPLAY_FOLDER_KEY. addPath( eclass->getModName() + folderPath + "/" + eclass->getName(), - [&](wxutil::TreeModel::Row& row, const std::string& path, + [&](TreeModel::Row& row, const std::string& path, const std::string& leafName, bool isFolder) { bool isFavourite = !isFolder && _favourites.count(leafName) > 0; @@ -116,7 +100,7 @@ class EntityClassTreePopulator: ); row[_columns.isFolder] = isFolder; row[_columns.isFavourite] = isFavourite; - row[_columns.name] = getItemFormat(isFavourite); // assign attributes + row[_columns.name] = TreeViewItemStyle::Declaration(isFavourite); // assign attributes row.SendItemAdded(); } ); @@ -133,7 +117,7 @@ class EntityClassChooser::ThreadedEntityClassLoader : // The tree store to populate. We must operate on our own tree store, since // updating the EntityClassChooser's tree store from a different thread // wouldn't be safe - wxutil::TreeModel::Ptr _treeStore; + TreeModel::Ptr _treeStore; // The class to be notified on finish wxEvtHandler* _finishedHandler; @@ -162,7 +146,7 @@ class EntityClassChooser::ThreadedEntityClassLoader : ScopedDebugTimer timer("ThreadedEntityClassLoader::run()"); // Create new treestoree - _treeStore = new wxutil::TreeModel(_columns); + _treeStore = new TreeModel(_columns); // Populate it with the list of entity classes by using a visitor class. EntityClassTreePopulator visitor(_treeStore, _columns); @@ -175,7 +159,7 @@ class EntityClassChooser::ThreadedEntityClassLoader : if (!TestDestroy()) { - wxQueueEvent(_finishedHandler, new wxutil::TreeModel::PopulationFinishedEvent(_treeStore)); + wxQueueEvent(_finishedHandler, new TreeModel::PopulationFinishedEvent(_treeStore)); } return static_cast(0); @@ -184,13 +168,13 @@ class EntityClassChooser::ThreadedEntityClassLoader : // Main constructor EntityClassChooser::EntityClassChooser() -: wxutil::DialogBase(_(ECLASS_CHOOSER_TITLE)), +: DialogBase(_(ECLASS_CHOOSER_TITLE)), _treeStore(nullptr), _treeView(nullptr), _selectedName("") { // Connect the finish callback to load the treestore - Bind(wxutil::EV_TREEMODEL_POPULATION_FINISHED, &EntityClassChooser::onTreeStorePopulationFinished, this); + Bind(EV_TREEMODEL_POPULATION_FINISHED, &EntityClassChooser::onTreeStorePopulationFinished, this); loadNamedPanel(this, "EntityClassChooserMainPanel"); @@ -206,7 +190,7 @@ EntityClassChooser::EntityClassChooser() // Add model preview to right-hand-side of main container wxPanel* rightPanel = findNamedObject(this, "EntityClassChooserRightPane"); - _modelPreview.reset(new wxutil::ModelPreview(rightPanel)); + _modelPreview.reset(new ModelPreview(rightPanel)); rightPanel->GetSizer()->Add(_modelPreview->getWidget(), 1, wxEXPAND); @@ -371,14 +355,14 @@ void EntityClassChooser::setTreeViewModel() void EntityClassChooser::setupTreeView() { // Use the TreeModel's full string search function - _treeStore = new wxutil::TreeModel(_columns); - wxutil::TreeModel::Row row = _treeStore->AddItem(); + _treeStore = new TreeModel(_columns); + TreeModel::Row row = _treeStore->AddItem(); row[_columns.name] = wxVariant(wxDataViewIconText(_("Loading..."))); wxPanel* parent = findNamedObject(this, "EntityClassChooserLeftPane"); - _treeView = wxutil::TreeView::CreateWithModel(parent, _treeStore.get()); + _treeView = TreeView::CreateWithModel(parent, _treeStore.get()); _treeView->AddSearchColumn(_columns.name); _treeView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &EntityClassChooser::onSelectionChanged, this); @@ -408,7 +392,7 @@ void EntityClassChooser::updateSelection() if (item.IsOk()) { - wxutil::TreeModel::Row row(item, *_treeStore); + TreeModel::Row row(item, *_treeStore); if (!row[_columns.isFolder].getBool()) { @@ -464,7 +448,7 @@ void EntityClassChooser::onSelectionChanged(wxDataViewEvent& ev) updateSelection(); } -void EntityClassChooser::onTreeStorePopulationFinished(wxutil::TreeModel::PopulationFinishedEvent& ev) +void EntityClassChooser::onTreeStorePopulationFinished(TreeModel::PopulationFinishedEvent& ev) { _treeView->UnselectAll(); diff --git a/libs/wxutil/EntityClassChooser.h b/libs/wxutil/EntityClassChooser.h index beb10bd021..71d3e7d385 100644 --- a/libs/wxutil/EntityClassChooser.h +++ b/libs/wxutil/EntityClassChooser.h @@ -24,31 +24,31 @@ typedef std::shared_ptr EntityClassChooserPtr; * of a class to create at the current location. */ class EntityClassChooser : - public wxutil::DialogBase, - private wxutil::XmlResourceBasedWidget + public DialogBase, + private XmlResourceBasedWidget { public: // Treemodel definition struct TreeColumns : - public wxutil::TreeModel::ColumnRecord + public TreeModel::ColumnRecord { TreeColumns() : - name(add(wxutil::TreeModel::Column::IconText)), - isFolder(add(wxutil::TreeModel::Column::Boolean)), - isFavourite(add(wxutil::TreeModel::Column::Boolean)) + name(add(TreeModel::Column::IconText)), + isFolder(add(TreeModel::Column::Boolean)), + isFavourite(add(TreeModel::Column::Boolean)) {} - wxutil::TreeModel::Column name; - wxutil::TreeModel::Column isFolder; - wxutil::TreeModel::Column isFavourite; + TreeModel::Column name; + TreeModel::Column isFolder; + TreeModel::Column isFavourite; }; private: TreeColumns _columns; // Tree model holding the classnames - wxutil::TreeModel::Ptr _treeStore; - wxutil::TreeView* _treeView; + TreeModel::Ptr _treeStore; + TreeView* _treeView; // Delegated object for loading entity classes in a separate thread class ThreadedEntityClassLoader; @@ -61,9 +61,9 @@ class EntityClassChooser : std::string _classToHighlight; // Model preview widget - wxutil::ModelPreviewPtr _modelPreview; + ModelPreviewPtr _modelPreview; - wxutil::PanedPosition _panedPosition; + PanedPosition _panedPosition; sigc::connection _defsReloaded; @@ -88,7 +88,7 @@ class EntityClassChooser : void onOK(wxCommandEvent& ev); void onSelectionChanged(wxDataViewEvent& ev); void onDeleteEvent(wxCloseEvent& ev); - void onTreeStorePopulationFinished(wxutil::TreeModel::PopulationFinishedEvent& ev); + void onTreeStorePopulationFinished(TreeModel::PopulationFinishedEvent& ev); void onMainFrameShuttingDown(); diff --git a/libs/wxutil/TreeViewItemStyle.h b/libs/wxutil/TreeViewItemStyle.h new file mode 100644 index 0000000000..22d7b7b596 --- /dev/null +++ b/libs/wxutil/TreeViewItemStyle.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +namespace wxutil +{ + +class TreeViewItemStyle +{ +public: + // Get the item format for favourites / non-favourites item in a declaration tree + static wxDataViewItemAttr Declaration(bool isFavourite) + { + if (isFavourite) + { + wxDataViewItemAttr blueBold; + blueBold.SetColour(wxColor(0, 0, 255)); + blueBold.SetBold(true); + + return blueBold; + } + + return wxDataViewItemAttr(); + } +}; + +} diff --git a/radiant/ui/mediabrowser/MediaBrowser.cpp b/radiant/ui/mediabrowser/MediaBrowser.cpp index d1b71dd745..4cc0e3a21e 100644 --- a/radiant/ui/mediabrowser/MediaBrowser.cpp +++ b/radiant/ui/mediabrowser/MediaBrowser.cpp @@ -12,6 +12,7 @@ #include "ifavourites.h" #include "wxutil/MultiMonitor.h" +#include "wxutil/TreeViewItemStyle.h" #include @@ -105,23 +106,6 @@ class MediaBrowser::Favourites : namespace { -// Get the item format for favourites / non-favourites -inline wxDataViewItemAttr getItemFormat(bool isFavourite) -{ - if (isFavourite) - { - wxDataViewItemAttr blueBold; - blueBold.SetColour(wxColor(0, 0, 255)); - blueBold.SetBold(true); - - return blueBold; - } - else - { - return wxDataViewItemAttr(); - } -} - /* Callback functor for processing shader names */ struct ShaderNameCompareFunctor { @@ -238,7 +222,7 @@ struct ShaderNameFunctor row[_columns.isFavourite] = isFavourite; // Formatting - row[_columns.iconAndName] = getItemFormat(isFavourite); + row[_columns.iconAndName] = wxutil::TreeViewItemStyle::Declaration(isFavourite); } }; @@ -887,7 +871,7 @@ void MediaBrowser::setFavouriteRecursively(wxutil::TreeModel::Row& row, bool isF // Not a folder, set the desired status on this item row[_columns.isFavourite] = isFavourite; - row[_columns.iconAndName] = getItemFormat(isFavourite); + row[_columns.iconAndName] = wxutil::TreeViewItemStyle::Declaration(isFavourite); // Keep track of this choice if (isFavourite) diff --git a/tools/msvc/wxutillib.vcxproj b/tools/msvc/wxutillib.vcxproj index 08c7bfbc63..7b03bcd81f 100644 --- a/tools/msvc/wxutillib.vcxproj +++ b/tools/msvc/wxutillib.vcxproj @@ -184,6 +184,7 @@ + diff --git a/tools/msvc/wxutillib.vcxproj.filters b/tools/msvc/wxutillib.vcxproj.filters index de12e5976f..e79475e72e 100644 --- a/tools/msvc/wxutillib.vcxproj.filters +++ b/tools/msvc/wxutillib.vcxproj.filters @@ -114,6 +114,7 @@ fsview +