From 7a5db12034cbb72ad5f0ba9fd33c54c8bdbb1ac1 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 29 Jul 2022 13:56:57 +0200 Subject: [PATCH] #6021: Move row assignment code from ThreadedParticlesLoader to ThreadedDeclarationTreePopulator --- .../ThreadedDeclarationTreePopulator.h | 47 +++++++++++++++++++ .../ui/particles/ThreadedParticlesLoader.h | 23 ++------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/libs/wxutil/dataview/ThreadedDeclarationTreePopulator.h b/libs/wxutil/dataview/ThreadedDeclarationTreePopulator.h index 17f17a66e6..8ba5afc817 100644 --- a/libs/wxutil/dataview/ThreadedDeclarationTreePopulator.h +++ b/libs/wxutil/dataview/ThreadedDeclarationTreePopulator.h @@ -3,8 +3,10 @@ #include "idecltypes.h" #include "ifavourites.h" +#include "../Bitmap.h" #include "DeclarationTreeView.h" #include "ThreadedResourceTreePopulator.h" +#include "TreeViewItemStyle.h" namespace wxutil { @@ -17,17 +19,36 @@ class ThreadedDeclarationTreePopulator : public ThreadedResourceTreePopulator { private: + static constexpr const char* const DEFAULT_DECL_ICON = "decl.png"; + static constexpr const char* const DEFAULT_FOLDER_ICON = "folder16.png"; + const DeclarationTreeView::Columns& _columns; std::set _favourites; + wxIcon _folderIcon; + wxIcon _declIcon; + public: ThreadedDeclarationTreePopulator(decl::Type type, const DeclarationTreeView::Columns& columns) : + ThreadedDeclarationTreePopulator(type, columns, DEFAULT_DECL_ICON, DEFAULT_FOLDER_ICON) + {} + + ThreadedDeclarationTreePopulator(decl::Type type, const DeclarationTreeView::Columns& columns, + const std::string& declIcon) : + ThreadedDeclarationTreePopulator(type, columns, declIcon, DEFAULT_FOLDER_ICON) + {} + + ThreadedDeclarationTreePopulator(decl::Type type, const DeclarationTreeView::Columns& columns, + const std::string& declIcon, const std::string& folderIcon) : ThreadedResourceTreePopulator(columns), _columns(columns) { // Assemble the set of favourites for the given declaration type _favourites = GlobalFavouritesManager().getFavourites(decl::getTypeName(type)); + + _declIcon.CopyFromBitmap(GetLocalBitmap(declIcon)); + _folderIcon.CopyFromBitmap(GetLocalBitmap(folderIcon)); } ~ThreadedDeclarationTreePopulator() override @@ -36,6 +57,32 @@ class ThreadedDeclarationTreePopulator : } protected: + /** + * Populates the given row with values matching for a certain declaration or folder + * + * @fullPath: The path to the row, mainly used for internal storage. + * @declName: The name of the declaration (including any folders and slashes) + * @leafName: The name part after the rightmost slash + * @isFolder: Whether this row is a folder (the folder icon will be assigned) + */ + void AssignValuesToRow(TreeModel::Row& row, const std::string& fullPath, + const std::string& declName, const std::string& leafName, bool isFolder) + { + ThrowIfCancellationRequested(); + + auto isFavourite = IsFavourite(declName); + + row[_columns.iconAndName] = wxVariant(wxDataViewIconText(leafName, !isFolder ? _declIcon : _folderIcon)); + row[_columns.iconAndName] = TreeViewItemStyle::Declaration(isFavourite); + row[_columns.fullName] = fullPath; + row[_columns.leafName] = leafName; + row[_columns.declName] = declName; + row[_columns.isFolder] = isFolder; + row[_columns.isFavourite] = isFavourite; + + row.SendItemAdded(); + } + const std::set& GetFavourites() const { return _favourites; diff --git a/radiant/ui/particles/ThreadedParticlesLoader.h b/radiant/ui/particles/ThreadedParticlesLoader.h index 1d8b6e7010..1f6d41c8aa 100644 --- a/radiant/ui/particles/ThreadedParticlesLoader.h +++ b/radiant/ui/particles/ThreadedParticlesLoader.h @@ -1,12 +1,9 @@ #pragma once -#include "ifavourites.h" - #include "debugging/ScopedDebugTimer.h" #include "wxutil/dataview/DeclarationTreeView.h" #include "wxutil/dataview/ThreadedDeclarationTreePopulator.h" -#include "wxutil/dataview/TreeViewItemStyle.h" namespace ui { @@ -18,13 +15,9 @@ namespace ui class ThreadedParticlesLoader final : public wxutil::ThreadedDeclarationTreePopulator { -private: - const wxutil::DeclarationTreeView::Columns& _columns; - public: ThreadedParticlesLoader(const wxutil::DeclarationTreeView::Columns& columns) : - ThreadedDeclarationTreePopulator(decl::Type::Particle, columns), - _columns(columns) + ThreadedDeclarationTreePopulator(decl::Type::Particle, columns, "particle16.png") {} ~ThreadedParticlesLoader() @@ -43,22 +36,12 @@ class ThreadedParticlesLoader final : ThrowIfCancellationRequested(); // Add the ".prt" extension to the name fo display in the list - std::string prtName = def.getDeclName() + ".prt"; + auto prtName = def.getDeclName() + ".prt"; // Add the Def name to the list store wxutil::TreeModel::Row row = model->AddItem(); - bool isFavourite = IsFavourite(def.getDeclName()); - - row[_columns.iconAndName] = wxVariant(wxDataViewIconText(prtName)); - row[_columns.iconAndName] = wxutil::TreeViewItemStyle::Declaration(isFavourite); - row[_columns.fullName] = prtName; - row[_columns.leafName] = prtName; - row[_columns.declName] = def.getDeclName(); - row[_columns.isFolder] = false; - row[_columns.isFavourite] = isFavourite; - - row.SendItemAdded(); + AssignValuesToRow(row, prtName, def.getDeclName(), prtName, false); }); } };