Skip to content

Commit

Permalink
Traktor: Refactored IEditorPlugin; no longer need a separate IEditorP…
Browse files Browse the repository at this point in the history
…luginFactory.
  • Loading branch information
apistol78 committed May 13, 2024
1 parent 11aca82 commit 147067b
Show file tree
Hide file tree
Showing 37 changed files with 249 additions and 926 deletions.
18 changes: 12 additions & 6 deletions code/Editor/App/DiscoveryPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
namespace traktor::editor
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.editor.DiscoveryPlugin", DiscoveryPlugin, IEditorPlugin)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.editor.DiscoveryPlugin", 0, DiscoveryPlugin, IEditorPlugin)

DiscoveryPlugin::DiscoveryPlugin(IEditor* editor)
: m_editor(editor)
bool DiscoveryPlugin::create(IEditor* editor, ui::Widget* parent, IEditorPageSite* site)
{
}
m_editor = editor;

bool DiscoveryPlugin::create(ui::Widget* parent, IEditorPageSite* site)
{
const PropertyGroup* settings = m_editor->getSettings();

uint32_t mode = net::MdFindServices;
Expand All @@ -45,6 +42,15 @@ void DiscoveryPlugin::destroy()
safeDestroy(m_discoveryManager);
}

int32_t DiscoveryPlugin::getOrdinal() const
{
return 0;
}

void DiscoveryPlugin::getCommands(std::list< ui::Command >& outCommands) const
{
}

bool DiscoveryPlugin::handleCommand(const ui::Command& command, bool result)
{
return false;
Expand Down
10 changes: 6 additions & 4 deletions code/Editor/App/DiscoveryPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class DiscoveryPlugin : public IEditorPlugin
T_RTTI_CLASS;

public:
explicit DiscoveryPlugin(IEditor* editor);

virtual bool create(ui::Widget* parent, IEditorPageSite* site) override final;
virtual bool create(IEditor* editor, ui::Widget* parent, IEditorPageSite* site) override final;

virtual void destroy() override final;

virtual int32_t getOrdinal() const override final;

virtual void getCommands(std::list< ui::Command >& outCommands) const override final;

virtual bool handleCommand(const ui::Command& command, bool result) override final;

virtual void handleDatabaseEvent(db::Database* database, const Guid& eventId) override final;
Expand All @@ -45,7 +47,7 @@ class DiscoveryPlugin : public IEditorPlugin
virtual void handleEditorClosed() override final;

private:
IEditor* m_editor;
IEditor* m_editor = nullptr;
Ref< net::DiscoveryManager > m_discoveryManager;
};

Expand Down
31 changes: 0 additions & 31 deletions code/Editor/App/DiscoveryPluginFactory.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions code/Editor/App/DiscoveryPluginFactory.h

This file was deleted.

26 changes: 11 additions & 15 deletions code/Editor/App/EditorForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "Editor/IEditorPage.h"
#include "Editor/IEditorPageFactory.h"
#include "Editor/IEditorPlugin.h"
#include "Editor/IEditorPluginFactory.h"
#include "Editor/IEditorTool.h"
#include "Editor/IObjectEditor.h"
#include "Editor/IObjectEditorFactory.h"
Expand Down Expand Up @@ -678,26 +677,23 @@ bool EditorForm::create(const CommandLine& cmdLine)
m_objectEditorFactories.push_back(objectEditorFactory);
}

// Create editor plugin factories.
for (const auto& editorPluginFactoryType : type_of< IEditorPluginFactory >().findAllOf(false))
// Instantiate editor plugins.
RefArray< IEditorPlugin > editorPlugins;
for (const auto& editorPluginType : type_of< IEditorPlugin >().findAllOf(false))
{
Ref< IEditorPluginFactory > editorPluginFactory = dynamic_type_cast< IEditorPluginFactory* >(editorPluginFactoryType->createInstance());
if (editorPluginFactory)
m_editorPluginFactories.push_back(editorPluginFactory);
Ref< IEditorPlugin > editorPlugin = dynamic_type_cast< IEditorPlugin* >(editorPluginType->createInstance());
if (editorPlugin)
editorPlugins.push_back(editorPlugin);
}

// Sort factories by ordinal; this will ensure creation order of plugins.
m_editorPluginFactories.sort([](IEditorPluginFactory* lh, IEditorPluginFactory* rh) {
// Sort plugins by ordinal; this will ensure creation order of plugins.
editorPlugins.sort([](IEditorPlugin* lh, IEditorPlugin* rh) {
return lh->getOrdinal() < rh->getOrdinal();
});

// Create editor plugins.
for (auto editorPluginFactory : m_editorPluginFactories)
for (auto editorPlugin : editorPlugins)
{
Ref< IEditorPlugin > editorPlugin = editorPluginFactory->createEditorPlugin(this);
if (!editorPlugin)
continue;

Ref< EditorPluginSite > site = new EditorPluginSite(this, editorPlugin);
if (site->create(this))
m_editorPluginSites.push_back(site);
Expand Down Expand Up @@ -778,10 +774,10 @@ bool EditorForm::create(const CommandLine& cmdLine)
m_shortcutCommands.insert(m_shortcutCommands.end(), editorPageCommands.begin(), editorPageCommands.end());
}

for (auto editorPluginFactory : m_editorPluginFactories)
for (auto editorPluginSite : m_editorPluginSites)
{
std::list< ui::Command > editorPluginCommands;
editorPluginFactory->getCommands(editorPluginCommands);
editorPluginSite->getCommands(editorPluginCommands);
m_shortcutCommands.insert(m_shortcutCommands.end(), editorPluginCommands.begin(), editorPluginCommands.end());
}

Expand Down
2 changes: 0 additions & 2 deletions code/Editor/App/EditorForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class EditorPageSite;
class EditorPluginSite;
class IEditorPage;
class IEditorPageFactory;
class IEditorPluginFactory;
class IEditorTool;
class IObjectEditor;
class IObjectEditorFactory;
Expand Down Expand Up @@ -179,7 +178,6 @@ class EditorForm

RefArray< IEditorPageFactory > m_editorPageFactories;
RefArray< IObjectEditorFactory > m_objectEditorFactories;
RefArray< IEditorPluginFactory > m_editorPluginFactories;
RefArray< IEditorTool > m_editorTools;
RefArray< EditorPluginSite > m_editorPluginSites;
Ref< net::StreamServer > m_streamServer;
Expand Down
7 changes: 6 additions & 1 deletion code/Editor/App/EditorPluginSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ EditorPluginSite::EditorPluginSite(EditorForm* editor, IEditorPlugin* editorPlug

bool EditorPluginSite::create(ui::Widget* parent)
{
return m_editorPlugin->create(parent, this);
return m_editorPlugin->create(m_editor, parent, this);
}

void EditorPluginSite::destroy()
{
safeDestroy(m_editorPlugin);
}

void EditorPluginSite::getCommands(std::list< ui::Command >& outCommands) const
{
m_editorPlugin->getCommands(outCommands);
}

bool EditorPluginSite::handleCommand(const ui::Command& command, bool result)
{
return m_editorPlugin->handleCommand(command, result);
Expand Down
16 changes: 7 additions & 9 deletions code/Editor/App/EditorPluginSite.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,18 +10,16 @@

#include "Editor/IEditorPageSite.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

class Command;
class Widget;

}
}

namespace editor
{
namespace traktor::editor
{

class EditorForm;
class IEditorPlugin;
Expand All @@ -40,6 +38,8 @@ class EditorPluginSite : public IEditorPageSite

void destroy();

void getCommands(std::list< ui::Command >& outCommands) const;

bool handleCommand(const ui::Command& command, bool result);

void handleDatabaseEvent(db::Database* database, const Guid& eventId);
Expand Down Expand Up @@ -67,6 +67,4 @@ class EditorPluginSite : public IEditorPageSite
Ref< IEditorPlugin > m_editorPlugin;
};

}
}

Binary file modified code/Editor/App/Resources/Splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 147067b

Please sign in to comment.