window: Properties button insensitive for no image

Make the toggle button insensitve if no image is shown.
Also close the properties if no image is shown anymore.

Closes #60

Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/193>
This commit is contained in:
Sophie Herold 2023-04-20 21:40:55 +02:00 • committed by Marge Bot
parent 2dbc7fa585
commit 4037b124d2
2 changed files with 10 additions and 9 deletions

View file

@ -87,7 +87,7 @@
</object> </object>
</child> </child>
<child type="end"> <child type="end">
<object class="GtkMenuButton" id="menu_button"> <object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property> <property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Main Menu</property> <property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="primary">True</property> <property name="primary">True</property>

View file

@ -72,8 +72,6 @@ mod imp {
#[template_child] #[template_child]
pub(super) properties_button: TemplateChild<gtk::ToggleButton>, pub(super) properties_button: TemplateChild<gtk::ToggleButton>,
#[template_child] #[template_child]
pub(super) menu_button: TemplateChild<gtk::MenuButton>,
#[template_child]
pub(super) toast_overlay: TemplateChild<adw::ToastOverlay>, pub(super) toast_overlay: TemplateChild<adw::ToastOverlay>,
#[template_child] #[template_child]
pub(super) stack: TemplateChild<gtk::Stack>, pub(super) stack: TemplateChild<gtk::Stack>,
@ -238,7 +236,7 @@ mod imp {
// and keeps the others usable // and keeps the others usable
gtk::WindowGroup::new().add_window(&*obj); gtk::WindowGroup::new().add_window(&*obj);
obj.set_actions_enabled(false); obj.images_available();
let current_image_signals = self.image_view.current_image_signals(); let current_image_signals = self.image_view.current_image_signals();
// clone! is a macro from glib-rs that allows // clone! is a macro from glib-rs that allows
@ -596,15 +594,18 @@ impl LpWindow {
fn images_available(&self) { fn images_available(&self) {
let imp = self.imp(); let imp = self.imp();
if imp.image_view.current_page().is_some() { let shows_image = imp.image_view.current_page().is_some();
imp.stack.set_visible_child(&*imp.image_view);
self.set_actions_enabled(true);
imp.image_view.grab_focus();
imp.properties_button.set_sensitive(shows_image);
self.set_actions_enabled(shows_image);
if shows_image {
imp.stack.set_visible_child(&*imp.image_view);
imp.image_view.grab_focus();
self.queue_hide_controls(); self.queue_hide_controls();
} else { } else {
imp.properties_button.set_active(false);
imp.stack.set_visible_child(&*imp.status_page); imp.stack.set_visible_child(&*imp.status_page);
self.set_actions_enabled(false);
imp.status_page.grab_focus(); imp.status_page.grab_focus();
} }
} }