[gnome-boxes/wip/wizard-n-props-in-dialog2: 5/10] Put properties in a modal dialog



commit 36bd59af8b9a707413d0b68f4cba1d4469360ecf
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Aug 28 18:33:27 2014 +0100

    Put properties in a modal dialog
    
    With some UI transitions removed during the port away from clutter, its
    better to have it in a dialog.

 data/gnome-boxes.gresource.xml |    2 +-
 data/ui/app-window.ui          |   46 -------------------------
 data/ui/properties-dialog.ui   |   74 ++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am                |    1 +
 src/app-window.vala            |   18 ++--------
 src/machine.vala               |    4 +-
 src/properties-dialog.vala     |   62 +++++++++++++++++++++++++++++++++
 src/properties-sidebar.vala    |    2 +-
 src/properties.vala            |   21 ++++++-----
 src/topbar.vala                |    4 --
 10 files changed, 155 insertions(+), 79 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 12d7896..2342a31 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -14,7 +14,7 @@
     <file preprocess="xml-stripblanks">ui/mini-graph.ui</file>
     <file preprocess="xml-stripblanks">ui/notification.ui</file>
     <file preprocess="xml-stripblanks">ui/properties-sidebar.ui</file>
-    <file preprocess="xml-stripblanks">ui/properties-toolbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/properties-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/searchbar.ui</file>
     <file preprocess="xml-stripblanks">ui/selectionbar.ui</file>
     <file preprocess="xml-stripblanks">ui/selection-toolbar.ui</file>
diff --git a/data/ui/app-window.ui b/data/ui/app-window.ui
index 6857c87..ed74372 100644
--- a/data/ui/app-window.ui
+++ b/data/ui/app-window.ui
@@ -18,14 +18,6 @@
      |     |        |
      |     |        |-> view = new Boxes.CollectionView ();
      |     |        |
-     |     |        |-> below_bin_hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-     |     |        |    |
-     |     |        |    |-> sidebar = new Boxes.Sidebar ();
-     |     |        |    |
-     |     |        |    |-> content_bin = Gtk.Stack ();
-     |     |        |        |
-     |     |        |        |-> properties = new Boxes.Properties ();
-     |     |        |
      |     |        |-> empty_boxes = new Boxes.EmptyBoxes ();
      |     |        |
      |     |        |-> display_page = new Boxes.DisplayPage ();
@@ -99,44 +91,6 @@
                 </child>
 
                 <child>
-                  <object class="GtkBox" id="below_bin_hbox">
-                    <property name="visible">True</property>
-                    <property name="orientation">horizontal</property>
-                    <property name="halign">fill</property>
-                    <property name="valign">fill</property>
-                    <property name="hexpand">True</property>
-                    <property name="vexpand">True</property>
-                    <property name="spacing">0</property>
-
-                    <child>
-                      <object class="BoxesSidebar" id="sidebar">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-
-                    <child>
-                      <object class="GtkStack" id="content_bin">
-                        <property name="visible">True</property>
-                        <property name="homogeneous">True</property>
-                        <property name="transition-type">slide-left-right</property>
-                        <property name="transition-duration">400</property>
-                        <property name="hexpand">True</property>
-                        <property name="vexpand">True</property>
-
-                        <child>
-                          <object class="BoxesProperties" id="properties">
-                            <property name="visible">True</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="name">below-bin-hbox</property>
-                  </packing>
-                </child>
-
-                <child>
                   <object class="BoxesDisplayPage" id="display_page">
                     <property name="visible">True</property>
                   </object>
diff --git a/data/ui/properties-dialog.ui b/data/ui/properties-dialog.ui
new file mode 100644
index 0000000..f965ebf
--- /dev/null
+++ b/data/ui/properties-dialog.ui
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+
+  <!-- Widget hierarchy:
+
+     Boxes.PropertiesDialog : Gtk.Dialog
+        |
+        |-> vbox (internal child)
+        |    |
+        |    |-> hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+        |    |
+        |    |-> sidebar = new Boxes.PropertiesSidebar ();
+        |    |
+        |    |-> properties = new Boxes.Properties ();
+        |
+        |-> close_button (action child) = new Gtk.Button ();
+  -->
+
+  <template class="BoxesPropertiesDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <signal name="delete-event" handler="on_delete_event"/>
+
+    <child internal-child="vbox">
+      <object class="GtkBox">
+
+        <child>
+          <object class="GtkBox" id="hbox">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="halign">fill</property>
+            <property name="valign">fill</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="spacing">0</property>
+
+            <child>
+              <object class="BoxesPropertiesSidebar" id="sidebar">
+                <property name="visible">True</property>
+              </object>
+            </child>
+
+            <child>
+              <object class="BoxesProperties" id="properties">
+                <property name="visible">True</property>
+              </object>
+            </child>
+
+          </object>
+        </child>
+      </object>
+    </child>
+
+    <child type="action">
+      <object class="GtkButton" id="close_button">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="use-underline">True</property>
+        <property name="can-default">True</property>
+        <property name="has-default">True</property>
+        <property name="label" translatable="yes">_Close</property>
+        <signal name="clicked" handler="on_close_button_clicked"/>
+        <style>
+          <class name="text-button"/>
+        </style>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="ok" default="true">close_button</action-widget>
+    </action-widgets>
+  </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 35e84d4..8f94e1f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,7 @@ gnome_boxes_SOURCES =                               \
        notificationbar.vala                    \
        os-database.vala                        \
        properties.vala                         \
+       properties-dialog.vala                  \
        properties-sidebar.vala                 \
        properties-toolbar.vala                 \
        remote-machine.vala                     \
diff --git a/src/app-window.vala b/src/app-window.vala
index 239453e..eaeecb9 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -37,6 +37,7 @@ private class Boxes.AppWindow: Gtk.ApplicationWindow, Boxes.UI {
     }
 
     public WizardDialog wizard_dialog;
+    public PropertiesDialog  props_dialog;
 
     [GtkChild]
     public Searchbar searchbar;
@@ -47,20 +48,12 @@ private class Boxes.AppWindow: Gtk.ApplicationWindow, Boxes.UI {
     [GtkChild]
     public Selectionbar selectionbar;
     [GtkChild]
-    public Sidebar sidebar;
-    [GtkChild]
-    public Properties properties;
-    [GtkChild]
     public DisplayPage display_page;
     [GtkChild]
     public EmptyBoxes empty_boxes;
     [GtkChild]
     public Gtk.Stack below_bin;
     [GtkChild]
-    private Gtk.Stack content_bin;
-    [GtkChild]
-    private Gtk.Box below_bin_hbox;
-    [GtkChild]
     public CollectionView view;
 
     public GLib.Settings settings;
@@ -110,12 +103,11 @@ private class Boxes.AppWindow: Gtk.ApplicationWindow, Boxes.UI {
         view.setup_ui (this);
         selectionbar.setup_ui (this);
         searchbar.setup_ui (this);
-        sidebar.setup_ui (this);
-        properties.setup_ui (this);
         empty_boxes.setup_ui (this);
         notificationbar.searchbar = searchbar;
 
         wizard_dialog = new WizardDialog (this);
+        props_dialog = new PropertiesDialog (this);
     }
 
     private void save_window_geometry () {
@@ -134,7 +126,7 @@ private class Boxes.AppWindow: Gtk.ApplicationWindow, Boxes.UI {
     private void ui_state_changed () {
         // The order is important for some widgets here (e.g properties must change its state before wizard 
so it can
         // flush any deferred changes for wizard to pick-up when going back from properties to wizard 
(review).
-        foreach (var ui in new Boxes.UI[] { sidebar, topbar, view, properties, wizard_dialog, empty_boxes }) 
{
+        foreach (var ui in new Boxes.UI[] { topbar, view, props_dialog, wizard_dialog, empty_boxes }) {
             ui.set_state (ui_state);
         }
 
@@ -167,11 +159,7 @@ private class Boxes.AppWindow: Gtk.ApplicationWindow, Boxes.UI {
         case UIState.CREDS:
         case UIState.DISPLAY:
         case UIState.WIZARD:
-
-            break;
-
         case UIState.PROPERTIES:
-            below_bin.visible_child = below_bin_hbox;
 
             break;
 
diff --git a/src/machine.vala b/src/machine.vala
index 6a90147..ca2773d 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -380,7 +380,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
             orig_pixbuf = small_screenshot;
             pixbuf = draw_vm (small_screenshot, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
             if (window.current_item == this)
-                window.sidebar.props_sidebar.screenshot.set_from_pixbuf (pixbuf);
+                window.props_dialog.sidebar.screenshot.set_from_pixbuf (pixbuf);
             if (save)
                 save_pixbuf_as_screenshot (small_screenshot);
 
@@ -541,7 +541,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
             } else {
                 pixbuf = this.pixbuf;
             }
-            window.sidebar.props_sidebar.screenshot.set_from_pixbuf (pixbuf);
+            window.props_dialog.sidebar.screenshot.set_from_pixbuf (pixbuf);
 
             break;
         }
diff --git a/src/properties-dialog.vala b/src/properties-dialog.vala
new file mode 100644
index 0000000..3918f1c
--- /dev/null
+++ b/src/properties-dialog.vala
@@ -0,0 +1,62 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/properties-dialog.ui")]
+private class Boxes.PropertiesDialog: Gtk.Dialog, Boxes.UI {
+    public UIState previous_ui_state { get; protected set; }
+    public UIState ui_state { get; protected set; }
+
+    [GtkChild]
+    public PropertiesSidebar sidebar;
+    [GtkChild]
+    public Properties properties;
+
+    private unowned AppWindow app_window;
+
+    private GLib.Binding item_name_bind;
+
+    construct {
+        use_header_bar = 1;
+    }
+
+    public PropertiesDialog (AppWindow app_window) {
+        this.app_window = app_window;
+
+        sidebar.setup_ui (app_window);
+        properties.setup_ui (app_window, this);
+
+        set_transient_for (app_window);
+
+        notify["ui-state"].connect (ui_state_changed);
+    }
+
+    private void ui_state_changed () {
+        properties.set_state (ui_state);
+        item_name_bind = null;
+
+        if (ui_state != UIState.PROPERTIES) {
+            this.visible = false;
+
+            return;
+        }
+
+        item_name_bind = app_window.current_item.bind_property ("name", this, "title", 
BindingFlags.SYNC_CREATE);
+        this.visible = true;
+    }
+
+    [GtkCallback]
+    private bool on_delete_event () {
+        revert_ui_state ();
+
+        return true;
+    }
+
+    [GtkCallback]
+    private void on_close_button_clicked () {
+        revert_ui_state ();
+    }
+
+    private void revert_ui_state () {
+        app_window.set_state (previous_ui_state);
+    }
+}
diff --git a/src/properties-sidebar.vala b/src/properties-sidebar.vala
index b98da6f..a2f8094 100644
--- a/src/properties-sidebar.vala
+++ b/src/properties-sidebar.vala
@@ -36,7 +36,7 @@ private class Boxes.PropertiesSidebar: Gtk.Box {
         Gtk.TreeIter filter_iter, iter;
         model_filter.get_iter (out filter_iter, path);
         model_filter.convert_iter_to_child_iter (out iter, filter_iter);
-        window.properties.page = (PropertiesPage) listmodel.get_path (iter).get_indices ()[0];
+        window.props_dialog.properties.page = (PropertiesPage) listmodel.get_path (iter).get_indices ()[0];
     }
 
     [GtkCallback]
diff --git a/src/properties.vala b/src/properties.vala
index 1eb5b40..dc44ef4 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -17,6 +17,7 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
     public UIState ui_state { get; protected set; }
 
     private AppWindow window;
+    private PropertiesSidebar sidebar;
 
     private ulong stats_id;
     private bool restore_fullscreen;
@@ -134,15 +135,14 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
     }
 
     private void populate () {
-        window.sidebar.props_sidebar.listmodel.clear ();
+        sidebar.listmodel.clear ();
         foreach (var page in get_children ())
             remove (page);
 
         var machine = window.current_item as Machine;
         var libvirt_machine = window.current_item as LibvirtMachine;
 
-        window.sidebar.props_sidebar.shutdown_button.sensitive = libvirt_machine != null &&
-                                                                 libvirt_machine.is_running ();
+        sidebar.shutdown_button.sensitive = libvirt_machine != null && libvirt_machine.is_running ();
 
         if (machine == null)
             return;
@@ -156,11 +156,11 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
                 var current_page = page;
                 this.populate ();
                 var path = new Gtk.TreePath.from_indices (current_page);
-                window.sidebar.props_sidebar.selection.select_path (path);
+                sidebar.selection.select_path (path);
                 page = current_page;
             });
 
-            list_append (window.sidebar.props_sidebar.listmodel, page.name, !page.empty);
+            list_append (sidebar.listmodel, page.name, !page.empty);
         }
 
         PropertiesPage current_page;
@@ -171,12 +171,13 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
             current_page = PropertiesPage.LOGIN;
 
         var path = new Gtk.TreePath.from_indices (current_page);
-        window.sidebar.props_sidebar.selection.select_path (path);
+        sidebar.selection.select_path (path);
         visible_child_name = page_names[current_page];
     }
 
-    public void setup_ui (AppWindow window) {
+    public void setup_ui (AppWindow window, PropertiesDialog dialog) {
         this.window = window;
+        this.sidebar = dialog.sidebar;
 
         transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;
         transition_duration = 400;
@@ -197,9 +198,9 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
             if (window.current_item is LibvirtMachine) {
                 var libvirt_machine = window.current_item as LibvirtMachine;
                 stats_id = libvirt_machine.stats_updated.connect (() => {
-                    window.sidebar.props_sidebar.cpu_graph.points = libvirt_machine.cpu_stats;
-                    window.sidebar.props_sidebar.net_graph.points = libvirt_machine.net_stats;
-                    window.sidebar.props_sidebar.io_graph.points = libvirt_machine.io_stats;
+                    sidebar.cpu_graph.points = libvirt_machine.cpu_stats;
+                    sidebar.net_graph.points = libvirt_machine.net_stats;
+                    sidebar.io_graph.points = libvirt_machine.io_stats;
                 });
             }
 
diff --git a/src/topbar.vala b/src/topbar.vala
index 867e7b2..9608442 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -107,10 +107,6 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
             page = TopbarPage.DISPLAY;
             break;
 
-        case UIState.PROPERTIES:
-            page = TopbarPage.PROPERTIES;
-            break;
-
         default:
             break;
         }


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