Skip to content

Commit a673dad

Browse files
committed
disable previous next buttons when not available, fix progress
1 parent 46b88fc commit a673dad

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

src/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ macro_rules! self_action {
66
let action = gio::SimpleAction::new($name, None);
77
action.connect_activate(clone!(@weak this => move |_,_| this.$method()));
88
$self.add_action(&action);
9+
action
910
}
1011
}
1112
}

src/tab.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use crate::common::{glibctx, HistoryItem, LossyTextRead, PageElement, RequestCtx
2323
use crate::draw_ctx::DrawCtx;
2424
use crate::gemini;
2525

26-
#[derive(Clone, glib::Boxed, Default)]
26+
#[derive(Clone, Debug, glib::Boxed, Default)]
2727
#[boxed_type(name = "GeopardHistoryStatus")]
2828
pub struct HistoryStatus {
29-
current: usize,
30-
available: usize,
29+
pub(crate) current: usize,
30+
pub(crate) available: usize,
3131
}
3232
pub mod imp {
3333

@@ -230,16 +230,20 @@ impl Tab {
230230
}
231231
fn add_to_history(&self, item: HistoryItem) -> usize {
232232
let imp = self.imp();
233-
let mut history = imp.history.borrow_mut();
234-
let i = *imp.current_hi.borrow();
235-
if let Some(i) = i {
236-
let scroll_progress = imp.scroll_win.vadjustment().value();
237-
history[i].scroll_progress = scroll_progress;
238-
history.truncate(i + 1);
233+
let i = {
234+
let mut history = imp.history.borrow_mut();
235+
let i = *imp.current_hi.borrow();
236+
if let Some(i) = i {
237+
let scroll_progress = imp.scroll_win.vadjustment().value();
238+
history[i].scroll_progress = scroll_progress;
239+
history.truncate(i + 1);
240+
};
241+
history.push(item);
242+
let i = history.len() - 1;
243+
imp.current_hi.replace(Some(i));
244+
i
239245
};
240-
history.push(item);
241-
let i = history.len() - 1;
242-
imp.current_hi.replace(Some(i));
246+
self.notify("history-status");
243247
self.log_history_position();
244248
i
245249
}
@@ -293,6 +297,9 @@ impl Tab {
293297
let imp = self.imp();
294298
let mut draw_ctx = imp.draw_ctx.borrow().clone().unwrap();
295299

300+
*self.imp().progress.borrow_mut() = 0.0;
301+
self.notify("progress");
302+
296303
*self.imp().title.borrow_mut() = url.to_string();
297304
self.notify("title");
298305

@@ -326,6 +333,7 @@ impl Tab {
326333
};
327334
imp.current_hi.replace(Some(i));
328335
self.log_history_position();
336+
self.notify("history-status");
329337

330338
let h = { imp.history.borrow_mut().get(i).cloned() };
331339
h.map(|x| self.spawn_request(self.open_history(x)))
@@ -342,6 +350,7 @@ impl Tab {
342350
};
343351
imp.current_hi.replace(Some(i));
344352
self.log_history_position();
353+
self.notify("history-status");
345354

346355
let h = { imp.history.borrow_mut().get(i).cloned() };
347356
h.map(|x| self.spawn_request(self.open_history(x)))

src/window.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use url::Url;
1616

1717
use crate::common::{bookmarks_url, glibctx, BOOKMARK_FILE_PATH};
1818
use crate::config;
19+
use crate::tab::HistoryStatus;
1920
use crate::tab::Tab;
2021
use crate::{self_action, view};
2122

@@ -38,6 +39,8 @@ pub mod imp {
3839
#[prop(get = Self::progress_animated, set = Self::set_progress_animated)]
3940
pub(crate) progress: PhantomData<f64>,
4041
pub(crate) scroll_ctrl: gtk::EventControllerScroll,
42+
pub(crate) action_previous: RefCell<Option<gio::SimpleAction>>,
43+
pub(crate) action_next: RefCell<Option<gio::SimpleAction>>,
4144
}
4245

4346
impl Window {
@@ -246,8 +249,11 @@ impl Window {
246249
fn setup_actions_signals(&self) {
247250
let imp = self.imp();
248251

249-
self_action!(self, "previous", previous);
250-
self_action!(self, "next", next);
252+
let action_previous = self_action!(self, "previous", previous);
253+
let action_next = self_action!(self, "next", next);
254+
imp.action_previous.borrow_mut().replace(action_previous);
255+
imp.action_next.borrow_mut().replace(action_next);
256+
251257
self_action!(self, "new-tab", add_tab_focused);
252258
self_action!(self, "show-bookmarks", add_tab_focused);
253259
self_action!(self, "bookmark-current", bookmark_current);
@@ -338,6 +344,30 @@ impl Window {
338344
tab.bind_property("progress", self, "progress")
339345
.flags(glib::BindingFlags::SYNC_CREATE)
340346
.build(),
347+
tab.bind_property(
348+
"history-status",
349+
imp.action_next.borrow().as_ref().unwrap(),
350+
"enabled",
351+
)
352+
.flags(glib::BindingFlags::SYNC_CREATE)
353+
.transform_to(|_, v| {
354+
let v: HistoryStatus = v.get().unwrap();
355+
let res = v.current + 1 < v.available;
356+
Some(res.to_value())
357+
})
358+
.build(),
359+
tab.bind_property(
360+
"history-status",
361+
imp.action_previous.borrow().as_ref().unwrap(),
362+
"enabled",
363+
)
364+
.flags(glib::BindingFlags::SYNC_CREATE)
365+
.transform_to(|_, v| {
366+
let v: HistoryStatus = v.get().unwrap();
367+
let res = v.available >= 1 && v.current > 0;
368+
Some(res.to_value())
369+
})
370+
.build(),
341371
]);
342372
};
343373
}

0 commit comments

Comments
 (0)