Skip to content

Commit

Permalink
#6021: Move row assignment code from ThreadedParticlesLoader to Threa…
Browse files Browse the repository at this point in the history
…dedDeclarationTreePopulator
  • Loading branch information
codereader committed Jul 29, 2022
1 parent 510d071 commit 7a5db12
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
47 changes: 47 additions & 0 deletions libs/wxutil/dataview/ThreadedDeclarationTreePopulator.h
Expand Up @@ -3,8 +3,10 @@
#include "idecltypes.h"
#include "ifavourites.h"

#include "../Bitmap.h"
#include "DeclarationTreeView.h"
#include "ThreadedResourceTreePopulator.h"
#include "TreeViewItemStyle.h"

namespace wxutil
{
Expand All @@ -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<std::string> _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
Expand All @@ -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<std::string>& GetFavourites() const
{
return _favourites;
Expand Down
23 changes: 3 additions & 20 deletions 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
{
Expand All @@ -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()
Expand All @@ -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);
});
}
};
Expand Down

0 comments on commit 7a5db12

Please sign in to comment.