[connections/move-new-connection-to-popover] topbar: Move connection creation into a popover




commit b36ed21acc2086d30912b01c17b20cfde18014ff
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon May 17 15:52:31 2021 +0200

    topbar: Move connection creation into a popover
    
    Fixes #46

 src/application.vala |   3 +-
 src/assistant.vala   |  20 +-----
 src/topbar.vala      |   7 +-
 src/ui/assistant.ui  | 179 ++++++++++++++++-----------------------------------
 src/ui/topbar.ui     |   7 +-
 src/window.vala      |   3 +-
 6 files changed, 71 insertions(+), 148 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index 43a97b9..b98ca0b 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -234,7 +234,8 @@ namespace Connections {
             if (opt_uris != null) {
                 var uri = opt_uris[0];
 
-                (new Connections.Assistant (main_window, uri)).run ();
+                // TODO: throw a notification if this fails.
+                add_connection (uri);
             }
 
             if (opt_file_import_uri != null) {
diff --git a/src/assistant.vala b/src/assistant.vala
index 3d00810..563e4b5 100644
--- a/src/assistant.vala
+++ b/src/assistant.vala
@@ -21,27 +21,12 @@
 
 namespace Connections {
     [GtkTemplate (ui = "/org/gnome/Connections/ui/assistant.ui")]
-    private class Assistant : Gtk.Dialog {
+    private class Assistant : Gtk.Popover {
         [GtkChild]
         private unowned Gtk.Entry url_entry;
         [GtkChild]
         private unowned Gtk.Button create_button; 
 
-        construct {
-            use_header_bar = 1;
-        }
-
-        public Assistant (Window window, string? uri = null) {
-            set_transient_for (window);
-
-            create_button.get_style_context ().add_class ("suggested-action");
-
-            url_entry.grab_focus ();
-
-            if (uri != null)
-                url_entry.text = uri;
-        }
-
         [GtkCallback]
         private void on_url_entry_changed () {
             if (url_entry.text == "") {
@@ -76,8 +61,9 @@ namespace Connections {
         [GtkCallback]
         private void on_create_connection_button_clicked () {
             Application.application.add_connection (url_entry.get_text ());
+            url_entry.set_text ("");
 
-            destroy ();
+            popdown ();
         }
 
         [GtkCallback]
diff --git a/src/topbar.vala b/src/topbar.vala
index 2ae4e7b..d1da4b0 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -28,6 +28,8 @@ namespace Connections {
         public unowned Gtk.Button search_button;
         [GtkChild]
         private unowned Gtk.HeaderBar display_toolbar;
+        [GtkChild]
+        public unowned Connections.Assistant assistant;
 
         private weak Connections.Connection connection;
         private const GLib.ActionEntry[] action_entries = {
@@ -87,11 +89,6 @@ namespace Connections {
                 !Application.application.main_window.fullscreened;
         }
 
-        [GtkCallback]
-        private void add_new_connection_button_clicked () {
-            (new Connections.Assistant (Application.application.main_window)).run ();
-        }
-
         [GtkCallback]
         private void back_button_clicked () {
             Application.application.main_window.show_collection_view ();
diff --git a/src/ui/assistant.ui b/src/ui/assistant.ui
index 2a6698a..aaab593 100644
--- a/src/ui/assistant.ui
+++ b/src/ui/assistant.ui
@@ -1,140 +1,75 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.20"/>
-    <template class="ConnectionsAssistant" parent="GtkDialog">
-      <property name="modal">True</property>
-      <property name="type-hint">dialog</property>
-      <property name="valign">start</property>
-      <property name="default-width">540</property>
-      <property name="title" translatable="yes">Create a New Connection</property>
-      <signal name="delete-event" handler="gtk_widget_hide_on_delete"/>
+    <template class="ConnectionsAssistant" parent="GtkPopover">
+      <property name="border-width">10</property>
 
-      <child internal-child="vbox">
-        <object class="GtkBox">
+      <child>
+        <object class="GtkGrid">
           <property name="visible">True</property>
+          <property name="row-spacing">10</property>
+          <property name="column-spacing">5</property>
 
           <child>
-            <object class="GtkStack" id="pages">
+            <object class="GtkLabel">
               <property name="visible">True</property>
+              <property name="halign">start</property>
+              <property name="label" translatable="yes">Connect to a Desktop</property>
+              <attributes>
+                <attribute name="weight" value="bold"/>
+              </attributes>
+            </object>
+            <packing>
+              <property name="top-attach">0</property>
+              <property name="left-attach">0</property>
+            </packing>
+          </child>
 
-              <child>
-                <object class="GtkBox">
-                  <property name="visible">True</property>
-                  <property name="orientation">vertical</property>
-                  <property name="margin">30</property>
-                  <property name="spacing">30</property>
-
-                  <child>
-                    <object class="GtkLabel">
-                      <property name="visible">True</property>
-                      <property name="wrap">True</property>
-                      <property name="halign">start</property>
-                      <property name="xalign">0</property>
-                      <property name="max-width-chars">60</property>
-                      <property name="label" translatable="yes">Enter a machine address to connect to. 
Address can begin with rdp:// or vnc://</property>
-                    </object>
-                  </child>
-
-                  <child>
-                    <object class="GtkListBox">
-                      <property name="visible">True</property>
-                      <property name="selection-mode">none</property>
-                      <style>
-                        <class name="frame"/>
-                      </style>
-
-                      <child>
-                        <object class="GtkListBoxRow">
-                          <property name="visible">True</property>
-                          <child>
-                            <object class="GtkBox">
-                              <property name="visible">True</property>
-                              <property name="spacing">60</property>
-                              <property name="border-width">15</property>
-
-                              <child>
-                                <object class="GtkLabel" id="server_label">
-                                  <property name="visible">True</property>
-                                  <property name="label" translatable="yes">Server</property>
-                                  <property name="mnemonic_widget">url_entry</property>
-                                </object>
-                              </child>
-                              <child>
-                                <object class="GtkEntry" id="url_entry">
-                                  <property name="visible">True</property>
-                                  <property name="hexpand">True</property>
-                                  <property name="completion">url_completion</property>
-                                  <signal name="changed" handler="on_url_entry_changed"/>
-                                  <signal name="activate" handler="on_url_entry_activated"/>
-                                </object>
-                              </child>
-                            </object> 
-                          </child>
-                        </object>
-                      </child> 
-
-                      <child>
-                        <object class="GtkSeparator">
-                          <property name="visible">False</property>
-                        </object>
-                      </child>
-
-                      <child>
-                        <object class="GtkListBoxRow">
-                          <property name="visible">False</property>
-                          <child>
-                            <object class="GtkBox">
-                              <property name="visible">True</property>
-                              <property name="spacing">60</property>
-                              <property name="border-width">15</property>
-
-                              <child>
-                                <object class="GtkLabel" id="display_name_label">
-                                  <property name="visible">True</property>
-                                  <property name="label" translatable="yes">Name</property>
-                                  <property name="mnemonic_widget">display_name_entry</property>
-                                </object>
-                              </child>
-                              <child>
-                                <object class="GtkEntry" id="display_name_entry">
-                                  <property name="visible">True</property>
-                                  <property name="hexpand">True</property>
-                                </object>
-                              </child>
-                            </object> 
-                          </child>
-                        </object>
-                      </child> 
-                    </object>
-                  </child>
-                </object>
-              </child>
+          <child>
+            <object class="GtkEntry" id="url_entry">
+              <property name="visible">True</property>
+              <property name="hexpand">True</property>
+              <property name="completion">url_completion</property>
+              <signal name="changed" handler="on_url_entry_changed"/>
+              <signal name="activate" handler="on_url_entry_activated"/>
             </object>
+            <packing>
+              <property name="top-attach">1</property>
+              <property name="left-attach">0</property>
+            </packing>
           </child>
-        </object>
-      </child>
 
-      <child type="action">
-        <object class="GtkButton" id="cancel_button">
-          <property name="visible">True</property>
-          <property name="label" translatable="yes">Cancel</property>
-          <signal name="clicked" handler="gtk_widget_hide_on_delete" object="ConnectionsAssistant"/>
-        </object>
-      </child>
+          <child>
+            <object class="GtkButton" id="create_button">
+              <property name="visible">True</property>
+              <property name="sensitive">False</property>
+              <property name="label" translatable="yes">Connect</property>
+              <signal name="clicked" handler="on_create_connection_button_clicked"/>
+              <style>
+                <class name="suggested-action"/>
+              </style>
+            </object>
+            <packing>
+              <property name="top-attach">1</property>
+              <property name="left-attach">1</property>
+            </packing>
+          </child>
 
-      <child type="action">
-        <object class="GtkButton" id="create_button">
-          <property name="visible">True</property>
-          <property name="sensitive">False</property>
-          <property name="label" translatable="yes">Create</property>
-          <signal name="clicked" handler="on_create_connection_button_clicked"/>
+          <child>
+            <object class="GtkLabel">
+              <property name="visible">True</property>
+              <property name="label" translatable="yes">Addresses start with either vnc:// or 
rdp://.</property>
+              <style>
+                <class name="dim-label"/>
+              </style>
+            </object>
+            <packing>
+              <property name="top-attach">2</property>
+              <property name="left-attach">0</property>
+            </packing>
+          </child>
         </object>
       </child>
-
-      <action-widgets>
-        <action-widget response="cancel">cancel_button</action-widget>
-        <action-widget response="ok">create_button</action-widget>
-      </action-widgets>
     </template>
 
     <object class="GtkEntryCompletion" id="url_completion">
diff --git a/src/ui/topbar.ui b/src/ui/topbar.ui
index 32c96bf..92e2199 100644
--- a/src/ui/topbar.ui
+++ b/src/ui/topbar.ui
@@ -12,9 +12,9 @@
           </style>
 
           <child>
-            <object class="GtkButton" id="new_button">
+            <object class="GtkMenuButton" id="new_button">
               <property name="visible">True</property>
-              <signal name="clicked" handler="add_new_connection_button_clicked"/>
+              <property name="popover">assistant</property>
 
               <child internal-child="accessible">
                 <object class="AtkObject" id="a11y-new-button">
@@ -273,4 +273,7 @@
       </child>
     </object>
 
+    <!-- Assistant popover -->
+  <object class="ConnectionsAssistant" id="assistant"/>
+
   </interface>
diff --git a/src/window.vala b/src/window.vala
index eb23e03..95bfb04 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -129,7 +129,8 @@ namespace Connections {
                 return true;
             } else if (event.keyval == Gdk.Key.n &&
                        (event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK) {
-                (new Connections.Assistant (this).run ());
+                topbar.assistant.popdown ();
+
                 return true;
             }
 


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