Add Ctrl+S and indicate when files are dirty
This commit is contained in:
@ -22,6 +22,9 @@ pub struct FileEditor {
|
||||
title: String,
|
||||
pub path: Option<PathBuf>,
|
||||
pub buffer: Vec<BufferItem>,
|
||||
|
||||
/// Whether the file has been edited since it was laste saved to disk.
|
||||
pub is_dirty: bool,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
@ -37,6 +40,7 @@ impl FileEditor {
|
||||
title: title.into(),
|
||||
path: None,
|
||||
buffer,
|
||||
is_dirty: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,9 +73,11 @@ impl FileEditor {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("new");
|
||||
if ui.button("text").clicked() {
|
||||
self.is_dirty = true;
|
||||
self.buffer.push(BufferItem::Text(Default::default()));
|
||||
}
|
||||
if ui.button("writing").clicked() {
|
||||
self.is_dirty = true;
|
||||
self.buffer
|
||||
.push(BufferItem::Handwriting(Default::default()));
|
||||
}
|
||||
@ -138,14 +144,18 @@ impl FileEditor {
|
||||
|
||||
let item_response = ui.allocate_ui(item_size, |ui| match item {
|
||||
BufferItem::Text(text_edit) => {
|
||||
text_edit.ui(ui);
|
||||
if text_edit.ui(ui).changed {
|
||||
self.is_dirty = true;
|
||||
}
|
||||
}
|
||||
BufferItem::Handwriting(painting) => {
|
||||
BufferItem::Handwriting(handwriting) => {
|
||||
let style = HandwritingStyle {
|
||||
animate: preferences.animations,
|
||||
..HandwritingStyle::from_theme(ui.ctx().theme())
|
||||
};
|
||||
painting.ui(&style, ui);
|
||||
if handwriting.ui(&style, ui).changed {
|
||||
self.is_dirty = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -211,10 +221,12 @@ impl FileEditor {
|
||||
Ordering::Greater => {
|
||||
let item = self.buffer.remove(from);
|
||||
self.buffer.insert(to, item);
|
||||
self.is_dirty = true;
|
||||
}
|
||||
Ordering::Less => {
|
||||
let item = self.buffer.remove(from);
|
||||
self.buffer.insert(to - 1, item);
|
||||
self.is_dirty = true;
|
||||
}
|
||||
Ordering::Equal => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user