[fractal/split-main-stack] Split main_stack in login and sessions




commit 01466a0958083249cf354e9992f14071344b7ab7
Author: Alejandro Domínguez <adomu net-c com>
Date:   Tue Jul 13 20:56:53 2021 +0200

    Split main_stack in login and sessions

 data/resources/ui/window.ui |  5 +++++
 src/window.rs               | 16 ++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/data/resources/ui/window.ui b/data/resources/ui/window.ui
index d9ac02a1..db6bdd19 100644
--- a/data/resources/ui/window.ui
+++ b/data/resources/ui/window.ui
@@ -10,6 +10,11 @@
         <child>
           <object class="Login" id="login" />
         </child>
+        <child>
+          <object class="GtkStack" id="sessions">
+            <property name="transition-type">crossfade</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/src/window.rs b/src/window.rs
index 266d0b07..453a7bb6 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -23,6 +23,8 @@ mod imp {
         pub main_stack: TemplateChild<gtk::Stack>,
         #[template_child]
         pub login: TemplateChild<Login>,
+        #[template_child]
+        pub sessions: TemplateChild<gtk::Stack>,
     }
 
     #[glib::object_subclass]
@@ -35,6 +37,7 @@ mod imp {
             Self {
                 main_stack: TemplateChild::default(),
                 login: TemplateChild::default(),
+                sessions: TemplateChild::default(),
             }
         }
 
@@ -102,8 +105,8 @@ impl Window {
 
     fn add_session(&self, session: &Session) {
         let priv_ = &imp::Window::from_instance(self);
-        priv_.main_stack.add_child(session);
-        priv_.main_stack.set_visible_child(session);
+        priv_.sessions.add_child(session);
+        priv_.sessions.set_visible_child(session);
         self.install_session_actions(session);
     }
 
@@ -132,6 +135,10 @@ impl Window {
                     session.login_with_previous_session(stored_session);
                     self.add_session(&session);
                 }
+
+                if sessions.len() > 0 {
+                    self.switch_to_sessions_page();
+                }
             }
             Err(error) => warn!("Failed to restore previous sessions: {:?}", error),
         }
@@ -171,4 +178,9 @@ impl Window {
             self.set_default_widget(gtk::NONE_WIDGET);
         }
     }
+
+    fn switch_to_sessions_page(&self) {
+        let priv_ = imp::Window::from_instance(self);
+        priv_.main_stack.set_visible_child(&priv_.sessions.get());
+    }
 }


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