Esempio n. 1
0
 public static YnoteSnippet Read(string snippetfile)
 {
     var snippet = new YnoteSnippet();
     snippet.File = snippetfile;
     using (var reader = XmlReader.Create(snippetfile))
     {
         while (reader.Read())
         {
             if (reader.IsStartElement())
             {
                 switch (reader.Name)
                 {
                     case "tabTrigger":
                         snippet.Tab = reader.ReadElementContentAsString();
                         break;
                     case "content":
                         snippet.Content = reader.ReadElementContentAsString();
                         break;
                     case "scope":
                         snippet.Scope = reader.ReadElementContentAsString().Split(',');
                         break;
                 }
             }
         }
     }
     return snippet;
 }
Esempio n. 2
0
        /* YnoteSnippet File Documentation
         * ----------------------
         * Functions
         * ----------------------
         * $file_name - File Name
         * $file_name_extension - File Name with Extension
         * $current_line - Text of Current line
         * $selection - SelectedText
         * ^ - Caret Position
         * -----------------------
         * Snippet File Structure
         * ----------------------
         * <?xml version="1.0"?>
         * <YnoteSnippet Version="1.0">
         *     <description></description>
         *     <tabTrigger></tabTrigger>
         *     <content></content>
         * </YnoteSnippet>
         */

        #endregion

        public static YnoteSnippet Read(string snippetfile)
        {
            var snippet = new YnoteSnippet();

            snippet.File = snippetfile;
            using (var reader = XmlReader.Create(snippetfile))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "tabTrigger":
                            snippet.Tab = reader.ReadElementContentAsString();
                            break;

                        case "content":
                            snippet.Content = reader.ReadElementContentAsString();
                            break;

                        case "scope":
                            snippet.Scope = reader.ReadElementContentAsString().Split(',');
                            break;
                        }
                    }
                }
            }
            return(snippet);
        }
Esempio n. 3
0
 public void InsertSnippet(YnoteSnippet snippet)
 {
     var selection = codebox.Selection.Clone();
     var content = snippet.GetSubstitutedContent(this);
     codebox.InsertText(content);
     var nselection = codebox.Selection.Clone();
     for (int i = selection.Start.iLine; i <= nselection.Start.iLine; i++)
     {
         codebox.Selection.Start = new Place(0, i);
         codebox.DoAutoIndent(i);
     }
     codebox.Selection.Start = new Place(nselection.End.iChar, nselection.End.iLine);
     if (snippet.Content.Contains('^'))
         PositionCaretTo('^');
 }