CtrlrChildWindow *CtrlrManagerWindowManager::createWindow(const CtrlrManagerWindowManager::WindowType window)
{
	if (isCreated(window))
	{
		return (nullptr);
	}

	CtrlrChildWindow *w = new CtrlrChildWindow (*this);

	switch (window)
	{
		case CtrlrManagerWindowManager::MidiMonWindow:
			w->setContent (new CtrlrMIDIMon (owner));
			break;

		case CtrlrManagerWindowManager::LogViewer:
			w->setContent (new CtrlrLogViewer (owner));
			break;

		case CtrlrManagerWindowManager::MIDICalculator:
			w->setContent (new CtrlrMIDICalculator (owner));
			break;

        case CtrlrManagerWindowManager::Repository:
            break;
	}

	w->setName("Ctrlr/" + w->getContent()->getContentName());
	windows.add (w);

	return (w);
}
void CtrlrPanelWindowManager::create(const CtrlrPanelWindowManager::WindowType window, const String &lastWindowState)
{
	CtrlrChildWindow *w			= createWindow(window);
	String windowState;

	if (w == nullptr)
	{
		return;
	}

	if (lastWindowState.isEmpty())
	{
		if (managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).isValid())
		{
			windowState = managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).getProperty (Ids::uiChildWindowState);
		}
	}
	else
	{
		windowState = lastWindowState;
	}

	if (windowState != String::empty)
	{
		w->restoreWindowStateFromString(windowState);
	}
	else
	{
		w->centreWithSize(w->getWidth(), w->getHeight());
	}

	if (managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).isValid())
	{
		if (w->getContent())
		{
			/* restore the stored state in our global tree */
			w->getContent()->restoreState (managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).getChildWithName(Ids::uiChildWindowContentState));

			/* remove the CONTENT state */
			managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).removeAllChildren (nullptr);

			/* reattach the CONTENT state but with the valid data reference */
			managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).addChild (w->getContent()->saveState(), -1, nullptr);
		}
	}
}
Component *CtrlrManagerWindowManager::getContent(const CtrlrManagerWindowManager::WindowType window)
{
	CtrlrChildWindow *w = getWindow(window);
	if (w)
	{
		return (w->getContent());
	}
	return (0);
}
void CtrlrManagerWindowManager::create(const CtrlrManagerWindowManager::WindowType window, const String &lastWindowState)
{
	CtrlrChildWindow *w			= createWindow(window);
	String windowState;

	if (w == nullptr)
	{
		return;
	}

	if (lastWindowState.isEmpty())
	{
		if (managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).isValid())
		{
			windowState = managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).getProperty (Ids::uiChildWindowState);
		}
	}
	else
	{
		windowState = lastWindowState;
	}

	if (windowState != String::empty)
	{
		w->restoreWindowStateFromString(windowState);
	}
	else
	{
		w->centreWithSize(w->getWidth(), w->getHeight());
	}

	if (managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).isValid())
	{
		if (w->getContent())
		{
			w->getContent()->restoreState (managerTree.getChildWithProperty (Ids::uiChildWindowName, getWindowName(window)).getChildWithName(Ids::uiChildWindowContentState));
		}
	}
}
CtrlrChildWindow *CtrlrPanelWindowManager::createWindow(const CtrlrPanelWindowManager::WindowType window)
{
	if (isCreated(window))
	{
		return (nullptr);
	}

	CtrlrChildWindow *w = new CtrlrChildWindow (*this);

	switch (window)
	{
		case CtrlrPanelWindowManager::LuaConsole:
			w->setContent (new CtrlrLuaConsole (owner));
			break;

		case CtrlrPanelWindowManager::LuaMethodEditor:
			w->setContent (new CtrlrLuaMethodEditor (owner));
			break;

		case CtrlrPanelWindowManager::ModulatorList:
			w->setContent (new CtrlrPanelModulatorList(owner));
			break;

		case CtrlrPanelWindowManager::LayerEditor:
			w->setContent (new CtrlrPanelLayerList(owner));
			break;

		case CtrlrPanelWindowManager::MIDILibrary:
			w->setContent (new CtrlrMIDILibraryEditor(owner));
			break;

		case CtrlrPanelWindowManager::BufferEditor:
			w->setContent (new CtrlrMIDIBufferEditor(owner));
			break;
	}

	w->setName(owner.getProperty (Ids::name).toString() + "/" + w->getContent()->getContentName());
	windows.add (w);

	return (w);
}