Compare commits

..

No commits in common. "jane400/open-envelope-in-image-viewer" and "main" have entirely different histories.

View file

@ -23,24 +23,18 @@ pub struct AdviceCard {
#[do_not_track]
metadata: Advice,
texture: Option<gdk::Texture>,
file: Option<gio::File>,
}
#[derive(Debug)]
pub enum AdviceCardCmds {
GotTexture(gio::File, gdk::Texture),
GotTexture(gdk::Texture),
Error(LibraryError),
}
#[derive(Debug)]
pub enum AdviceCardInput {
OpenFile
}
#[relm4::factory(pub)]
impl FactoryComponent for AdviceCard {
type Init = Advice;
type Input = AdviceCardInput;
type Input = ();
type Output = ();
type CommandOutput = AdviceCardCmds;
type ParentWidget = gtk::FlowBox;
@ -48,8 +42,8 @@ impl FactoryComponent for AdviceCard {
/* TODO:
* Action "View in Image viewer":
* Triggers:
* - [x] One click on "enlarge" button
* - [ ] Double click on "texture" itself
* - 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...
*/
@ -84,8 +78,6 @@ impl FactoryComponent for AdviceCard {
set_icon_name: "four-arrows-pointing-outward-symbolic",
set_margin_all: 8,
connect_clicked => AdviceCardInput::OpenFile,
},
#[wrap(Some)]
@ -102,7 +94,6 @@ impl FactoryComponent for AdviceCard {
let _self = Self {
metadata: value.clone(),
texture: None,
file: None,
tracker: 0,
};
@ -128,7 +119,7 @@ impl FactoryComponent for AdviceCard {
file
};
let image = glycin::Loader::new(file.clone())
let image = glycin::Loader::new(file)
.load()
.await
.expect("Image decoding failed");
@ -137,7 +128,7 @@ impl FactoryComponent for AdviceCard {
.await
.expect("Image frame decoding failed");
AdviceCardCmds::GotTexture(file, frame.texture())
AdviceCardCmds::GotTexture(frame.texture())
});
_self
@ -145,21 +136,8 @@ impl FactoryComponent for AdviceCard {
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {
match message {
AdviceCardCmds::GotTexture(file, texture) => {
self.set_texture(Some(texture));
self.set_file(Some(file));
},
AdviceCardCmds::GotTexture(texture) => self.set_texture(Some(texture)),
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::<&gtk::Window>, None::<&gio::Cancellable>, |_| {});
},
}
}
}