예제 #1
0
        public static CodeSnippet FromFile(string aFile)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(aFile);
            CodeSnippet ret = new CodeSnippet();
            ret.Name = doc.DocumentElement.GetAttribute("name");
            ret.Extension = doc.DocumentElement.GetAttribute("extension");

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("option"))
            {
                CodeSnippetOption opt = new CodeSnippetOption { Name = elem.GetAttribute("name"), Key = elem.GetAttribute("key") };
                ret.Inputs.Add(opt);
            }

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("input")) {
                CodeSnippetInput input = new CodeSnippetInput();
                input.Name = elem.GetAttribute("name");
                input.Key = elem.GetAttribute("key");
                ret.Inputs.Add(input);
            }
            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("code")) {
                string requires = elem.GetAttribute("requires");
                if (requires != null && requires.Length > 0)
                {
                    ret.Code.Add(new CodeBlock { Code = elem.InnerText, Requires = requires.Split(' ') });
                }
                else
                    ret.Code.Add(new CodeBlock { Code = elem.InnerText, Requires = null });
            }
            return ret;
        }
예제 #2
0
        private void snippetCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            snippetInputs.Children.Clear();
            inputs_.Clear();
            CodeSnippet snip = snippetCombo.SelectedItem as CodeSnippet;

            foreach (CodeSnippetInput input in snip.Inputs)
            {
                StackPanel pnl = new StackPanel {
                    Orientation = Orientation.Horizontal
                };
                if (input is CodeSnippetOption)
                {
                    CheckBox cb = new CheckBox {
                        Content = input.Name, Margin = new Thickness(5.0), Tag = input.Key
                    };
                    cb.Checked += cb_Checked;
                    pnl.Children.Add(cb);
                }
                else
                {
                    Label lbl = new Label {
                        Content = input.Name, Margin = new Thickness(5.0)
                    };
                    TextBox tb = new TextBox {
                        Tag = input.Name, MinWidth = 160
                    };
                    tb.TextChanged += tb_TextChanged;
                    pnl.Children.Add(lbl);
                    pnl.Children.Add(tb);
                }
                snippetInputs.Children.Add(pnl);
            }
        }
예제 #3
0
        public static CodeSnippet FromFile(string aFile)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(aFile);
            CodeSnippet ret = new CodeSnippet();

            ret.Name      = doc.DocumentElement.GetAttribute("name");
            ret.Extension = doc.DocumentElement.GetAttribute("extension");

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("option"))
            {
                CodeSnippetOption opt = new CodeSnippetOption {
                    Name = elem.GetAttribute("name"), Key = elem.GetAttribute("key")
                };
                ret.Inputs.Add(opt);
            }

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("input"))
            {
                CodeSnippetInput input = new CodeSnippetInput();
                input.Name = elem.GetAttribute("name");
                input.Key  = elem.GetAttribute("key");
                ret.Inputs.Add(input);
            }
            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("code"))
            {
                string requires = elem.GetAttribute("requires");
                if (requires != null && requires.Length > 0)
                {
                    ret.Code.Add(new CodeBlock {
                        Code = elem.InnerText, Requires = requires.Split(' ')
                    });
                }
                else
                {
                    ret.Code.Add(new CodeBlock {
                        Code = elem.InnerText, Requires = null
                    });
                }
            }
            return(ret);
        }
예제 #4
0
        public static SnippetData inst()
        {
            if (inst_ == null)
            {
                inst_          = new SnippetData();
                inst_.Snippets = new ObservableCollection <CodeSnippet>();

                string path = System.IO.Path.GetDirectoryName(Assembly.GetAssembly(typeof(SnippetData)).Location);
                path = System.IO.Path.Combine(path, "snippets");
                if (System.IO.Directory.Exists(path))
                {
                    foreach (string file in System.IO.Directory.EnumerateFiles(path))
                    {
                        inst_.Snippets.Add(CodeSnippet.FromFile(file));
                    }
                }
            }
            return(inst_);
        }