//------------ Load User Shortcuts --------------

        public void ExecuteImportShortcuts()
        {
            // Let user browse for a .vssettings file to import. Default to the last file saved.
            string chosenFile = BrowseForVsSettingsFile();

            if (chosenFile == null || !File.Exists(chosenFile))
            {
                // No file chosen. Possibly Cancel or ESC pressed.
                return;
            }
            if (!(Path.GetExtension(chosenFile).Equals(".vssettings", StringComparison.InvariantCultureIgnoreCase) ||
                  Path.GetExtension(chosenFile).Equals(".xml", StringComparison.InvariantCultureIgnoreCase)))
            {
                MessageBox.Show($"The chosen file is not a valid Visual Studio settings file.\n\nPlease chose a 'vssettings' file or 'xml' file.", MSG_CAPTION_IMPORT);
                return;
            }

            // Parse the XML of the VSSettings file
            XDocument         vsSettingsXDoc = XDocument.Load(chosenFile);
            List <VSShortcut> shortcutList   = ParseVSSettingsFile(vsSettingsXDoc);

            // Launch the Import Shortcuts window
            ImportShortcuts window = new ImportShortcuts(chosenFile, vsSettingsXDoc, shortcutList);

            window.ShowModal();
        }
Exemplo n.º 2
0
        //------------ Load User Shortcuts --------------

        public void ExecuteImportShortcuts()
        {
            // Let user browse for a .vssettings file to import. Default to the last file saved.
            string chosenFile = BrowseForVsSettingsFile();

            if (chosenFile == null || !File.Exists(chosenFile))
            {
                // No file chosen. Possibly Cancel or ESC pressed.
                return;
            }
            if (!(Path.GetExtension(chosenFile).Equals(".vssettings", StringComparison.InvariantCultureIgnoreCase) ||
                  Path.GetExtension(chosenFile).Equals(".xml", StringComparison.InvariantCultureIgnoreCase)))
            {
                MessageBox.Show($"The chosen file is not a valid Visual Studio settings file.\n\nPlease chose a 'vssettings' file or 'xml' file.", MSG_CAPTION_IMPORT);
                return;
            }

            XDocument vsSettingsFile = XDocument.Load(chosenFile);
            var       shortcutList   = ParseVSSettingsFile(vsSettingsFile);
            var       window         = new ImportShortcuts(shortcutList);

            window.ShowModal();
            if (!window.isCancelled)
            {
                var removeList = window.GetUncheckedShortcuts();
                var newFile    = UpdateAndSaveNewSettingsFile(vsSettingsFile, removeList);
                LoadKeyboardShortcutsFromVSSettingsFile(newFile);
                try
                {
                    File.Delete(newFile);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Unable to delete temporary settings file: {0}", e.ToString());
                }

                AddUserShortcutsFileToRegistry(chosenFile);
            }
        }