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<std::pair<QString, QString>> SUIT_ShortcutContainer::setShortcut(QString theModuleID, const QString& theInModuleActionID, const QKeySequence& theKeySequence, bool theOverride)
{
if (!SUIT_ShortcutMgr::isModuleIDValid(theModuleID)) {
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.");
}
}
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<bool, QKeySequence> SUIT_ShortcutHistorian::getOldUserDefinedKeySequence(const QString& theActionID) const
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.");
std::set<QString> 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.
/*! \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:
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<bool, QKeySequence> 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();
/** {sectionNamePrefixOld, shortcutContainer}[]. */
std::map<QString, SUIT_ShortcutContainer> myShortcutContainers;
+
+ /** Merged myShortcutContainers. Merge is performed from the oldest to the newest, newer shortcuts override older ones. */
+ SUIT_ShortcutContainer myShortcutContainer;
};
"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"
}
}
]