window: Fix title not changed when no image shown

Closes #279
This commit is contained in:
Sophie Herold 2023-11-29 20:15:42 +01:00
parent 7d36c93029
commit 4b510412e1
4 changed files with 19 additions and 18 deletions

View file

@ -132,6 +132,14 @@ mod imp {
// Manually mange widget layout, see `WidgetImpl` for details // Manually mange widget layout, see `WidgetImpl` for details
obj.set_layout_manager(None::<gtk::LayoutManager>); obj.set_layout_manager(None::<gtk::LayoutManager>);
self.sliding_view.connect_current_page_notify(
glib::clone!(@weak obj => move |_| obj.page_changed()),
);
self.sliding_view.connect_target_page_reached(
glib::clone!(@weak obj => move || obj.target_page_reached()),
);
let signal_group = glib::SignalGroup::new::<LpImage>(); let signal_group = glib::SignalGroup::new::<LpImage>();
obj.connect_notify_local( obj.connect_notify_local(
Some("current-page"), Some("current-page"),
@ -574,11 +582,10 @@ impl LpImageView {
self.imp().drag_source.clone() self.imp().drag_source.clone()
} }
#[template_callback] fn page_changed(&self) {
fn page_changed_cb(&self) { self.notify_current_page();
self.notify("current-page"); self.notify_is_next_available();
self.notify("is-previous-available"); self.notify_is_previous_available();
self.notify("is-next-available");
let Some(new_page) = self.current_page() else { let Some(new_page) = self.current_page() else {
log::debug!("Page changed but no current page"); log::debug!("Page changed but no current page");
@ -590,9 +597,8 @@ impl LpImageView {
} }
} }
#[template_callback]
/// Called when page change animation completed /// Called when page change animation completed
fn target_page_reached_cb(&self) { fn target_page_reached(&self) {
let current_page = self.current_page(); let current_page = self.current_page();
if self.imp().preserve_content.get() { if self.imp().preserve_content.get() {

View file

@ -8,10 +8,7 @@
<object class="GtkOverlay" id="bin_child"> <object class="GtkOverlay" id="bin_child">
<property name="hexpand">True</property> <property name="hexpand">True</property>
<child> <child>
<object class="LpSlidingView" id="sliding_view"> <object class="LpSlidingView" id="sliding_view" />
<signal name="notify::current-page" handler="page_changed_cb" swapped="yes" />
<signal name="target-page-reached" handler="target_page_reached_cb" swapped="yes" />
</object>
</child> </child>
<child type="overlay"> <child type="overlay">
<object class="GtkBox" id="controls_box_start"> <object class="GtkBox" id="controls_box_start">

View file

@ -36,7 +36,7 @@ use std::path::{Path, PathBuf};
use crate::config; use crate::config;
use crate::util::{self, Direction, Position}; use crate::util::{self, Direction, Position};
use crate::widgets::{LpDragOverlay, LpImage, LpImageView, LpPropertiesView}; use crate::widgets::{LpDragOverlay, LpImage, LpImagePage, LpImageView, LpPropertiesView};
/// Show window after X milliseconds even if image dimensions are not known yet /// Show window after X milliseconds even if image dimensions are not known yet
const SHOW_WINDOW_AFTER: u64 = 2000; const SHOW_WINDOW_AFTER: u64 = 2000;
@ -884,7 +884,9 @@ impl LpWindow {
// have multiple `match` or `if let` branches, and without needing // have multiple `match` or `if let` branches, and without needing
// to unwrap. // to unwrap.
#[template_callback] #[template_callback]
fn window_title(&self, file: Option<&gio::File>) -> String { fn window_title(&self, current_page: Option<&LpImagePage>) -> String {
let file = current_page.and_then(|x| x.image().file());
// ensure that templates are initialized // ensure that templates are initialized
if file.is_none() { if file.is_none() {
gettext("Image Viewer") gettext("Image Viewer")

View file

@ -65,11 +65,7 @@
<signal name="notify::fullscreened" handler="on_fullscreened" swapped="yes" /> <signal name="notify::fullscreened" handler="on_fullscreened" swapped="yes" />
<binding name="title"> <binding name="title">
<closure type="gchararray" function="window_title"> <closure type="gchararray" function="window_title">
<lookup name="file">
<lookup name="image">
<lookup name="current-page">image_view</lookup> <lookup name="current-page">image_view</lookup>
</lookup>
</lookup>
</closure> </closure>
</binding> </binding>
<child> <child>