feat: implement "Save" menu

merge-requests/21/head
Nefo Fortressia 2021-12-16 14:06:33 +07:00
parent 52d1bdf7db
commit d8c7f104ab
Signed by: fortressia
GPG Key ID: 6D7972CC76174995
2 changed files with 25 additions and 1 deletions

View File

@ -8,12 +8,13 @@ use glib::clone;
use gtk::{
prelude::*, subclass::prelude::*, FileChooserAction, FileChooserDialog, Label, ResponseType,
};
use sourceview::File;
use sourceview::{File, FileExt as SourceFileExt};
pub trait FileImplementedEditor {
fn action_open_file(&self);
fn open_file(notebook: &gtk::Notebook, file: gio::File);
fn action_save_file_as(&self);
fn action_save_file(&self);
}
impl FileImplementedEditor for super::EchidnaWindow {
@ -104,4 +105,16 @@ impl FileImplementedEditor for super::EchidnaWindow {
}));
}
fn action_save_file(&self) {
let page: EchidnaCoreEditor = self
.get_current_tab()
.expect("Can't find the current tab because there are no tabs.");
match page.file().location() {
Some(_) => {
page.save_file(None);
}
None => self.action_save_file_as(),
}
}
}

View File

@ -122,5 +122,16 @@ impl MenubarImplementedEditor for EchidnaWindow {
window.action_save_file_as();
}));
}
{
let action_save = SimpleAction::new("save", None);
self.add_action(&action_save);
action_save.connect_activate(clone!(@weak self as window =>
move |_, _| {
window.action_save_file();
}
));
}
}
}