feat: implement win.new-file action

merge-requests/20/head
Nefo Fortressia 2021-11-14 10:29:51 +07:00
parent 0bd8b34cfe
commit 87fdfc8d9c
Signed by: fortressia
GPG Key ID: 6D7972CC76174995
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 {
@ -139,4 +139,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

@ -120,5 +120,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();
}));
}
}
}