Skip to content

Commit

Permalink
Added Rescan option to the PluginRegistrationDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksoze95 committed Aug 9, 2022
1 parent 11ecb32 commit 0c8c66d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 33 deletions.
15 changes: 14 additions & 1 deletion libraries/lib-module-manager/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void PluginManager::Initialize(FileConfigFactory factory)
// Allow the module to auto-register children
module->AutoRegisterPlugins(*this);
}

InitializePlugins();
}

Expand Down Expand Up @@ -1143,6 +1143,19 @@ ComponentInterface *PluginManager::Load(const PluginID & ID)
return nullptr;
}

void PluginManager::ClearEffectPlugins()
{
for (auto it = mRegisteredPlugins.cbegin(); it != mRegisteredPlugins.cend(); ++it)
{
auto& desc = it->second;
if (desc.GetPluginType() == PluginTypeEffect)
{
mLoadedInterfaces.erase(desc.GetID());
it = mRegisteredPlugins.erase(it);
}
}
}

std::map<wxString, std::vector<wxString>> PluginManager::CheckPluginUpdates()
{
wxArrayString pathIndex;
Expand Down
2 changes: 2 additions & 0 deletions libraries/lib-module-manager/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class MODULE_MANAGER_API PluginManager final : public PluginManagerInterface
const ComponentInterfaceSymbol & GetSymbol(const PluginID & ID);
ComponentInterface *Load(const PluginID & ID);

void ClearEffectPlugins();

/**
* \brief Ensures that all currently registered plugins still exist
* and scans for new ones.
Expand Down
101 changes: 69 additions & 32 deletions src/PluginRegistrationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "EffectInterface.h"
#include "ModuleManager.h"
#include "PluginManager.h"
#include "PluginStartupRegistration.h"
#include "ShuttleGui.h"
#include "widgets/AudacityMessageBox.h"
#include "widgets/ProgressDialog.h"
Expand Down Expand Up @@ -359,6 +360,7 @@ enum
ID_List,
ID_ClearAll,
ID_SelectAll,
ID_Rescan,
ID_Enable,
ID_Disable,
};
Expand All @@ -376,6 +378,7 @@ BEGIN_EVENT_TABLE(PluginRegistrationDialog, wxDialogWrapper)
EVT_LIST_COL_CLICK(ID_List, PluginRegistrationDialog::OnSort)
EVT_BUTTON(wxID_OK, PluginRegistrationDialog::OnOK)
EVT_BUTTON(wxID_CANCEL, PluginRegistrationDialog::OnCancel)
EVT_BUTTON(ID_Rescan, PluginRegistrationDialog::OnRescan)
EVT_BUTTON(ID_ClearAll, PluginRegistrationDialog::OnClearAll)
EVT_BUTTON(ID_SelectAll, PluginRegistrationDialog::OnSelectAll)
EVT_BUTTON(ID_Enable, PluginRegistrationDialog::OnEnable)
Expand Down Expand Up @@ -510,6 +513,7 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
{
S.Id(ID_SelectAll).AddButton(XXO("&Select All"));
S.Id(ID_ClearAll).AddButton(XXO("C&lear All"));
S.Id(ID_Rescan).AddButton(XXO("Rescan"));

S.StartHorizontalLay(wxALIGN_CENTER);
{
Expand Down Expand Up @@ -543,45 +547,20 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
}

PluginManager & pm = PluginManager::Get();
for (auto &plug : pm.AllPlugins()) {
PluginType plugType = plug.GetPluginType();
if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
continue;
PopulateItemsList(pm);

const auto &path = plug.GetPath();
ItemData & item = mItems[path]; // will create NEW entry
item.plugs.push_back(&plug);
item.path = path;
item.state = plug.IsEnabled() ? STATE_Enabled : STATE_Disabled;
item.valid = plug.IsValid();

if (plugType == PluginTypeEffect)
{
item.name = plug.GetSymbol().Translation();
}
// This is not right and will not work when other plugin types are added.
// But it's presumed that the plugin manager dialog will be fully developed
// by then.
else if (plugType == PluginTypeStub)
{
wxFileName fname { path };
item.name = fname.GetName().Trim(false).Trim(true);
#ifndef DISABLE_STATE_NEW
if (!item.valid)
{
item.state = STATE_New;
}
#endif
}
for (const auto& item : mItems)
{
const auto& itemData = item.second;

int x;
mEffects->GetTextExtent(item.name, &x, NULL);
mEffects->GetTextExtent(itemData.name, &x, NULL);
colWidths[COL_Name] = wxMax(colWidths[COL_Name], x);

mEffects->GetTextExtent(item.path, &x, NULL);
mEffects->GetTextExtent(itemData.path, &x, NULL);
if (x > colWidths[COL_Path])
{
mLongestPath = item.path;
mLongestPath = itemData.path;
}
colWidths[COL_Path] = wxMax(colWidths[COL_Path], x);
}
Expand Down Expand Up @@ -626,6 +605,42 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)

}

void PluginRegistrationDialog::PopulateItemsList(PluginManager& pm)
{
for (auto& plug : pm.AllPlugins())
{
PluginType plugType = plug.GetPluginType();
if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
continue;

const auto& path = plug.GetPath();
ItemData& item = mItems[path]; // will create NEW entry
item.plugs.push_back(&plug);
item.path = path;
item.state = plug.IsEnabled() ? STATE_Enabled : STATE_Disabled;
item.valid = plug.IsValid();

if (plugType == PluginTypeEffect)
{
item.name = plug.GetSymbol().Translation();
}
// This is not right and will not work when other plugin types are added.
// But it's presumed that the plugin manager dialog will be fully developed
// by then.
else if (plugType == PluginTypeStub)
{
wxFileName fname{ path };
item.name = fname.GetName().Trim(false).Trim(true);
#ifndef DISABLE_STATE_NEW
if (!item.valid)
{
item.state = STATE_New;
}
#endif
}
}
}

void PluginRegistrationDialog::RegenerateEffectsList(int filter)
{
mFilter = filter;
Expand Down Expand Up @@ -851,6 +866,28 @@ void PluginRegistrationDialog::OnClearAll(wxCommandEvent & WXUNUSED(evt))
}
}

void PluginRegistrationDialog::OnRescan(wxCommandEvent& WXUNUSED(evt))
{
mItems.clear();
mEffects->DeleteAllItems();
mEffects->Update();

wxTheApp->CallAfter([this] {
auto& pm = PluginManager::Get();
pm.ClearEffectPlugins();

auto newPlugins = PluginManager::Get().CheckPluginUpdates();
if (!newPlugins.empty())
{
PluginStartupRegistration reg(newPlugins);
reg.Run();
}

PopulateItemsList(pm);
RegenerateEffectsList(mFilter);
});
}

void PluginRegistrationDialog::OnEnable(wxCommandEvent & WXUNUSED(evt))
{
std::vector<long> items;
Expand Down
3 changes: 3 additions & 0 deletions src/PluginRegistrationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class CheckListAx;
enum EffectType : int;
class PluginDescriptor;
class PluginManager;
class ShuttleGui;
class wxListEvent;
class wxListCtrl;
Expand Down Expand Up @@ -44,6 +45,7 @@ class PluginRegistrationDialog final : public wxDialogWrapper

void Populate();
void PopulateOrExchange(ShuttleGui & S);
void PopulateItemsList(PluginManager& pm);
void RegenerateEffectsList(int iShowWhat);
void SetState(int i, bool toggle, bool state = true);

Expand All @@ -58,6 +60,7 @@ class PluginRegistrationDialog final : public wxDialogWrapper
void OnCancel(wxCommandEvent & evt);
void OnSelectAll(wxCommandEvent & evt);
void OnClearAll(wxCommandEvent & evt);
void OnRescan(wxCommandEvent & evt);
void OnEnable(wxCommandEvent & evt);
void OnDisable(wxCommandEvent & evt);

Expand Down

0 comments on commit 0c8c66d

Please sign in to comment.