Skip to content

Commit

Permalink
Traktor: Moved target logs to target pane and handled by the Runtime.…
Browse files Browse the repository at this point in the history
…Editor module.
  • Loading branch information
apistol78 committed May 29, 2024
1 parent 784305a commit 99d1d56
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 238 deletions.
53 changes: 7 additions & 46 deletions code/Editor/App/EditorForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "Editor/IObjectEditor.h"
#include "Editor/IObjectEditorFactory.h"
#include "Editor/IPipeline.h"
#include "Editor/LogView.h"
#include "Editor/PipelineDependency.h"
#include "Editor/PipelineDependencySet.h"
#include "Editor/TypeBrowseFilter.h"
Expand All @@ -60,7 +61,6 @@
#include "Editor/App/EditorForm.h"
#include "Editor/App/EditorPageSite.h"
#include "Editor/App/EditorPluginSite.h"
#include "Editor/App/LogView.h"
#include "Editor/App/MRU.h"
#include "Editor/App/NewInstanceDialog.h"
#include "Editor/App/NewWorkspaceDialog.h"
Expand Down Expand Up @@ -594,18 +594,9 @@ bool EditorForm::create(const CommandLine& cmdLine)
m_paneSouth->dock(m_dataBaseView);

// Create output panel.
m_tabOutput = new ui::Tab();
m_tabOutput->create(m_dock, ui::Tab::WsLine | ui::Tab::WsBottom);
m_tabOutput->setText(i18n::Text(L"TITLE_OUTPUT"));
if (!m_mergedSettings->getProperty< bool >(L"Editor.LogVisible"))
m_tabOutput->hide();

Ref< ui::TabPage > tabPageLog = new ui::TabPage();
tabPageLog->create(m_tabOutput, i18n::Text(L"TITLE_LOG"), new ui::FloodLayout());

m_logView = new LogView(this);
m_logView->create(tabPageLog);
m_logView->setText(i18n::Text(L"TITLE_LOG"));
m_logView->create(m_dock);
m_logView->setText(i18n::Text(L"TITLE_OUTPUT"));

// Replay logs into log view.
infoLog->replay(m_logView->getLogTarget());
Expand All @@ -616,10 +607,7 @@ bool EditorForm::create(const CommandLine& cmdLine)
log::warning.setGlobalTarget(new LogRedirectTarget(defaultWarningLog, m_logView->getLogTarget()));
log::error.setGlobalTarget(new LogRedirectTarget(defaultErrorLog, m_logView->getLogTarget()));

m_tabOutput->addPage(tabPageLog);
m_tabOutput->setActivePage(tabPageLog);

m_paneSouth->dock(m_tabOutput);
m_paneSouth->dock(m_logView);

// Create tab groups; only add one by default, user needs to add more groups manually.
m_tabGroupContainer = new ui::MultiSplitter();
Expand Down Expand Up @@ -913,33 +901,6 @@ void EditorForm::revertWorkspaceSettings()
{
}

Ref< ILogTarget > EditorForm::createLogTarget(const std::wstring& title)
{
if (m_logTargets[title] == nullptr)
{
Ref< ui::TabPage > tabPageLog = new ui::TabPage();
if (!tabPageLog->create(m_tabOutput, title, new ui::FloodLayout()))
return nullptr;

Ref< LogView > logView = new LogView(this);
logView->create(tabPageLog);
logView->setText(title);

Ref< ui::TabPage > activePage = m_tabOutput->getActivePage();
m_tabOutput->addPage(tabPageLog);

if (m_globalSettings->getProperty< bool >(L"Editor.ShowNewLogTargets"))
m_tabOutput->setActivePage(tabPageLog);
else
m_tabOutput->setActivePage(activePage);

m_tabOutput->update();

m_logTargets[title] = logView->getLogTarget();
}
return m_logTargets[title];
}

Ref< db::Database > EditorForm::getSourceDatabase() const
{
return m_sourceDatabase;
Expand Down Expand Up @@ -2739,7 +2700,7 @@ bool EditorForm::handleCommand(const ui::Command& command)
}
else if (command == L"Editor.ViewLog")
{
m_dock->showWidget(m_tabOutput);
m_dock->showWidget(m_logView);
}
else if (command == L"Editor.ViewOther")
{
Expand Down Expand Up @@ -2964,8 +2925,8 @@ void EditorForm::eventClose(ui::CloseEvent* event)
m_globalSettings->setProperty< PropertyInteger >(L"Editor.PaneEastWidth", unit(m_paneEast->getPaneRect().getWidth()).get());

// Save panes visible.
m_globalSettings->setProperty< PropertyBoolean >(L"Editor.DatabaseVisible", m_dataBaseView->isVisible(false));
m_globalSettings->setProperty< PropertyBoolean >(L"Editor.LogVisible", m_tabOutput->isVisible(false));
m_globalSettings->setProperty< PropertyBoolean >(L"Editor.DatabaseVisible", m_dock->isWidgetVisible(m_dataBaseView));
m_globalSettings->setProperty< PropertyBoolean >(L"Editor.LogVisible", m_dock->isWidgetVisible(m_logView));

// Save form placement.
const ui::Rect rc = getNormalRect();
Expand Down
4 changes: 0 additions & 4 deletions code/Editor/App/EditorForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ class EditorForm

virtual void revertWorkspaceSettings() override final;

virtual Ref< ILogTarget > createLogTarget(const std::wstring& title) override final;

virtual Ref< db::Database > getSourceDatabase() const override final;

virtual Ref< db::Database > getOutputDatabase() const override final;
Expand Down Expand Up @@ -205,8 +203,6 @@ class EditorForm
Ref< ui::Menu > m_menuTab;
Ref< ui::ToolBarMenu > m_menuTools;
Ref< DatabaseView > m_dataBaseView;
Ref< ui::Tab > m_tabOutput;
std::map< std::wstring, Ref< ILogTarget > > m_logTargets;
Ref< LogView > m_logView;
Ref< db::Database > m_sourceDatabase;
Ref< db::Database > m_outputDatabase;
Expand Down
5 changes: 0 additions & 5 deletions code/Editor/App/ObjectEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ void ObjectEditor::revertWorkspaceSettings()
m_editor->revertWorkspaceSettings();
}

Ref< ILogTarget > ObjectEditor::createLogTarget(const std::wstring& title)
{
return m_editor->createLogTarget(title);
}

Ref< db::Database > ObjectEditor::getSourceDatabase() const
{
return m_editor->getSourceDatabase();
Expand Down
2 changes: 0 additions & 2 deletions code/Editor/App/ObjectEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class ObjectEditor

virtual void revertWorkspaceSettings() override final;

virtual Ref< ILogTarget > createLogTarget(const std::wstring& title) override final;

virtual Ref< db::Database > getSourceDatabase() const override final;

virtual Ref< db::Database > getOutputDatabase() const override final;
Expand Down
3 changes: 0 additions & 3 deletions code/Editor/IEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ class T_NOVTABLE IEditor

/*! \} */

/*! Create log targets. */
virtual Ref< ILogTarget > createLogTarget(const std::wstring& title) = 0;

/*! Get source asset database. */
virtual Ref< db::Database > getSourceDatabase() const = 0;

Expand Down
2 changes: 1 addition & 1 deletion code/Editor/App/LogView.cpp → code/Editor/LogView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "Database/Instance.h"
#include "Database/Traverse.h"
#include "Editor/IEditor.h"
#include "Editor/App/LogView.h"
#include "Editor/LogView.h"
#include "I18N/Text.h"
#include "Ui/Edit.h"
#include "Ui/Menu.h"
Expand Down
10 changes: 9 additions & 1 deletion code/Editor/App/LogView.h → code/Editor/LogView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
#include "Ui/Container.h"
#include "Ui/LogList/LogList.h"

// import/export mechanism.
#undef T_DLLCLASS
#if defined(T_EDITOR_EXPORT)
# define T_DLLCLASS T_DLLEXPORT
#else
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
{

Expand All @@ -35,7 +43,7 @@ namespace traktor::editor

class IEditor;

class LogView
class T_DLLCLASS LogView
: public ui::Container
, public ui::LogList::ISymbolLookup
{
Expand Down
34 changes: 31 additions & 3 deletions code/Runtime/Editor/EditorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Drawing/PixelFormat.h"
#include "Editor/IEditorPage.h"
#include "Editor/IEditorPageSite.h"
#include "Editor/LogView.h"
#include "I18N/Text.h"
#include "Net/BidirectionalObjectTransport.h"
#include "Net/Network.h"
Expand Down Expand Up @@ -62,8 +63,11 @@
#include "Ui/Clipboard.h"
#include "Ui/Command.h"
#include "Ui/Container.h"
#include "Ui/FloodLayout.h"
#include "Ui/MenuItem.h"
#include "Ui/Splitter.h"
#include "Ui/Tab.h"
#include "Ui/TabPage.h"
#include "Ui/TableLayout.h"
#include "Ui/ToolBar/ToolBar.h"
#include "Ui/ToolBar/ToolBarButtonClickEvent.h"
Expand Down Expand Up @@ -199,8 +203,8 @@ bool EditorPlugin::create(editor::IEditor* editor, ui::Widget* parent, editor::I

// Performance panel
{
Ref< ui::Container > container = new ui::Container();
container->create(m_splitter, ui::WsNone, new ui::TableLayout(L"100%", L"100%", 0_ut, 0_ut));
m_tabOutput = new ui::Tab();
m_tabOutput->create(m_splitter, ui::Tab::WsLine | ui::Tab::WsBottom);
}

m_site->createAdditionalPanel(m_splitter, 200_ut, false);
Expand Down Expand Up @@ -352,7 +356,9 @@ void EditorPlugin::handleWorkspaceOpened()
updateTargetLists();

// Create target manager.
m_targetManager = new TargetManager(m_editor);
m_targetManager = new TargetManager(m_editor, [=, this](const std::wstring& name) -> Ref< ILogTarget > {
return createLogTarget(name);
});
if (!m_targetManager->create())
{
log::error << L"Unable to create target manager; target manager disabled" << Endl;
Expand Down Expand Up @@ -488,6 +494,28 @@ void EditorPlugin::updateTargetManagers()
}
}

Ref< ILogTarget > EditorPlugin::createLogTarget(const std::wstring& name)
{
if (m_logTargets[name] == nullptr)
{
Ref< ui::TabPage > tabPageLog = new ui::TabPage();
if (!tabPageLog->create(m_tabOutput, name, new ui::FloodLayout()))
return nullptr;

Ref< editor::LogView > logView = new editor::LogView(m_editor);
logView->create(tabPageLog);
logView->setText(name);

Ref< ui::TabPage > activePage = m_tabOutput->getActivePage();
m_tabOutput->addPage(tabPageLog);
m_tabOutput->setActivePage(tabPageLog);
m_tabOutput->update();

m_logTargets[name] = logView->getLogTarget();
}
return m_logTargets[name];
}

Ref< PropertyGroup > EditorPlugin::getTweakSettings() const
{
Ref< PropertyGroup > tweakSettings = new PropertyGroup();
Expand Down
5 changes: 5 additions & 0 deletions code/Runtime/Editor/EditorPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace traktor::ui

class Container;
class Splitter;
class Tab;
class TimerEvent;
class ToolBar;
class ToolBarButtonClickEvent;
Expand Down Expand Up @@ -115,6 +116,8 @@ class EditorPlugin : public editor::IEditorPlugin
Ref< ui::ToolBarDropMenu > m_toolTweaks;
Ref< ui::ToolBarDropDown > m_toolLanguage;
Ref< TargetListControl > m_targetList;
Ref< ui::Tab > m_tabOutput;
std::map< std::wstring, Ref< ILogTarget > > m_logTargets;
// \}

// \name Tool
Expand Down Expand Up @@ -146,6 +149,8 @@ class EditorPlugin : public editor::IEditorPlugin

void updateTargetManagers();

Ref< ILogTarget > createLogTarget(const std::wstring& name);

Ref< PropertyGroup > getTweakSettings() const;

void launch(TargetInstance* targetInstance);
Expand Down
5 changes: 3 additions & 2 deletions code/Runtime/Editor/TargetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ namespace traktor::runtime

T_IMPLEMENT_RTTI_CLASS(L"traktor.runtime.TargetManager", TargetManager, Object)

TargetManager::TargetManager(editor::IEditor *editor)
TargetManager::TargetManager(editor::IEditor* editor, const fn_new_log_target_t& newLogTargetFn)
: m_editor(editor)
, m_newLogTargetFn(newLogTargetFn)
, m_port(0)
{
}
Expand Down Expand Up @@ -143,7 +144,7 @@ bool TargetManager::update()
if (running > 0)
logName += L" (" + toString(running) + L")";

Ref< ILogTarget > targetLog = m_editor->createLogTarget(logName);
Ref< ILogTarget > targetLog = m_newLogTargetFn(logName);

// Create connection object and add to instance.
Ref< script::IScriptDebuggerSessions > debuggerSessions = m_editor->getObjectStore()->get< script::IScriptDebuggerSessions >();
Expand Down
6 changes: 5 additions & 1 deletion code/Runtime/Editor/TargetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#pragma once

#include <functional>
#include "Core/RefArray.h"
#include "Net/TcpSocket.h"

Expand Down Expand Up @@ -38,7 +39,9 @@ class TargetManager : public Object
T_RTTI_CLASS;

public:
explicit TargetManager(editor::IEditor *editor);
typedef std::function< Ref< ILogTarget >(const std::wstring& name) > fn_new_log_target_t;

explicit TargetManager(editor::IEditor* editor, const fn_new_log_target_t& newLogTargetFn);

bool create();

Expand All @@ -56,6 +59,7 @@ class TargetManager : public Object

private:
editor::IEditor* m_editor;
fn_new_log_target_t m_newLogTargetFn;
Ref< net::TcpSocket > m_listenSocket;
RefArray< TargetInstance > m_instances;
uint16_t m_port;
Expand Down
Loading

0 comments on commit 99d1d56

Please sign in to comment.