mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-28 12:04:13 +00:00
add view source
menu item
This commit is contained in:
parent
85735d33e2
commit
e66b065fc3
@ -197,6 +197,14 @@ impl App {
|
|||||||
),
|
),
|
||||||
&["<Primary>s"],
|
&["<Primary>s"],
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
format!(
|
||||||
|
"{}.{}",
|
||||||
|
browser.window.action.id,
|
||||||
|
browser.window.action.source.gobject.name()
|
||||||
|
),
|
||||||
|
&["<Primary>u"],
|
||||||
|
),
|
||||||
(
|
(
|
||||||
format!(
|
format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
|
@ -86,6 +86,11 @@ impl Window {
|
|||||||
move |position| tab.save_as(position)
|
move |position| tab.save_as(position)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
action.source.connect_activate({
|
||||||
|
let tab = tab.clone();
|
||||||
|
move |position| tab.source(position)
|
||||||
|
});
|
||||||
|
|
||||||
action.history_back.connect_activate({
|
action.history_back.connect_activate({
|
||||||
let tab = tab.clone();
|
let tab = tab.clone();
|
||||||
move |position| {
|
move |position| {
|
||||||
|
@ -8,6 +8,7 @@ mod home;
|
|||||||
mod pin;
|
mod pin;
|
||||||
mod reload;
|
mod reload;
|
||||||
mod save_as;
|
mod save_as;
|
||||||
|
mod source;
|
||||||
|
|
||||||
use append::Append;
|
use append::Append;
|
||||||
use bookmark::Bookmark;
|
use bookmark::Bookmark;
|
||||||
@ -19,6 +20,7 @@ use home::Home;
|
|||||||
use pin::Pin;
|
use pin::Pin;
|
||||||
use reload::Reload;
|
use reload::Reload;
|
||||||
use save_as::SaveAs;
|
use save_as::SaveAs;
|
||||||
|
use source::Source;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleActionGroup,
|
gio::SimpleActionGroup,
|
||||||
@ -42,6 +44,7 @@ pub struct Action {
|
|||||||
pub pin: Rc<Pin>,
|
pub pin: Rc<Pin>,
|
||||||
pub reload: Rc<Reload>,
|
pub reload: Rc<Reload>,
|
||||||
pub save_as: Rc<SaveAs>,
|
pub save_as: Rc<SaveAs>,
|
||||||
|
pub source: Rc<Source>,
|
||||||
// Group
|
// Group
|
||||||
pub id: GString,
|
pub id: GString,
|
||||||
pub gobject: SimpleActionGroup,
|
pub gobject: SimpleActionGroup,
|
||||||
@ -63,6 +66,7 @@ impl Action {
|
|||||||
let pin = Rc::new(Pin::new());
|
let pin = Rc::new(Pin::new());
|
||||||
let reload = Rc::new(Reload::new());
|
let reload = Rc::new(Reload::new());
|
||||||
let save_as = Rc::new(SaveAs::new());
|
let save_as = Rc::new(SaveAs::new());
|
||||||
|
let source = Rc::new(Source::new());
|
||||||
|
|
||||||
// Generate unique group ID
|
// Generate unique group ID
|
||||||
let id = uuid_string_random();
|
let id = uuid_string_random();
|
||||||
@ -81,6 +85,7 @@ impl Action {
|
|||||||
gobject.add_action(&pin.gobject);
|
gobject.add_action(&pin.gobject);
|
||||||
gobject.add_action(&reload.gobject);
|
gobject.add_action(&reload.gobject);
|
||||||
gobject.add_action(&save_as.gobject);
|
gobject.add_action(&save_as.gobject);
|
||||||
|
gobject.add_action(&source.gobject);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Self {
|
Self {
|
||||||
@ -94,6 +99,7 @@ impl Action {
|
|||||||
pin,
|
pin,
|
||||||
reload,
|
reload,
|
||||||
save_as,
|
save_as,
|
||||||
|
source,
|
||||||
id,
|
id,
|
||||||
gobject,
|
gobject,
|
||||||
}
|
}
|
||||||
|
64
src/app/browser/window/action/source.rs
Normal file
64
src/app/browser/window/action/source.rs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
use gtk::{
|
||||||
|
gio::SimpleAction,
|
||||||
|
glib::uuid_string_random,
|
||||||
|
prelude::{ActionExt, ToVariant},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
|
||||||
|
/// C-compatible variant type
|
||||||
|
const DEFAULT_STATE: i32 = -1;
|
||||||
|
|
||||||
|
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Source` action of `Window` group
|
||||||
|
pub struct Source {
|
||||||
|
pub gobject: SimpleAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Source {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self`
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
gobject: SimpleAction::new_stateful(
|
||||||
|
&uuid_string_random(),
|
||||||
|
None,
|
||||||
|
&DEFAULT_STATE.to_variant(),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
/// Change action [state](https://docs.gtk.org/gio/method.SimpleAction.set_state.html)
|
||||||
|
/// * set `DEFAULT_STATE` on `None`
|
||||||
|
pub fn change_state(&self, state: Option<i32>) {
|
||||||
|
self.gobject.change_state(
|
||||||
|
&match state {
|
||||||
|
Some(value) => value,
|
||||||
|
None => DEFAULT_STATE,
|
||||||
|
}
|
||||||
|
.to_variant(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Events
|
||||||
|
|
||||||
|
/// Define callback function for
|
||||||
|
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
|
||||||
|
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
|
||||||
|
self.gobject.connect_activate(move |this, _| {
|
||||||
|
let state = this
|
||||||
|
.state()
|
||||||
|
.expect("State value required")
|
||||||
|
.get::<i32>()
|
||||||
|
.expect("Parameter type does not match `i32`");
|
||||||
|
|
||||||
|
callback(if state == DEFAULT_STATE {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(state)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -59,6 +59,17 @@ impl Menu {
|
|||||||
|
|
||||||
main_page.append_section(None, &main_page_mark);
|
main_page.append_section(None, &main_page_mark);
|
||||||
|
|
||||||
|
// Main > Page > Tools
|
||||||
|
let main_page_tools = gio::Menu::new();
|
||||||
|
|
||||||
|
main_page_tools.append(Some("Source"), Some(&format!(
|
||||||
|
"{}.{}",
|
||||||
|
window_action.id,
|
||||||
|
window_action.source.gobject.name()
|
||||||
|
)));
|
||||||
|
|
||||||
|
main_page.append_section(None, &main_page_tools);
|
||||||
|
|
||||||
// Main > Page > Navigation
|
// Main > Page > Navigation
|
||||||
let main_page_navigation = gio::Menu::new();
|
let main_page_navigation = gio::Menu::new();
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ impl Tab {
|
|||||||
action.pin.change_state(state);
|
action.pin.change_state(state);
|
||||||
action.reload.change_state(state);
|
action.reload.change_state(state);
|
||||||
action.save_as.change_state(state);
|
action.save_as.change_state(state);
|
||||||
|
action.source.change_state(state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -161,6 +162,14 @@ impl Tab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// View source for page at given `position`, `None` to use selected page (if available)
|
||||||
|
pub fn source(&self, page_position: Option<i32>) {
|
||||||
|
if let Some(item) = self.item(page_position) {
|
||||||
|
item.page.navigation.request.to_source();
|
||||||
|
item.page.load(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Toggle `Bookmark` in current `Profile` for `Page` at given `position` (current page on `None`)
|
/// Toggle `Bookmark` in current `Profile` for `Page` at given `position` (current page on `None`)
|
||||||
/// * return `true` on bookmark created, `false` on deleted; `Error` otherwise.
|
/// * return `true` on bookmark created, `false` on deleted; `Error` otherwise.
|
||||||
pub fn bookmark(&self, page_position: Option<i32>) -> Result<bool, Error> {
|
pub fn bookmark(&self, page_position: Option<i32>) -> Result<bool, Error> {
|
||||||
|
@ -94,6 +94,10 @@ impl Request {
|
|||||||
self.widget.entry.set_text(&self.download());
|
self.widget.entry.set_text(&self.download());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_source(&self) {
|
||||||
|
self.widget.entry.set_text(&self.source());
|
||||||
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
pub fn uri(&self) -> Option<Uri> {
|
pub fn uri(&self) -> Option<Uri> {
|
||||||
@ -120,6 +124,10 @@ impl Request {
|
|||||||
pub fn download(&self) -> GString {
|
pub fn download(&self) -> GString {
|
||||||
gformat!("download:{}", self.strip_prefix())
|
gformat!("download:{}", self.strip_prefix())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn source(&self) -> GString {
|
||||||
|
gformat!("source:{}", self.strip_prefix())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
|
@ -56,6 +56,19 @@ impl Menu {
|
|||||||
|
|
||||||
main.append_section(None, &main_mark);
|
main.append_section(None, &main_mark);
|
||||||
|
|
||||||
|
let main_tools = gtk::gio::Menu::new();
|
||||||
|
|
||||||
|
main_tools.append(
|
||||||
|
Some("Source"),
|
||||||
|
Some(&format!(
|
||||||
|
"{}.{}",
|
||||||
|
window_action.id,
|
||||||
|
window_action.source.gobject.name()
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
main.append_section(None, &main_tools);
|
||||||
|
|
||||||
let navigation = gtk::gio::Menu::new();
|
let navigation = gtk::gio::Menu::new();
|
||||||
|
|
||||||
navigation.append(
|
navigation.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user