connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ),
this, SLOT( onModuleActivation( const QString& ) ) );
connect( moduleAction, SIGNAL( adding() ),
- this, SLOT( onModuleAdding() ) );
+ this, SLOT( onExtAdding() ) );
connect( moduleAction, SIGNAL( removing( QString ) ),
- this, SLOT( onModuleRemoving( QString ) ) );
+ this, SLOT( onExtRemoving( QString ) ) );
connect( moduleAction, SIGNAL(showExtInfo()),
this, SLOT(onShowExtInfo()));
activateModule( modTitle );
}
-/*!On module adding action.*/
-void LightApp_Application::onModuleAdding()
+/*!On extension adding action.*/
+void LightApp_Application::onExtAdding()
{
// Show dialog to browse a salome extension file
- QStringList filters = ( QStringList() << tr( "Salome extension files") + " (*.salomex)" << tr( "All files" ) + " (*)" );
- QStringList paths = getOpenFileNames( QString(), filters.join( ";;" ), QString(), desktop() );
- if ( paths.isEmpty() ) // cancelled
+ QStringList filters = (QStringList() << tr("Salome extension files") + " (*.salomex)" << tr("All files") + " (*)");
+ QStringList paths = getOpenFileNames(QString(), filters.join(";;"), QString(), desktop());
+ if (paths.isEmpty()) // cancelled
return;
// It should be set on the app start
PyObjWrapper unpackedModules = PyObject_CallMethod(
extensionUnpacker, (char*)"install_salomex", (char*)"s", extPath.c_str());
- ASSERT(unpackedModules);
if (!unpackedModules)
{
- MESSAGE("Couldn't unpack a salome extension!");
+ SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_FAILED_UNPACK_EXTENSION").arg(path) );
continue;
}
addUserModule(moduleName, moduleDir, true);
}
+ // Add an extension to GUI
+ LightApp_ModuleAction* moduleAction = qobject_cast<LightApp_ModuleAction*>(action(ModulesListId));
+ ASSERT(moduleAction);
+ if (moduleAction)
+ {
+ QFileInfo extFileInfo(path);
+ QString extName = extFileInfo.baseName();
+ moduleAction->insertExtension(extName);
+ }
+
// read description file (.salomex) and check it's OK
// QtxResourceMgr resMgr;
// if ( !resMgr.addResource( path ) )
}
/*!On module removing action.*/
-void LightApp_Application::onModuleRemoving( const QString& title )
+void LightApp_Application::onExtRemoving(const QString& title)
{
- QString root = resourceMgr()->stringValue( "user_modules", moduleName( title ) );
- QDir rootDirectory = QDir( root );
+ MESSAGE("Remove an extension...");
+ std::string extName = title.toStdString();
+ SCRUTE(extName);
- if ( rootDirectory.exists() )
+ // It should be set on the app start
+ auto extRootDir = getenv("SALOME_APPLICATION_DIR");
+ ASSERT(extRootDir)
+ if (!extRootDir)
{
- int answer = SUIT_MessageBox::question( desktop(),
- tr( "TLT_REMOVE_MODULE" ),
- tr( "QUE_REMOVE_MODULE_DIR" ).arg( root ),
- SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel,
- SUIT_MessageBox::No );
- if ( answer == SUIT_MessageBox::Cancel )
- return; // cancelled
- if ( answer == SUIT_MessageBox::Yes )
+ MESSAGE("Cannot get SALOME_APPLICATION_DIR env variable! Cancel adding selected extensions.");
+ return;
+ }
+ SCRUTE(extRootDir);
+
+ // Import Python module that manages SALOME extensions.
+ PyLockWrapper lck; // acquire GIL
+ PyObjWrapper extensionRemover = PyImport_ImportModule((char*)"SalomeOnDemandTK.extension_remover");
+ PyObjWrapper removedModules = PyObject_CallMethod(
+ extensionRemover, (char*)"remove_salomex", (char*)"ss", extRootDir, extName.c_str());
+ if (!removedModules)
+ {
+ SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_FAILED_REMOVE_EXTENSION").arg(title) );
+ return;
+ }
+
+ // We need it to remove ext and modules from UI
+ LightApp_ModuleAction* moduleAction = qobject_cast<LightApp_ModuleAction*>(action(ModulesListId));
+ ASSERT(moduleAction);
+
+ // Module's content was already removed on python remove_salomex call,
+ // then all we do next - just remove UI items.
+ for (Py_ssize_t pos = 0; pos < PyList_Size(removedModules); ++pos)
+ {
+ // Get the current module's name
+ auto moduleNameItem = PyList_GetItem(removedModules, pos);
+ QString name(PyUnicode_AsUTF8(moduleNameItem));
+ SCRUTE(name.toStdString());
+
+ // Set current state in modules combo box
+ if (activeModule() && activeModule()->moduleName() == name)
+ activateModule( "" );
+
+ // Remove from "Modules" menu and toolbar
+ if (moduleAction)
{
- if ( activeStudy() && activeStudy()->isModified() && !onSaveDoc() )
- // doc is not saved, or saving cancelled
- return;
- if ( !rootDirectory.removeRecursively() )
- {
- // canont remove directory
- if ( SUIT_MessageBox::question( desktop(),
- tr( "WRN_WARNING" ),
- tr( "WRN_CANNOT_REMOVE_DIR" ).arg( root ),
- SUIT_MessageBox::Yes | SUIT_MessageBox::No,
- SUIT_MessageBox::No ) == SUIT_MessageBox::No )
- return; // removal is cancelled
- }
+ moduleAction->removeModule(name);
}
- }
- if ( activeModule() && activeModule()->moduleName() == title )
- activateModule( "" );
+ // Remove Help menu items
+ removeHelpItems(name);
- // remove from "Modules" menu and toolbar
- LightApp_ModuleAction* moduleAction = qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
- if ( moduleAction )
+ // Remove Preferences
+ LightApp_Preferences* prefs = preferences();
+ if (prefs)
+ prefs->removeModule(name);
+
+ // Remove settings
+ QStringList customModules = resourceMgr()->stringValue("launch", "user_modules").split(";", QString::SkipEmptyParts);
+ customModules.removeAll(moduleName(name));
+ resourceMgr()->setValue("launch", "user_modules", customModules.join(";"));
+ removeModuleInfo(moduleName(name));
+ }
+
+ // Remove an ext from UI
+ if (moduleAction)
{
- moduleAction->removeModule( title );
+ moduleAction->removeExtension(title);
}
- // remove Help menu items
- removeHelpItems( title );
- // remove Preferences
- LightApp_Preferences* prefs = preferences();
- if ( prefs )
- prefs->removeModule( title );
- // remove settings
- QStringList customModules = resourceMgr()->stringValue( "launch", "user_modules" ).split( ";", QString::SkipEmptyParts );
- customModules.removeAll( moduleName( title ) );
- resourceMgr()->setValue( "launch", "user_modules", customModules.join( ";" ) );
- removeModuleInfo( moduleName( title ) );
- // update windows (in particular, Info panel)
+
+ // Update windows (in particular, Info panel)
updateWindows();
}
#include <QMenu>
#include <QSignalMapper>
+#include <utilities.h>
+
/*!
\class LightApp_ModuleAction::ActionSet
\brief Internal class to represent list of modules buttons.
QtxAction* a = new QtxAction( name, ico, name, 0, this, true );
a->setStatusTip( tr( "ACTIVATE_MODULE_TOP" ).arg( name ) );
a->setData( isCustom );
- if ( isCustom )
- {
- myRemove->setEnabled( true );
- QAction* inserted = myRemove->menu()->addAction( name );
- connect( inserted, SIGNAL( triggered() ), myMapper, SLOT( map() ) );
- myMapper->setMapping( inserted, name );
- }
+
+ // Commented because of using buttons for extension instead of modules
+ // if ( isCustom )
+ // {
+ // myRemove->setEnabled( true );
+ // QAction* inserted = myRemove->menu()->addAction( name );
+ // connect( inserted, SIGNAL( triggered() ), myMapper, SLOT( map() ) );
+ // myMapper->setMapping( inserted, name );
+ // }
mySet->insertAction( a, -1, idx );
update();
*/
void LightApp_ModuleAction::removeModule( const QString& name )
{
+ MESSAGE("Start to remove module...");
+
int id = mySet->moduleId( name );
if ( id == -1 )
+ MESSAGE("Can't get a module's id! Return");
return;
QAction* a = moduleAction( name );
bool isCustom = a->data().toBool();
+ SCRUTE(id);
mySet->removeAction( id );
- if ( isCustom )
+ // Commented because of using buttons for extension instead of modules
+ // if ( isCustom )
+ // {
+ // foreach ( QAction* ma, myRemove->menu()->actions() )
+ // {
+ // if ( ma->text() == name )
+ // {
+ // myRemove->menu()->removeAction( ma );
+ // break;
+ // }
+ // }
+ // myRemove->setEnabled( !myRemove->menu()->actions().isEmpty() );
+ // }
+
+ update();
+
+ MESSAGE("Module was removed");
+}
+
+/*!
+ \brief Add an installed extension. Now only to the Remove button's menu.
+ \param name an extension's name
+ \sa removeExtension()
+*/
+void LightApp_ModuleAction::insertExtension(const QString& name)
+{
+ MESSAGE("Insert an extension's action...");
+ SCRUTE(name.toStdString());
+
+ myRemove->setEnabled(true);
+
+ // Find a place to insert in the alphabetical order
+ QAction* insertBefore = nullptr;
+ foreach(QAction* curAction, myRemove->menu()->actions())
+ {
+ int compareRes = QString::compare(curAction->text(), name, Qt::CaseInsensitive);
+ if (!compareRes)
+ {
+ return; // already added
+ }
+ else if (compareRes > 0)
+ {
+ insertBefore = curAction;
+
+ SCRUTE(insertBefore->text().toStdString());
+ break;
+ }
+ }
+
+ QAction* inserted = new QAction(name);
+ myRemove->menu()->insertAction(insertBefore, inserted);
+ connect(inserted, SIGNAL(triggered()), myMapper, SLOT(map()));
+ myMapper->setMapping(inserted, name);
+
+ MESSAGE("An extension's action was inserted");
+}
+
+/*!
+ \brief Remove an installed extension.
+ \param name an extension's name
+ \sa insertExtension()
+*/
+void LightApp_ModuleAction::removeExtension(const QString& name)
+{
+ MESSAGE("Remove an extension's action...");
+ SCRUTE(name.toStdString());
+
+ foreach(QAction* ma, myRemove->menu()->actions())
{
- foreach ( QAction* ma, myRemove->menu()->actions() )
+ if (ma->text() == name)
{
- if ( ma->text() == name )
- {
- myRemove->menu()->removeAction( ma );
- break;
- }
+ myRemove->menu()->removeAction(ma);
+
+ MESSAGE("Extension's action was removed");
+ break;
}
- myRemove->setEnabled( !myRemove->menu()->actions().isEmpty() );
}
+ myRemove->setEnabled(!myRemove->menu()->actions().isEmpty());
+
update();
}