Skip to content

Commit

Permalink
#5127: Subscribe to favourite changes to update the list
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 6, 2021
1 parent f27e9f0 commit 69e799d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
35 changes: 28 additions & 7 deletions radiant/ui/favourites/FavouritesBrowser.cpp
Expand Up @@ -43,6 +43,18 @@ void FavouritesBrowser::construct()
_iconList.reset(new wxImageList(16, 16));
_listView->SetImageList(_iconList.get(), wxIMAGE_LIST_SMALL);

setupCategories();

auto* toolHBox = new wxBoxSizer(wxHORIZONTAL);
toolHBox->Add(createLeftToolBar(), 1, wxEXPAND);
toolHBox->Add(createRightToolBar(), 0, wxEXPAND);

_mainWidget->GetSizer()->Add(toolHBox, 0, wxEXPAND);
_mainWidget->GetSizer()->Add(_listView, 1, wxEXPAND);
}

void FavouritesBrowser::setupCategories()
{
auto prefix = GlobalUIManager().ArtIdPrefix();

_categories.emplace_back(FavouriteCategory{
Expand All @@ -66,13 +78,13 @@ void FavouritesBrowser::construct()
nullptr
});


auto* toolHBox = new wxBoxSizer(wxHORIZONTAL);
toolHBox->Add(createLeftToolBar(), 1, wxEXPAND);
toolHBox->Add(createRightToolBar(), 0, wxEXPAND);

_mainWidget->GetSizer()->Add(toolHBox, 0, wxEXPAND);
_mainWidget->GetSizer()->Add(_listView, 1, wxEXPAND);
// Subscribe to any favourite changes
for (auto& category : _categories)
{
changedConnections.emplace_back(GlobalFavouritesManager().getSignalForType(category.type).connect(
sigc::mem_fun(this, &FavouritesBrowser::onFavouritesChanged)
));
}
}

wxToolBar* FavouritesBrowser::createRightToolBar()
Expand Down Expand Up @@ -182,6 +194,11 @@ void FavouritesBrowser::initialiseModule(const IApplicationContext& ctx)
void FavouritesBrowser::shutdownModule()
{
_iconList.reset();

for (auto& connection : changedConnections)
{
connection.disconnect();
}
}

void FavouritesBrowser::togglePage(const cmd::ArgumentList& args)
Expand Down Expand Up @@ -220,6 +237,10 @@ void FavouritesBrowser::onShowFullPathToggled(wxCommandEvent& ev)
reloadFavourites();
}

void FavouritesBrowser::onFavouritesChanged()
{
reloadFavourites(); // TODO: lazy
}

module::StaticModule<FavouritesBrowser> favouritesBrowserModule;

Expand Down
4 changes: 4 additions & 0 deletions radiant/ui/favourites/FavouritesBrowser.h
Expand Up @@ -6,6 +6,7 @@
#include <wx/listctrl.h>
#include <wx/imaglist.h>
#include <wx/toolbar.h>
#include <sigc++/connection.h>

namespace ui
{
Expand All @@ -31,6 +32,7 @@ class FavouritesBrowser :

// Maps decl type to icon index
std::list<FavouriteCategory> _categories;
std::list<sigc::connection> changedConnections;

wxCheckBox* _showFullPath;

Expand All @@ -47,7 +49,9 @@ class FavouritesBrowser :
wxToolBar* createLeftToolBar();
wxToolBar* createRightToolBar();
void onMainFrameConstructed();
void onFavouritesChanged();
void reloadFavourites();
void setupCategories();

void togglePage(const cmd::ArgumentList& args);
void onCategoryToggled(wxCommandEvent& ev);
Expand Down

0 comments on commit 69e799d

Please sign in to comment.