Example #1
0
        protected override string GenerateContent(IDataContext context, string outputFolder)
        {
            var shortcutsXmlDoc  = new XDocument();
            var actionMapElement = new XElement("Keymap");

            shortcutsXmlDoc.Add(actionMapElement);
            XmlHelpers.AddAutoGenComment(shortcutsXmlDoc.Root);

            const string menuPathLibId      = "Menupath_by_ID";
            var          menuPathLibrary    = XmlHelpers.CreateHmTopic(menuPathLibId);
            const string accessIntroLibId   = "AccessIntro_by_ID";
            var          accessIntroLibrary = XmlHelpers.CreateHmTopic(accessIntroLibId);

            var actionManager = context.GetComponent <IActionManager>();

            var productcatalogs = context.GetComponent <IPartCatalogSet>();
            var actionParts     = PartSelector.LeafsAndHides.SelectParts(
                productcatalogs.Catalogs.SelectMany(catalog => catalog.GetPartsWithAttribute <ActionAttribute>().ToEnumerable()))
                                  .ToList();

            foreach (PartCatalogType actionPart in actionParts)
            {
                var attributes = actionPart.GetPartAttributes <ActionAttribute>();

                if (attributes.Count == 0)
                {
                    Assertion.Fail("{0} has no ActionAttribute", actionPart);
                }

                if (attributes.Count > 1)
                {
                    Assertion.Fail("{0} has {1} ActionAttribute annotations. Only one annotation is supported.",
                                   actionPart, attributes.Count);
                }

                PartCatalogAttribute attribute = attributes.GetItemAt(0);
                var actionId =
                    (attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_ActionId].GetStringValueIfDefined() ??
                     StringSource.Empty).ToRuntimeString();
                if (actionId.IsEmpty())
                {
                    actionId = ActionDefines.GetIdFromName(actionPart.LocalName);
                }
                var actionText =
                    (attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_Text].GetStringValueIfDefined() ??
                     StringSource.Empty).ToRuntimeString();
                if (actionText.IsEmpty())
                {
                    actionText = actionId;
                }
                actionText = actionText.Replace("&", String.Empty);
                var vsShortcuts =
                    attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_VsShortcuts].GetArrayValueIfDefined();
                var ideaShortcuts =
                    attribute.ArgumentsOptional[ActionAttribute.ActionAttribute_IdeaShortcuts].GetArrayValueIfDefined();
                if (actionId.Equals("CompleteCodeBasic"))
                {
                    vsShortcuts = new object[] { "Control+Space" }
                }
                ;
                if (actionId.Equals("CompleteStatement"))
                {
                    vsShortcuts = new object[] { "Control+Shift+Enter" }
                }
                ;
                if (actionId.Equals("CompleteCodeBasic"))
                {
                    ideaShortcuts = new object[] { "Control+Space" }
                }
                ;
                if (actionId.Equals("CompleteStatement"))
                {
                    ideaShortcuts = new object[] { "Control+Shift+Enter" }
                }
                ;
                string pathToTheRoot;
                try
                {
                    pathToTheRoot =
                        (context.GetComponent <ActionPresentationHelper>()
                         .GetPathPresentationToRoot(actionManager.Defs.GetActionDefById(actionId)));
                }
                catch (Exception e)
                {
                    pathToTheRoot = "";
                }
                if (!pathToTheRoot.IsEmpty() && !actionText.IsEmpty())
                {
                    pathToTheRoot = pathToTheRoot.Replace('→', '|') + " | " + actionText;
                }
                var actionElement = new XElement("Action");
                var pattern       = new Regex("[_.]");

                actionId = pattern.Replace(actionId, String.Empty);

                actionElement.Add(
                    new XAttribute("id", actionId),
                    new XAttribute("title", actionText),
                    new XAttribute("menupath", pathToTheRoot));
                var accessIntroChunk   = XmlHelpers.CreateChunk(actionId);
                var accessIntroWrapper = new XElement("p");
                if (!pathToTheRoot.IsNullOrEmpty())
                {
                    var menupPathChunk = XmlHelpers.CreateChunk(actionId);
                    pathToTheRoot =
                        pathToTheRoot.Replace("ReSharper | Navigate ", "%navigateMenu%")
                        .Replace("ReSharper | Windows ", "%windowsMenu%");
                    menupPathChunk.Add(new XElement("menupath", pathToTheRoot));
                    accessIntroWrapper.Add(new XElement("menupath", pathToTheRoot));
                    accessIntroWrapper.Add(new XElement("br"));
                    menuPathLibrary.Root.Add(menupPathChunk);
                }
                if (ideaShortcuts != null || vsShortcuts != null)
                {
                    accessIntroWrapper.Add(new XElement("shortcut", new XAttribute("key", actionId)));
                    accessIntroWrapper.Add(new XElement("br"));
                }
                accessIntroWrapper.Add(new XElement("code", String.Format("ReSharper_{0}", actionId),
                                                    new XAttribute("product", "rs,dcv")));
                accessIntroChunk.Add(accessIntroWrapper);
                accessIntroLibrary.Root.Add(accessIntroChunk);

                AddShortcuts(ideaShortcuts, actionElement, "rs");
                AddShortcuts(vsShortcuts, actionElement, "vs");

                if (actionId == "ParameterInfoShow")
                {
                    actionElement.Add(new XElement("Shortcut", "Control+Shift+Space", new XAttribute("layout", "vs")));
                }
                if (actionId == "GotoDeclaration")
                {
                    actionElement.Add(new XElement("Shortcut", "F12", new XAttribute("layout", "vs")));
                }
                if (actionId == "GotoImplementation")
                {
                    actionElement.Add(new XElement("Shortcut", "Ctrl+F12", new XAttribute("layout", "vs")));
                }
                // TODO: check if this hack works

                actionMapElement.Add(actionElement);
            }

            shortcutsXmlDoc.Save(Path.Combine(outputFolder, "keymap.xml"));
            menuPathLibrary.Save(Path.Combine(outputFolder, menuPathLibId + ".xml"));
            accessIntroLibrary.Save(Path.Combine(outputFolder, accessIntroLibId + ".xml"));
            return("Shortcuts and actions");
        }