window: Add reload button and F5 shortcut

Reloading makes sense for out of memory situations or filesystems that
don't support inotify.
This commit is contained in:
Sophie Herold 2024-07-29 04:59:10 +02:00
parent c3547f82fc
commit 053aa5da7e
6 changed files with 56 additions and 7 deletions

View file

@ -56,13 +56,19 @@
</property>
<child type="bottom">
<object class="GtkButton" id="report">
<property name="label" translatable="yes">Report Issue…</property>
<property name="halign">center</property>
<property name="margin-bottom">24</property>
<style>
<class name="suggested-action" />
<class name="pill" />
</style>
<child>
<object class="AdwButtonContent">
<property name="icon-name">external-link-symbolic</property>
<property name="label" translatable="yes">Report _Issue</property>
<property name="use-underline">true</property>
</object>
</child>
</object>
</child>
</object>

View file

@ -290,6 +290,15 @@ impl LpImage {
self.imp().file.replace(Some(file.clone()));
}
pub async fn reload(&self) {
dbg!("reloadking");
if let Some(file) = self.file() {
self.load(&file).await;
} else {
log::error!("Trying to reload image without file");
}
}
pub async fn load(&self, file: &gio::File) {
let imp = self.imp();
log::debug!("Loading file {}", file.uri());

View file

@ -47,7 +47,7 @@
<property name="hexpand">true</property>
<property name="vexpand">true</property>
<child>
<object class="AdwSpinner" id="spinner"/>
<object class="AdwSpinner" id="spinner" />
</child>
</object>
</child>
@ -56,12 +56,30 @@
<property name="icon-name">image-missing-symbolic</property>
<property name="title" translatable="yes">Could not Load Image</property>
<child>
<object class="GtkButton" id="error_more_info">
<property name="label" translatable="true">More Information…</property>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<property name="halign">center</property>
<style>
<class name="pill" />
</style>
<child>
<object class="GtkButton" id="error_more_info">
<property name="label" translatable="true">More _Information</property>
<property name="use-underline">true</property>
<style>
<class name="suggested-action" />
<class name="pill" />
</style>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="true">_Reload</property>
<property name="use-underline">true</property>
<property name="action-name">win.reload</property>
<style>
<class name="pill" />
</style>
</object>
</child>
</object>
</child>
</object>

View file

@ -758,6 +758,8 @@ impl LpWindow {
for action in ACTIONS {
self.action_set_enabled(action, enabled);
}
self.action_set_enabled(Action::Reload.as_ref(), true);
}
/// Handles change in image and availability of images

View file

@ -194,6 +194,8 @@ pub enum Action {
ToggleProperties,
#[strum(to_string = "win.about")]
About,
#[strum(to_string = "win.reload")]
Reload,
}
impl Action {
@ -467,6 +469,17 @@ impl Action {
win.show_about().await
});
}
Action::Reload => {
klass.install_action_async(&action, None, move |win, _, _| async move {
if let Some(current_page) = win.imp().image_view.current_page() {
current_page.image().reload().await;
} else {
log::error!("No current image to reload");
}
});
klass.add_binding_action(gdk::Key::F5, gdk::ModifierType::empty(), &action);
}
}
}
}