Skip to content

Commit

Permalink
#5108: Expand the maps/ folder after loading the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 19, 2020
1 parent b510768 commit d58ed92
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
23 changes: 19 additions & 4 deletions libs/wxutil/fsview/FileSystemView.cpp
Expand Up @@ -112,11 +112,11 @@ void FileSystemView::Populate(const std::string& preselectPath)

wxutil::TreeModel::Row row = _treeStore->AddItem();

wxIcon prefabIcon;
prefabIcon.CopyFromBitmap(
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "cmenu_add_prefab.png"));
wxIcon loadingIcon;
loadingIcon.CopyFromBitmap(
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + _fileIcon));

row[Columns().filename] = wxVariant(wxDataViewIconText(_("Loading..."), prefabIcon));
row[Columns().filename] = wxVariant(wxDataViewIconText(_("Loading..."), loadingIcon));
row[Columns().isFolder] = false;
row[Columns().vfspath] = "__loadingnode__"; // to prevent that item from being found
row.SendItemAdded();
Expand All @@ -138,6 +138,13 @@ void FileSystemView::SelectPath(const std::string& path)
SelectItem(_treeStore->FindString(path, Columns().vfspath));
}

void FileSystemView::ExpandPath(const std::string& path)
{
if (path.empty()) return;

Expand(_treeStore->FindString(path, Columns().vfspath));
}

std::string FileSystemView::GetSelectedPath()
{
wxDataViewItem item = GetSelection();
Expand Down Expand Up @@ -213,6 +220,14 @@ void FileSystemView::OnTreeStorePopulationFinished(TreeModel::PopulationFinished

// Auto-size the first level
TriggerColumnSizeEvent();

// Call client code
_signalTreePopulated.emit();
}

sigc::signal<void>& FileSystemView::signal_TreePopulated()
{
return _signalTreePopulated;
}

}
6 changes: 6 additions & 0 deletions libs/wxutil/fsview/FileSystemView.h
Expand Up @@ -33,6 +33,8 @@ class FileSystemView :

std::set<std::string> _fileExtensions;

sigc::signal<void> _signalTreePopulated;

public:
class SelectionChangedEvent :
public wxEvent
Expand Down Expand Up @@ -83,6 +85,10 @@ class FileSystemView :
std::string GetSelectedPath();
bool GetIsFolderSelected();

void ExpandPath(const std::string& path);

sigc::signal<void>& signal_TreePopulated();

private:
TreeModel::Ptr CreateDefaultModel();

Expand Down
5 changes: 3 additions & 2 deletions libs/wxutil/fsview/Populator.cpp
Expand Up @@ -66,11 +66,12 @@ void Populator::visitFile(const vfs::FileInfo& fileInfo)
{
// The population callback will be called multiple times for deeper files,
// but only one of them will be have isFolder == false, which is our actual file

std::string fullPath = _basePath + path;

// Get the display path, everything after rightmost slash
row[_columns.filename] = wxVariant(wxDataViewIconText(leafName,
isFolder ? _folderIcon : GetIconForFile(leafName)));
row[_columns.vfspath] = _basePath + path;
row[_columns.vfspath] = isFolder ? os::standardPathWithSlash(fullPath) : fullPath;
row[_columns.isFolder] = isFolder;

if (!isFolder)
Expand Down
12 changes: 9 additions & 3 deletions radiant/ui/mapselector/MapSelector.cpp
Expand Up @@ -34,7 +34,7 @@ MapSelector::MapSelector() :
vbox->Add(_treeView, 1, wxEXPAND);

_buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
wxButton* reloadButton = new wxButton(this, wxID_ANY, _("Rescan"));
wxButton* reloadButton = new wxButton(this, wxID_ANY, _("Refresh"));
reloadButton->Bind(wxEVT_BUTTON, &MapSelector::onRescanPath, this);

_buttons->Prepend(reloadButton, 0, wxRIGHT, 32);
Expand Down Expand Up @@ -87,7 +87,8 @@ void MapSelector::setupTreeView(wxWindow* parent)
{
_treeView = wxutil::FileSystemView::Create(parent, wxBORDER_STATIC | wxDV_NO_HEADER);
_treeView->Bind(wxutil::EV_FSVIEW_SELECTION_CHANGED, &MapSelector::onSelectionChanged, this);
_treeView->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &MapSelector::OnItemActivated, this);;
_treeView->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &MapSelector::onItemActivated, this);;
_treeView->signal_TreePopulated().connect(sigc::mem_fun(this, &MapSelector::onFileViewTreePopulated));

// Get the extensions from all possible patterns (e.g. *.map or *.mapx)
FileTypePatterns patterns = GlobalFiletypes().getPatternsForType(filetype::TYPE_MAP);
Expand Down Expand Up @@ -185,7 +186,7 @@ void MapSelector::onSelectionChanged(wxutil::FileSystemView::SelectionChangedEve
updateButtonSensitivity();
}

void MapSelector::OnItemActivated(wxDataViewEvent& ev)
void MapSelector::onItemActivated(wxDataViewEvent& ev)
{
auto selectedPath = _treeView->GetSelectedPath();
auto extension = string::to_lower_copy(os::getExtension(selectedPath));
Expand All @@ -201,6 +202,11 @@ void MapSelector::OnItemActivated(wxDataViewEvent& ev)
}
}

void MapSelector::onFileViewTreePopulated()
{
_treeView->ExpandPath("maps/");
}

std::string MapSelector::getSelectedPath()
{
return _treeView->GetSelectedPath();
Expand Down
3 changes: 2 additions & 1 deletion radiant/ui/mapselector/MapSelector.h
Expand Up @@ -52,8 +52,9 @@ class MapSelector :
std::string getSelectedPath();

void onRescanPath(wxCommandEvent& ev);
void OnItemActivated(wxDataViewEvent& ev);
void onItemActivated(wxDataViewEvent& ev);
void onSelectionChanged(wxutil::FileSystemView::SelectionChangedEvent& ev);
void onFileViewTreePopulated();
void updateButtonSensitivity();
void onPathSelectionChanged();

Expand Down

0 comments on commit d58ed92

Please sign in to comment.