feat: mplement creating a new file

Merge branch 'feat/new-file' into 'main'

Closes #23

See merge request EchidnaHQ/Echidna!20
merge-requests/20/merge
Nefo Fortressia 2021-12-17 02:38:42 +00:00
commit a7665f5752
2 changed files with 20 additions and 2 deletions

View File

@ -2,9 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::lib::prelude::*;
use crate::components::editor::EchidnaCoreEditor;
use crate::lib::prelude::*;
use gio::Cancellable;
use glib::{clone, Priority};
use gtk::{
@ -16,6 +15,7 @@ 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_new_file(&self);
}
impl FileImplementedEditor for super::EchidnaWindow {
@ -135,4 +135,12 @@ impl FileImplementedEditor for super::EchidnaWindow {
}));
}
fn action_new_file(&self) {
let editor_page = EchidnaCoreEditor::new(None);
self.to_imp()
.notebook
.prepend_closable_page(&editor_page, Some(&gtk::Label::new(Some(&"Untitled"))));
}
}

View File

@ -122,5 +122,15 @@ impl MenubarImplementedEditor for EchidnaWindow {
window.action_save_file_as();
}));
}
{
let action_new_file = SimpleAction::new("new-file", None);
self.add_action(&action_new_file);
action_new_file.connect_activate(clone!(@weak self as window =>
move |_action, _variant| {
window.action_new_file();
}));
}
}
}