-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect actions directly, use trait implementation for navigation but…
…tons
- Loading branch information
yggverse
committed
Jan 23, 2025
1 parent
10c73f4
commit 5145a53
Showing
9 changed files
with
87 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 24 additions & 18 deletions
42
src/app/browser/window/tab/item/page/navigation/bookmark.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
mod widget; | ||
|
||
use widget::Widget; | ||
|
||
use crate::app::browser::window::action::Action as WindowAction; | ||
use super::WindowAction; | ||
use gtk::{ | ||
prelude::{ActionExt, ButtonExt}, | ||
Button, | ||
}; | ||
use std::rc::Rc; | ||
|
||
pub struct Bookmark { | ||
pub widget: Rc<Widget>, | ||
} | ||
const ICON_YES: &str = "starred-symbolic"; | ||
const ICON_NON: &str = "non-starred-symbolic"; | ||
|
||
impl Bookmark { | ||
// Constructors | ||
pub trait Bookmark { | ||
fn bookmark(action: &Rc<WindowAction>) -> Self; | ||
fn _update(&self, has_bookmark: bool); // @TODO | ||
} | ||
|
||
/// Build new `Self` | ||
pub fn build(action: &Rc<WindowAction>) -> Self { | ||
Self { | ||
widget: Rc::new(Widget::build(action)), | ||
} | ||
impl Bookmark for Button { | ||
fn bookmark(action: &Rc<WindowAction>) -> Self { | ||
Button::builder() | ||
.action_name(format!( | ||
"{}.{}", | ||
action.id, | ||
action.bookmark.simple_action.name() | ||
)) // @TODO | ||
.icon_name(ICON_NON) | ||
.tooltip_text("Bookmark") | ||
.build() | ||
} | ||
|
||
// Actions | ||
pub fn update(&self, has_bookmark: bool) { | ||
self.widget.update(has_bookmark); | ||
fn _update(&self, has_bookmark: bool) { | ||
self.set_icon_name(if has_bookmark { ICON_YES } else { ICON_NON }); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
src/app/browser/window/tab/item/page/navigation/bookmark/widget.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 12 additions & 35 deletions
47
src/app/browser/window/tab/item/page/navigation/history/back.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,21 @@ | ||
use super::WindowAction; | ||
use gtk::{ | ||
prelude::{ButtonExt, WidgetExt}, | ||
Button, | ||
}; | ||
use gtk::{prelude::ActionExt, Button}; | ||
use std::rc::Rc; | ||
|
||
pub struct Back { | ||
action: Rc<WindowAction>, | ||
pub button: Button, | ||
pub trait Back { | ||
fn back(action: &Rc<WindowAction>) -> Self; | ||
} | ||
|
||
impl Back { | ||
// Constructors | ||
|
||
/// Build new `Self` | ||
pub fn build(action: &Rc<WindowAction>) -> Self { | ||
// Init gobject | ||
let button = Button::builder() | ||
impl Back for Button { | ||
fn back(action: &Rc<WindowAction>) -> Self { | ||
Button::builder() | ||
.action_name(format!( | ||
"{}.{}", | ||
action.id, | ||
action.history_back.simple_action.name() | ||
)) // @TODO | ||
.icon_name("go-previous-symbolic") | ||
.tooltip_text("Back") | ||
.sensitive(false) | ||
.build(); | ||
|
||
// Init events | ||
button.connect_clicked({ | ||
let action = action.clone(); | ||
move |_| action.history_back.activate() | ||
}); | ||
|
||
// Return activated `Self` | ||
Self { | ||
action: action.clone(), | ||
button, | ||
} | ||
} | ||
|
||
// Actions | ||
|
||
pub fn update(&self, status: bool) { | ||
self.action.history_back.simple_action.set_enabled(status); | ||
self.button.set_sensitive(status); | ||
.build() | ||
} | ||
} |
51 changes: 12 additions & 39 deletions
51
src/app/browser/window/tab/item/page/navigation/history/forward.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,21 @@ | ||
use gtk::{ | ||
prelude::{ButtonExt, WidgetExt}, | ||
Button, | ||
}; | ||
|
||
use super::WindowAction; | ||
use gtk::{prelude::ActionExt, Button}; | ||
use std::rc::Rc; | ||
|
||
pub struct Forward { | ||
action: Rc<WindowAction>, | ||
pub button: Button, | ||
pub trait Forward { | ||
fn forward(action: &Rc<WindowAction>) -> Self; | ||
} | ||
|
||
impl Forward { | ||
// Constructors | ||
|
||
/// Build new `Self` | ||
pub fn build(action: &Rc<WindowAction>) -> Self { | ||
// Init gobject | ||
let button = Button::builder() | ||
impl Forward for Button { | ||
fn forward(action: &Rc<WindowAction>) -> Self { | ||
Button::builder() | ||
.action_name(format!( | ||
"{}.{}", | ||
action.id, | ||
action.history_back.simple_action.name() | ||
)) // @TODO | ||
.icon_name("go-next-symbolic") | ||
.tooltip_text("Forward") | ||
.sensitive(false) | ||
.build(); | ||
|
||
// Init events | ||
button.connect_clicked({ | ||
let action = action.clone(); | ||
move |_| action.history_forward.activate() | ||
}); | ||
|
||
// Return activated `Self` | ||
Self { | ||
action: action.clone(), | ||
button, | ||
} | ||
} | ||
|
||
// Actions | ||
pub fn update(&self, status: bool) { | ||
self.action | ||
.history_forward | ||
.simple_action | ||
.set_enabled(status); | ||
|
||
self.button.set_sensitive(status); | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,21 @@ | ||
use super::WindowAction; | ||
use gtk::{ | ||
prelude::{ButtonExt, WidgetExt}, | ||
Button, | ||
}; | ||
use gtk::{prelude::ActionExt, Button}; | ||
use std::rc::Rc; | ||
|
||
pub struct Home { | ||
action: Rc<WindowAction>, | ||
pub button: Button, | ||
pub trait Home { | ||
fn home(action: &Rc<WindowAction>) -> Self; | ||
} | ||
|
||
impl Home { | ||
// Construct | ||
pub fn build(action: &Rc<WindowAction>) -> Self { | ||
// Init gobject | ||
let button = Button::builder() | ||
impl Home for Button { | ||
fn home(action: &Rc<WindowAction>) -> Self { | ||
Button::builder() | ||
.action_name(format!( | ||
"{}.{}", | ||
action.id, | ||
action.home.simple_action.name() | ||
)) // @TODO | ||
.icon_name("go-home-symbolic") | ||
.tooltip_text("Home") | ||
.sensitive(false) | ||
.build(); | ||
|
||
// Init events | ||
button.connect_clicked({ | ||
let action = action.clone(); | ||
move |_| action.home.activate() | ||
}); | ||
|
||
// Return activated `Self` | ||
Self { | ||
action: action.clone(), | ||
button, | ||
} | ||
} | ||
|
||
// Actions | ||
pub fn update(&self, has_home: bool) { | ||
self.action.home.simple_action.set_enabled(has_home); | ||
self.button.set_sensitive(has_home); | ||
.build() | ||
} | ||
} |
Oops, something went wrong.