mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
begin libadwaita headerbar tabs integration
This commit is contained in:
parent
765a24f331
commit
ce29a06dda
16 changed files with 269 additions and 156 deletions
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()
|
||||
}
|
||||
}
|
||||
35
src/app/browser/window/header/bar/append/widget.rs
Normal file
35
src/app/browser/window/header/bar/append/widget.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt},
|
||||
Align, Button,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(action_tab_append: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init gobject
|
||||
let gobject = Button::builder()
|
||||
.icon_name("tab-new-symbolic")
|
||||
.css_classes(["flat"])
|
||||
.valign(Align::Center)
|
||||
.tooltip_text("New tab")
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
gobject.connect_clicked(move |_| {
|
||||
action_tab_append.activate(None);
|
||||
});
|
||||
|
||||
Arc::new(Self { gobject })
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Button {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
87
src/app/browser/window/header/bar/menu.rs
Normal file
87
src/app/browser/window/header/bar/menu.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{
|
||||
gio::{self, SimpleAction},
|
||||
glib::{gformat, GString},
|
||||
prelude::ActionExt,
|
||||
MenuButton,
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Menu {
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
#[rustfmt::skip] // @TODO template builder?
|
||||
impl Menu {
|
||||
pub fn new_arc(
|
||||
action_tool_debug: Arc<SimpleAction>,
|
||||
action_tool_profile_directory: Arc<SimpleAction>,
|
||||
action_quit: Arc<SimpleAction>,
|
||||
action_tab_append: Arc<SimpleAction>,
|
||||
action_tab_close: Arc<SimpleAction>,
|
||||
action_tab_close_all: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||
action_tab_pin: Arc<SimpleAction>,
|
||||
) -> Arc<Self> {
|
||||
// Init model
|
||||
let model = gio::Menu::new();
|
||||
|
||||
let model_tab = gio::Menu::new();
|
||||
model_tab.append(Some("New"), Some(&detailed_action_name(action_tab_append)));
|
||||
model_tab.append(Some("Pin"), Some(&detailed_action_name(action_tab_pin)));
|
||||
|
||||
let model_tab_page = gio::Menu::new();
|
||||
|
||||
let model_tab_page_navigation = gio::Menu::new();
|
||||
model_tab_page_navigation.append(Some("Base"), Some(&detailed_action_name(action_tab_page_navigation_base)));
|
||||
|
||||
let model_tab_page_navigation_history = gio::Menu::new();
|
||||
model_tab_page_navigation_history.append(Some("Back"), Some(&detailed_action_name(action_tab_page_navigation_history_back)));
|
||||
model_tab_page_navigation_history.append(Some("Forward"), Some(&detailed_action_name(action_tab_page_navigation_history_forward)));
|
||||
|
||||
model_tab_page_navigation.append_submenu(Some("History"), &model_tab_page_navigation_history);
|
||||
model_tab_page_navigation.append(Some("Reload"), Some(&detailed_action_name(action_tab_page_navigation_reload)));
|
||||
// @TODO model_tab_page_navigation.append(Some("Bookmark"), Some("win.tab_page_bookmark"));
|
||||
|
||||
model_tab_page.append_submenu(Some("Navigation"), &model_tab_page_navigation);
|
||||
|
||||
model_tab.append_submenu(Some("Page"), &model_tab_page);
|
||||
|
||||
let model_tab_close = gio::Menu::new();
|
||||
model_tab_close.append(Some("Current"), Some(&detailed_action_name(action_tab_close)));
|
||||
model_tab_close.append(Some("All"), Some(&detailed_action_name(action_tab_close_all)));
|
||||
|
||||
model_tab.append_submenu(Some("Close"), &model_tab_close);
|
||||
|
||||
model.append_submenu(Some("Tab"), &model_tab);
|
||||
|
||||
let model_tool = gio::Menu::new();
|
||||
model_tool.append(Some("Debug"), Some(&detailed_action_name(action_tool_debug)));
|
||||
model_tool.append(Some("Profile directory"), Some(&detailed_action_name(action_tool_profile_directory)));
|
||||
|
||||
model.append_submenu(Some("Tool"), &model_tool);
|
||||
|
||||
model.append(Some("Quit"), Some(&detailed_action_name(action_quit)));
|
||||
|
||||
// Result
|
||||
Arc::new(Self { widget:Widget::new_arc(&model) })
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &MenuButton {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
fn detailed_action_name(action: Arc<SimpleAction>) -> GString {
|
||||
gformat!("win.{}", action.name()) // @TODO find the way to ident parent group
|
||||
// without application-wide dependencies import
|
||||
// see also src/app/action.rs
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue