Update gtk-rs
This brings us a neat new function, `imp()`, that lets us drop `from_instance()` everywhere.
This commit is contained in:
parent
400672b6b6
commit
56a47fb447
4 changed files with 48 additions and 48 deletions
|
|
@ -173,13 +173,13 @@ glib::wrapper! {
|
|||
|
||||
impl LpImage {
|
||||
pub fn file(&self) -> Option<gio::File> {
|
||||
let imp = imp::LpImage::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
imp.file.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn set_file(&self, file: &gio::File) {
|
||||
let imp = imp::LpImage::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
match gdk::Texture::from_file(file) {
|
||||
Ok(texture) => {
|
||||
|
|
@ -197,12 +197,12 @@ impl LpImage {
|
|||
}
|
||||
|
||||
pub fn image_width(&self) -> i32 {
|
||||
let imp = imp::LpImage::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
imp.image_width.get()
|
||||
}
|
||||
|
||||
pub fn image_height(&self) -> i32 {
|
||||
let imp = imp::LpImage::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
imp.image_height.get()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ glib::wrapper! {
|
|||
|
||||
impl LpImageView {
|
||||
pub fn set_image_from_file(&self, file: &gio::File) -> anyhow::Result<(i32, i32)> {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
|
||||
if let Some(current_file) = imp.picture.file() {
|
||||
if current_file.path().as_deref() == file.path().as_deref() {
|
||||
|
|
@ -170,7 +170,7 @@ impl LpImageView {
|
|||
}
|
||||
|
||||
fn set_parent_from_file(&self, file: &gio::File) {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
|
||||
if let Some(parent) = file.parent() {
|
||||
let parent_path = parent.path().map(|p| p.to_str().unwrap().to_string());
|
||||
|
|
@ -231,7 +231,7 @@ impl LpImageView {
|
|||
}
|
||||
|
||||
fn update_image(&self) {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
|
||||
let path = &format!(
|
||||
"{}/{}",
|
||||
|
|
@ -248,21 +248,21 @@ impl LpImageView {
|
|||
}
|
||||
|
||||
pub fn next(&self) {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
// TODO: Replace with `Cell::update()` once stabilized
|
||||
imp.index.set(imp.index.get() + 1);
|
||||
self.update_image();
|
||||
}
|
||||
|
||||
pub fn previous(&self) {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
// TODO: Replace with `Cell::update()` once stabilized
|
||||
imp.index.set(imp.index.get() - 1);
|
||||
self.update_image();
|
||||
}
|
||||
|
||||
pub fn update_action_state(&self) {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
let index = imp.index.get();
|
||||
self.action_set_enabled("iv.next", index < imp.directory_pictures.borrow().len() - 1);
|
||||
self.action_set_enabled("iv.previous", index > 0);
|
||||
|
|
@ -297,7 +297,7 @@ impl LpImageView {
|
|||
}
|
||||
|
||||
pub fn print(&self) -> anyhow::Result<()> {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
|
||||
let operation = gtk::PrintOperation::new();
|
||||
let path = &format!(
|
||||
|
|
@ -338,17 +338,17 @@ impl LpImageView {
|
|||
}
|
||||
|
||||
pub fn uri(&self) -> Option<String> {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
imp.uri.borrow().to_owned()
|
||||
}
|
||||
|
||||
pub fn filename(&self) -> Option<String> {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
imp.filename.borrow().to_owned()
|
||||
}
|
||||
|
||||
pub fn show_popover_at(&self, x: f64, y: f64) {
|
||||
let imp = imp::LpImageView::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
|
||||
let rect = gdk::Rectangle::new(x as i32, y as i32, 0, 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ impl LpWindow {
|
|||
}
|
||||
|
||||
fn toggle_fullscreen(&self, fullscreen: bool) {
|
||||
let imp = imp::LpWindow::from_instance(&self);
|
||||
let imp = self.imp();
|
||||
|
||||
if fullscreen {
|
||||
imp.flap.set_fold_policy(adw::FlapFoldPolicy::Always);
|
||||
|
|
@ -262,7 +262,7 @@ impl LpWindow {
|
|||
}
|
||||
|
||||
fn open_with(&self) {
|
||||
let imp = imp::LpWindow::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
if let Some(uri) = imp.image_view.uri() {
|
||||
std::process::Command::new("xdg-open")
|
||||
|
|
@ -275,7 +275,7 @@ impl LpWindow {
|
|||
}
|
||||
|
||||
fn set_wallpaper(&self) {
|
||||
let imp = imp::LpWindow::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
if let Err(e) = imp.image_view.set_wallpaper() {
|
||||
log::error!("Failed to set wallpaper: {}", e);
|
||||
|
|
@ -283,7 +283,7 @@ impl LpWindow {
|
|||
}
|
||||
|
||||
fn print(&self) {
|
||||
let imp = imp::LpWindow::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
if let Err(e) = imp.image_view.print() {
|
||||
log::error!("Failed to print file: {}", e);
|
||||
|
|
@ -291,7 +291,7 @@ impl LpWindow {
|
|||
}
|
||||
|
||||
fn show_toast(&self, text: &impl AsRef<str>, priority: adw::ToastPriority) {
|
||||
let imp = imp::LpWindow::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
let toast = adw::Toast::new(text.as_ref());
|
||||
toast.set_priority(priority);
|
||||
|
|
@ -300,7 +300,7 @@ impl LpWindow {
|
|||
}
|
||||
|
||||
pub fn set_image_from_file(&self, file: &gio::File, resize: bool) {
|
||||
let imp = imp::LpWindow::from_instance(self);
|
||||
let imp = self.imp();
|
||||
|
||||
log::debug!("Loading file: {}", file.uri().to_string());
|
||||
match imp.image_view.set_image_from_file(file) {
|
||||
|
|
@ -326,7 +326,7 @@ impl LpWindow {
|
|||
|
||||
// Adapted from https://gitlab.gnome.org/GNOME/eog/-/blob/master/src/eog-window.c:eog_window_obtain_desired_size
|
||||
pub fn resize_from_dimensions(&self, img_width: i32, img_height: i32) {
|
||||
let imp = imp::LpWindow::from_instance(self);
|
||||
let imp = self.imp();
|
||||
let mut final_width = img_width;
|
||||
let mut final_height = img_height;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue