Compare commits
No commits in common. "jane400/open-envelope-in-image-viewer" and "main" have entirely different histories.
jane400/op
...
main
1 changed files with 7 additions and 29 deletions
|
@ -23,24 +23,18 @@ pub struct AdviceCard {
|
||||||
#[do_not_track]
|
#[do_not_track]
|
||||||
metadata: Advice,
|
metadata: Advice,
|
||||||
texture: Option<gdk::Texture>,
|
texture: Option<gdk::Texture>,
|
||||||
file: Option<gio::File>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AdviceCardCmds {
|
pub enum AdviceCardCmds {
|
||||||
GotTexture(gio::File, gdk::Texture),
|
GotTexture(gdk::Texture),
|
||||||
Error(LibraryError),
|
Error(LibraryError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum AdviceCardInput {
|
|
||||||
OpenFile
|
|
||||||
}
|
|
||||||
|
|
||||||
#[relm4::factory(pub)]
|
#[relm4::factory(pub)]
|
||||||
impl FactoryComponent for AdviceCard {
|
impl FactoryComponent for AdviceCard {
|
||||||
type Init = Advice;
|
type Init = Advice;
|
||||||
type Input = AdviceCardInput;
|
type Input = ();
|
||||||
type Output = ();
|
type Output = ();
|
||||||
type CommandOutput = AdviceCardCmds;
|
type CommandOutput = AdviceCardCmds;
|
||||||
type ParentWidget = gtk::FlowBox;
|
type ParentWidget = gtk::FlowBox;
|
||||||
|
@ -48,8 +42,8 @@ impl FactoryComponent for AdviceCard {
|
||||||
/* TODO:
|
/* TODO:
|
||||||
* Action "View in Image viewer":
|
* Action "View in Image viewer":
|
||||||
* Triggers:
|
* Triggers:
|
||||||
* - [x] One click on "enlarge" button
|
* - One click on "enlarge" button
|
||||||
* - [ ] Double click on "texture" itself
|
* - Double click on "texture" itself
|
||||||
* (Is there a better way than this?)
|
* (Is there a better way than this?)
|
||||||
* Create temporary file, let application open this file...
|
* 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_icon_name: "four-arrows-pointing-outward-symbolic",
|
||||||
|
|
||||||
set_margin_all: 8,
|
set_margin_all: 8,
|
||||||
|
|
||||||
connect_clicked => AdviceCardInput::OpenFile,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
#[wrap(Some)]
|
#[wrap(Some)]
|
||||||
|
@ -102,7 +94,6 @@ impl FactoryComponent for AdviceCard {
|
||||||
let _self = Self {
|
let _self = Self {
|
||||||
metadata: value.clone(),
|
metadata: value.clone(),
|
||||||
texture: None,
|
texture: None,
|
||||||
file: None,
|
|
||||||
tracker: 0,
|
tracker: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,7 +119,7 @@ impl FactoryComponent for AdviceCard {
|
||||||
file
|
file
|
||||||
};
|
};
|
||||||
|
|
||||||
let image = glycin::Loader::new(file.clone())
|
let image = glycin::Loader::new(file)
|
||||||
.load()
|
.load()
|
||||||
.await
|
.await
|
||||||
.expect("Image decoding failed");
|
.expect("Image decoding failed");
|
||||||
|
@ -137,7 +128,7 @@ impl FactoryComponent for AdviceCard {
|
||||||
.await
|
.await
|
||||||
.expect("Image frame decoding failed");
|
.expect("Image frame decoding failed");
|
||||||
|
|
||||||
AdviceCardCmds::GotTexture(file, frame.texture())
|
AdviceCardCmds::GotTexture(frame.texture())
|
||||||
});
|
});
|
||||||
|
|
||||||
_self
|
_self
|
||||||
|
@ -145,21 +136,8 @@ impl FactoryComponent for AdviceCard {
|
||||||
|
|
||||||
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {
|
fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender<Self>) {
|
||||||
match message {
|
match message {
|
||||||
AdviceCardCmds::GotTexture(file, texture) => {
|
AdviceCardCmds::GotTexture(texture) => self.set_texture(Some(texture)),
|
||||||
self.set_texture(Some(texture));
|
|
||||||
self.set_file(Some(file));
|
|
||||||
},
|
|
||||||
AdviceCardCmds::Error(err) => todo!(),
|
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