[gnome-boxes] Put properties in a separate window



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

    Put properties in a separate window
    
    With some UI transitions removed during the port away from clutter, its
    better to have it in a separate window.
    
    Known issues:
    
    * Similar to WizardWindow, notifications are going into AppWindow.
    
    * Our snapshots UI relies on disabling all controls to get out of the
      snapshots view while an operation is in progress. We lose most of this
      ability to disable all controls with this patch. We really shouldn't be
      doing this anyway so lets actually solve this issue after these UI
      rework changes are merged into git master.
    
    * Troubleshooting dialog is not accessible unless you close properties
      window. Although the real solution would be to not launch dialogs from
      dialogs (or dialog-like windows), we'll solve this in a following
      patch by making troubleshooting dialog also modal.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733367

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/app-window.ui          |   46 -------------------------------
 data/ui/properties-window.ui   |   58 ++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am                |    1 +
 src/app-window.vala            |   18 ++----------
 src/machine.vala               |    4 +-
 src/properties-sidebar.vala    |    2 +-
 src/properties-window.vala     |   52 +++++++++++++++++++++++++++++++++++
 src/properties.vala            |   21 +++++++-------
 src/snapshots-property.vala    |    6 +---
 10 files changed, 131 insertions(+), 78 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 8d4aae5..69580f7 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -15,6 +15,7 @@
     <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-window.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-window.ui b/data/ui/properties-window.ui
new file mode 100644
index 0000000..42e27ed
--- /dev/null
+++ b/data/ui/properties-window.ui
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+
+  <!-- Widget hierarchy:
+
+     Boxes.PropertiesWindow : Gtk.Window
+        |
+        |
+        |-> hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+        |    |
+        |    |-> sidebar = new Boxes.PropertiesSidebar ();
+        |    |
+        |    |-> properties = new Boxes.Properties ();
+        |
+        |-> topbar = new Boxes.PropertiesToolbar (); // as titlebar
+  -->
+
+  <template class="BoxesPropertiesWindow" parent="GtkWindow">
+    <property name="can_focus">False</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type-hint">dialog</property>
+    <signal name="key-press-event" after="yes" handler="on_key_pressed"/>
+    <signal name="delete-event" handler="on_delete_event"/>
+
+    <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>
+
+    <child type="titlebar">
+      <object class="BoxesPropertiesToolbar" id="topbar">
+        <property name="visible">True</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index b89484d..f25d5b2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -123,6 +123,7 @@ gnome_boxes_SOURCES =                               \
        notificationbar.vala                    \
        os-database.vala                        \
        properties.vala                         \
+       properties-window.vala                  \
        properties-sidebar.vala                 \
        properties-toolbar.vala                 \
        remote-machine.vala                     \
diff --git a/src/app-window.vala b/src/app-window.vala
index 9f2c8da..341d8b8 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -61,6 +61,7 @@ private class Boxes.AppWindow: Gtk.ApplicationWindow, Boxes.UI {
     }
 
     public WizardWindow wizard_window;
+    public PropertiesWindow  props_window;
 
     [GtkChild]
     public Searchbar searchbar;
@@ -71,20 +72,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;
@@ -134,12 +127,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_window = new WizardWindow (this);
+        props_window = new PropertiesWindow (this);
     }
 
     private void save_window_geometry () {
@@ -158,7 +150,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_window, empty_boxes }) 
{
+        foreach (var ui in new Boxes.UI[] { topbar, view, props_window, wizard_window, empty_boxes }) {
             ui.set_state (ui_state);
         }
 
@@ -192,11 +184,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 1613940..ab330e1 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -427,7 +427,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_window.sidebar.screenshot.set_from_pixbuf (pixbuf);
             if (save)
                 save_pixbuf_as_screenshot (small_screenshot);
 
@@ -587,7 +587,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_window.sidebar.screenshot.set_from_pixbuf (pixbuf);
 
             break;
         }
diff --git a/src/properties-sidebar.vala b/src/properties-sidebar.vala
index b98da6f..f5e30c8 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_window.properties.page = (PropertiesPage) listmodel.get_path (iter).get_indices ()[0];
     }
 
     [GtkCallback]
diff --git a/src/properties-window.vala b/src/properties-window.vala
new file mode 100644
index 0000000..ce2c68e
--- /dev/null
+++ b/src/properties-window.vala
@@ -0,0 +1,52 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/properties-window.ui")]
+private class Boxes.PropertiesWindow: Gtk.Window, 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;
+    [GtkChild]
+    public PropertiesToolbar topbar;
+
+    private unowned AppWindow app_window;
+
+    public PropertiesWindow (AppWindow app_window) {
+        this.app_window = app_window;
+
+        sidebar.setup_ui (app_window);
+        properties.setup_ui (app_window, this);
+        topbar.setup_ui (app_window);
+
+        set_transient_for (app_window);
+
+        notify["ui-state"].connect (ui_state_changed);
+    }
+
+    private void ui_state_changed () {
+        properties.set_state (ui_state);
+
+        visible = (ui_state == UIState.PROPERTIES);
+        topbar.back_button.visible = (previous_ui_state == UIState.WIZARD);
+        topbar.show_close_button = (previous_ui_state != UIState.WIZARD);
+    }
+
+    [GtkCallback]
+    private bool on_key_pressed (Widget widget, Gdk.EventKey event) {
+        if (event.keyval == Gdk.Key.Escape) // ESC -> back
+            topbar.back_button.clicked ();
+
+        return false;
+    }
+
+    [GtkCallback]
+    private bool on_delete_event () {
+        topbar.back_button.clicked ();
+
+        return true;
+    }
+}
diff --git a/src/properties.vala b/src/properties.vala
index 0990c5e..c2397af 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;
@@ -135,15 +136,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;
@@ -157,11 +157,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;
@@ -172,12 +172,13 @@ private class Boxes.Properties: Gtk.Stack, Boxes.UI {
             current_page = PropertiesPage.GENERAL;
 
         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, PropertiesWindow dialog) {
         this.window = window;
+        this.sidebar = dialog.sidebar;
 
         transition_type = Gtk.StackTransitionType.SLIDE_UP_DOWN;
         transition_duration = 400;
@@ -198,9 +199,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/snapshots-property.vala b/src/snapshots-property.vala
index 584d503..38aed80 100644
--- a/src/snapshots-property.vala
+++ b/src/snapshots-property.vala
@@ -11,13 +11,11 @@ private class Boxes.SnapshotsProperty : Boxes.Property {
         set {
             if (value == null) {
                 snapshot_stack.visible_child = snapshot_box;
-                machine.window.sidebar.sensitive = true;
-                machine.window.topbar.props_toolbar.back_button.sensitive = true;
+                machine.window.props_window.sidebar.sensitive = true;
             } else {
                 activity_label.label = value;
                 snapshot_stack.visible_child = activity_box;
-                machine.window.sidebar.sensitive = false;
-                machine.window.topbar.props_toolbar.back_button.sensitive = false;
+                machine.window.props_window.sidebar.sensitive = false;
             }
         }
     }


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