From: kosta Date: Mon, 13 Feb 2023 19:31:15 +0000 (+0100) Subject: [bos #32523][EDF] SALOME on Demand GUI. Added a message box on pressing the Ext Remov... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6c888913c8017c73ed982fd33d4c90f8b349c252;p=modules%2Fgui.git [bos #32523][EDF] SALOME on Demand GUI. Added a message box on pressing the Ext Remove button. Removing modules moved into separated method. --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c9c4582bf..b739a1a52 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -932,10 +932,9 @@ void LightApp_Application::onExtAdding() // It should be set on the app start auto extRootDir = getenv(salomeAppDir); - ASSERT(extRootDir) if (!extRootDir) { - MESSAGE("Cannot get SALOME_APPLICATION_DIR env variable! Cancel adding selected extensions."); + SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_SALOME_APPLICATION_DIR")); return; } SCRUTE(extRootDir); @@ -986,30 +985,6 @@ void LightApp_Application::onExtAdding() QString extName = extFileInfo.baseName(); moduleAction->insertExtension(extName); } - - // read description file (.salomex) and check it's OK - // QtxResourceMgr resMgr; - // if ( !resMgr.addResource( path ) ) - // { - // SUIT_MessageBox::warning( desktop(), tr( "WRN_WARNING" ), tr( "WRN_MODULE_BAD_SALOMEX_FILE" ).arg( path ) ); - // continue; - // } - // // retrieve module name - // QString name = resMgr.stringValue( "General", "name" ).trimmed(); - // if ( name.isEmpty() ) - // { - // SUIT_MessageBox::warning( desktop(), tr( "WRN_WARNING" ), tr( "WRN_MODULE_EMPTY_NAME" ).arg( path ) ); - // continue; - // } - // // retrieve root directory - // QString root = resMgr.stringValue( "General", "root" ).trimmed(); - // if ( root.isEmpty() ) - // { - // SUIT_MessageBox::warning( desktop(), tr( "WRN_WARNING" ), tr( "WRN_MODULE_EMPTY_ROOT" ).arg( path ) ); - // continue; - // } - - //addUserModule( name, root, true ); } } @@ -1109,6 +1084,47 @@ bool LightApp_Application::addUserModule( const QString& name, const QString& ro return true; } +/*!Remove user module from UI.*/ +void LightApp_Application::removeUserModule(const QString& moduleInnerName, LightApp_ModuleAction* moduleAction) +{ + MESSAGE("Remove a module from UI..."); + SCRUTE(moduleInnerName.toStdString()); + + // There is a some confusion point, because now we have a module's 'inner' name + // from the extension's salomexd file. + // But, in the next GUI methods we need to use a module title (user name). + // For example, PYHELLO (inner name) and PyHello (user name to display in GUI). + // Then, from the inner module's name we need to get a user one. + QString moduleUserName = moduleTitle(moduleInnerName); + SCRUTE(moduleUserName.toStdString()); + + // Set current state in modules combo box + // Don't confuse again, because activeModule()->moduleName() returns a module title, not an inner one! + if (activeModule() && activeModule()->moduleName() == moduleUserName) + activateModule(""); + + // Remove from "Modules" menu and toolbar + if (moduleAction) + { + moduleAction->removeModule(moduleUserName); + } + + // Remove Help menu items + removeHelpItems(moduleUserName); + + // Remove Preferences + LightApp_Preferences* prefs = preferences(); + if (prefs) + prefs->removeModule(moduleUserName); + + // Remove settings + // Here we use an inner module name! + QStringList customModules = resourceMgr()->stringValue("launch", "user_modules").split(";", QString::SkipEmptyParts); + customModules.removeAll(moduleInnerName); + resourceMgr()->setValue("launch", "user_modules", customModules.join(";")); + removeModuleInfo(moduleInnerName); +} + /*!On module removing action.*/ void LightApp_Application::onExtRemoving(const QString& title) { @@ -1116,12 +1132,37 @@ void LightApp_Application::onExtRemoving(const QString& title) std::string extName = title.toStdString(); SCRUTE(extName); + // Ask user if he's ready to completely remove an extension and all its modules. + int answer = SUIT_MessageBox::question( + desktop(), + tr("TLT_REMOVE_EXTENSION"), + tr("QUE_REMOVE_EXTENSION").arg(title), + SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, + SUIT_MessageBox::Ok + ); + + if (answer == SUIT_MessageBox::Cancel) + { + MESSAGE("Removing of an extension was cancelled"); + return; // cancelled + } + + if (activeStudy() && activeStudy()->isModified() && !onSaveDoc()) + { + // doc is not saved, or saving cancelled + SUIT_MessageBox::warning( + desktop(), + tr("WRN_WARNING"), tr("WRN_CANCEL_REMOVE_EXTENSION_UNSAVE").arg(title) + ); + + return; + } + // It should be set on the app start auto extRootDir = getenv(salomeAppDir); - ASSERT(extRootDir) if (!extRootDir) { - MESSAGE("Cannot get SALOME_APPLICATION_DIR env variable! Cancel adding selected extensions."); + SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_SALOME_APPLICATION_DIR")); return; } SCRUTE(extRootDir); @@ -1133,13 +1174,16 @@ void LightApp_Application::onExtRemoving(const QString& title) extensionRemover, (char*)"remove_salomex", (char*)"ss", extRootDir, extName.c_str()); if (!removedModules || removedModules == Py_None) { - SUIT_MessageBox::warning(desktop(), tr("WRN_WARNING"), tr("WRN_FAILED_REMOVE_EXTENSION").arg(title) ); + 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(action(ModulesListId)); - ASSERT(moduleAction); + if (!moduleAction) + { + MESSAGE("Cannot get a pointer to LightApp_ModuleAction! Removing from menue and toolbars will skipped."); + } // Module's content was already removed on python remove_salomex call, // then all we do next - just remove UI items. @@ -1147,42 +1191,9 @@ void LightApp_Application::onExtRemoving(const QString& title) { // Get the current module's name auto moduleNameItem = PyList_GetItem(removedModules, pos); - QString moduleInnerName(PyUnicode_AsUTF8(moduleNameItem)); - SCRUTE(moduleInnerName.toStdString()); - - // There is a some confusion point, because now we have a module's 'inner' name - // from the extension's salomexd file. - // But, in the next GUI methods we need to use a module title (user name). - // For example, PYHELLO (inner name) and PyHello (user name to display in GUI). - // Then, from the inner module's name we need to get a user one. - QString moduleUserName = moduleTitle(moduleInnerName); - SCRUTE(moduleUserName.toStdString()); - - // Set current state in modules combo box - // Don't confuse again, because activeModule()->moduleName() returns a module title, not an inner one! - if (activeModule() && activeModule()->moduleName() == moduleUserName) - activateModule(""); - - // Remove from "Modules" menu and toolbar - if (moduleAction) - { - moduleAction->removeModule(moduleUserName); - } - - // Remove Help menu items - removeHelpItems(moduleUserName); - - // Remove Preferences - LightApp_Preferences* prefs = preferences(); - if (prefs) - prefs->removeModule(moduleUserName); + const QString moduleInnerName(PyUnicode_AsUTF8(moduleNameItem)); - // Remove settings - // Here we use an inner module name! - QStringList customModules = resourceMgr()->stringValue("launch", "user_modules").split(";", QString::SkipEmptyParts); - customModules.removeAll(moduleInnerName); - resourceMgr()->setValue("launch", "user_modules", customModules.join(";")); - removeModuleInfo(moduleInnerName); + removeUserModule(moduleInnerName, moduleAction); } // Remove an ext from UI diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 027ca395b..a45ef0c8b 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -332,6 +332,7 @@ protected: private: bool addUserModule( const QString&, const QString&, bool = false ); + void removeUserModule(const QString& moduleInnerName, LightApp_ModuleAction* moduleAction); void emptyPreferences( const QString& ); QList findToolBars( const QStringList& names = QStringList() ); void createHelpItems( const QString& ); diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index e9280a4f0..539ebdbf2 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -1251,6 +1251,28 @@ Continue? WRN_FAILED_REMOVE_EXTENSION Failed to remove a salome extension: %1. + + WRN_SALOME_APPLICATION_DIR + Cannot get SALOME_APPLICATION_DIR env variable! +Cancel current extensions operation. + + + + TLT_REMOVE_EXTENSION + Remove extension + + + QUE_REMOVE_EXTENSION + Do you want to completely remove an extension %1 and all its modules and files? +If you answer "Ok", you may need to save your study before removal. +Continue? + + + + WRN_CANCEL_REMOVE_EXTENSION_UNSAVE + Removing of a salome extension %1 was cancelled because current doc is unsaved. + + LightApp_Module diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index f7ef63c63..da3460b3b 100644 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -1185,6 +1185,28 @@ Le fichier n'existe pas WRN_FAILED_REMOVE_EXTENSION Échec de la suppression d'une extension Salomé: %1. + + WRN_SALOME_APPLICATION_DIR + Impossible d'obtenir la variable d'environnement SALOME_APPLICATION_DIR! +Annulez l'opération d'extensions en cours. + + + + TLT_REMOVE_EXTENSION + Supprimer l'extension + + + QUE_REMOVE_EXTENSION + Voulez-vous supprimer complètement une extension %1 et tous ses modules et fichiers? +Si vous répondez "Ok", vous devrez peut-être enregistrer votre étude avant de la supprimer. +Continuer? + + + + WRN_CANCEL_REMOVE_EXTENSION_UNSAVE + La suppression d'une extension salome %1 a été annulée car la documentation actuelle n'est pas enregistrée. + + WRN_MODULE_BAD_RESDIR Bad or non-existing resources directory: diff --git a/src/LightApp/resources/LightApp_msg_ja.ts b/src/LightApp/resources/LightApp_msg_ja.ts index 5ba010c30..ebda4f5a1 100644 --- a/src/LightApp/resources/LightApp_msg_ja.ts +++ b/src/LightApp/resources/LightApp_msg_ja.ts @@ -1206,15 +1206,37 @@ If you answer "Yes", you may need to save your study before removal. - - - WRN_FAILED_UNPACK_EXTENSION - ファイルからサロメ拡張機能を解凍できませんでした: %1. - - - WRN_FAILED_REMOVE_EXTENSION - サロメ エクステンションの削除に失敗しました: %1. - + + + WRN_FAILED_UNPACK_EXTENSION + ファイルからサロメ拡張機能を解凍できませんでした: %1. + + + WRN_FAILED_REMOVE_EXTENSION + サロメ エクステンションの削除に失敗しました: %1. + + + WRN_SALOME_APPLICATION_DIR + SALOME_APPLICATION_DIR 環境変数を取得できません! +現在の拡張操作をキャンセルします. + + + + TLT_REMOVE_EXTENSION + 拡張子を削除 + + + QUE_REMOVE_EXTENSION + 拡張機能を完全に削除しますか %1 およびそのすべてのモジュールとファイル? +"Ok" と答えた場合、削除する前にスタディを保存する必要があるかもしれません。 +続く? + + + + WRN_CANCEL_REMOVE_EXTENSION_UNSAVE + サロメ拡張の除去 %1 現在のドキュメントが保存されていないため、キャンセルされました。 + + LightApp_Module