feat: implement "Save" menu
parent
52d1bdf7db
commit
d8c7f104ab
|
@ -8,12 +8,13 @@ use glib::clone;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::*, subclass::prelude::*, FileChooserAction, FileChooserDialog, Label, ResponseType,
|
prelude::*, subclass::prelude::*, FileChooserAction, FileChooserDialog, Label, ResponseType,
|
||||||
};
|
};
|
||||||
use sourceview::File;
|
use sourceview::{File, FileExt as SourceFileExt};
|
||||||
|
|
||||||
pub trait FileImplementedEditor {
|
pub trait FileImplementedEditor {
|
||||||
fn action_open_file(&self);
|
fn action_open_file(&self);
|
||||||
fn open_file(notebook: >k::Notebook, file: gio::File);
|
fn open_file(notebook: >k::Notebook, file: gio::File);
|
||||||
fn action_save_file_as(&self);
|
fn action_save_file_as(&self);
|
||||||
|
fn action_save_file(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileImplementedEditor for super::EchidnaWindow {
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,5 +122,16 @@ impl MenubarImplementedEditor for EchidnaWindow {
|
||||||
window.action_save_file_as();
|
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();
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue