void CtrlrPanelCanvas::replaceComponent (CtrlrModulator &modulator, const String &targetComponentType)
{
	CtrlrComponent *oldComponent = modulator.getComponent();
	CtrlrComponent *newComponent = nullptr;

	/* detach the existing component so it doesn't get notified about anything, the pointer will be invalid */
    if (getOwner().getSelection())
    {
        getOwner().getSelection()->deselectAll();
        getOwner().getSelection()->dispatchPendingMessages();
        getOwner().getSelection()->removeChangeListener(oldComponent);
    }

	if (oldComponent)
	{
		/* keep a copy of the old properties, we need to find out if the component is in a group */
		ValueTree oldComponentProperties = oldComponent->getObjectTree().createCopy();

		modulator.setComponentType(targetComponentType, false);

		/* get the new component pointer and attach it */
		newComponent = modulator.getComponent();
        if (getOwner().getSelection())
            getOwner().getSelection()->addChangeListener (newComponent);

		addAndMakeVisibleNg (modulator.getComponent(), nullptr, true);

		/* attach the new component to any group components the old component was int */
		if (oldComponentProperties.hasProperty(Ids::componentGroupName))
		{
			CtrlrGroup *group = dynamic_cast<CtrlrGroup*>(owner.getOwner().getComponent(oldComponentProperties.getProperty(Ids::componentGroupName)));
			if (group)
			{
				group->setOwned (newComponent, true);
			}
		}

		if (oldComponentProperties.hasProperty(Ids::componentTabName))
		{
			CtrlrTabsComponent *tabs = dynamic_cast<CtrlrTabsComponent*>(owner.getOwner().getComponent(oldComponentProperties.getProperty(Ids::componentTabName)));
			if (tabs)
			{
				tabs->setOwned (newComponent, oldComponentProperties.getProperty(Ids::componentTabId), true);
			}
		}

		/* copy any old properties to the new component */
        for (int i=0; i<oldComponentProperties.getNumProperties(); i++)
		{
			const Identifier propName 	= oldComponentProperties.getPropertyName(i);
			const var propValue			= oldComponentProperties.getProperty(propName);

			if (propName != Ids::uiType)
			{
				if (newComponent->getObjectTree().hasProperty(propName))
					newComponent->setProperty (propName, propValue);
			}
		}
	}
}
Esempio n. 2
0
void CtrlrTabsContentComponent::parentNameChanged(const String &newName)
{
	for (int i=0; i<getNumChildComponents(); i++)
	{
		CtrlrComponent *c = dynamic_cast<CtrlrComponent*>(getChildComponent(i));
		if (c!=0)
		{
			c->setProperty (Ids::componentTabName, newName);
		}
	}
}
Esempio n. 3
0
void CtrlrGroup::modulatorNameChanged (const String &newName)
{
	for (int i=0; i<content.getNumChildComponents(); i++)
	{
		CtrlrComponent *c = dynamic_cast<CtrlrComponent*>(content.getChildComponent(i));
		if (c!=0)
		{
			c->setProperty (Ids::componentGroupName, newName, true);
		}
	}
}
void CtrlrPanelCanvas::handleRightClickOnComponent(const MouseEvent &e)
{
	CtrlrComponent *c = findEventComponent(e);

	if (c == 0)
		return;

	if (dynamic_cast<ResizableBorderComponent*>(e.eventComponent) == 0 && getOwner().getSelection())
	{
		getOwner().getSelection()->selectOnly (c);
	}

	PopupMenu m;
	PopupMenu componentSubMenu = CtrlrComponentTypeManager::getComponentMenu(true);
	m.addSectionHeader ("Actions");
	m.addItem (512, "Export component");
	m.addItem (513, "Lock", true, c->getProperty(Ids::componentIsLocked));

	m.addSectionHeader ("Layout");
	m.addItem (1024, "Send to back");
	m.addItem (1025, "Send to front");
	m.addSubMenu ("Send to layer", getLayerMenu());
	m.addSeparator();
	m.addSubMenu ("Replace with", componentSubMenu, true);

	m.addSeparator();
	getEditMenu(m);

	m.addSeparator();
	if (CtrlrComponentTypeManager::isGroupingComponent(c))
	{
		m.addItem (1026, "Delete with children");
		m.addItem (1027, "Copy with children");
	}

	const int ret = m.show();

	if (ret == 512)
	{
		exportSelectedComponents();
	}
	else if (ret == 513)
	{
		c->setProperty (Ids::componentIsLocked, !c->getProperty(Ids::componentIsLocked));
	}
	if (ret == 1024)
	{
		c->toBack();
		c->setProperty (Ids::componentSentBack, true);
	}
	else if (ret == 1025)
	{
		c->toFront(false);
		c->setProperty (Ids::componentSentBack, false);
	}
	else if (ret == 1026)
	{
		deleteWithChildren (c);
	}
	else if (ret == 1027)
	{
		copyWithChildren (c);
	}
	else if (ret >= 2048 && ret < 4096)
	{
		handleEditMenu (ret, e);
	}
	else if (ret >= 4096 && ret < 8192)
    {
        handleLayerMenu (ret, e);
    }
	else if (ret < 1024 && ret > 10)
	{
		PopupMenu::MenuItemIterator iterator((const PopupMenu &)componentSubMenu);
		while (iterator.next())
		{
			if (iterator.getItem().subMenu)
			{
				PopupMenu::MenuItemIterator iterator2(*iterator.getItem().subMenu);
				while (iterator2.next())
				{
					if (iterator2.getItem().itemID == ret)
					{
						if (c)
						{
							replaceComponent (c->getOwner(), iterator2.getItem().text);
							return;
						}
					}
				}
			}
		}
	}
}