private async void LoadFile(string path, bool initialLoad = false) { try { var json = await File.ReadAllTextAsync(path); var deserializedSnippets = JsonConvert.DeserializeObject <List <Snippet> >(json); SnippetsList.Clear(); if (deserializedSnippets?.Any() ?? false) { deserializedSnippets.ForEach(snippet => SnippetsList.Add(snippet)); } AppSettings.CurrentFilePath = path; if (!initialLoad) { AppSettings.AutoSaveEnabled = false; } } catch (Exception) { if (!initialLoad) { await this.ShowChildWindowAsync(new MessageDialog { MessageBoxText = "Couldn't read file.", Caption = "Error" }); } AppSettings.CurrentFilePath = null; } }
private void AddNewClick(object sender, RoutedEventArgs e) { var editorWindow = new EditorWindow(new Snippet(), false); if (editorWindow.ShowDialog() == true) { SnippetsList.Add(editorWindow.Snippet); } }
public SnippetTextEditor() { Name = "Snippet"; Description = "Returns a string of text defined in the snippet.xml file."; exampleInput = "doesn't matter"; exampleCommand = "snippet thingIAlwaysWrite"; exampleOutput = "this is the text I always write"; DefineParameters(); _snippets = new SnippetsList(); }
private void EditSnippet(object sender, MouseButtonEventArgs e) { var rowIndex = SnippetsDataGrid.SelectedIndex; if (rowIndex < 0) { return; } var snippet = rowIndex < SnippetsList.Count ? SnippetsList[rowIndex] : new Snippet(); var isEdit = rowIndex < SnippetsList.Count; var editorWindow = new EditorWindow(snippet, isEdit); if (editorWindow.ShowDialog() != true) { return; } if (editorWindow.IsSetToDelete) { SnippetsList.RemoveAt(rowIndex); Clipboard.Clear(); return; } if (rowIndex < SnippetsList.Count) { SnippetsList[rowIndex].Name = editorWindow.Snippet.Name; SnippetsList[rowIndex].Value = editorWindow.Snippet.Value; } else { SnippetsList.Add(editorWindow.Snippet); } Clipboard.SetDataObject($"{editorWindow.Snippet.Value}"); }
public SnippetEditor() { Snippets = new SnippetsList(); InitializeComponent(); }