diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp index 1b95071bb3f4..e641efe9a757 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp @@ -210,7 +210,7 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector(secondKeyOfChord)), tempShortcut); + } + else if (operationType == 2) + { + auto secondKeyOfChord = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, 0); + auto tempShortcut = Shortcut(newRemapKeys.c_str()); + tempShortcut.operationType = Shortcut::OperationType::OpenURI; + tempShortcut.uriToOpen = it.GetObjectW().GetNamedString(KeyboardManagerConstants::ShortcutOpenURI, L""); + + AddAppSpecificShortcut(targetApp.c_str(), Shortcut(originalKeys.c_str(), static_cast(secondKeyOfChord)), tempShortcut); + } if (!newRemapKeys.empty()) { @@ -268,7 +306,6 @@ bool MappingConfiguration::LoadShortcutRemaps(const json::JsonObject& jsonData, auto originalKeys = it.GetObjectW().GetNamedString(KeyboardManagerConstants::OriginalKeysSettingName); auto newRemapKeys = it.GetObjectW().GetNamedString(KeyboardManagerConstants::NewRemapKeysSettingName, {}); auto newRemapText = it.GetObjectW().GetNamedString(KeyboardManagerConstants::NewTextSettingName, {}); - //auto isRunProgram = it.GetObjectW().GetNamedBoolean(KeyboardManagerConstants::IsRunProgramSettingName, false); auto operationType = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::ShortcutOperationType, 0); if (operationType == 1) @@ -515,7 +552,33 @@ bool MappingConfiguration::SaveSettingsToFile() // For shortcut to shortcut remapping else if (itKeys.second.targetShortcut.index() == 1) { - keys.SetNamedValue(KeyboardManagerConstants::NewRemapKeysSettingName, json::value(std::get(itKeys.second.targetShortcut).ToHstringVK())); + auto targetShortcut = std::get(itKeys.second.targetShortcut); + + //keys.SetNamedValue(KeyboardManagerConstants::IsRunProgramSettingName, json::value(targetShortcut.isRunProgram)); + + if (targetShortcut.operationType == Shortcut::OperationType::RunProgram) + { + keys.SetNamedValue(KeyboardManagerConstants::RunProgramElevationLevelSettingName, json::value(static_cast(targetShortcut.elevationLevel))); + keys.SetNamedValue(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, json::value(static_cast(itKeys.first.secondKey))); + keys.SetNamedValue(KeyboardManagerConstants::ShortcutOperationType, json::value(static_cast(targetShortcut.operationType))); + + keys.SetNamedValue(KeyboardManagerConstants::RunProgramFilePathSettingName, json::value(targetShortcut.runProgramFilePath)); + keys.SetNamedValue(KeyboardManagerConstants::RunProgramArgsSettingName, json::value(targetShortcut.runProgramArgs)); + keys.SetNamedValue(KeyboardManagerConstants::RunProgramStartInDirSettingName, json::value(targetShortcut.runProgramStartInDir)); + } + else if (targetShortcut.operationType == Shortcut::OperationType::OpenURI) + { + keys.SetNamedValue(KeyboardManagerConstants::RunProgramElevationLevelSettingName, json::value(static_cast(targetShortcut.elevationLevel))); + keys.SetNamedValue(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, json::value(static_cast(itKeys.first.secondKey))); + keys.SetNamedValue(KeyboardManagerConstants::ShortcutOperationType, json::value(static_cast(targetShortcut.operationType))); + + keys.SetNamedValue(KeyboardManagerConstants::ShortcutOpenURI, json::value(targetShortcut.uriToOpen)); + } + else + { + keys.SetNamedValue(KeyboardManagerConstants::ShortcutOperationType, json::value(static_cast(targetShortcut.operationType))); + keys.SetNamedValue(KeyboardManagerConstants::NewRemapKeysSettingName, json::value(std::get(itKeys.second.targetShortcut).ToHstringVK())); + } } else if (itKeys.second.targetShortcut.index() == 2) { diff --git a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs index c6cf7d13b336..41bf5f04b9ab 100644 --- a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs +++ b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs @@ -319,8 +319,23 @@ public static string GetRegSettingsBackupAndRestoreRegItem(string itemName) // the settings file needs to be updated, update the real one with non-excluded stuff... Logger.LogInfo($"Settings file {currentFile.Key} is different and is getting updated from backup"); - var newCurrentSettingsFile = JsonMergeHelper.Merge(File.ReadAllText(currentSettingsFiles[currentFile.Key]), settingsToRestoreJson); - File.WriteAllText(currentSettingsFiles[currentFile.Key], newCurrentSettingsFile); + var overwrite = false; + if (backupRestoreSettings["CustomRestoreSettings"] != null && backupRestoreSettings["CustomRestoreSettings"][currentFile.Key] != null) + { + var customRestoreSettings = backupRestoreSettings["CustomRestoreSettings"][currentFile.Key]; + overwrite = customRestoreSettings["overwrite"] != null && (bool)customRestoreSettings["overwrite"]; + } + + if (overwrite) + { + File.WriteAllText(currentSettingsFiles[currentFile.Key], settingsToRestoreJson); + } + else + { + var newCurrentSettingsFile = JsonMergeHelper.Merge(File.ReadAllText(currentSettingsFiles[currentFile.Key]), settingsToRestoreJson); + File.WriteAllText(currentSettingsFiles[currentFile.Key], newCurrentSettingsFile); + } + anyFilesUpdated = true; } } diff --git a/src/settings-ui/Settings.UI.Library/backup_restore_settings.json b/src/settings-ui/Settings.UI.Library/backup_restore_settings.json index 1863ed457505..84a03db71379 100644 --- a/src/settings-ui/Settings.UI.Library/backup_restore_settings.json +++ b/src/settings-ui/Settings.UI.Library/backup_restore_settings.json @@ -26,6 +26,11 @@ ] } ], + "CustomRestoreSettings": { + "\\Keyboard Manager\\default.json": { + "overwrite": true + } + }, "IgnoredSettings": { "backup-restore_settings.json": [ "RestartAfterRestore"