summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 244c09f..8e73a33 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
 
 use adw::prelude::*;
 use gtk::GridLayoutChild;
-use relm4::{gtk, prelude::{AsyncComponent, AsyncComponentController, AsyncComponentParts, AsyncController}, AsyncComponentSender, RelmWidgetExt};
+use relm4::{gtk, prelude::{AsyncComponent, AsyncComponentController, AsyncComponentParts, AsyncController, ComponentController, Controller}, AsyncComponentSender, Component, RelmWidgetExt};
 
 pub mod components {
     pub(crate) mod smart_summary;
@@ -35,7 +35,7 @@ pub struct PostComposerModel {
 
     #[do_not_track] micropub: Arc<micropub::Client>,
 
-    #[do_not_track] smart_summary: AsyncController<components::SmartSummaryButton>,
+    #[do_not_track] smart_summary: Controller<components::SmartSummaryButton>,
 }
 
 impl PostComposerModel {
@@ -342,18 +342,28 @@ impl AsyncComponent for PostComposerModel {
 
         match message {
             PostComposerInput::SmartSummary(components::SmartSummaryOutput::Start) => {
-                self.set_smart_summary_busy_guard(
-                    Some(relm4::main_adw_application().mark_busy())
-                );
-                if self.smart_summary.sender().send(components::SmartSummaryInput::Text(
-                    self.content_buffer.text(
+                widgets.content_textarea.set_sensitive(false);
+                if self.content_buffer.char_count() == 0 {
+                    let _ = self.smart_summary.sender().send(
+                        components::SmartSummaryInput::Cancel
+                    );
+                } else {
+                    let text = self.content_buffer.text(
                         &self.content_buffer.start_iter(),
                         &self.content_buffer.end_iter(),
                         false
-                    ).into()
-                )).is_ok() {
-                    self.summary_buffer.set_text("");
+                    );
+
+                    self.set_smart_summary_busy_guard(
+                        Some(relm4::main_adw_application().mark_busy())
+                    );
+                    if self.smart_summary.sender().send(
+                        components::SmartSummaryInput::Text(text.into())
+                    ).is_ok() {
+                        self.summary_buffer.set_text("");
+                    }
                 }
+                widgets.content_textarea.set_sensitive(true);
             },
             PostComposerInput::SmartSummary(components::SmartSummaryOutput::Chunk(text)) => {
                 self.summary_buffer.insert_text(self.summary_buffer.length(), text);