mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
draft history navigation
This commit is contained in:
parent
fceb3a75a4
commit
f44b48a8ab
@ -89,10 +89,13 @@ impl Page {
|
|||||||
.get::<String>()
|
.get::<String>()
|
||||||
.expect("Parameter does not match `String`");
|
.expect("Parameter does not match `String`");
|
||||||
|
|
||||||
|
let request = GString::from(uri);
|
||||||
|
|
||||||
navigation.set_request_text(
|
navigation.set_request_text(
|
||||||
&GString::from(uri),
|
&request, true, // activate (page reload)
|
||||||
true, // activate (page reload)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
navigation.add_history(request);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -85,6 +85,10 @@ impl Navigation {
|
|||||||
self.request.widget().grab_focus();
|
self.request.widget().grab_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_history(&self, request: GString) {
|
||||||
|
self.history.add(request, true);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(&self, progress_fraction: Option<f64>) {
|
pub fn update(&self, progress_fraction: Option<f64>) {
|
||||||
self.base.update(self.request.uri());
|
self.base.update(self.request.uri());
|
||||||
self.history.update();
|
self.history.update();
|
||||||
|
@ -17,8 +17,8 @@ pub struct History {
|
|||||||
back: Back,
|
back: Back,
|
||||||
forward: Forward,
|
forward: Forward,
|
||||||
// Extras
|
// Extras
|
||||||
memory: Vec<Memory>,
|
memory: RefCell<Vec<Memory>>,
|
||||||
index: RefCell<i32>,
|
index: RefCell<Option<usize>>,
|
||||||
// GTK
|
// GTK
|
||||||
widget: Box,
|
widget: Box,
|
||||||
}
|
}
|
||||||
@ -45,10 +45,10 @@ impl History {
|
|||||||
widget.append(forward.widget());
|
widget.append(forward.widget());
|
||||||
|
|
||||||
// Init memory
|
// Init memory
|
||||||
let memory = Vec::new();
|
let memory = RefCell::new(Vec::new());
|
||||||
|
|
||||||
// Init index
|
// Init index
|
||||||
let index = RefCell::new(-1);
|
let index = RefCell::new(None);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
// Actions
|
// Actions
|
||||||
@ -63,9 +63,55 @@ impl History {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
pub fn add(&self, request: GString, follow_to_index: bool) {
|
||||||
|
// Append new Memory record
|
||||||
|
self.memory.borrow_mut().push(Memory { request, time: 0 });
|
||||||
|
|
||||||
|
if follow_to_index {
|
||||||
|
// Navigate to the last record appended
|
||||||
|
self.index.replace(Some(self.memory.borrow().len()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_back(&self, follow_to_index: bool) -> Option<GString> {
|
||||||
|
if let Some(index) = self.index.take() {
|
||||||
|
if let Some(memory) = self.memory.borrow().get(index - 1) {
|
||||||
|
if follow_to_index {
|
||||||
|
self.index.replace(Some(index - 1));
|
||||||
|
}
|
||||||
|
return Some(memory.request.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @TODO
|
||||||
|
pub fn try_current(&self) -> bool {
|
||||||
|
true
|
||||||
|
} */
|
||||||
|
|
||||||
|
pub fn try_forward(&self, follow_to_index: bool) -> Option<GString> {
|
||||||
|
if let Some(index) = self.index.take() {
|
||||||
|
if let Some(memory) = self.memory.borrow().get(index + 1) {
|
||||||
|
if follow_to_index {
|
||||||
|
self.index.replace(Some(index + 1));
|
||||||
|
}
|
||||||
|
return Some(memory.request.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
self.back.update();
|
match self.try_back(false) {
|
||||||
self.forward.update();
|
Some(_) => self.back.update(true),
|
||||||
|
None => self.back.update(false),
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.try_forward(false) {
|
||||||
|
Some(_) => self.forward.update(true),
|
||||||
|
None => self.forward.update(false),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
prelude::{ActionExt, ButtonExt},
|
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||||
Button,
|
Button,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -37,8 +37,10 @@ impl Back {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self) {
|
pub fn update(&self, status: bool) {
|
||||||
// @TODO
|
self.action_tab_page_navigation_history_back
|
||||||
|
.set_enabled(status);
|
||||||
|
self.widget.set_sensitive(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::{ActionExt, ButtonExt},
|
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||||
{gio::SimpleAction, Button},
|
{gio::SimpleAction, Button},
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -36,8 +36,10 @@ impl Forward {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn update(&self) {
|
pub fn update(&self, status: bool) {
|
||||||
// @TODO
|
self.action_tab_page_navigation_history_forward
|
||||||
|
.set_enabled(status);
|
||||||
|
self.widget.set_sensitive(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
Loading…
x
Reference in New Issue
Block a user