private void InitEditor(ICodeEditor editor, string settingName) { editor.Preferences = _preferences; editor.ViewModel = new JsonEditViewModel(editor.TextBox, new JsonCodeCompletion(editor), _preferences) { SettingName = settingName }; var lastFile = JTranEdit.user.Default[settingName]?.ToString() ?? ""; if (!string.IsNullOrWhiteSpace(lastFile)) { try { editor.LoadFile(lastFile); } catch { // If can't load last file then just ignore // Set last file to nothing JTranEdit.user.Default[settingName] = ""; } } }
/// <summary> /// Load a file and set text of json editor /// </summary> /// <param name="editor"></param> public static void LoadFile(this ICodeEditor editor, string filter, string lastFile) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (!string.IsNullOrWhiteSpace(editor.CurrentFileName)) { openFileDialog.InitialDirectory = Path.GetDirectoryName(editor.CurrentFileName); } else if (!string.IsNullOrWhiteSpace(lastFile)) { openFileDialog.InitialDirectory = Path.GetDirectoryName(lastFile); } openFileDialog.Filter = filter; if (openFileDialog.ShowDialog() == true) { editor.LoadFile(openFileDialog.FileName); } return; }