From 87fdfc8d9c2ee9f410fcdea22c97d31a884c8220 Mon Sep 17 00:00:00 2001 From: Nefo Fortressia Date: Sun, 14 Nov 2021 10:29:51 +0700 Subject: [PATCH] feat: implement win.new-file action --- src/components/window/file.rs | 12 ++++++++++-- src/components/window/menubar.rs | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/window/file.rs b/src/components/window/file.rs index 3a51ce0..2d25670 100644 --- a/src/components/window/file.rs +++ b/src/components/window/file.rs @@ -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: >k::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(>k::Label::new(Some(&"Untitled")))); + } } diff --git a/src/components/window/menubar.rs b/src/components/window/menubar.rs index e7706a8..1cf13db 100644 --- a/src/components/window/menubar.rs +++ b/src/components/window/menubar.rs @@ -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(); + })); + } } }