[gnome-boxes] App: Move shared code into position_item_actor_at_icon helper



commit 804c5026c853b2f19ea72de06165d908f64b8e94
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Nov 16 16:33:37 2012 +0100

    App: Move shared code into position_item_actor_at_icon helper
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688473

 src/app.vala        |   33 ++++++++++++++++++++-------------
 src/machine.vala    |   11 +++--------
 src/properties.vala |   17 ++++++-----------
 src/searchbar.vala  |    6 ------
 src/sidebar.vala    |   12 ++++--------
 src/wizard.vala     |    4 +---
 6 files changed, 34 insertions(+), 49 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index c7cab21..d1d54db 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -546,6 +546,21 @@ private class Boxes.App: Boxes.UI {
         notebook.page = Boxes.AppPage.MAIN;
     }
 
+    private void position_item_actor_at_icon (CollectionItem item) {
+        float item_x, item_y;
+        view.get_item_pos (item, out item_x, out item_y);
+        var actor = item.actor;
+        var old_duration = actor.get_easing_duration ();
+        // We temporarily set the duration to 0 because we don't want to animate
+        // fixed_x/y, but rather immidiately set it to the target value and then
+        // animate actor.allocation which is set based on these.
+        actor.set_easing_duration (0);
+        actor.fixed_x = item_x;
+        actor.fixed_y = item_y;
+        actor.min_width = actor.natural_width = Machine.SCREENSHOT_WIDTH;
+        actor.set_easing_duration (old_duration);
+    }
+
     public override void ui_state_changed () {
         action_fullscreen.set_enabled (ui_state == UIState.DISPLAY);
         action_properties.set_enabled (ui_state == UIState.DISPLAY);
@@ -579,24 +594,16 @@ private class Boxes.App: Boxes.UI {
 
             // Animate current_item actor to collection position
             if (current_item != null) {
-                float item_x, item_y;
-                view.get_item_pos (current_item, out item_x, out item_y);
-
                 var actor = current_item.actor;
-                actor.set_easing_duration (0);
-                actor.show ();
 
-                actor.fixed_x = item_x;
-                actor.fixed_y = item_y;
-                actor.min_width = actor.natural_width = Machine.SCREENSHOT_WIDTH;
+                actor.show ();
+                position_item_actor_at_icon (current_item);
 
-                actor.set_easing_duration (App.app.duration);
+                // Also track size changes in the icon_view during the animation
                 var id = view.icon_view.size_allocate.connect ((allocation) => {
+                    // We do this in an idle to avoid causing a layout inside a size_allocate cycle
                     Idle.add_full (Priority.HIGH, () => {
-                        float item_x2, item_y2;
-                        view.get_item_pos (current_item, out item_x2, out item_y2);
-                        actor.x = item_x2;
-                        actor.y = item_y2;
+                        position_item_actor_at_icon (current_item);
                         return false;
                     });
                 });
diff --git a/src/machine.vala b/src/machine.vala
index 63f402b..1590cc2 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -457,17 +457,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     public override void ui_state_changed () {
         machine_actor.ui_state = ui_state;
 
-        switch (ui_state) {
-        case Boxes.UIState.DISPLAY:
-        case Boxes.UIState.PROPERTIES:
-        case Boxes.UIState.CREDS:
-            /* These are allowed display states */
-            break;
-        default:
+        if (ui_state != Boxes.UIState.DISPLAY &&
+            ui_state != Boxes.UIState.PROPERTIES &&
+            ui_state != Boxes.UIState.CREDS) {
             /* Disconnect if we go to any other state */
             machine_actor.update_thumbnail (null, false);
             disconnect_display ();
-            break;
         }
 
     }
diff --git a/src/properties.vala b/src/properties.vala
index 3de2fdf..49efe7c 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -294,8 +294,7 @@ private class Boxes.Properties: Boxes.UI {
             stats_id = 0;
         }
 
-        switch (ui_state) {
-        case UIState.PROPERTIES:
+        if (ui_state == UIState.PROPERTIES) {
             if (App.app.current_item is LibvirtMachine) {
                 var libvirt_machine = App.app.current_item as LibvirtMachine;
                 stats_id = libvirt_machine.stats_updated.connect (() => {
@@ -311,15 +310,11 @@ private class Boxes.Properties: Boxes.UI {
             else
                 toolbar_label.label = "";
             populate ();
-            break;
-        default:
-            if (previous_ui_state == UIState.PROPERTIES)
-                for (var i = 0; i < PropertiesPage.LAST; i++) {
-                    var page = notebook.get_data<PageWidget> (@"boxes-property-$i");
-
-                    page.flush_changes ();
-                }
-            break;
+        } else if (previous_ui_state == UIState.PROPERTIES) {
+            for (var i = 0; i < PropertiesPage.LAST; i++) {
+                var page = notebook.get_data<PageWidget> (@"boxes-property-$i");
+                page.flush_changes ();
+            }
         }
 
         fade_actor (actor, ui_state == UIState.PROPERTIES ? 255 : 0);
diff --git a/src/searchbar.vala b/src/searchbar.vala
index d2f5960..c54ed1f 100644
--- a/src/searchbar.vala
+++ b/src/searchbar.vala
@@ -157,11 +157,5 @@ private class Boxes.Searchbar: Boxes.UI {
     }
 
     public override void ui_state_changed () {
-        switch (ui_state) {
-        case UIState.COLLECTION:
-            break;
-        default:
-            break;
-        }
     }
 }
diff --git a/src/sidebar.vala b/src/sidebar.vala
index d4d9b53..cffa590 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -26,19 +26,15 @@ private class Boxes.Sidebar: Boxes.UI {
 
     public override void ui_state_changed () {
         switch (ui_state) {
-        case UIState.COLLECTION:
-            App.app.sidebar_revealer.unreveal ();
-            break;
-
-        default:
-            App.app.sidebar_revealer.unreveal ();
-            break;
-
         case UIState.WIZARD:
         case UIState.PROPERTIES:
             App.app.sidebar_revealer.reveal ();
             notebook.page = ui_state == UIState.WIZARD ? SidebarPage.WIZARD : SidebarPage.PROPERTIES;
             break;
+
+        default:
+            App.app.sidebar_revealer.unreveal ();
+            break;
         }
     }
 
diff --git a/src/wizard.vala b/src/wizard.vala
index eb788ff..c72c8e3 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -672,15 +672,13 @@ private class Boxes.Wizard: Boxes.UI {
     }
 
     public override void ui_state_changed () {
-        switch (ui_state) {
-        case UIState.WIZARD:
+        if (ui_state == UIState.WIZARD) {
             if (previous_ui_state == UIState.PROPERTIES)
                 review.begin ();
             else {
                 wizard_source.uri = "";
                 page = WizardPage.INTRODUCTION;
             }
-            break;
         }
 
         fade_actor (actor, ui_state == UIState.WIZARD ? 255 : 0);



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