private void SelectCommand(Ca65Command command)
        {
            if (command == _selected)
            {
                return;
            }
            _selected       = command;
            _adjustControls = new List <Control>();

            var allCommands = Ca65Parser.GetCommands();

            title.Text = string.Join(", ", command.Aliases);
            SuspendLayout();

            descriptionPanel.Controls.Clear();
            for (var i = command.Description.Count - 1; i >= 0; i--)
            {
                var description = command.Description[i];
                var line        = new Label
                {
                    Text        = description.Text,
                    Padding     = new Padding(0, 5, 0, 0),
                    Dock        = DockStyle.Top,
                    AutoSize    = true,
                    MaximumSize = description.CodeExample ? Size.Empty : new Size(descriptionPanel.Width, 0)
                };
                if (!description.CodeExample)
                {
                    _adjustControls.Add(line);
                }
                if (description.CodeExample)
                {
                    line.Font = _codeFont;
                }
                descriptionPanel.Controls.Add(line);
            }

            seeAlsoContainer.Visible = command.SeeAlso.Count > 0;
            seeAlsoPanel.Controls.Clear();
            foreach (var reference in command.SeeAlso)
            {
                var label = new LinkLabel {
                    Text = reference, AutoSize = true
                };
                if (allCommands.ContainsKey(reference))
                {
                    label.Click += (a, s) => SelectCommand(allCommands[reference]);
                }
                seeAlsoPanel.Controls.Add(label);
            }

            ResumeLayout();
        }
Esempio n. 2
0
        public static Dictionary <string, Ca65Command> GetCommands()
        {
            if (_list != null)
            {
                return(_list);
            }

            _list = new Dictionary <string, Ca65Command>();
            var html = new HtmlDocument();

            html.LoadHtml(Resources.ca65);
            var header     = html.DocumentNode.SelectSingleNode("//a[@name='pseudo-variables']").ParentNode;
            var lastHeader = html.DocumentNode.SelectSingleNode("//a[@name='macros']").ParentNode;

            while ((header = header.SelectSingleNode("./following-sibling::h2")) != lastHeader)
            {
                var commandHeader = header.SelectSingleNode(".//code");
                if (commandHeader == null)
                {
                    continue;
                }
                var ca65Command = new Ca65Command();
                var commands    = commandHeader.InnerText.Trim().Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var command in commands.Where(c => c.StartsWith(".")))
                {
                    ca65Command.Aliases.Add(command);
                    _list[command] = ca65Command;
                }

                if (ca65Command.Aliases.Count == 0)
                {
                    continue;
                }

                var descriptionNode = header;
                while ((descriptionNode = descriptionNode.SelectSingleNode("./following-sibling::*")).Name != "h2")
                {
                    var text = _cleanText.Replace(descriptionNode.InnerText, " ").Trim();
                    if (string.IsNullOrWhiteSpace(text))
                    {
                        continue;
                    }

                    if (text.StartsWith("See also") || text.StartsWith("See:"))
                    {
                        foreach (var referenceNode in descriptionNode.SelectNodes(".//a"))
                        {
                            if (referenceNode.InnerText.Trim().StartsWith("."))
                            {
                                ca65Command.SeeAlso.Add(referenceNode.InnerText.Trim());
                            }
                        }
                        continue;
                    }

                    var isCode = descriptionNode.Name == "blockquote";
                    ca65Command.Description.Add(new Ca65CommandDescription
                    {
                        Text        = isCode ? descriptionNode.SelectSingleNode(".//pre").InnerText : text,
                        CodeExample = isCode
                    });
                }
            }

            return(_list);
        }