feat: click envelope image to open with an image viewer
This commit is contained in:
parent
12de95ca55
commit
464b97f889
1 changed files with 29 additions and 7 deletions
|
@ -23,18 +23,24 @@ pub struct AdviceCard {
|
|||
#[do_not_track]
|
||||
metadata: Advice,
|
||||
texture: Option<gdk::Texture>,
|
||||
file: Option<gio::File>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AdviceCardCmds {
|
||||
GotTexture(gdk::Texture),
|
||||
GotTexture(gio::File, gdk::Texture),
|
||||
Error(LibraryError),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AdviceCardInput {
|
||||
OpenFile
|
||||
}
|
||||
|
||||
#[relm4::factory(pub)]
|
||||
impl FactoryComponent for AdviceCard {
|
||||
type Init = Advice;
|
||||
type Input = ();
|
||||
type Input = AdviceCardInput;
|
||||
type Output = ();
|
||||
type CommandOutput = AdviceCardCmds;
|
||||
type ParentWidget = gtk::FlowBox;
|
||||
|
@ -42,8 +48,8 @@ impl FactoryComponent for AdviceCard {
|
|||
/* TODO:
|
||||
* Action "View in Image viewer":
|
||||
* Triggers:
|
||||
* - One click on "enlarge" button
|
||||
* - Double click on "texture" itself
|
||||
* - [x] One click on "enlarge" button
|
||||
* - [ ] Double click on "texture" itself
|
||||
* (Is there a better way than this?)
|
||||
* Create temporary file, let application open this file...
|
||||
*/
|
||||
|
@ -78,6 +84,8 @@ impl FactoryComponent for AdviceCard {
|
|||
set_icon_name: "four-arrows-pointing-outward-symbolic",
|
||||
|
||||
set_margin_all: 8,
|
||||
|
||||
connect_clicked => AdviceCardInput::OpenFile,
|
||||
},
|
||||
|
||||
#[wrap(Some)]
|
||||
|
@ -94,6 +102,7 @@ impl FactoryComponent for AdviceCard {
|
|||
let _self = Self {
|
||||
metadata: value.clone(),
|
||||
texture: None,
|
||||
file: None,
|
||||
tracker: 0,
|
||||
};
|
||||
|
||||
|
@ -119,7 +128,7 @@ impl FactoryComponent for AdviceCard {
|
|||
file
|
||||
};
|
||||
|
||||
let image = glycin::Loader::new(file)
|
||||
let image = glycin::Loader::new(file.clone())
|
||||
.load()
|
||||
.await
|
||||
.expect("Image decoding failed");
|
||||
|
@ -128,7 +137,7 @@ impl FactoryComponent for AdviceCard {
|
|||
.await
|
||||
.expect("Image frame decoding failed");
|
||||
|
||||
AdviceCardCmds::GotTexture(frame.texture())
|
||||
AdviceCardCmds::GotTexture(file, frame.texture())
|
||||
});
|
||||
|
||||
_self
|
||||
|
@ -136,8 +145,21 @@ impl FactoryComponent for AdviceCard {
|
|||
|
||||
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
AdviceCardCmds::GotTexture(texture) => self.set_texture(Some(texture)),
|
||||
AdviceCardCmds::GotTexture(file, texture) => {
|
||||
self.set_texture(Some(texture));
|
||||
self.set_file(Some(file));
|
||||
},
|
||||
AdviceCardCmds::Error(err) => todo!(),
|
||||
};
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
AdviceCardInput::OpenFile => {
|
||||
let file_launcher = gtk::FileLauncher::new(self.get_file().as_ref());
|
||||
file_launcher.set_always_ask(true);
|
||||
file_launcher.launch(None::<>k::Window>, None::<&gio::Cancellable>, |_| {});
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue