edit: Add Cancel button
This commit is contained in:
parent
1fc9674cb8
commit
b6bdc9398d
3 changed files with 34 additions and 6 deletions
|
|
@ -21,12 +21,11 @@ use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
|
|
||||||
use super::edit::LpEditCrop;
|
use super::edit::LpEditCrop;
|
||||||
use super::LpImage;
|
use super::{LpImage, LpWindow};
|
||||||
use crate::deps::*;
|
use crate::deps::*;
|
||||||
mod imp {
|
|
||||||
|
|
||||||
|
mod imp {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::widgets::LpImage;
|
|
||||||
|
|
||||||
#[derive(Debug, Default, gtk::CompositeTemplate, glib::Properties)]
|
#[derive(Debug, Default, gtk::CompositeTemplate, glib::Properties)]
|
||||||
#[properties(wrapper_type = super::LpEditWindow)]
|
#[properties(wrapper_type = super::LpEditWindow)]
|
||||||
|
|
@ -34,7 +33,11 @@ mod imp {
|
||||||
pub struct LpEditWindow {
|
pub struct LpEditWindow {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
toolbar_view: TemplateChild<adw::ToolbarView>,
|
toolbar_view: TemplateChild<adw::ToolbarView>,
|
||||||
|
#[template_child]
|
||||||
|
cancel: TemplateChild<gtk::Button>,
|
||||||
|
|
||||||
|
#[property(get, construct_only)]
|
||||||
|
window: OnceCell<LpWindow>,
|
||||||
#[property(get, construct_only)]
|
#[property(get, construct_only)]
|
||||||
original_image: OnceCell<LpImage>,
|
original_image: OnceCell<LpImage>,
|
||||||
}
|
}
|
||||||
|
|
@ -63,6 +66,14 @@ mod imp {
|
||||||
|
|
||||||
self.toolbar_view
|
self.toolbar_view
|
||||||
.set_content(Some(&LpEditCrop::new(obj.original_image())));
|
.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 {
|
impl LpEditWindow {
|
||||||
pub fn new(image: LpImage) -> Self {
|
pub fn new(window: LpWindow, image: LpImage) -> Self {
|
||||||
glib::Object::builder()
|
glib::Object::builder()
|
||||||
|
.property("window", window)
|
||||||
.property("original_image", image)
|
.property("original_image", image)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,18 @@
|
||||||
<template class="LpEditWindow" parent="AdwBin">
|
<template class="LpEditWindow" parent="AdwBin">
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="AdwToolbarView" id="toolbar_view">
|
<object class="AdwToolbarView" id="toolbar_view">
|
||||||
|
<property name="top-bar-style">raised</property>
|
||||||
<child type="top">
|
<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>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -189,11 +189,17 @@ impl LpWindow {
|
||||||
about.present(Some(self));
|
about.present(Some(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_image(&self) {
|
||||||
|
self.imp()
|
||||||
|
.stack
|
||||||
|
.set_visible_child(&*self.imp().image_window);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show_edit(&self) {
|
pub fn show_edit(&self) {
|
||||||
if let Some(image) = self.image_view().current_image() {
|
if let Some(image) = self.image_view().current_image() {
|
||||||
let edit_child = &*self.imp().edit_window_child;
|
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);
|
self.imp().stack.set_visible_child(edit_child);
|
||||||
} else {
|
} else {
|
||||||
log::error!("Can't open image editor since no current image exists");
|
log::error!("Can't open image editor since no current image exists");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue