private bool Save() { try { File.WriteAllText(FileName, Text); RecentFilesDialog.UpdateRecentFiles(FileName, EditBox.SelectionStart); Settings.Default.LastOpenFile = FileName.AddOffsetToFileName(EditBox.SelectionStart); IsModified = false; return(true); } catch (Exception e) { MessageBox.Show(e.Message, App.Title, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
public bool LoadFile(string file) { try { if (string.IsNullOrWhiteSpace(file)) { NewFile(); return(true); } EditBox.Text = File.ReadAllText(file); EditBox.ScrollToHome(); Settings.Default.LastOpenFile = file; RecentFilesDialog.UpdateRecentFiles(file); IsModified = false; FileName = file; return(true); } catch (Exception e) { MessageBox.Show(e.Message, @"Load File", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
public bool LoadFile(string file) { try { if (string.IsNullOrWhiteSpace(file)) { NewFile(); return(true); } var parts = file.Split(new[] { '|' }, 2); var filename = parts[0]; var offset = ConvertToOffset(parts.Length == 2 ? parts[1] : "0"); EditBox.Text = File.ReadAllText(filename); if (App.UserSettings.EditorOpenLastCursorPosition) { EditBox.ScrollToLine(EditBox.Document.GetLineByOffset(offset)?.LineNumber ?? 0); EditBox.SelectionStart = offset; } else { EditBox.ScrollToHome(); } Settings.Default.LastOpenFile = file; RecentFilesDialog.UpdateRecentFiles(filename, offset); IsModified = false; FileName = filename; return(true); } catch (Exception e) { MessageBox.Show(e.Message, App.Title, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }