private List <VSShortcut> ParseVSSettingsFile(XDocument vsSettingsFile) { VSShortcutQueryEngine engine = new VSShortcutQueryEngine(ServiceProvider); var userShortcuts = vsSettingsFile.Descendants("UserShortcuts"); var shortcutList = new List <VSShortcut>(); foreach (var userShortcut in userShortcuts) { foreach (var shortcut in userShortcut.Descendants("Shortcut")) { var scope = engine.GetScopeByName(shortcut.Attribute("Scope").Value); var sequences = engine.GetBindingSequencesFromBindingString(shortcut.Value); var conflictTexts = new List <string>(); ThreadHelper.JoinableTaskFactory.Run(async() => { var conflicts = await engine.GetConflictsAsync(scope, sequences); foreach (var conflict in conflicts) { foreach (var binding in conflict.AffectedBindings) { conflictTexts.Add($"[{binding.Item1.Scope.Name}] {binding.Item2.CanonicalName} ({binding.Item1.OriginalDTEString})"); } } }); shortcutList.Add(new VSShortcut { Command = shortcut.Attribute("Command").Value, Scope = shortcut.Attribute("Scope").Value, Shortcut = shortcut.Value, Conflicts = conflictTexts }); } } return(shortcutList); }
private List <string> GetConflictListText(string scopeText, string shortcutText) { // Convert text to objects KeybindingScope scope = queryEngine.GetScopeByName(scopeText); IEnumerable <BindingSequence> sequences = queryEngine.GetBindingSequencesFromBindingString(shortcutText); // Get all conflicts for the given Scope/Shortcut (as objects) IEnumerable <BindingConflict> conflicts = GetAllConflictObjects(scope, sequences); // Add the localized text for each conflict to a list and return it. return(ConvertToLocalizedTextList(conflicts)); }
/// <summary> /// Parse the XML elemenent into a valid VSShortcuts object. /// /// Note: Deliberately NOT parsing the Command text. We will display the command text /// unparsed and allow it to fail at the time of import. Not all commands will always /// be available on a user's instance of VS. But it's good to show that the VSSettings /// file did include the shortcut for it. /// </summary> private VSShortcut CreateShortcutItem(XElement shortcut) { // Read values from XML definitions string operationType = shortcut.Name.LocalName; string scopeText = shortcut.Attribute("Scope").Value; string commandText = shortcut.Attribute("Command").Value; string shortcutText = shortcut.Value; // Parse the Operation type (Add or Remove shortcut) if (!ShortcutOperations.ContainsKey(operationType)) { Debug.WriteLine("Ignoring UserShortcut element: " + operationType + " with value: " + shortcut.Value); return(null); } string operationDisplayName = ShortcutOperations[operationType]; // Parse the text into known objects. Abort if text is not recognized. KeybindingScope scope = queryEngine.GetScopeByName(scopeText); if (scope == null) { Debug.WriteLine("Unable to parse scopeText: " + scopeText); return(null); } // Parse the shortcut key combinations IEnumerable <BindingSequence> sequences = queryEngine.GetBindingSequencesFromBindingString(shortcutText); if (sequences == null) { Debug.WriteLine("Unable to parse shortcutText: " + shortcutText); return(null); } // Prepare the conflict list List <string> conflictList = GetConflictListText(scope, sequences); return(new VSShortcut { Operation = operationDisplayName, Command = commandText, Scope = scopeText, Shortcut = shortcutText, Conflicts = conflictList }); }