mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
begin libadwaita headerbar tabs integration
This commit is contained in:
parent
765a24f331
commit
ce29a06dda
@ -14,7 +14,7 @@ use std::sync::Arc;
|
|||||||
use gtk::{gio::SimpleAction, glib::GString, Box};
|
use gtk::{gio::SimpleAction, glib::GString, Box};
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
header: Arc<Header>,
|
//header: Arc<Header>,
|
||||||
tab: Arc<Tab>,
|
tab: Arc<Tab>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
@ -36,8 +36,18 @@ impl Window {
|
|||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_tab_pin: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
// @TODO testing
|
||||||
|
let tab_view = adw::TabView::new();
|
||||||
|
|
||||||
|
let p1 = tab_view.append(>k::Label::new(Some("test 1")));
|
||||||
|
let p2 = tab_view.append(>k::Label::new(Some("test 2")));
|
||||||
|
|
||||||
|
p1.set_title("title 1");
|
||||||
|
p2.set_title("title 2");
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let header = Arc::new(Header::new(
|
let header = Header::new_arc(
|
||||||
|
// Actions
|
||||||
action_tool_debug.clone(),
|
action_tool_debug.clone(),
|
||||||
action_tool_profile_directory.clone(),
|
action_tool_profile_directory.clone(),
|
||||||
action_quit.clone(),
|
action_quit.clone(),
|
||||||
@ -49,15 +59,17 @@ impl Window {
|
|||||||
action_tab_page_navigation_history_forward.clone(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
action_tab_page_navigation_reload.clone(),
|
action_tab_page_navigation_reload.clone(),
|
||||||
action_tab_pin.clone(),
|
action_tab_pin.clone(),
|
||||||
));
|
// Widgets
|
||||||
|
&tab_view,
|
||||||
|
);
|
||||||
|
|
||||||
let tab = Arc::new(Tab::new(
|
let tab = Tab::new_arc(
|
||||||
action_tab_page_navigation_base,
|
action_tab_page_navigation_base,
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back,
|
||||||
action_tab_page_navigation_history_forward,
|
action_tab_page_navigation_history_forward,
|
||||||
action_tab_page_navigation_reload,
|
action_tab_page_navigation_reload,
|
||||||
action_update,
|
action_update,
|
||||||
));
|
);
|
||||||
tab.activate(tab.clone());
|
tab.activate(tab.clone());
|
||||||
|
|
||||||
// GTK
|
// GTK
|
||||||
@ -65,7 +77,7 @@ impl Window {
|
|||||||
|
|
||||||
// Init struct
|
// Init struct
|
||||||
Self {
|
Self {
|
||||||
header,
|
//header,
|
||||||
tab,
|
tab,
|
||||||
widget,
|
widget,
|
||||||
}
|
}
|
||||||
@ -105,19 +117,6 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
// Update header
|
|
||||||
let title = match self.tab.page_title() {
|
|
||||||
Some(value) => value,
|
|
||||||
None => GString::new(), // @TODO
|
|
||||||
};
|
|
||||||
|
|
||||||
let subtitle = match self.tab.page_description() {
|
|
||||||
Some(value) => value,
|
|
||||||
None => GString::new(), // @TODO
|
|
||||||
};
|
|
||||||
|
|
||||||
self.header.update(title.as_str(), subtitle.as_str());
|
|
||||||
|
|
||||||
self.tab.update();
|
self.tab.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,21 @@
|
|||||||
mod title;
|
mod bar;
|
||||||
mod tray;
|
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use title::Title;
|
use bar::Bar;
|
||||||
use tray::Tray;
|
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
|
|
||||||
use adw::HeaderBar;
|
use adw::{TabView, ToolbarView};
|
||||||
use gtk::gio::SimpleAction;
|
use gtk::gio::SimpleAction;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
title: Arc<Title>,
|
|
||||||
// tray: Arc<Subject>,
|
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Header {
|
impl Header {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new_arc(
|
||||||
|
// Actions
|
||||||
action_tool_debug: Arc<SimpleAction>,
|
action_tool_debug: Arc<SimpleAction>,
|
||||||
action_tool_profile_directory: Arc<SimpleAction>,
|
action_tool_profile_directory: Arc<SimpleAction>,
|
||||||
action_quit: Arc<SimpleAction>,
|
action_quit: Arc<SimpleAction>,
|
||||||
@ -30,9 +27,11 @@ impl Header {
|
|||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_tab_pin: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Self {
|
// Widgets
|
||||||
|
tab_view: &TabView,
|
||||||
|
) -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
let tray = Tray::new(
|
let bar = Bar::new_arc(
|
||||||
action_tool_debug,
|
action_tool_debug,
|
||||||
action_tool_profile_directory,
|
action_tool_profile_directory,
|
||||||
action_quit,
|
action_quit,
|
||||||
@ -44,24 +43,17 @@ impl Header {
|
|||||||
action_tab_page_navigation_history_forward,
|
action_tab_page_navigation_history_forward,
|
||||||
action_tab_page_navigation_reload,
|
action_tab_page_navigation_reload,
|
||||||
action_tab_pin,
|
action_tab_pin,
|
||||||
|
tab_view,
|
||||||
);
|
);
|
||||||
|
|
||||||
let title = Arc::new(Title::new());
|
|
||||||
|
|
||||||
// Init widget
|
|
||||||
let widget = Arc::new(Widget::new(tray.gobject(), Some(title.gobject())));
|
|
||||||
|
|
||||||
// Return new struct
|
// Return new struct
|
||||||
Self { title, widget }
|
Arc::new(Self {
|
||||||
}
|
widget: Widget::new_arc(bar.gobject()),
|
||||||
|
})
|
||||||
// Actions
|
|
||||||
pub fn update(&self, title: &str, description: &str) {
|
|
||||||
self.title.update(title, description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &HeaderBar {
|
pub fn gobject(&self) -> &ToolbarView {
|
||||||
&self.widget.gobject()
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
|
mod append;
|
||||||
|
mod control;
|
||||||
mod menu;
|
mod menu;
|
||||||
mod tab;
|
mod tab;
|
||||||
|
mod widget;
|
||||||
|
|
||||||
|
use append::Append;
|
||||||
|
use control::Control;
|
||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use adw::TabView;
|
||||||
gio::SimpleAction,
|
use gtk::{gio::SimpleAction, Box};
|
||||||
prelude::BoxExt,
|
|
||||||
{Box, Orientation},
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Tray {
|
pub struct Bar {
|
||||||
gobject: Box,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tray {
|
impl Bar {
|
||||||
pub fn new(
|
// Construct
|
||||||
|
pub fn new_arc(
|
||||||
action_tool_debug: Arc<SimpleAction>,
|
action_tool_debug: Arc<SimpleAction>,
|
||||||
action_tool_profile_directory: Arc<SimpleAction>,
|
action_tool_profile_directory: Arc<SimpleAction>,
|
||||||
action_quit: Arc<SimpleAction>,
|
action_quit: Arc<SimpleAction>,
|
||||||
@ -29,11 +32,13 @@ impl Tray {
|
|||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_tab_pin: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Self {
|
view: &TabView,
|
||||||
|
) -> Arc<Self> {
|
||||||
// Init components
|
// Init components
|
||||||
let tab = Tab::new(action_tab_append.clone());
|
let control = Control::new_arc();
|
||||||
|
let tab = Tab::new_arc(view);
|
||||||
let menu = Menu::new(
|
let append = Append::new_arc(action_tab_append.clone());
|
||||||
|
let menu = Menu::new_arc(
|
||||||
action_tool_debug,
|
action_tool_debug,
|
||||||
action_tool_profile_directory,
|
action_tool_profile_directory,
|
||||||
action_quit,
|
action_quit,
|
||||||
@ -47,21 +52,19 @@ impl Tray {
|
|||||||
action_tab_pin,
|
action_tab_pin,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Init widget
|
// Build result
|
||||||
let gobject = Box::builder()
|
Arc::new(Self {
|
||||||
.orientation(Orientation::Horizontal)
|
widget: Widget::new_arc(
|
||||||
.spacing(8)
|
control.gobject(),
|
||||||
.build();
|
append.gobject(),
|
||||||
|
menu.gobject(),
|
||||||
gobject.append(menu.gobject());
|
tab.gobject(),
|
||||||
gobject.append(tab.gobject());
|
),
|
||||||
|
})
|
||||||
// Return new struct
|
|
||||||
Self { gobject }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.gobject
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
24
src/app/browser/window/header/bar/append.rs
Normal file
24
src/app/browser/window/header/bar/append.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
mod widget;
|
||||||
|
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
|
use gtk::{gio::SimpleAction, Button};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Append {
|
||||||
|
pub widget: Arc<Widget>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Append {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc(action_tab_append: Arc<SimpleAction>) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
widget: Widget::new_arc(action_tab_append),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &Button {
|
||||||
|
&self.widget.gobject()
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,22 @@
|
|||||||
use gtk::{gio::SimpleAction, prelude::ActionExt, prelude::ButtonExt, Button};
|
use gtk::{
|
||||||
|
gio::SimpleAction,
|
||||||
|
prelude::{ActionExt, ButtonExt},
|
||||||
|
Align, Button,
|
||||||
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Tab {
|
pub struct Widget {
|
||||||
pub gobject: Button,
|
gobject: Button,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tab {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(action_tab_append: Arc<SimpleAction>) -> Self {
|
pub fn new_arc(action_tab_append: Arc<SimpleAction>) -> Arc<Self> {
|
||||||
// Init widget
|
// Init gobject
|
||||||
let gobject = Button::builder()
|
let gobject = Button::builder()
|
||||||
.icon_name("tab-new-symbolic")
|
.icon_name("tab-new-symbolic")
|
||||||
|
.css_classes(["flat"])
|
||||||
|
.valign(Align::Center)
|
||||||
.tooltip_text("New tab")
|
.tooltip_text("New tab")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -19,8 +25,7 @@ impl Tab {
|
|||||||
action_tab_append.activate(None);
|
action_tab_append.activate(None);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return activated struct
|
Arc::new(Self { gobject })
|
||||||
Self { gobject }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
24
src/app/browser/window/header/bar/control.rs
Normal file
24
src/app/browser/window/header/bar/control.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
mod widget;
|
||||||
|
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
|
use gtk::WindowControls;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Control {
|
||||||
|
widget: Arc<Widget>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Control {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc() -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
widget: Widget::new_arc(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &WindowControls {
|
||||||
|
&self.widget.gobject()
|
||||||
|
}
|
||||||
|
}
|
20
src/app/browser/window/header/bar/control/widget.rs
Normal file
20
src/app/browser/window/header/bar/control/widget.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use gtk::{PackType, WindowControls};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Widget {
|
||||||
|
gobject: WindowControls,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc() -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
gobject: WindowControls::new(PackType::End),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &WindowControls {
|
||||||
|
&self.gobject
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
|
mod widget;
|
||||||
|
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{self, SimpleAction},
|
gio::{self, SimpleAction},
|
||||||
glib::{gformat, GString},
|
glib::{gformat, GString},
|
||||||
@ -8,11 +12,11 @@ use gtk::{
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Menu {
|
pub struct Menu {
|
||||||
gobject: MenuButton,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
#[rustfmt::skip] // @TODO template builder?
|
#[rustfmt::skip] // @TODO template builder?
|
||||||
impl Menu {
|
impl Menu {
|
||||||
pub fn new(
|
pub fn new_arc(
|
||||||
action_tool_debug: Arc<SimpleAction>,
|
action_tool_debug: Arc<SimpleAction>,
|
||||||
action_tool_profile_directory: Arc<SimpleAction>,
|
action_tool_profile_directory: Arc<SimpleAction>,
|
||||||
action_quit: Arc<SimpleAction>,
|
action_quit: Arc<SimpleAction>,
|
||||||
@ -24,7 +28,7 @@ impl Menu {
|
|||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_tab_pin: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Arc<Self> {
|
||||||
// Init model
|
// Init model
|
||||||
let model = gio::Menu::new();
|
let model = gio::Menu::new();
|
||||||
|
|
||||||
@ -65,17 +69,13 @@ impl Menu {
|
|||||||
|
|
||||||
model.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
|
model.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
|
||||||
|
|
||||||
// Init widget
|
|
||||||
let gobject = MenuButton::builder().tooltip_text("Menu").build();
|
|
||||||
gobject.set_menu_model(Some(&model));
|
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self { gobject }
|
Arc::new(Self { widget:Widget::new_arc(&model) })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &MenuButton {
|
pub fn gobject(&self) -> &MenuButton {
|
||||||
&self.gobject
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
src/app/browser/window/header/bar/menu/widget.rs
Normal file
26
src/app/browser/window/header/bar/menu/widget.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use gtk::{gio::Menu, Align, MenuButton};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Widget {
|
||||||
|
gobject: MenuButton,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc(model: &Menu) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
gobject: MenuButton::builder()
|
||||||
|
.css_classes(["flat"])
|
||||||
|
.icon_name("open-menu-symbolic")
|
||||||
|
.menu_model(model)
|
||||||
|
.tooltip_text("Menu")
|
||||||
|
.valign(Align::Center)
|
||||||
|
.build(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &MenuButton {
|
||||||
|
&self.gobject
|
||||||
|
}
|
||||||
|
}
|
24
src/app/browser/window/header/bar/tab.rs
Normal file
24
src/app/browser/window/header/bar/tab.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
mod widget;
|
||||||
|
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
|
use adw::{TabBar, TabView};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Tab {
|
||||||
|
widget: Arc<Widget>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tab {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc(view: &TabView) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
widget: Widget::new_arc(view),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &TabBar {
|
||||||
|
&self.widget.gobject()
|
||||||
|
}
|
||||||
|
}
|
20
src/app/browser/window/header/bar/tab/widget.rs
Normal file
20
src/app/browser/window/header/bar/tab/widget.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use adw::{TabBar, TabView};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Widget {
|
||||||
|
gobject: TabBar,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc(view: &TabView) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
gobject: TabBar::builder().view(&view).build(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &TabBar {
|
||||||
|
&self.gobject
|
||||||
|
}
|
||||||
|
}
|
34
src/app/browser/window/header/bar/widget.rs
Normal file
34
src/app/browser/window/header/bar/widget.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
use adw::TabBar;
|
||||||
|
use gtk::{prelude::BoxExt, Box, Button, MenuButton, Orientation, WindowControls};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub struct Widget {
|
||||||
|
gobject: Box,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget {
|
||||||
|
// Construct
|
||||||
|
pub fn new_arc(
|
||||||
|
control: &WindowControls,
|
||||||
|
append: &Button,
|
||||||
|
menu: &MenuButton,
|
||||||
|
tab: &TabBar,
|
||||||
|
) -> Arc<Self> {
|
||||||
|
let gobject = Box::builder()
|
||||||
|
.orientation(Orientation::Horizontal)
|
||||||
|
.spacing(8)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
gobject.append(tab);
|
||||||
|
gobject.append(append);
|
||||||
|
gobject.append(menu);
|
||||||
|
gobject.append(control);
|
||||||
|
|
||||||
|
Arc::new(Self { gobject })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
pub fn gobject(&self) -> &Box {
|
||||||
|
&self.gobject
|
||||||
|
}
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
use adw::WindowTitle;
|
|
||||||
|
|
||||||
const DEFAULT_TITLE: &str = "Yoda"; // @TODO
|
|
||||||
const DEFAULT_SUBTITLE: &str = "";
|
|
||||||
|
|
||||||
pub struct Title {
|
|
||||||
gobject: WindowTitle,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Title {
|
|
||||||
// Construct
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
gobject: WindowTitle::new(DEFAULT_TITLE, DEFAULT_SUBTITLE),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
pub fn update(&self, title: &str, subtitle: &str) {
|
|
||||||
// Update title
|
|
||||||
let mut parts = Vec::new();
|
|
||||||
|
|
||||||
if !title.is_empty() {
|
|
||||||
parts.push(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
parts.push(DEFAULT_TITLE);
|
|
||||||
|
|
||||||
self.gobject.set_title(&parts.join(" - "));
|
|
||||||
|
|
||||||
// Update subtitle
|
|
||||||
self.gobject.set_subtitle(subtitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
pub fn gobject(&self) -> &WindowTitle {
|
|
||||||
&self.gobject
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +1,23 @@
|
|||||||
use adw::{HeaderBar, WindowTitle};
|
use adw::ToolbarView;
|
||||||
use gtk::Box;
|
use gtk::Box;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
gobject: HeaderBar,
|
gobject: ToolbarView,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(pack_start: &Box, title_widget: Option<&WindowTitle>) -> Self {
|
pub fn new_arc(top_bar: &Box) -> Arc<Self> {
|
||||||
let gobject = HeaderBar::builder().build();
|
let gobject = ToolbarView::builder().build();
|
||||||
|
|
||||||
gobject.pack_start(pack_start);
|
gobject.add_top_bar(top_bar);
|
||||||
gobject.set_title_widget(title_widget);
|
|
||||||
|
|
||||||
Self { gobject }
|
Arc::new(Self { gobject })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn gobject(&self) -> &HeaderBar {
|
pub fn gobject(&self) -> &ToolbarView {
|
||||||
&self.gobject
|
&self.gobject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,14 @@ pub struct Tab {
|
|||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new_arc(
|
||||||
// Actions
|
// Actions
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Arc<Self> {
|
||||||
// Init empty HashMap index as no tabs appended yet
|
// Init empty HashMap index as no tabs appended yet
|
||||||
let index = RefCell::new(HashMap::new());
|
let index = RefCell::new(HashMap::new());
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ impl Tab {
|
|||||||
let widget = Arc::new(Widget::new());
|
let widget = Arc::new(Widget::new());
|
||||||
|
|
||||||
// Return non activated struct
|
// Return non activated struct
|
||||||
Self {
|
Arc::new(Self {
|
||||||
// Define action links
|
// Define action links
|
||||||
action_tab_page_navigation_base,
|
action_tab_page_navigation_base,
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back,
|
||||||
@ -58,7 +58,7 @@ impl Tab {
|
|||||||
index,
|
index,
|
||||||
// GTK
|
// GTK
|
||||||
widget,
|
widget,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -276,25 +276,6 @@ impl Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn page_title(&self) -> Option<GString> {
|
|
||||||
if let Some(id) = self.widget.current_name() {
|
|
||||||
if let Some(item) = self.index.borrow().get(&id) {
|
|
||||||
return item.page_title();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn page_description(&self) -> Option<GString> {
|
|
||||||
if let Some(id) = self.widget.current_name() {
|
|
||||||
// Get page by widget ID
|
|
||||||
if let Some(item) = self.index.borrow().get(&id) {
|
|
||||||
return item.page_description();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gobject(&self) -> &Notebook {
|
pub fn gobject(&self) -> &Notebook {
|
||||||
self.widget.gobject()
|
self.widget.gobject()
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use adw::HeaderBar;
|
use adw::ToolbarView;
|
||||||
use gtk::{prelude::BoxExt, Box, Notebook, Orientation};
|
use gtk::{prelude::BoxExt, Box, Notebook, Orientation};
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
@ -7,7 +7,7 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(header: &HeaderBar, tab: &Notebook) -> Self {
|
pub fn new(header: &ToolbarView, tab: &Notebook) -> Self {
|
||||||
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
||||||
gobject.append(header);
|
gobject.append(header);
|
||||||
gobject.append(tab);
|
gobject.append(tab);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user