Skip to content

Commit

Permalink
#5537: Each DeclarationSelector monitors its corresponding decl::Type…
Browse files Browse the repository at this point in the history
… to refresh the tree on reloadDecls.
  • Loading branch information
codereader committed Sep 18, 2022
1 parent 43f426f commit e488861
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
29 changes: 3 additions & 26 deletions libs/wxutil/EntityClassChooser.cpp
Expand Up @@ -224,6 +224,8 @@ class EntityClassSelector :

AddPreviewToRightPane(_preview.get());
AddPreviewToBottom(new EntityClassDescription(this));

Populate();
}

void Populate() override
Expand All @@ -234,7 +236,6 @@ class EntityClassSelector :

EntityClassChooser::EntityClassChooser(Purpose purpose) :
DeclarationSelectorDialog(decl::Type::EntityDef, getDialogTitle(purpose), "EntityClassChooser"),
_selector(nullptr),
_restoreSelectionFromRegistry(true)
{
auto affirmativeButton = GetAffirmativeButton();
Expand All @@ -254,25 +255,12 @@ EntityClassChooser::EntityClassChooser(Purpose purpose) :
throw std::logic_error("Unknown entity class chooser purpose");
}

// Listen for defs-reloaded signal (cannot bind directly to
// ThreadedEntityClassLoader method because it is not sigc::trackable)
_defsReloaded = GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::EntityDef).connect(
[this]() { GlobalUserInterface().dispatch([this]() { loadEntityClasses(); }); }
);

SetSelector(setupSelector(this));

loadEntityClasses();
SetSelector(new EntityClassSelector(this));

// Save the state of the selector widget on dialog close
RegisterPersistableObject(this);
}

EntityClassChooser::~EntityClassChooser()
{
_defsReloaded.disconnect();
}

std::string EntityClassChooser::ChooseEntityClass(Purpose purpose, const std::string& eclassToSelect)
{
EntityClassChooser instance{ purpose };
Expand All @@ -291,11 +279,6 @@ std::string EntityClassChooser::ChooseEntityClass(Purpose purpose, const std::st
return ""; // Empty selection on cancel
}

void EntityClassChooser::loadEntityClasses()
{
_selector->Populate();
}

void EntityClassChooser::SetSelectedDeclName(const std::string& declName)
{
DeclarationSelectorDialog::SetSelectedDeclName(declName);
Expand All @@ -320,10 +303,4 @@ void EntityClassChooser::saveToPath(const std::string& registryKey)
GlobalRegistry().setAttribute(registryKey, "lastSelectedDeclName", GetSelectedDeclName());
}

EntityClassSelector* EntityClassChooser::setupSelector(wxWindow* parent)
{
_selector = new EntityClassSelector(parent);
return _selector;
}

} // namespace ui
12 changes: 0 additions & 12 deletions libs/wxutil/EntityClassChooser.h
Expand Up @@ -3,14 +3,11 @@
#include "decl/DeclarationSelectorDialog.h"
#include "ui/iwindowstate.h"

#include <sigc++/connection.h>
#include <wx/dataview.h>

namespace wxutil
{

class EntityClassSelector;

/**
* Dialog window displaying a tree of Entity Classes, allowing the selection
* of a class to create at the current location.
Expand All @@ -30,19 +27,10 @@ class EntityClassChooser final :
};

private:
EntityClassSelector* _selector;

sigc::connection _defsReloaded;

bool _restoreSelectionFromRegistry;

private:
EntityClassChooser(Purpose purpose);
~EntityClassChooser() override;

void loadEntityClasses();

EntityClassSelector* setupSelector(wxWindow * parent);

public:
void loadFromPath(const std::string& registryKey) override;
Expand Down
11 changes: 11 additions & 0 deletions libs/wxutil/decl/DeclarationSelector.cpp
Expand Up @@ -4,6 +4,7 @@
#include <wx/splitter.h>
#include "../dataview/ResourceTreeViewToolbar.h"
#include "DeclFileInfo.h"
#include "ui/iuserinterface.h"

namespace wxutil
{
Expand Down Expand Up @@ -41,6 +42,16 @@ DeclarationSelector::DeclarationSelector(wxWindow* parent, decl::Type declType,

_leftPanel->GetSizer()->Add(_treeVbox, 1, wxEXPAND);
// the right panel has room for a preview widget => AddPreviewToRightPane

// Listen for decls-reloaded signal to refresh the tree
_declsReloaded = GlobalDeclarationManager().signal_DeclsReloaded(_declType).connect(
[this]() { GlobalUserInterface().dispatch([this]() { Populate(); }); }
);
}

DeclarationSelector::~DeclarationSelector()
{
_declsReloaded.disconnect();
}

void DeclarationSelector::AddPreviewToRightPane(ui::IDeclarationPreview* preview, int sizerProportion)
Expand Down
6 changes: 6 additions & 0 deletions libs/wxutil/decl/DeclarationSelector.h
@@ -1,6 +1,8 @@
#pragma once

#include <vector>
#include <sigc++/connection.h>

#include "idecltypes.h"
#include "ui/iwindowstate.h"
#include <wx/panel.h>
Expand Down Expand Up @@ -42,13 +44,17 @@ class DeclarationSelector :

std::unique_ptr<PanedPosition> _panedPosition;

sigc::connection _declsReloaded;

public:
// Construct a selector widget with the default set of tree view columns
DeclarationSelector(wxWindow* parent, decl::Type declType);

// Construct a selector widget with the given set of tree view columns
DeclarationSelector(wxWindow* parent, decl::Type declType, const DeclarationTreeView::Columns& columns);

~DeclarationSelector() override;

/**
* Return the declaration selected by the user, or an empty string if there
* was no selection.
Expand Down

0 comments on commit e488861

Please sign in to comment.