コード例 #1
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var agentManager = new AgentManager(lifetime, this);

            agentManager.Initialise();

            // Note, using this lifetime means we get alerts for ALL balloons,
            // not just the current one (i.e. other classes could also create
            // a balloon, and we'd get those clicks, too)
            agent = new Agent(lifetime, agentManager);
            agent.BalloonOptionClicked.Advise(lifetime,
                                              tag => MessageBox.ShowExclamation(string.Format("Clicked: {0}", tag)));
            agent.ButtonClicked.Advise(lifetime,
                                       button => MessageBox.ShowExclamation(string.Format("Clicked button: {0}", button)));

            var character = agent.AgentCharacter.Character;

            Animations.ItemsSource   = character.Animations.OrderBy();
            Animations.SelectedIndex = 0;

            firstTime = true;
        }
コード例 #2
0
        private void CreateXml(TemplateApplicability applicability, IContextBoundSettingsStore bound,
                               string saveDirectoryPath, string version, IDataContext context)
        {
            string      type;
            ScopeFilter scopeFilter = ScopeFilter.Language;

            switch (applicability)
            {
            case TemplateApplicability.Live:
                type = "Live";
                break;

            case TemplateApplicability.Surround:
                type = "Surround";
                break;

            case TemplateApplicability.File:
                type        = "File";
                scopeFilter = ScopeFilter.Project;
                break;

            default: return;
            }

            var topicId   = "Reference__Templates_Explorer__" + type + "_Templates";
            var fileName  = Path.Combine(saveDirectoryPath, topicId + ".xml");
            var topic     = XmlHelpers.CreateHmTopic(topicId);
            var topicRoot = topic.Root;

            topicRoot.Add(new XElement("p",
                                       new XElement("menupath", "ReSharper | Templates Explorer | " + type + " Templates")));

            topicRoot.Add(new XElement("p",
                                       "This section lists all predefined " + type + " templates in ReSharper " + version + "."));

            topicRoot.Add(new XElement("p", XmlHelpers.CreateInclude("Templates__Template_Basics__Template_Types", type)));
            var summaryTable     = XmlHelpers.CreateTable(new[] { "Template", "Description" }, new[] { "20%", "80%" });
            var summaryItems     = new List <Tuple <string, XElement> >();
            var tables           = new Dictionary <string, XElement>();
            var defaultTemplates = context.GetComponent <StoredTemplatesProvider>()
                                   .EnumerateTemplates(bound, applicability, false);

            var myScopeCategoryManager = context.GetComponent <ScopeCategoryManager>();

            foreach (var template in defaultTemplates)
            {
                var templateIdPresentable = !template.Shortcut.IsNullOrEmpty() ? template.Shortcut : template.Description;
                templateIdPresentable = Regex.Replace(templateIdPresentable, "&Enum", "Enum");
                var currentTemplateLangs = new List <string>();
                var imported             = String.Empty;
                var scopeString          = String.Empty;
                var cat = String.Empty;

                foreach (var category in template.Categories)
                {
                    if (category.Contains("Imported"))
                    {
                        imported = category;
                        break;
                    }
                    if (category.Contains("C#"))
                    {
                        cat = "C#";
                    }
                    if (category.Contains("VB.NET"))
                    {
                        cat = "VB.NET";
                    }
                }

                foreach (var point in template.ScopePoints)
                {
                    foreach (var provider in myScopeCategoryManager.GetCoveredProviders(scopeFilter, point))
                    {
                        var lang = provider.CategoryCaption;
                        if (lang == "ASP.NET" && type == "Surround" && !cat.IsNullOrEmpty())
                        {
                            lang = lang + "(" + cat + ")";
                        }
                        if (!lang.IsNullOrEmpty())
                        {
                            currentTemplateLangs.Add(lang);
                            if (!tables.ContainsKey(lang))
                            {
                                tables.Add(lang, XmlHelpers.CreateTable(new[] { "Template", "Details" }, new[] { "20%", "80%" }));
                            }
                        }
                    }

                    if (currentTemplateLangs.Count == 0)
                    {
                        MessageBox.ShowExclamation(String.Format("The '{0}' template has no associated languages",
                                                                 templateIdPresentable));
                    }

                    scopeString += " " + point.PresentableShortName + ",";
                }

                scopeString = scopeString.TrimEnd(',');

                var paramElement = new XElement("list");
                foreach (var param in template.Fields)
                {
                    var expr             = param.Expression as MacroCallExpressionNew;
                    var paramItemElement = new XElement("li", new XElement("code", param.Name));
                    if (expr != null)
                    {
                        var macro = MacroDescriptionFormatter.GetMacroAttribute(expr.Definition);
                        paramItemElement.Add(" - " + macro.LongDescription + " (",
                                             XmlHelpers.CreateHyperlink(macro.Name, "Template_Macros", macro.Name),
                                             ")");
                    }
                    else
                    {
                        paramItemElement.Add(" - " + "no macro");
                    }
                    paramElement.Add(paramItemElement);
                }

                if (template.Text.Contains("$SELECTION$"))
                {
                    paramElement.Add(new XElement("li",
                                                  new XElement("code", "SELECTION"), " - The text selected by the user before invoking the template."));
                }

                if (template.Text.Contains("$END$"))
                {
                    paramElement.Add(new XElement("li",
                                                  new XElement("code", "END"), " - The caret position after the template is applied."));
                }

                var processedLangs = new List <string>();

                foreach (var lang in currentTemplateLangs)
                {
                    if (!processedLangs.Contains(lang))
                    {
                        AddTemplateRow(tables, summaryItems, lang, templateIdPresentable, template, scopeString, paramElement, type,
                                       imported);
                        processedLangs.Add(lang);
                    }
                }
            }

            foreach (var table in tables)
            {
                summaryTable.Add(new XElement("tr",
                                              new XElement("td",
                                                           new XAttribute("colspan", "2"),
                                                           new XElement("b", table.Key))));

                foreach (var item in summaryItems)
                {
                    if (item.Item1 == table.Key)
                    {
                        summaryTable.Add(item.Item2);
                    }
                }

                var langForHeading = table.Key;
                if (langForHeading == "Global")
                {
                    langForHeading = "Global Usage";
                }
                CreateTopicForLang(langForHeading, type, table.Value, saveDirectoryPath, version);
            }

            var indexChapter = XmlHelpers.CreateChapter(String.Format("Index of {0} Templates", type));

            topicRoot.Add(new XComment("Total " + type + " templates: " + summaryItems.Count));
            indexChapter.Add(summaryTable);
            topicRoot.Add(indexChapter);
            topic.Save(fileName);
        }