[fractal/split-async-state-ui-appop-mgmt: 6/12] Move start_chat from AppOp to UI




commit c1f9f33973203dbdb3fc0a45b4b05e09d0e05939
Author: Alejandro Domínguez <adomu net-c com>
Date:   Thu Dec 3 18:21:49 2020 +0100

    Move start_chat from AppOp to UI

 fractal-gtk/src/appop/start_chat.rs  | 71 ++----------------------------------
 fractal-gtk/src/meson.build          |  1 +
 fractal-gtk/src/ui/connect/direct.rs |  4 +-
 fractal-gtk/src/ui/mod.rs            |  1 +
 fractal-gtk/src/ui/start_chat.rs     | 60 ++++++++++++++++++++++++++++++
 5 files changed, 67 insertions(+), 70 deletions(-)
---
diff --git a/fractal-gtk/src/appop/start_chat.rs b/fractal-gtk/src/appop/start_chat.rs
index 17ad8503..e7e63ae7 100644
--- a/fractal-gtk/src/appop/start_chat.rs
+++ b/fractal-gtk/src/appop/start_chat.rs
@@ -1,9 +1,7 @@
-use crate::backend::room;
-use gtk::prelude::*;
-
 use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::appop::SearchType;
+use crate::backend::room;
 use crate::backend::HandleError;
 
 impl AppOp {
@@ -29,74 +27,11 @@ impl AppOp {
             }
         });
 
-        self.close_direct_chat_dialog();
+        self.ui.close_direct_chat_dialog();
     }
 
     pub fn show_direct_chat_dialog(&mut self) {
-        let dialog = self
-            .ui
-            .builder
-            .get_object::<gtk::Dialog>("direct_chat_dialog")
-            .expect("Can't find direct_chat_dialog in ui file.");
-        let scroll = self
-            .ui
-            .builder
-            .get_object::<gtk::Widget>("direct_chat_search_scroll")
-            .expect("Can't find direct_chat_search_scroll in ui file.");
         self.search_type = SearchType::DirectChat;
-        if let Some(btn) = self
-            .ui
-            .builder
-            .get_object::<gtk::Button>("direct_chat_button")
-        {
-            btn.set_sensitive(false)
-        }
-        dialog.present();
-        scroll.hide();
-    }
-
-    pub fn close_direct_chat_dialog(&mut self) {
-        let listbox = self
-            .ui
-            .builder
-            .get_object::<gtk::ListBox>("direct_chat_search_box")
-            .expect("Can't find direct_chat_search_box in ui file.");
-        let scroll = self
-            .ui
-            .builder
-            .get_object::<gtk::Widget>("direct_chat_search_scroll")
-            .expect("Can't find direct_chat_search_scroll in ui file.");
-        let to_chat_entry = self
-            .ui
-            .builder
-            .get_object::<gtk::TextView>("to_chat_entry")
-            .expect("Can't find to_chat_entry in ui file.");
-        let entry = self
-            .ui
-            .builder
-            .get_object::<gtk::TextView>("to_chat_entry")
-            .expect("Can't find to_chat_entry in ui file.");
-        let dialog = self
-            .ui
-            .builder
-            .get_object::<gtk::Dialog>("direct_chat_dialog")
-            .expect("Can't find direct_chat_dialog in ui file.");
-
-        self.ui.invite_list = vec![];
-        if let Some(buffer) = to_chat_entry.get_buffer() {
-            let mut start = buffer.get_start_iter();
-            let mut end = buffer.get_end_iter();
-
-            buffer.delete(&mut start, &mut end);
-        }
-        for ch in listbox.get_children().iter() {
-            listbox.remove(ch);
-        }
-        scroll.hide();
-        if let Some(buffer) = entry.get_buffer() {
-            buffer.set_text("");
-        }
-        dialog.hide();
-        dialog.resize(300, 200);
+        self.ui.show_direct_chat_dialog();
     }
 }
diff --git a/fractal-gtk/src/meson.build b/fractal-gtk/src/meson.build
index c9ef03b3..4d53f52c 100644
--- a/fractal-gtk/src/meson.build
+++ b/fractal-gtk/src/meson.build
@@ -103,6 +103,7 @@ app_sources = files(
   'ui/attach.rs',
   'ui/directory.rs',
   'ui/mod.rs',
+  'ui/start_chat.rs',
   'util/i18n.rs',
   'util/mod.rs',
   'widgets/address.rs',
diff --git a/fractal-gtk/src/ui/connect/direct.rs b/fractal-gtk/src/ui/connect/direct.rs
index 76957f1b..af5ccfb6 100644
--- a/fractal-gtk/src/ui/connect/direct.rs
+++ b/fractal-gtk/src/ui/connect/direct.rs
@@ -112,11 +112,11 @@ pub fn connect(ui: &UI, app_runtime: AppRuntime) {
     }
 
     dialog.connect_delete_event(clone!(@strong app_runtime => move |_, _| {
-        app_runtime.update_state_with(|state| state.close_direct_chat_dialog());
+        app_runtime.update_state_with(|state| state.ui.close_direct_chat_dialog());
         glib::signal::Inhibit(true)
     }));
     cancel.connect_clicked(clone!(@strong app_runtime => move |_| {
-        app_runtime.update_state_with(|state| state.close_direct_chat_dialog());
+        app_runtime.update_state_with(|state| state.ui.close_direct_chat_dialog());
     }));
     invite.set_sensitive(false);
     invite.connect_clicked(move |_| {
diff --git a/fractal-gtk/src/ui/mod.rs b/fractal-gtk/src/ui/mod.rs
index 9968b1b9..2915829c 100644
--- a/fractal-gtk/src/ui/mod.rs
+++ b/fractal-gtk/src/ui/mod.rs
@@ -12,6 +12,7 @@ pub mod about;
 pub mod attach;
 pub mod connect;
 pub mod directory;
+pub mod start_chat;
 
 pub struct UI {
     pub builder: gtk::Builder,
diff --git a/fractal-gtk/src/ui/start_chat.rs b/fractal-gtk/src/ui/start_chat.rs
new file mode 100644
index 00000000..a0b79a38
--- /dev/null
+++ b/fractal-gtk/src/ui/start_chat.rs
@@ -0,0 +1,60 @@
+use super::UI;
+use gtk::prelude::*;
+
+impl UI {
+    pub fn show_direct_chat_dialog(&self) {
+        let dialog = self
+            .builder
+            .get_object::<gtk::Dialog>("direct_chat_dialog")
+            .expect("Can't find direct_chat_dialog in ui file.");
+        let scroll = self
+            .builder
+            .get_object::<gtk::Widget>("direct_chat_search_scroll")
+            .expect("Can't find direct_chat_search_scroll in ui file.");
+        if let Some(btn) = self.builder.get_object::<gtk::Button>("direct_chat_button") {
+            btn.set_sensitive(false)
+        }
+        dialog.present();
+        scroll.hide();
+    }
+
+    pub fn close_direct_chat_dialog(&mut self) {
+        let listbox = self
+            .builder
+            .get_object::<gtk::ListBox>("direct_chat_search_box")
+            .expect("Can't find direct_chat_search_box in ui file.");
+        let scroll = self
+            .builder
+            .get_object::<gtk::Widget>("direct_chat_search_scroll")
+            .expect("Can't find direct_chat_search_scroll in ui file.");
+        let to_chat_entry = self
+            .builder
+            .get_object::<gtk::TextView>("to_chat_entry")
+            .expect("Can't find to_chat_entry in ui file.");
+        let entry = self
+            .builder
+            .get_object::<gtk::TextView>("to_chat_entry")
+            .expect("Can't find to_chat_entry in ui file.");
+        let dialog = self
+            .builder
+            .get_object::<gtk::Dialog>("direct_chat_dialog")
+            .expect("Can't find direct_chat_dialog in ui file.");
+
+        self.invite_list = vec![];
+        if let Some(buffer) = to_chat_entry.get_buffer() {
+            let mut start = buffer.get_start_iter();
+            let mut end = buffer.get_end_iter();
+
+            buffer.delete(&mut start, &mut end);
+        }
+        for ch in listbox.get_children().iter() {
+            listbox.remove(ch);
+        }
+        scroll.hide();
+        if let Some(buffer) = entry.get_buffer() {
+            buffer.set_text("");
+        }
+        dialog.hide();
+        dialog.resize(300, 200);
+    }
+}


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