[fractal/split-async-state-ui-appop-mgmt: 3/13] Move attach module from AppOp to UI




commit 544e1be36646f7466fd5743a2b05fea2254bb181
Author: Alejandro Domínguez <adomu net-c com>
Date:   Thu Dec 3 13:59:05 2020 +0100

    Move attach module from AppOp to UI

 fractal-gtk/src/appop/mod.rs            |  1 -
 fractal-gtk/src/meson.build             |  2 +-
 fractal-gtk/src/{appop => ui}/attach.rs | 28 ++++++++++------------------
 fractal-gtk/src/ui/connect/send.rs      |  2 +-
 fractal-gtk/src/ui/mod.rs               |  1 +
 5 files changed, 13 insertions(+), 21 deletions(-)
---
diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs
index 42d35898..4ddee2a8 100644
--- a/fractal-gtk/src/appop/mod.rs
+++ b/fractal-gtk/src/appop/mod.rs
@@ -22,7 +22,6 @@ use crate::cache;
 use crate::ui;
 
 mod account;
-pub mod attach;
 mod directory;
 mod invite;
 mod login;
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index fb6a507c..27e8867b 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -55,7 +55,6 @@ app_sources = files(
   'app/mod.rs',
   'app/windowstate.rs',
   'appop/account.rs',
-  'appop/attach.rs',
   'appop/directory.rs',
   'appop/invite.rs',
   'appop/login.rs',
@@ -101,6 +100,7 @@ app_sources = files(
   'ui/connect/send.rs',
   'ui/connect/swipeable_widgets.rs',
   'ui/about.rs',
+  'ui/attach.rs',
   'ui/mod.rs',
   'util/i18n.rs',
   'util/mod.rs',
diff --git a/fractal-gtk/src/appop/attach.rs b/fractal-gtk/src/ui/attach.rs
similarity index 90%
rename from fractal-gtk/src/appop/attach.rs
rename to fractal-gtk/src/ui/attach.rs
index 21c77bbf..9d7bbca9 100644
--- a/fractal-gtk/src/appop/attach.rs
+++ b/fractal-gtk/src/ui/attach.rs
@@ -1,20 +1,16 @@
+use super::UI;
+use crate::util::get_pixbuf_data;
 use crate::util::i18n::i18n;
-
+use crate::APPOP;
+use anyhow::Error;
+use gdk_pixbuf::Pixbuf;
 use glib::clone;
+use gtk::prelude::*;
 use std::fs::File;
 use std::io::prelude::*;
 use std::path::PathBuf;
 
-use anyhow::Error;
-
-use gtk::prelude::*;
-
-use crate::appop::AppOp;
-
-use crate::util::get_pixbuf_data;
-use gdk_pixbuf::Pixbuf;
-
-impl AppOp {
+impl UI {
     fn draw_image_paste_dialog(&self, pixb: &Pixbuf) {
         let w = pixb.get_width();
         let h = pixb.get_height();
@@ -25,15 +21,10 @@ impl AppOp {
         };
 
         if let Some(pb) = scaled {
-            let window: gtk::ApplicationWindow = self
-                .ui
-                .builder
-                .get_object("main_window")
-                .expect("Can't find main_window in ui file.");
             let img = gtk::Image::new();
             let dialog = gtk::Dialog::with_buttons(
                 Some(i18n("Image from Clipboard").as_str()),
-                Some(&window),
+                Some(&self.main_window),
                 gtk::DialogFlags::MODAL
                     | gtk::DialogFlags::USE_HEADER_BAR
                     | gtk::DialogFlags::DESTROY_WITH_PARENT,
@@ -59,7 +50,7 @@ impl AppOp {
                 closebtn.connect_clicked(clone!(@strong dialog => move |_| {
                     dialog.close();
                 }));
-                /* FIXME: make this a action */
+                /* FIXME: make this an action */
                 okbtn.connect_clicked(clone!(@strong pixb, @strong dialog => move |_| {
                     if let Ok(path) = store_pixbuf(&pixb) {
                         APPOP!(attach_message, (path))
@@ -91,6 +82,7 @@ impl AppOp {
     }
 }
 
+// TODO: Make async
 fn store_pixbuf(pixb: &Pixbuf) -> Result<PathBuf, Error> {
     let data = get_pixbuf_data(pixb)?;
     let mut path = glib::get_tmp_dir().unwrap_or_else(|| PathBuf::from("/tmp"));
diff --git a/fractal-gtk/src/ui/connect/send.rs b/fractal-gtk/src/ui/connect/send.rs
index cfbe41a7..3af6fca8 100644
--- a/fractal-gtk/src/ui/connect/send.rs
+++ b/fractal-gtk/src/ui/connect/send.rs
@@ -51,7 +51,7 @@ pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     }));
 
     msg_entry.connect_paste_clipboard(move |_| {
-        app_runtime.update_state_with(|state| state.paste());
+        app_runtime.update_state_with(|state| state.ui.paste());
     });
 
     msg_entry.connect_focus_in_event(clone!(@strong msg_entry_box => move |_, _| {
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index a15ec1e0..98313440 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -9,6 +9,7 @@ use std::path::PathBuf;
 use url::Url;
 
 pub mod about;
+pub mod attach;
 pub mod connect;
 
 pub struct UI {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]