edit: Add Cancel button

This commit is contained in:
Sophie Herold 2024-09-17 22:13:35 +02:00
parent 1fc9674cb8
commit b6bdc9398d
3 changed files with 34 additions and 6 deletions

View file

@ -21,12 +21,11 @@ use adw::prelude::*;
use adw::subclass::prelude::*;
use super::edit::LpEditCrop;
use super::LpImage;
use super::{LpImage, LpWindow};
use crate::deps::*;
mod imp {
mod imp {
use super::*;
use crate::widgets::LpImage;
#[derive(Debug, Default, gtk::CompositeTemplate, glib::Properties)]
#[properties(wrapper_type = super::LpEditWindow)]
@ -34,7 +33,11 @@ mod imp {
pub struct LpEditWindow {
#[template_child]
toolbar_view: TemplateChild<adw::ToolbarView>,
#[template_child]
cancel: TemplateChild<gtk::Button>,
#[property(get, construct_only)]
window: OnceCell<LpWindow>,
#[property(get, construct_only)]
original_image: OnceCell<LpImage>,
}
@ -63,6 +66,14 @@ mod imp {
self.toolbar_view
.set_content(Some(&LpEditCrop::new(obj.original_image())));
self.cancel.connect_clicked(glib::clone!(
#[weak]
obj,
move |_| {
obj.window().show_image();
}
));
}
}
@ -76,8 +87,9 @@ glib::wrapper! {
}
impl LpEditWindow {
pub fn new(image: LpImage) -> Self {
pub fn new(window: LpWindow, image: LpImage) -> Self {
glib::Object::builder()
.property("window", window)
.property("original_image", image)
.build()
}

View file

@ -3,8 +3,18 @@
<template class="LpEditWindow" parent="AdwBin">
<property name="child">
<object class="AdwToolbarView" id="toolbar_view">
<property name="top-bar-style">raised</property>
<child type="top">
<object class="AdwHeaderBar"></object>
<object class="AdwHeaderBar">
<property name="show-title">false</property>
<property name="show-start-title-buttons">false</property>
<property name="show-start-title-buttons">false</property>
<child type="start">
<object class="GtkButton" id="cancel">
<property name="label" translatable="true">Cancel</property>
</object>
</child>
</object>
</child>
</object>
</property>

View file

@ -189,11 +189,17 @@ impl LpWindow {
about.present(Some(self));
}
pub fn show_image(&self) {
self.imp()
.stack
.set_visible_child(&*self.imp().image_window);
}
pub fn show_edit(&self) {
if let Some(image) = self.image_view().current_image() {
let edit_child = &*self.imp().edit_window_child;
edit_child.set_child(Some(&LpEditWindow::new(image)));
edit_child.set_child(Some(&LpEditWindow::new(self.clone(), image)));
self.imp().stack.set_visible_child(edit_child);
} else {
log::error!("Can't open image editor since no current image exists");