public bool LoadKeyboardShortcutsFromVSSettingsFile(string importFilePath) { if (!File.Exists(importFilePath)) { MessageBox.Show($"File does not exist: {importFilePath}", MSG_CAPTION_IMPORT); return(false); } // Handle the change in mapping scheme, if there is one. string preloadMappingScheme = GetMappingScheme(); // Import the User Shortcuts from the .vssettings file IVsProfileSettingsTree importShortcutsSettingsTree = GetShortcutsSettingsTreeForImport(importFilePath); if (!ImportSettingsFromSettingsTree(importShortcutsSettingsTree)) { return(false); } MessageBox.Show($"Keyboard shortcuts successfully imported!", MSG_CAPTION_IMPORT); // Now check if the mapping scheme changed. If so, alert the user and offer to revert it. RevertMappingSchemeIfRequired(preloadMappingScheme); return(true); }
public void Setup() { _manager = Mock.Create <IVsProfileDataManager>(); _errorInformation = Mock.Create <IVsSettingsErrorInformation>(); _files = Mock.Create <IVsProfileSettingsFileCollection>(); _xmlRepository = Mock.Create <IXmlRepository>(); _settingsFileInfo = Mock.Create <IVsProfileSettingsFileInfo>(); _sets = Mock.Create <IVsProfileSettingsTree>(); }
private static bool ImportSettingsFromSettingsTree(IVsProfileSettingsTree profileSettingsTree) { //EnableKeyboardOnlyInProfileSettingsTree(profileSettingsTree); IVsProfileDataManager vsProfileDataManager = (IVsProfileDataManager)Package.GetGlobalService(typeof(SVsProfileDataManager)); int result = vsProfileDataManager.ImportSettings(profileSettingsTree, out IVsSettingsErrorInformation errorInfo); if (ErrorHandler.Failed(result)) { // Something went wrong. TODO: Handle error. MessageBox.Show("Error occurred attempting to import settings."); return(false); } return(true); }
private static void EnableKeyboardOnlyInProfileSettingsTree(IVsProfileSettingsTree profileSettingsTree) { // Disable all settings profileSettingsTree.SetEnabled(0, 1); // Enable Keyboard settings profileSettingsTree.FindChildTree("Environment_Group\\Environment_KeyBindings", out IVsProfileSettingsTree keyboardSettingsTree); if (keyboardSettingsTree != null) { int enabledValue = 1; // true int setChildren = 0; // true (redundant) keyboardSettingsTree.SetEnabled(enabledValue, setChildren); } return; }
public static void LoadKeyboardShortcutsFromVSSettingsFile(string importFilePath) { if (!File.Exists(importFilePath)) { MessageBox.Show($"File does not exist: {importFilePath}", MSG_CAPTION_IMPORT); return; } IVsProfileSettingsTree importShortcutsSettingsTree = GetShortcutsSettingsTreeForImport(importFilePath); bool success = ImportSettingsFromSettingsTree(importShortcutsSettingsTree); if (success) { MessageBox.Show($"Keyboard shortcuts successfully imported!", MSG_CAPTION_IMPORT); } }
//-------- Backup Shortcuts -------- public void ExecuteSaveShortcuts() { // Confirm Save operation //if (MessageBox.Show("Save current keyboard shortcuts?", MSG_CAPTION_BACKUP, MessageBoxButtons.OKCancel) != DialogResult.OK) //{ // return; //} IVsProfileDataManager vsProfileDataManager = (IVsProfileDataManager)ServiceProvider.GetService(typeof(SVsProfileDataManager)); // Generate default path for saving shortcuts // e.g. c:\users\justcla\appdata\local\microsoft\visualstudio\15.0_cf83efb8exp\Settings\Exp\CurrentSettings-2017-12-27-1.vssettings string uniqueExportPath = GetExportFilePath(vsProfileDataManager); string userExportPath = Path.GetDirectoryName(uniqueExportPath); string uniqueFilename = Path.GetFileNameWithoutExtension(uniqueExportPath); string fileExtension = Path.GetExtension(uniqueExportPath); // Open UI to let user name the file string shortcutsName = uniqueFilename; if (!SaveShortcuts.GetShortcutsName(ref shortcutsName)) { // Cancel or ESC pressed return; } // Construct the filename where the vssettings file will be saved string saveFilePath = Path.Combine(userExportPath, $"{shortcutsName}{fileExtension}"); // Check if file already exists if (File.Exists(saveFilePath)) { // Prompt to overwrite if (MessageBox.Show($"The settings file already exists {saveFilePath}\n\nDo you want to replace this file?", MSG_CAPTION_SAVE_SHORTCUTS, MessageBoxButtons.YesNo) != DialogResult.Yes) { // Duplicate file. User does not want to overwrite. Exit out. // TODO: Consider returning the user to the file name dialog. return; } } // Check if name already used if (userShortcutsManager.HasUserShortcuts(shortcutsName)) { // Prompt to overwrite if (MessageBox.Show($"Settings already exist with the name: {saveFilePath}\n\nDo you want to replace these settings?", MSG_CAPTION_SAVE_SHORTCUTS, MessageBoxButtons.YesNo) != DialogResult.Yes) { // Duplicate file. User does not want to overwrite. Exit out. // TODO: Consider returning the user to the file name dialog. return; } } // Do the export IVsProfileSettingsTree keyboardOnlyExportSettings = GetShortcutsSettingsTreeForExport(vsProfileDataManager); int result = vsProfileDataManager.ExportSettings(saveFilePath, keyboardOnlyExportSettings, out IVsSettingsErrorInformation errorInfo); if (result != VSConstants.S_OK) { // Something went wrong. TODO: Handle error. MessageBox.Show($"Oops.... Something went wrong trying to export settings to the following file:\n\n{saveFilePath}", MSG_CAPTION_SAVE_SHORTCUTS); return; } // Save Backup file path to SettingsManager and to UserShortcutsRegistry SaveBackupFilePath(saveFilePath); AddUserShortcutsFileToRegistry(saveFilePath); // Report success string Text = $"Your keyboard shortcuts have been saved to the following file:\n\n{saveFilePath}"; MessageBox.Show(Text, MSG_CAPTION_SAVE_SHORTCUTS, MessageBoxButtons.OK); }