mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
begin actions encapsulation
This commit is contained in:
parent
832b90d37d
commit
b56b6e3879
6 changed files with 83 additions and 40 deletions
|
|
@ -4,7 +4,7 @@ mod tray;
|
|||
use subject::Subject;
|
||||
use tray::Tray;
|
||||
|
||||
use gtk::{glib::GString, HeaderBar};
|
||||
use gtk::{gio::SimpleAction, glib::GString, HeaderBar};
|
||||
|
||||
pub struct Header {
|
||||
widget: HeaderBar,
|
||||
|
|
@ -13,14 +13,18 @@ pub struct Header {
|
|||
|
||||
impl Header {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
let tray = Tray::new();
|
||||
pub fn new(action_debug: &SimpleAction, action_quit: &SimpleAction) -> Self {
|
||||
// Init components
|
||||
let tray = Tray::new(action_debug, action_quit);
|
||||
|
||||
let subject = Subject::new();
|
||||
|
||||
// Init widget
|
||||
let widget = HeaderBar::builder().build();
|
||||
widget.pack_start(tray.widget());
|
||||
widget.set_title_widget(Some(subject.widget()));
|
||||
|
||||
// Return new struct
|
||||
Self { widget, subject }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
mod menu;
|
||||
mod tab;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use gtk::prelude::BoxExt;
|
||||
use gtk::{Box, Orientation};
|
||||
use menu::Menu;
|
||||
|
|
@ -11,10 +12,12 @@ pub struct Tray {
|
|||
}
|
||||
|
||||
impl Tray {
|
||||
pub fn new() -> Self {
|
||||
let menu = Menu::new();
|
||||
pub fn new(action_debug: &SimpleAction, action_quit: &SimpleAction) -> Self {
|
||||
// Init components
|
||||
let menu = Menu::new(action_debug, action_quit);
|
||||
let tab = Tab::new();
|
||||
|
||||
// Init widget
|
||||
let widget = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(8)
|
||||
|
|
@ -23,6 +26,7 @@ impl Tray {
|
|||
widget.append(menu.widget());
|
||||
widget.append(tab.widget());
|
||||
|
||||
// Return new struct
|
||||
Self { widget }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
use gtk::{gio, MenuButton};
|
||||
use gtk::{
|
||||
gio::{self, MenuItem, SimpleAction},
|
||||
glib::{gformat, GString},
|
||||
prelude::ActionExt,
|
||||
MenuButton,
|
||||
};
|
||||
|
||||
pub struct Menu {
|
||||
widget: MenuButton,
|
||||
}
|
||||
|
||||
impl Menu {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(action_debug: &SimpleAction, action_quit: &SimpleAction) -> Self {
|
||||
// Init model
|
||||
let model_tab = gio::Menu::new();
|
||||
model_tab.append(Some("New"), Some("win.tab_append"));
|
||||
|
|
@ -30,9 +35,10 @@ impl Menu {
|
|||
model_tab.append_submenu(Some("Close"), &model_tab_close);
|
||||
|
||||
let model = gio::Menu::new();
|
||||
|
||||
model.append_submenu(Some("Tab"), &model_tab);
|
||||
model.append(Some("Debug"), Some("win.debug"));
|
||||
model.append(Some("Quit"), Some("win.quit"));
|
||||
model.append(Some("Debug"), Some(&detailed_action_name(action_debug)));
|
||||
model.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
|
||||
|
||||
// Init widget
|
||||
let widget = MenuButton::builder().tooltip_text("Menu").build();
|
||||
|
|
@ -47,3 +53,8 @@ impl Menu {
|
|||
&self.widget
|
||||
}
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
fn detailed_action_name(action: &SimpleAction) -> GString {
|
||||
gformat!("win.{}", action.name()) // @TODO
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
|||
|
||||
use tab::Tab;
|
||||
|
||||
use gtk::{glib::GString, prelude::BoxExt, Box, Orientation};
|
||||
use gtk::{gio::SimpleAction, glib::GString, prelude::BoxExt, Box, Orientation};
|
||||
|
||||
pub struct Main {
|
||||
tab: Arc<Tab>,
|
||||
|
|
@ -13,7 +13,11 @@ pub struct Main {
|
|||
|
||||
impl Main {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
pub fn new(
|
||||
action_debug: &SimpleAction,
|
||||
action_quit: &SimpleAction,
|
||||
action_update: &SimpleAction,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let tab = Arc::new(Tab::new());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue