[fractal/multi-account: 2/2] Add button in login page to go back to sessions page




commit fe10a2f827fee7a594560e49747121a2f8d09d3a
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Aug 16 07:48:51 2021 +0200

    Add button in login page to go back to sessions page

 data/resources/ui/login.ui | 11 +++++++++++
 src/application.rs         |  8 ++++++++
 src/login.rs               |  8 ++++++++
 src/window.rs              |  6 +++++-
 4 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/data/resources/ui/login.ui b/data/resources/ui/login.ui
index be175612..f5bfd3d2 100644
--- a/data/resources/ui/login.ui
+++ b/data/resources/ui/login.ui
@@ -11,6 +11,17 @@
                 <property name="title">Fractal</property>
               </object>
             </property>
+            <child type="start">
+              <object class="GtkButton" id="back_to_session_button">
+                <property name="action_name">app.switch-to-sessions</property>
+                <property name="visible">false</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">go-previous-symbolic</property>
+                  </object>
+                </child>
+              </object>
+            </child>
             <child type="end">
               <object class="GtkButton" id="next_button">
                 <property name="action_name">login.next</property>
diff --git a/src/application.rs b/src/application.rs
index 7dc2aa4a..92921b96 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -126,6 +126,14 @@ impl Application {
                 app.get_main_window().switch_to_login_page();
             })
         );
+
+        action!(
+            self,
+            "switch-to-sessions",
+            clone!(@weak self as app => move |_, _| {
+                app.get_main_window().switch_to_sessions_page();
+            })
+        );
     }
 
     /// Sets up keyboard shortcuts for application and window actions.
diff --git a/src/login.rs b/src/login.rs
index 85900483..b6e711d2 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -36,6 +36,8 @@ mod imp {
         pub password_entry: TemplateChild<gtk::PasswordEntry>,
         #[template_child]
         pub error_message: TemplateChild<gtk::Label>,
+        #[template_child]
+        pub back_to_session_button: TemplateChild<gtk::Button>,
     }
 
     #[glib::object_subclass]
@@ -180,6 +182,12 @@ impl Login {
         imp::Login::from_instance(self).next_button.get().upcast()
     }
 
+    pub fn show_back_to_session_button(&self, show: bool) {
+        let priv_ = imp::Login::from_instance(self);
+
+        priv_.back_to_session_button.set_visible(show);
+    }
+
     pub fn set_handler_for_prepared_session(&self, session: &Session) {
         session.connect_prepared(clone!(@weak self as login => move |session| {
             if let Some(error) = session.get_error() {
diff --git a/src/window.rs b/src/window.rs
index 8175e0d8..b382c620 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -184,13 +184,17 @@ impl Window {
         }
     }
 
-    fn switch_to_sessions_page(&self) {
+    pub fn switch_to_sessions_page(&self) {
         let priv_ = imp::Window::from_instance(self);
         priv_.main_stack.set_visible_child(&priv_.sessions.get());
     }
 
     pub fn switch_to_login_page(&self) {
         let priv_ = imp::Window::from_instance(self);
+        priv_
+            .login
+            .get()
+            .show_back_to_session_button(priv_.sessions.get().pages().n_items() > 0);
         priv_.main_stack.set_visible_child(&priv_.login.get());
     }
 }


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