Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/addfxcontextmenu.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/fxselection.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxcommand.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxdag.h"
Toshihiro Shimizu 890ddd
#include "toonz/tapplication.h"
Toshihiro Shimizu 890ddd
#include "tw/stringtable.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "texternfx.h"
Toshihiro Shimizu 890ddd
#include "tmacrofx.h"
Toshihiro Shimizu 890ddd
#include "tfxattributes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qmenu></qmenu>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qstack></qstack>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "pluginhost.h"
Toshihiro Shimizu 890ddd
#include <map></map>
Toshihiro Shimizu 890ddd
#include <string></string>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
std::map<std::string, *="" plugininformation=""> plugin_dict_;</std::string,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TFx *createFxByName(std::string fxId)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (fxId.find("_ext_") == 0)
Toshihiro Shimizu 890ddd
		return TExternFx::create(fxId.substr(5));
Toshihiro Shimizu 890ddd
	if (fxId.find("_plg_") == 0) {
Toshihiro Shimizu 890ddd
		std::string id = fxId.substr(5);
Toshihiro Shimizu 890ddd
		std::map<std::string, *="" plugininformation="">::iterator it = plugin_dict_.find(id);</std::string,>
Toshihiro Shimizu 890ddd
		if (it != plugin_dict_.end()) {
Toshihiro Shimizu 890ddd
			RasterFxPluginHost *plugin = new RasterFxPluginHost(it->second);
Toshihiro Shimizu 890ddd
			plugin->notify();
Toshihiro Shimizu 890ddd
			return plugin;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return NULL;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		return TFx::create(fxId);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFx *createPresetFxByName(TFilePath path)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::string id = path.getParentDir().getName();
Toshihiro Shimizu 890ddd
	TFx *fx = createFxByName(id);
Toshihiro Shimizu 890ddd
	if (fx) {
Toshihiro Shimizu 890ddd
		TIStream is(path);
Toshihiro Shimizu 890ddd
		fx->loadPreset(is);
Toshihiro Shimizu 890ddd
		fx->setName(path.getWideName());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFx *createMacroFxByPath(TFilePath path, TXsheet *xsheet)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TIStream is(path);
Toshihiro Shimizu 890ddd
		TPersist *p = 0;
Toshihiro Shimizu 890ddd
		is >> p;
Toshihiro Shimizu 890ddd
		TMacroFx *fx = dynamic_cast<tmacrofx *="">(p);</tmacrofx>
Toshihiro Shimizu 890ddd
		if (!fx)
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
		fx->setName(path.getWideName());
Toshihiro Shimizu 890ddd
		//Assign a unic ID to each fx in the macro!
Toshihiro Shimizu 890ddd
		if (!xsheet)
Toshihiro Shimizu 890ddd
			return fx;
Toshihiro Shimizu 890ddd
		FxDag *fxDag = xsheet->getFxDag();
Toshihiro Shimizu 890ddd
		if (!fxDag)
Toshihiro Shimizu 890ddd
			return fx;
Shinya Kitaoka 3bfa54
		std::vector<tfxp> fxs;</tfxp>
Toshihiro Shimizu 890ddd
		fxs = fx->getFxs();
Shinya Kitaoka 3bfa54
		QMap<std::wstring, std::wstring=""> oldNewId;</std::wstring,>
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)fxs.size(); i++) {
Shinya Kitaoka 3bfa54
			std::wstring oldId = fxs[i]->getFxId();
Toshihiro Shimizu 890ddd
			fxDag->assignUniqueId(fxs[i].getPointer());
Shinya Kitaoka 3bfa54
			std::wstring newId = fxs[i]->getFxId();
Toshihiro Shimizu 890ddd
			oldNewId[oldId] = newId;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//cambiando l'id degli effetti interni di una macro si rompono i legami tra il nome della porta
Toshihiro Shimizu 890ddd
			//e la porta a cui e' legato: devo cambiare i nomei delle porte e rimapparli all'interno della macro
Toshihiro Shimizu 890ddd
			int j;
Toshihiro Shimizu 890ddd
			for (j = 0; j < fx->getInputPortCount(); j++) {
Toshihiro Shimizu 890ddd
				QString inputName = QString::fromStdString(fx->getInputPortName(j));
Toshihiro Shimizu 890ddd
				if (inputName.endsWith(QString::fromStdWString(oldId))) {
Toshihiro Shimizu 890ddd
					QString newInputName = inputName;
Toshihiro Shimizu 890ddd
					newInputName.replace(QString::fromStdWString(oldId), QString::fromStdWString(newId));
Toshihiro Shimizu 890ddd
					fx->renamePort(inputName.toStdString(), newInputName.toStdString());
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Shinya Kitaoka 3bfa54
		/* QStack<qpair<std::string, tfxport*=""> > newPortNames;</qpair<std::string,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
      //Devo cambiare il nome alle porte: contengono l'id dei vecchi effetti
Toshihiro Shimizu 890ddd
      for(i=fx->getInputPortCount()-1; i>=0; i--)
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
        string oldPortName = fx->getInputPortName(i);
Toshihiro Shimizu 890ddd
        string inFxOldId = oldPortName;
Toshihiro Shimizu 890ddd
        inFxOldId.erase(0,inFxOldId.find_last_of("_")+1);
Toshihiro Shimizu 890ddd
        assert(oldNewId.contains(toWideString(inFxOldId)));
Toshihiro Shimizu 890ddd
        string inFxNewId = toString(oldNewId[toWideString(inFxOldId)]);
Toshihiro Shimizu 890ddd
        string newPortName = oldPortName;
Toshihiro Shimizu 890ddd
        newPortName.erase(newPortName.find_last_of("_")+1,newPortName.size()-1);
Toshihiro Shimizu 890ddd
        newPortName.append(inFxNewId);
Toshihiro Shimizu 890ddd
        TFxPort* fxPort = fx->getInputPort(i);
Shinya Kitaoka 3bfa54
        newPortNames.append(QPair<std::string, tfxport*="">(newPortName,fxPort));</std::string,>
Toshihiro Shimizu 890ddd
        fx->removeInputPort(oldPortName);
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
      while(!newPortNames.isEmpty())
Toshihiro Shimizu 890ddd
      {
Shinya Kitaoka 3bfa54
        QPair<std::string, tfxport*=""> newPort = newPortNames.pop();</std::string,>
Toshihiro Shimizu 890ddd
        fx->addInputPort(newPort.first,*newPort.second);
Toshihiro Shimizu 890ddd
      }*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return fx;
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFx *createFx(QAction *action, TXsheetHandle *xshHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = xshHandle->getXsheet();
Toshihiro Shimizu 890ddd
	QString text = action->data().toString();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (text.isEmpty())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFx *fx = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath path = TFilePath(text.toStdWString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TFileStatus(path).doesExist() && TFileStatus(path.getParentDir()).isDirectory()) {
Shinya Kitaoka 3bfa54
		std::string folder = path.getParentDir().getName();
Toshihiro Shimizu 890ddd
		if (folder == "macroFx") //have to load a Macro
Toshihiro Shimizu 890ddd
			fx = createMacroFxByPath(path, xsh);
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			folder = path.getParentDir().getParentDir().getName();
Toshihiro Shimizu 890ddd
			if (folder == "presets") //have to load a preset
Toshihiro Shimizu 890ddd
				fx = createPresetFxByName(path);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		fx = createFxByName(text.toStdString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//***************************************************
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//AddFxContextMenu
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//***************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
AddFxContextMenu::AddFxContextMenu()
Toshihiro Shimizu 890ddd
	: QObject(), m_app(0), m_currentCursorScenePos(0, 0), m_againCommand(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_fxListPath = TFilePath(ToonzFolder::getProfileFolder() + "layouts" + "fxs" + "fxs.lst");
Toshihiro Shimizu 890ddd
	m_presetPath = TFilePath(ToonzFolder::getFxPresetFolder() + "presets");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_insertMenu = new QMenu(tr("Insert FX"), 0);
Toshihiro Shimizu 890ddd
	m_insertActionGroup = new QActionGroup(m_insertMenu);
Toshihiro Shimizu 890ddd
	m_addMenu = new QMenu(tr("Add FX"), 0);
Toshihiro Shimizu 890ddd
	m_addActionGroup = new QActionGroup(m_addMenu);
Toshihiro Shimizu 890ddd
	m_replaceMenu = new QMenu(tr("Replace FX"), 0);
Toshihiro Shimizu 890ddd
	m_replaceActionGroup = new QActionGroup(m_replaceMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	connect(m_insertActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(onInsertFx(QAction *)));
Toshihiro Shimizu 890ddd
	connect(m_addActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(onAddFx(QAction *)));
Toshihiro Shimizu 890ddd
	connect(m_replaceActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(onReplaceFx(QAction *)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	fillMenus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
static void clear_all_plugins()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (std::map<std::string, *="" plugininformation="">::iterator it = plugin_dict_.begin();</std::string,>
Toshihiro Shimizu 890ddd
		 it != plugin_dict_.end(); ++it) {
Toshihiro Shimizu 890ddd
		it->second->release();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	plugin_dict_.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
AddFxContextMenu::~AddFxContextMenu()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	clear_all_plugins();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::setApplication(TApplication *app)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_app = app;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TFxHandle *fxHandle = app->getCurrentFx()) {
Toshihiro Shimizu 890ddd
		connect(fxHandle, SIGNAL(fxPresetSaved()), this, SLOT(onFxPresetHandled()));
Toshihiro Shimizu 890ddd
		connect(fxHandle, SIGNAL(fxPresetRemoved()), this, SLOT(onFxPresetHandled()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::fillMenus()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	loadFxs();
Toshihiro Shimizu 890ddd
	loadMacro();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void scan_all_plugins(const std::string &basedir, QObject *listener)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//clear_all_plugins();
Toshihiro Shimizu 890ddd
	new PluginLoadController(basedir, listener);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::result(PluginInformation *pi)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/* slot receives PluginInformation on the main thread たぶん */
Toshihiro Shimizu 890ddd
	printf("AddFxContextMenu::result() pi:%p\n", pi);
Toshihiro Shimizu 890ddd
	/* addfxcontextmenu.cpp の dict に登録する */
Toshihiro Shimizu 890ddd
	if (pi)
Toshihiro Shimizu 890ddd
		plugin_dict_.insert(std::pair<std::string, *="" plugininformation="">(pi->desc_->id_, pi));</std::string,>
Toshihiro Shimizu 890ddd
	//RasterFxPluginHost* plug = new RasterFxPluginHost(pi);
Toshihiro Shimizu 890ddd
	//pi->handler_->create(plug);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::fixup()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	loadFxPluginGroup();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::loadFxs()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TIStream is(m_fxListPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	try {
Shinya Kitaoka 3bfa54
		std::string tagName;
Toshihiro Shimizu 890ddd
		if (is.matchTag(tagName) && tagName == "fxs") {
Toshihiro Shimizu 890ddd
			loadFxGroup(&is);
Toshihiro Shimizu 890ddd
			is.closeChild();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	scan_all_plugins("", this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::loadFxPluginGroup()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString groupName = QString::fromStdString("Plugins");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::auto_ptr<qmenu> insertFxGroup(new QMenu(groupName, m_insertMenu));</qmenu>
Toshihiro Shimizu 890ddd
	std::auto_ptr<qmenu> addFxGroup(new QMenu(groupName, m_addMenu));</qmenu>
Toshihiro Shimizu 890ddd
	std::auto_ptr<qmenu> replaceFxGroup(new QMenu(groupName, m_replaceMenu));</qmenu>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	loadFxPlugins(insertFxGroup.get(), addFxGroup.get(), replaceFxGroup.get());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!insertFxGroup->isEmpty())
Toshihiro Shimizu 890ddd
		m_insertMenu->addMenu(insertFxGroup.release());
Toshihiro Shimizu 890ddd
	if (!addFxGroup->isEmpty())
Toshihiro Shimizu 890ddd
		m_addMenu->addMenu(addFxGroup.release());
Toshihiro Shimizu 890ddd
	if (!replaceFxGroup->isEmpty())
Toshihiro Shimizu 890ddd
		m_replaceMenu->addMenu(replaceFxGroup.release());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::loadFxGroup(TIStream *is)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	while (!is->eos()) {
Shinya Kitaoka 3bfa54
		std::string tagName;
Toshihiro Shimizu 890ddd
		if (is->matchTag(tagName)) {
Toshihiro Shimizu 890ddd
			QString groupName = QString::fromStdString(tagName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			std::auto_ptr<qmenu> insertFxGroup(new QMenu(groupName, m_insertMenu));</qmenu>
Toshihiro Shimizu 890ddd
			std::auto_ptr<qmenu> addFxGroup(new QMenu(groupName, m_addMenu));</qmenu>
Toshihiro Shimizu 890ddd
			std::auto_ptr<qmenu> replaceFxGroup(new QMenu(groupName, m_replaceMenu));</qmenu>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			loadFx(is, insertFxGroup.get(), addFxGroup.get(), replaceFxGroup.get());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (!insertFxGroup->isEmpty())
Toshihiro Shimizu 890ddd
				m_insertMenu->addMenu(insertFxGroup.release());
Toshihiro Shimizu 890ddd
			if (!addFxGroup->isEmpty())
Toshihiro Shimizu 890ddd
				m_addMenu->addMenu(addFxGroup.release());
Toshihiro Shimizu 890ddd
			if (!replaceFxGroup->isEmpty())
Toshihiro Shimizu 890ddd
				m_replaceMenu->addMenu(replaceFxGroup.release());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			is->closeChild();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
void AddFxContextMenu::loadFxPlugins(QMenu *insertFxGroup, QMenu *addFxGroup, QMenu *replaceFxGroup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// list vendors
Toshihiro Shimizu 890ddd
	std::vector<std::string> vendors;</std::string>
Toshihiro Shimizu 890ddd
	for (auto &&plugin : plugin_dict_) {
Toshihiro Shimizu 890ddd
		PluginDescription *desc = plugin.second->desc_;
Toshihiro Shimizu 890ddd
		vendors.push_back(desc->vendor_);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	std::sort(std::begin(vendors), std::end(vendors));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// add vendor folders
Toshihiro Shimizu 890ddd
	std::map<std::string, *="" qmenu=""> insVendors;</std::string,>
Toshihiro Shimizu 890ddd
	std::map<std::string, *="" qmenu=""> addVendors;</std::string,>
Toshihiro Shimizu 890ddd
	std::map<std::string, *="" qmenu=""> repVendors;</std::string,>
Toshihiro Shimizu 890ddd
	for (std::string vendor : vendors) {
Toshihiro Shimizu 890ddd
		std::map<std::string, *="" qmenu="">::iterator v = insVendors.find(vendor);</std::string,>
Toshihiro Shimizu 890ddd
		if (v == insVendors.end()) {
Toshihiro Shimizu 890ddd
			QString vendorQStr = QString::fromStdString(vendor);
Toshihiro Shimizu 890ddd
			insVendors.insert(std::make_pair(vendor, insertFxGroup->addMenu(vendorQStr)));
Toshihiro Shimizu 890ddd
			addVendors.insert(std::make_pair(vendor, addFxGroup->addMenu(vendorQStr)));
Toshihiro Shimizu 890ddd
			repVendors.insert(std::make_pair(vendor, replaceFxGroup->addMenu(vendorQStr)));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// add actions
Toshihiro Shimizu 890ddd
	for (auto &&plugin : plugin_dict_) {
Toshihiro Shimizu 890ddd
		PluginDescription *desc = plugin.second->desc_;
Toshihiro Shimizu 890ddd
		QString label = QString::fromStdString(desc->name_);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QAction *insertAction = new QAction(label, insertFxGroup);
Toshihiro Shimizu 890ddd
		QAction *addAction = new QAction(label, addFxGroup);
Toshihiro Shimizu 890ddd
		QAction *replaceAction = new QAction(label, replaceFxGroup);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		insertAction->setData(QVariant("_plg_" + QString::fromStdString(desc->id_)));
Toshihiro Shimizu 890ddd
		addAction->setData(QVariant("_plg_" + QString::fromStdString(desc->id_)));
Toshihiro Shimizu 890ddd
		replaceAction->setData(QVariant("_plg_" + QString::fromStdString(desc->id_)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		(*insVendors.find(desc->vendor_)).second->addAction(insertAction);
Toshihiro Shimizu 890ddd
		(*addVendors.find(desc->vendor_)).second->addAction(addAction);
Toshihiro Shimizu 890ddd
		(*repVendors.find(desc->vendor_)).second->addAction(replaceAction);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_insertActionGroup->addAction(insertAction);
Toshihiro Shimizu 890ddd
		m_addActionGroup->addAction(addAction);
Toshihiro Shimizu 890ddd
		m_replaceActionGroup->addAction(replaceAction);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// sort actions
Toshihiro Shimizu 890ddd
	auto const comp = [](QAction *lhs, QAction *rhs) {
Toshihiro Shimizu 890ddd
		return lhs->text() < rhs->text();
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (auto &&ins : insVendors) {
Toshihiro Shimizu 890ddd
		QList<qaction *=""> actions = ins.second->actions();</qaction>
Toshihiro Shimizu 890ddd
		ins.second->clear();
Toshihiro Shimizu 890ddd
		qSort(actions.begin(), actions.end(), comp);
Toshihiro Shimizu 890ddd
		ins.second->addActions(actions);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (auto &&ins : addVendors) {
Toshihiro Shimizu 890ddd
		QList<qaction *=""> actions = ins.second->actions();</qaction>
Toshihiro Shimizu 890ddd
		ins.second->clear();
Toshihiro Shimizu 890ddd
		qSort(actions.begin(), actions.end(), comp);
Toshihiro Shimizu 890ddd
		ins.second->addActions(actions);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (auto &&ins : repVendors) {
Toshihiro Shimizu 890ddd
		QList<qaction *=""> actions = ins.second->actions();</qaction>
Toshihiro Shimizu 890ddd
		ins.second->clear();
Toshihiro Shimizu 890ddd
		qSort(actions.begin(), actions.end(), comp);
Toshihiro Shimizu 890ddd
		ins.second->addActions(actions);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::loadFx(TIStream *is, QMenu *insertFxGroup, QMenu *addFxGroup, QMenu *replaceFxGroup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	while (!is->eos()) {
Shinya Kitaoka 3bfa54
		std::string fxName;
Toshihiro Shimizu 890ddd
		*is >> fxName;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!fxName.empty()) {
Toshihiro Shimizu 890ddd
			if (!loadPreset(fxName, insertFxGroup, addFxGroup, replaceFxGroup)) {
Toshihiro Shimizu 890ddd
				QString translatedName = QString::fromStdWString(TStringTable::translate(fxName));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				QAction *insertAction = new QAction(translatedName, insertFxGroup);
Toshihiro Shimizu 890ddd
				QAction *addAction = new QAction(translatedName, addFxGroup);
Toshihiro Shimizu 890ddd
				QAction *replaceAction = new QAction(translatedName, replaceFxGroup);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				insertAction->setData(QVariant(QString::fromStdString(fxName)));
Toshihiro Shimizu 890ddd
				addAction->setData(QVariant(QString::fromStdString(fxName)));
Toshihiro Shimizu 890ddd
				replaceAction->setData(QVariant(QString::fromStdString(fxName)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				insertFxGroup->addAction(insertAction);
Toshihiro Shimizu 890ddd
				addFxGroup->addAction(addAction);
Toshihiro Shimizu 890ddd
				replaceFxGroup->addAction(replaceAction);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				m_insertActionGroup->addAction(insertAction);
Toshihiro Shimizu 890ddd
				m_addActionGroup->addAction(addAction);
Toshihiro Shimizu 890ddd
				m_replaceActionGroup->addAction(replaceAction);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool AddFxContextMenu::loadPreset(const std::string &name,
Toshihiro Shimizu 890ddd
								  QMenu *insertFxGroup, QMenu *addFxGroup, QMenu *replaceFxGroup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath presetsFilepath(m_presetPath + name);
Toshihiro Shimizu 890ddd
	if (TFileStatus(presetsFilepath).isDirectory()) {
Toshihiro Shimizu 890ddd
		TFilePathSet presets = TSystem::readDirectory(presetsFilepath, false);
Toshihiro Shimizu 890ddd
		if (!presets.empty()) {
Toshihiro Shimizu 890ddd
			QMenu *inserMenu = new QMenu(QString::fromStdWString(TStringTable::translate(name)), insertFxGroup);
Toshihiro Shimizu 890ddd
			insertFxGroup->addMenu(inserMenu);
Toshihiro Shimizu 890ddd
			QMenu *addMenu = new QMenu(QString::fromStdWString(TStringTable::translate(name)), addFxGroup);
Toshihiro Shimizu 890ddd
			addFxGroup->addMenu(addMenu);
Toshihiro Shimizu 890ddd
			QMenu *replaceMenu = new QMenu(QString::fromStdWString(TStringTable::translate(name)), replaceFxGroup);
Toshihiro Shimizu 890ddd
			replaceFxGroup->addMenu(replaceMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//This is a workaround to set the bold style to the first element of this menu
Toshihiro Shimizu 890ddd
			//Setting a font directly to a QAction is not enought; style sheet definitions
Toshihiro Shimizu 890ddd
			//preval over QAction font settings.
Toshihiro Shimizu 890ddd
			inserMenu->setObjectName("fxMenu");
Toshihiro Shimizu 890ddd
			addMenu->setObjectName("fxMenu");
Toshihiro Shimizu 890ddd
			replaceMenu->setObjectName("fxMenu");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			QAction *insertAction = new QAction(QString::fromStdWString(TStringTable::translate(name)), inserMenu);
Toshihiro Shimizu 890ddd
			QAction *addAction = new QAction(QString::fromStdWString(TStringTable::translate(name)), addMenu);
Toshihiro Shimizu 890ddd
			QAction *replaceAction = new QAction(QString::fromStdWString(TStringTable::translate(name)), replaceMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			insertAction->setCheckable(true);
Toshihiro Shimizu 890ddd
			addAction->setCheckable(true);
Toshihiro Shimizu 890ddd
			replaceAction->setCheckable(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			insertAction->setData(QVariant(QString::fromStdString(name)));
Toshihiro Shimizu 890ddd
			addAction->setData(QVariant(QString::fromStdString(name)));
Toshihiro Shimizu 890ddd
			replaceAction->setData(QVariant(QString::fromStdString(name)));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			inserMenu->addAction(insertAction);
Toshihiro Shimizu 890ddd
			addMenu->addAction(addAction);
Toshihiro Shimizu 890ddd
			replaceMenu->addAction(replaceAction);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_insertActionGroup->addAction(insertAction);
Toshihiro Shimizu 890ddd
			m_addActionGroup->addAction(addAction);
Toshihiro Shimizu 890ddd
			m_replaceActionGroup->addAction(replaceAction);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			for (TFilePathSet::iterator it2 = presets.begin(); it2 != presets.end(); ++it2) {
Toshihiro Shimizu 890ddd
				TFilePath presetName = *it2;
Toshihiro Shimizu 890ddd
				QString qPresetName = QString::fromStdWString(presetName.getWideName());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				insertAction = new QAction(qPresetName, inserMenu);
Toshihiro Shimizu 890ddd
				addAction = new QAction(qPresetName, addMenu);
Toshihiro Shimizu 890ddd
				replaceAction = new QAction(qPresetName, replaceMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				insertAction->setData(QVariant(QString::fromStdWString(presetName.getWideString())));
Toshihiro Shimizu 890ddd
				addAction->setData(QVariant(QString::fromStdWString(presetName.getWideString())));
Toshihiro Shimizu 890ddd
				replaceAction->setData(QVariant(QString::fromStdWString(presetName.getWideString())));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				inserMenu->addAction(insertAction);
Toshihiro Shimizu 890ddd
				addMenu->addAction(addAction);
Toshihiro Shimizu 890ddd
				replaceMenu->addAction(replaceAction);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				m_insertActionGroup->addAction(insertAction);
Toshihiro Shimizu 890ddd
				m_addActionGroup->addAction(addAction);
Toshihiro Shimizu 890ddd
				m_replaceActionGroup->addAction(replaceAction);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::loadMacro()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath macroDir = m_presetPath + TFilePath("macroFx");
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		if (TFileStatus(macroDir).isDirectory()) {
Toshihiro Shimizu 890ddd
			TFilePathSet macros = TSystem::readDirectory(macroDir);
Toshihiro Shimizu 890ddd
			if (macros.empty())
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			QMenu *insertMacroMenu = new QMenu("Macro", m_insertMenu);
Toshihiro Shimizu 890ddd
			QMenu *addMacroMenu = new QMenu("Macro", m_addMenu);
Toshihiro Shimizu 890ddd
			QMenu *replaceMacroMenu = new QMenu("Macro", m_replaceMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_insertMenu->addMenu(insertMacroMenu);
Toshihiro Shimizu 890ddd
			m_addMenu->addMenu(addMacroMenu);
Toshihiro Shimizu 890ddd
			m_replaceMenu->addMenu(replaceMacroMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			for (TFilePathSet::iterator it = macros.begin(); it != macros.end(); ++it) {
Toshihiro Shimizu 890ddd
				TFilePath macroPath = *it;
Toshihiro Shimizu 890ddd
				QString name = QString::fromStdWString(macroPath.getWideName());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				QAction *insertAction = new QAction(name, insertMacroMenu);
Toshihiro Shimizu 890ddd
				QAction *addAction = new QAction(name, addMacroMenu);
Toshihiro Shimizu 890ddd
				QAction *replaceAction = new QAction(name, replaceMacroMenu);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				insertAction->setData(QVariant(QString::fromStdWString(macroPath.getWideString())));
Toshihiro Shimizu 890ddd
				addAction->setData(QVariant(QString::fromStdWString(macroPath.getWideString())));
Toshihiro Shimizu 890ddd
				replaceAction->setData(QVariant(QString::fromStdWString(macroPath.getWideString())));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				insertMacroMenu->addAction(insertAction);
Toshihiro Shimizu 890ddd
				addMacroMenu->addAction(addAction);
Toshihiro Shimizu 890ddd
				replaceMacroMenu->addAction(replaceAction);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				m_insertActionGroup->addAction(insertAction);
Toshihiro Shimizu 890ddd
				m_addActionGroup->addAction(addAction);
Toshihiro Shimizu 890ddd
				m_replaceActionGroup->addAction(replaceAction);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::onInsertFx(QAction *action)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (action->isCheckable() && action->isChecked())
Toshihiro Shimizu 890ddd
		action->setChecked(false);
Toshihiro Shimizu 890ddd
	TFx *fx = createFx(action, m_app->getCurrentXsheet());
Toshihiro Shimizu 890ddd
	if (fx) {
Toshihiro Shimizu 890ddd
		QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Toshihiro Shimizu 890ddd
		QList<tfxcommand::link> links = m_selection->getLinks();</tfxcommand::link>
Toshihiro Shimizu 890ddd
		TFxCommand::insertFx(fx, fxs, links, m_app,
Toshihiro Shimizu 890ddd
							 m_app->getCurrentColumn()->getColumnIndex(), m_app->getCurrentFrame()->getFrameIndex());
Toshihiro Shimizu 890ddd
		m_app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		//memorize the latest operation
Toshihiro Shimizu 890ddd
		m_app->getCurrentFx()->setPreviousActionString(QString("I ") + action->data().toString());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::onAddFx(QAction *action)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (action->isCheckable() && action->isChecked())
Toshihiro Shimizu 890ddd
		action->setChecked(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFx *fx = createFx(action, m_app->getCurrentXsheet());
Toshihiro Shimizu 890ddd
	if (fx) {
Toshihiro Shimizu 890ddd
		QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Toshihiro Shimizu 890ddd
		// try to add node at cursor position
Toshihiro Shimizu 890ddd
		if (m_currentCursorScenePos.x() != 0 || m_currentCursorScenePos.y() != 0) {
Toshihiro Shimizu 890ddd
			fx->getAttributes()->setDagNodePos(TPointD(m_currentCursorScenePos.x(), m_currentCursorScenePos.y()));
Toshihiro Shimizu 890ddd
			m_currentCursorScenePos.setX(0);
Toshihiro Shimizu 890ddd
			m_currentCursorScenePos.setY(0);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFxCommand::addFx(fx, fxs, m_app,
Toshihiro Shimizu 890ddd
						  m_app->getCurrentColumn()->getColumnIndex(), m_app->getCurrentFrame()->getFrameIndex());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		//memorize the latest operation
Toshihiro Shimizu 890ddd
		m_app->getCurrentFx()->setPreviousActionString(QString("A ") + action->data().toString());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::onReplaceFx(QAction *action)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (action->isCheckable() && action->isChecked())
Toshihiro Shimizu 890ddd
		action->setChecked(false);
Toshihiro Shimizu 890ddd
	TFx *fx = createFx(action, m_app->getCurrentXsheet());
Toshihiro Shimizu 890ddd
	if (fx) {
Toshihiro Shimizu 890ddd
		QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Toshihiro Shimizu 890ddd
		TFxCommand::replaceFx(fx, fxs, m_app->getCurrentXsheet(), m_app->getCurrentFx());
Toshihiro Shimizu 890ddd
		m_app->getCurrentXsheet()->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		//memorize the latest operation
Toshihiro Shimizu 890ddd
		m_app->getCurrentFx()->setPreviousActionString(QString("R ") + action->data().toString());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void AddFxContextMenu::onFxPresetHandled()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_insertMenu->clear();
Toshihiro Shimizu 890ddd
	m_addMenu->clear();
Toshihiro Shimizu 890ddd
	m_replaceMenu->clear();
Toshihiro Shimizu 890ddd
	fillMenus();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
/*! repeat the last fx creation command done in the schematic.
Toshihiro Shimizu 890ddd
    arrgument "command" is sum of the ids of available commands(Insert, Add, Replace)
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
QAction *AddFxContextMenu::getAgainCommand(int command)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString commandName = m_app->getCurrentFx()->getPreviousActionString();
Toshihiro Shimizu 890ddd
	//return if the last action is not registered
Toshihiro Shimizu 890ddd
	if (commandName.isEmpty())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//classify action by commandName
Toshihiro Shimizu 890ddd
	Commands com;
Toshihiro Shimizu 890ddd
	QString commandStr;
Toshihiro Shimizu 890ddd
	if (commandName.startsWith("I ")) {
Toshihiro Shimizu 890ddd
		com = Insert;
Toshihiro Shimizu 890ddd
		commandStr = tr("Insert ");
Toshihiro Shimizu 890ddd
	} else if (commandName.startsWith("A ")) {
Toshihiro Shimizu 890ddd
		com = Add;
Toshihiro Shimizu 890ddd
		commandStr = tr("Add ");
Toshihiro Shimizu 890ddd
	} else if (commandName.startsWith("R ")) {
Toshihiro Shimizu 890ddd
		com = Replace;
Toshihiro Shimizu 890ddd
		commandStr = tr("Replace ");
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//return if the action is not available
Toshihiro Shimizu 890ddd
	if (!(command & com))
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString fxStr = commandName.right(commandName.size() - 2);
Toshihiro Shimizu 890ddd
	QString translatedCommandName = commandStr + QString::fromStdWString(TStringTable::translate(fxStr.toStdString()));
Toshihiro Shimizu 890ddd
	//return the action if the command is the exactly same
Toshihiro Shimizu 890ddd
	if (m_againCommand && translatedCommandName == m_againCommand->text())
Toshihiro Shimizu 890ddd
		return m_againCommand;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//create an action
Toshihiro Shimizu 890ddd
	if (!m_againCommand) {
Toshihiro Shimizu 890ddd
		m_againCommand = new QAction(translatedCommandName, 0);
Toshihiro Shimizu 890ddd
		m_againCommand->setData(QVariant(fxStr));
Toshihiro Shimizu 890ddd
		connect(m_againCommand, SIGNAL(triggered()), this, SLOT(onAgainCommand()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	//compare the m_againCommand's name and commandName
Toshihiro Shimizu 890ddd
	else if (translatedCommandName != m_againCommand->text()) {
Toshihiro Shimizu 890ddd
		//change the action name
Toshihiro Shimizu 890ddd
		m_againCommand->setText(translatedCommandName);
Toshihiro Shimizu 890ddd
		m_againCommand->setData(QVariant(fxStr));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return m_againCommand;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
/*! change the command behavior according to the command name
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void AddFxContextMenu::onAgainCommand()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// TODO: 日本語インタフェースの場合、対応が必要 2016/1/8 shun_iwasawa
Toshihiro Shimizu 890ddd
	if (m_againCommand->text().startsWith("Insert")) {
Toshihiro Shimizu 890ddd
		onInsertFx(m_againCommand);
Toshihiro Shimizu 890ddd
	} else if (m_againCommand->text().startsWith("Add")) {
Toshihiro Shimizu 890ddd
		onAddFx(m_againCommand);
Toshihiro Shimizu 890ddd
	} else if (m_againCommand->text().startsWith("Replace")) {
Toshihiro Shimizu 890ddd
		onReplaceFx(m_againCommand);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}