Browse Source

Improve start-up behavior

Ruben 5 years ago
parent
commit
9912319dad
2 changed files with 40 additions and 34 deletions
  1. 28 34
      PicView/UI/Loading/StartLoading.cs
  2. 12 0
      PicView/UI/PicGallery/GalleryLoad.cs

+ 28 - 34
PicView/UI/Loading/StartLoading.cs

@@ -99,41 +99,53 @@ namespace PicView.UI.Loading
             }
             else
             {
+                if (!AutoFitWindow)
+                {
+                    SetDefaultSize();
+                }
+                else
+                {
+                    if (!ScaleImage.TryFitImage(arg.ToString()))
+                    {
+                        SetDefaultSize();
+                    }
+                }
+
                 Pic(arg.ToString());
             }
 
+            // Load UI and events
             AddUIElementsAndUpdateValues();
 
+            // Change into prefered UI, if needed.
             if (Properties.Settings.Default.Fullscreen)
             {
-                if (!ScaleImage.TryFitImage(arg.ToString()))
+                if (arg == null)
                 {
-                    SetDefaultSize();
+                    // Don't start it in fullscreen with no image
+                    Properties.Settings.Default.Fullscreen = false;
+                }
+                else
+                {
+                    Fullscreen_Restore(true);
                 }
-
-                Fullscreen_Restore(true);
             }
             else if (Properties.Settings.Default.Maximized)
             {
-                if (!ScaleImage.TryFitImage(arg.ToString()))
-                {
-                    SetDefaultSize();
-                }
-
                 Maximize();
             }
-            else
+            // Load PicGallery, if needed
+            else if (Properties.Settings.Default.PicGallery == 2)
             {
-                if (AutoFitWindow)
+                if (arg == null)
                 {
-                    if (!ScaleImage.TryFitImage(arg.ToString()))
-                    {
-                        SetDefaultSize();
-                    }
+                    // Reset PicGallery and don't allow it to run,
+                    // if only 1 image
+                    Properties.Settings.Default.PicGallery = 1;
                 }
                 else
                 {
-                    SetDefaultSize();
+                    GalleryToggle.OpenFullscreenGallery();
                 }
             }
 
@@ -192,24 +204,6 @@ namespace PicView.UI.Loading
                 Visibility.Visible;
             }
 
-            // Load PicGallery, if needed
-            if (Properties.Settings.Default.PicGallery > 0)
-            {
-                picGallery = new UserControls.PicGallery
-                {
-                    Opacity = 0,
-                    Visibility = Visibility.Collapsed
-                };
-
-                TheMainWindow.ParentContainer.Children.Add(picGallery);
-                Panel.SetZIndex(picGallery, 999);
-
-                if (Properties.Settings.Default.PicGallery == 2)
-                {
-                    GalleryToggle.OpenFullscreenGallery();
-                }
-            }
-
             // Add UserControls :)
             LoadTooltipStyle();
             LoadFileMenu();

+ 12 - 0
PicView/UI/PicGallery/GalleryLoad.cs

@@ -22,6 +22,18 @@ namespace PicView.UI.PicGallery
 
         internal static void LoadLayout()
         {
+            if (picGallery == null)
+            {
+                picGallery = new UserControls.PicGallery
+                {
+                    Opacity = 0,
+                    Visibility = Visibility.Collapsed
+                };
+
+                TheMainWindow.ParentContainer.Children.Add(picGallery);
+                Panel.SetZIndex(picGallery, 999);
+            }
+
             // TODO Make this code more clean and explain what's going on?
             if (Properties.Settings.Default.PicGallery == 1)
             {