From 9634ffa4994baa8a4c59baf4a8a0ec6b917f2bdf Mon Sep 17 00:00:00 2001 From: dish Date: Wed, 27 Nov 2024 02:42:47 +0000 Subject: [PATCH] TMP --- src/LightApp/resources/LightApp.xml | 3 + src/SUIT/SUIT_ShortcutMgr.cxx | 61 +++++++++++++++++++++ src/SUIT/SUIT_ShortcutMgr.h | 16 +++++- src/SUIT/resources/action_id_mutations.json | 8 ++- 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 5e0d3cbf8..70869070a 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -253,6 +253,9 @@
+
+ +
diff --git a/src/SUIT/SUIT_ShortcutMgr.cxx b/src/SUIT/SUIT_ShortcutMgr.cxx index ecd6c64af..99857e3c0 100644 --- a/src/SUIT/SUIT_ShortcutMgr.cxx +++ b/src/SUIT/SUIT_ShortcutMgr.cxx @@ -569,6 +569,16 @@ std::set SUIT_ShortcutContainer::getIDsOfAllModules() const return res; } +bool SUIT_ShortcutContainer::isEmpty() const +{ + for (const auto& moduleIDAndShortcuts : myShortcutsInversed) { + const auto& moduleShortcutsInversed = moduleIDAndShortcuts.second; + if (!moduleShortcutsInversed.empty()) + return false; + } + return true; +} + std::set> SUIT_ShortcutContainer::setShortcut(QString theModuleID, const QString& theInModuleActionID, const QKeySequence& theKeySequence, bool theOverride) { if (!SUIT_ShortcutMgr::isModuleIDValid(theModuleID)) { @@ -1526,6 +1536,19 @@ SUIT_ShortcutMgr::~SUIT_ShortcutMgr() myShortcutMgr = new SUIT_ShortcutMgr(); myShortcutMgr->setAssetsFromResources(); myShortcutMgr->setShortcutsFromPreferences(); + + { // Migrate old shortcut preferences. + SUIT_ShortcutHistorian historian; + myShortcutMgr->mergeShortcutContainer( + historian.getContainerWithOldShortcuts(), + true /*theOverride*/, + false /*theTreatAbsentIncomingAsDisabled*/, + true /*theSaveToPreferences*/ + ); + + historian.removeOldShortcutPreferences(); + } + ShCutDbg("SUIT_ShortcutMgr initialization has finished."); } } @@ -3491,6 +3514,24 @@ SUIT_ShortcutHistorian::SUIT_ShortcutHistorian() { SUIT_ShortcutMgr::fillContainerFromPreferences(container, false, oldPrefix); } ShCutDbg("SUIT_ShortcutHistorian: parsing of old shortcut preference sections finished."); + + for (auto itPrefix = SUIT_ShortcutHistorian::SECTION_PREFIX_EVOLUTION.rbegin(); itPrefix != SUIT_ShortcutHistorian::SECTION_PREFIX_EVOLUTION.rend(); itPrefix++) { + const auto itPrefixAndContainer = myShortcutContainers.find(*itPrefix); + if (itPrefixAndContainer == myShortcutContainers.end()) + continue; + + myShortcutContainer.merge(itPrefixAndContainer->second, true /*theOverride*/, false /*theTreatAbsentIncomingAsDisabled*/); + } +} + +bool SUIT_ShortcutHistorian::doOldShortcutPreferencesExist() const +{ + for (const auto& prefixAndContainer : myShortcutContainers) { + const auto& container = prefixAndContainer.second; + if (!container.isEmpty()) + return true; + } + return false; } std::pair SUIT_ShortcutHistorian::getOldUserDefinedKeySequence(const QString& theActionID) const @@ -3514,6 +3555,26 @@ std::pair SUIT_ShortcutHistorian::getOldUserDefinedKeySequen return result; } +void SUIT_ShortcutHistorian::removeOldShortcutPreferences() +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + if (!resMgr) { + Warning("SUIT_ShortcutHistorian: can't retrieve resource manager!"); + return; + } + + for (const auto& prefixAndContainer : myShortcutContainers) { + const auto& sectionNamePrefix = prefixAndContainer.first; + const auto& container = prefixAndContainer.second; + + const auto& moduleIDs = container.getIDsOfAllModules(); + for (const QString& moduleID : moduleIDs) { + const QString sectionName = sectionNamePrefix + resMgr->sectionsToken() + moduleID; + resMgr->remove(sectionName); // TODO Check if SUIT_ResourceMgr really removes sections from preference files, not just from its fields. + } + } +} + void SUIT_ShortcutHistorian::parseMutations() { ShCutDbg() && ShCutDbg("Parsing action ID mutation files."); diff --git a/src/SUIT/SUIT_ShortcutMgr.h b/src/SUIT/SUIT_ShortcutMgr.h index 32e59a86b..2a138d0a3 100644 --- a/src/SUIT/SUIT_ShortcutMgr.h +++ b/src/SUIT/SUIT_ShortcutMgr.h @@ -76,6 +76,9 @@ public: std::set getIDsOfAllModules() const; + /*! \returns True, if no shortcut is added. */ + bool isEmpty() const; + /*! \brief Checks for conflicts. If theOverride, modifies incoming and disables all conflicting shortcuts. Redefining a key sequence for the action, if theKeySequence does not conflict with other shortcuts, is not considered as a conflict. \param theModuleID The method has no effect if theModuleID is invalid. \ref See SUIT_ShortcutMgr::isModuleIDValid(const QString&) for details. @@ -830,7 +833,7 @@ private: /*! \returns True, if both old and new prefixes are the same as ones of theOther. */ bool isConcurrent(const AIDSMutation& theOther) const; - /*! \returns True. if mutation maps are extended. */ + /*! \returns True, if mutation maps are augmented. */ bool merge(const AIDSMutation& theOther); private: @@ -850,11 +853,19 @@ private: public: SUIT_ShortcutHistorian(); + /*! \returns True, if myShortcutContainers has at least one shortcut. */ + bool doOldShortcutPreferencesExist() const; + /*! \param theActionID Action ID in latest version (as elsewhere in ShortcutMgr code). \returns {false, _ }, if shortcut is not defined in any outdated shortcut section of user preference files. */ std::pair getOldUserDefinedKeySequence(const QString& theActionID) const; + const SUIT_ShortcutContainer& getContainerWithOldShortcuts() const { return myShortcutContainer; }; + + /*! \brief Removes old shortcut sections from preference files and clears myShortcutContainers. */ + void removeOldShortcutPreferences(); + private: void parseMutations(); @@ -869,6 +880,9 @@ private: /** {sectionNamePrefixOld, shortcutContainer}[]. */ std::map myShortcutContainers; + + /** Merged myShortcutContainers. Merge is performed from the oldest to the newest, newer shortcuts override older ones. */ + SUIT_ShortcutContainer myShortcutContainer; }; diff --git a/src/SUIT/resources/action_id_mutations.json b/src/SUIT/resources/action_id_mutations.json index eec74dc08..8092ece62 100644 --- a/src/SUIT/resources/action_id_mutations.json +++ b/src/SUIT/resources/action_id_mutations.json @@ -4,7 +4,13 @@ "sectionPrefixOld": "shortcuts", "sectionPrefixNew": "shortcuts_vA1.0", "newToOldActionIDMap": { - + "File/Close" : "TOT_DESK_FILE_CLOSE", + "File/Exit" : "TOT_DESK_FILE_EXIT", + "File/New" : "TOT_DESK_FILE_NEW", + "File/Open" : "TOT_DESK_FILE_OPEN", + "File/Preferences" : "PRP_DESK_PREFERENCES", + "File/Save" : "TOT_DESK_FILE_SAVE", + "File/SaveAs" : "TOT_DESK_FILE_SAVEAS" } } ] -- 2.39.2