/// <summary> /// Insert a Snippet /// </summary> /// <param name="snippet"></param> public void InsertSnippet(YnoteSnippet snippet) { #if DEBUG var watch = new Stopwatch(); watch.Start(); #endif 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 = nselection; if (snippet.Content.Contains('^')) { PositionCaretTo('^'); } #if DEBUG watch.Stop(); Debug.WriteLine(watch.Elapsed + " ms InsertSnippet()"); #endif }
/// <summary> /// Loads Snippets /// </summary> private void LoadSnippets() { Globals.Snippets = new List <YnoteSnippet>(); string[] snippets = Directory.GetFiles(GlobalSettings.SettingsDir, "*.ynotesnippet", SearchOption.AllDirectories); Thread.Sleep(5); foreach (string snippet in snippets) { YnoteSnippet snip = YnoteSnippet.Read(snippet); Globals.Snippets.Add(snip); } }
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('^'); } }
/// <summary> /// Loads Snippets /// </summary> private void LoadSnippets() { #if DEBUG var watch = new Stopwatch(); watch.Start(); #endif Globals.Snippets = new List <YnoteSnippet>(); string[] snippets = Directory.GetFiles(GlobalSettings.SettingsDir, "*.ynotesnippet", SearchOption.AllDirectories); Thread.Sleep(5); foreach (string snippet in snippets) { YnoteSnippet snip = YnoteSnippet.Read(snippet); Globals.Snippets.Add(snip); } #if DEBUG watch.Stop(); Debug.WriteLine(string.Format("Loaded {0} Snippets in {1} ms", Globals.Snippets.Count, watch.ElapsedMilliseconds)); #endif }