From 2bc0cde14b96ffec193743497fd4c4f18859c636 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sun, 12 Mar 2023 20:44:37 +0100 Subject: [PATCH] cleanup, add message when saving file --- src/editor.rs | 20 +++----------------- src/main.rs | 6 +++--- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 01ac38d..1f7f665 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -58,7 +58,7 @@ impl Editor { }) } - pub fn new_empty(clipboard: Clipboard) -> Self { + pub fn new(clipboard: Clipboard, path: Option) -> Self { Editor { text: String::new(), lines: vec![0..0], @@ -66,22 +66,7 @@ impl Editor { cursor: Cursor { line: 0, column: 0 }, marker: None, clipboard, - path: None, - active: false, - unsaved_changes: true, - message: None, - } - } - - pub fn new_named(clipboard: Clipboard, path: PathBuf) -> Self { - Editor { - text: String::new(), - lines: vec![0..0], - scroll: 0, - cursor: Cursor { line: 0, column: 0 }, - marker: None, - clipboard, - path: Some(path), + path, active: false, unsaved_changes: true, message: None, @@ -468,6 +453,7 @@ impl Editor { if let Some(path) = &self.path { match File::create(path) { Ok(mut file) => { + self.message(format!("Saved file as '{}'", path.display())); file.write_all(self.text.as_bytes()).unwrap(); self.unsaved_changes = false; } diff --git a/src/main.rs b/src/main.rs index 8d9f59a..df4e011 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,11 +53,11 @@ impl Navigator { editors.push(editor); } } else { - editors.push(Editor::new_named(clipboard.clone(), arg)); + editors.push(Editor::new(clipboard.clone(), Some(arg))); } } if args.is_empty() { - editors.push(Editor::new_empty(clipboard.clone())); + editors.push(Editor::new(clipboard.clone(), None)); } let immediate_open = editors.len() == 1; Self { @@ -200,7 +200,7 @@ impl Navigator { fn new_editor(&mut self) { self.selected = self.editors.len(); - self.editors.push(Editor::new_empty(self.clipboard.clone())); + self.editors.push(Editor::new(self.clipboard.clone(), None)); self.open_selected(); }