Skip to content

Commit

Permalink
#5127: Migrate ModelSelector tree model to use the standard ResourceT…
Browse files Browse the repository at this point in the history
…reeView::Columns set
  • Loading branch information
codereader committed Jan 3, 2021
1 parent 1a2f05b commit df46bf9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
18 changes: 10 additions & 8 deletions radiant/ui/modelselector/ModelDataInserter.h
Expand Up @@ -63,29 +63,31 @@ class ModelDataInserter :
std::string fullPath = isExplicit ? (MODELS_FOLDER + path) : "";

// Pixbuf depends on model type
row[_columns.filename] = wxVariant(wxDataViewIconText(displayName, isExplicit ? _modelIcon : _folderIcon));
row[_columns.vfspath] = fullPath;
row[_columns.iconAndName] = wxVariant(wxDataViewIconText(displayName, isExplicit ? _modelIcon : _folderIcon));
row[_columns.fullName] = fullPath;
row[_columns.leafName] = displayName;
row[_columns.skin] = std::string();
row[_columns.isSkin] = false;
row[_columns.isFolder] = !isExplicit;
row[_columns.isFavourite] = false;

if (!_includeSkins) return; // done

// Now check if there are any skins for this model, and add them as
// children if so
const StringList& skinList = GlobalModelSkinCache().getSkinsForModel(fullPath);

for (StringList::const_iterator i = skinList.begin();
i != skinList.end();
++i)
for (const auto& skinName : skinList)
{
wxutil::TreeModel::Row skinRow = store.AddItem(row.getItem());

skinRow[_columns.filename] = wxVariant(wxDataViewIconText(*i, _skinIcon));
skinRow[_columns.vfspath] = fullPath;
skinRow[_columns.skin] = *i;
skinRow[_columns.iconAndName] = wxVariant(wxDataViewIconText(skinName, _skinIcon));
skinRow[_columns.fullName] = fullPath;
skinRow[_columns.leafName] = skinName;
skinRow[_columns.skin] = skinName;
skinRow[_columns.isSkin] = true;
skinRow[_columns.isFolder] = false;
skinRow[_columns.isFavourite] = false;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/modelselector/ModelPopulator.h
Expand Up @@ -110,7 +110,7 @@ class ModelPopulator :
if (TestDestroy()) return static_cast<wxThread::ExitCode>(0);

// Sort the model before returning it
_treeStore->SortModelFoldersFirst(_columns.filename, _columns.isFolder);
_treeStore->SortModelFoldersFirst(_columns.iconAndName, _columns.isFolder);

if (!TestDestroy())
{
Expand Down
18 changes: 9 additions & 9 deletions radiant/ui/modelselector/ModelSelector.cpp
Expand Up @@ -197,7 +197,7 @@ void ModelSelector::onTreeStorePopulationProgress(wxutil::TreeModel::PopulationP
}

wxutil::TreeModel::Row row(_progressItem, *_treeStore);
row[_columns.filename] = wxVariant(wxDataViewIconText(ev.GetMessage(), _modelIcon));
row[_columns.iconAndName] = wxVariant(wxDataViewIconText(ev.GetMessage(), _modelIcon));
row.SendItemChanged();
}

Expand Down Expand Up @@ -240,7 +240,7 @@ void ModelSelector::preSelectModel()
wxutil::TreeModel* model = static_cast<wxutil::TreeModel*>(_treeView->GetModel());

// Lookup the model path in the treemodel
wxDataViewItem found = model->FindString(previouslySelected, _columns.vfspath);
wxDataViewItem found = model->FindString(previouslySelected, _columns.fullName);

if (found.IsOk())
{
Expand Down Expand Up @@ -378,7 +378,7 @@ void ModelSelector::setupTreeView(wxWindow* parent)

// Single visible column, containing the directory/shader name and the icon
_treeView->AppendIconTextColumn(
_("Model Path"), _columns.filename.getColumnIndex(),
_("Model Path"), _columns.iconAndName.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE,
wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE
);
Expand All @@ -388,7 +388,7 @@ void ModelSelector::setupTreeView(wxWindow* parent)
wxDataViewEventHandler(ModelSelector::onSelectionChanged), NULL, this);

// Use the TreeModel's full string search function
_treeView->AddSearchColumn(_columns.filename);
_treeView->AddSearchColumn(_columns.iconAndName);

parent->GetSizer()->Prepend(_treeView.get(), 1, wxEXPAND);
parent->GetSizer()->Layout();
Expand All @@ -401,7 +401,7 @@ void ModelSelector::populateModels()
_treeStore->Clear();

wxutil::TreeModel::Row row = _treeStore->AddItem();
row[_columns.filename] = wxVariant(wxDataViewIconText(_("Loading..."), _modelIcon));
row[_columns.iconAndName] = wxVariant(wxDataViewIconText(_("Loading..."), _modelIcon));
row[_columns.isSkin] = false;
row[_columns.isFolder] = false;
row[_columns.isFolder] = std::string();
Expand Down Expand Up @@ -445,7 +445,7 @@ void ModelSelector::showInfoForSelectedModel()

// Get the model name, if this is blank we are looking at a directory,
// so leave the table empty
std::string mName = getSelectedValue(_columns.vfspath);
std::string mName = getSelectedValue(_columns.fullName);
if (mName.empty())
return;

Expand All @@ -460,7 +460,7 @@ void ModelSelector::showInfoForSelectedModel()
void ModelSelector::onOK(wxCommandEvent& ev)
{
// Remember the selected model then exit from the recursive main loop
_lastModel = getSelectedValue(_columns.vfspath);
_lastModel = getSelectedValue(_columns.fullName);
_lastSkin = getSelectedValue(_columns.skin);

_panedPosition.saveToPath(RKEY_SPLIT_POS);
Expand All @@ -480,7 +480,7 @@ void ModelSelector::onReloadModels(wxCommandEvent& ev)
findNamedObject<wxButton>(this, "ModelSelectorReloadSkinsButton")->Enable(false);

// Remember the selected model before reloading
_preselectedModel = getSelectedValue(_columns.vfspath);
_preselectedModel = getSelectedValue(_columns.fullName);

// This will fire the models reloaded signal after some time
GlobalModelCache().refreshModels(false);
Expand All @@ -491,7 +491,7 @@ void ModelSelector::onReloadSkins(wxCommandEvent& ev)
findNamedObject<wxButton>(this, "ModelSelectorReloadModelsButton")->Enable(false);
findNamedObject<wxButton>(this, "ModelSelectorReloadSkinsButton")->Enable(false);

_preselectedModel = getSelectedValue(_columns.vfspath);
_preselectedModel = getSelectedValue(_columns.fullName);

// When this is done, the skins reloaded signal is fired
GlobalModelSkinCache().refresh();
Expand Down
13 changes: 5 additions & 8 deletions radiant/ui/modelselector/ModelSelector.h
Expand Up @@ -12,6 +12,7 @@
#include "wxutil/preview/ModelPreview.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/PanedPosition.h"
#include "wxutil/dataview/ResourceTreeView.h"
#include "wxutil/dataview/TreeModelFilter.h"
#include "wxutil/XmlResourceBasedWidget.h"
#include "wxutil/dataview/KeyValueTable.h"
Expand Down Expand Up @@ -52,21 +53,17 @@ class ModelSelector :
public:
// Treemodel definition
struct TreeColumns :
public wxutil::TreeModel::ColumnRecord
public wxutil::ResourceTreeView::Columns
{
TreeColumns() :
filename(add(wxutil::TreeModel::Column::IconText)),
vfspath(add(wxutil::TreeModel::Column::String)),
skin(add(wxutil::TreeModel::Column::String)),
isSkin(add(wxutil::TreeModel::Column::Boolean)),
isFolder(add(wxutil::TreeModel::Column::Boolean))
isSkin(add(wxutil::TreeModel::Column::Boolean))
{}

wxutil::TreeModel::Column filename; // e.g. "chair1.lwo"
wxutil::TreeModel::Column vfspath; // e.g. "models/darkmod/props/chair1.lwo"
// iconAndName column contains the filename, e.g. "chair1.lwo"
// fullPath column contains the VFS path, e.g. "models/darkmod/props/chair1.lwo"
wxutil::TreeModel::Column skin; // e.g. "chair1_brown_wood", or "" for no skin
wxutil::TreeModel::Column isSkin; // TRUE if this is a skin entry, FALSE if actual model or folder
wxutil::TreeModel::Column isFolder; // whether this is a folder
};

private:
Expand Down

0 comments on commit df46bf9

Please sign in to comment.