[fractal] fractal-gtk: Block out the text box when we can't send



commit 6bc2e46f148bff0903237dc06a43195662230a2c
Author: Alistair Francis <alistair alistair23 me>
Date:   Tue Aug 20 22:59:02 2019 -0700

    fractal-gtk: Block out the text box when we can't send
    
    When a user doesn't have permission to send a message to the room let's
    block out the text box.
    
    Signed-off-by: Alistair Francis <alistair alistair23 me>

 fractal-gtk/src/appop/room.rs |  9 +++++++++
 fractal-gtk/src/uibuilder.rs  | 22 ++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index 5e3eaa7e..14ae2d4c 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -140,6 +140,12 @@ impl AppOp {
             }
 
             let msg_entry = self.ui.sventry.view.clone();
+            let msg_entry_stack = self
+                .ui
+                .sventry_box
+                .clone()
+                .downcast::<gtk::Stack>()
+                .unwrap();
 
             let user_power = match room.admins.get(&self.uid.clone().unwrap_or_default()) {
                 Some(p) => *p,
@@ -152,6 +158,8 @@ impl AppOp {
 
             if user_power >= 0 {
                 msg_entry.set_editable(true);
+                msg_entry_stack.set_visible_child_name("Text Entry");
+
                 if let Some(buffer) = msg_entry.get_buffer() {
                     let start = buffer.get_start_iter();
                     let end = buffer.get_end_iter();
@@ -176,6 +184,7 @@ impl AppOp {
                 }
             } else {
                 msg_entry.set_editable(false);
+                msg_entry_stack.set_visible_child_name("Disabled Entry");
             }
         }
 
diff --git a/fractal-gtk/src/uibuilder.rs b/fractal-gtk/src/uibuilder.rs
index e4720e21..e408fe6d 100644
--- a/fractal-gtk/src/uibuilder.rs
+++ b/fractal-gtk/src/uibuilder.rs
@@ -1,3 +1,4 @@
+use crate::i18n::i18n;
 use crate::widgets::SVEntry;
 use gtk::{self, prelude::*};
 
@@ -5,6 +6,7 @@ use gtk::{self, prelude::*};
 pub struct UI {
     pub builder: gtk::Builder,
     pub sventry: SVEntry,
+    pub sventry_box: Box<gtk::Stack>,
 }
 
 impl UI {
@@ -42,9 +44,21 @@ impl UI {
             .expect("Can't load ui file: main_window.ui");
 
         // Order which sventry is created matters
+        let sventry_stack = gtk::Stack::new();
+
         let sventry = SVEntry::default();
+        sventry_stack.add_named(&sventry.column, "Text Entry");
+        let sventry_disabled = gtk::Label::new(Some(&i18n(
+            "You don\u{2019}t have permission to post to this room",
+        )));
+        sventry_disabled.set_hexpand(false);
+        sventry_disabled.get_style_context().add_class("dim-label");
+        sventry_disabled.set_line_wrap_mode(pango::WrapMode::WordChar);
+        sventry_stack.add_named(&sventry_disabled, "Disabled Entry");
+
+        let sventry_box = Box::new(sventry_stack.clone());
         let parent: gtk::Box = builder.get_object("room_parent").unwrap();
-        parent.add(&sventry.column);
+        parent.add(&sventry_stack);
 
         // Depends on main_window
         // These are all dialogs transient for main_window
@@ -73,6 +87,10 @@ impl UI {
             .add_from_resource("/org/gnome/Fractal/ui/account_settings.ui")
             .expect("Can't load ui file: account_settings.ui");
 
-        UI { builder, sventry }
+        UI {
+            builder,
+            sventry,
+            sventry_box,
+        }
     }
 }


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