Просмотр исходного кода

Updates to title bar text when file is from web

Ruben 5 лет назад
Родитель
Сommit
2351500e95

+ 1 - 1
PicView/FileHandling/FileFunctions.cs

@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
 
 namespace PicView.FileHandling
 {
-    internal class FileFunctions
+    internal static class FileFunctions
     {
         internal static bool RenameFile(string path, string newPath)
         {

+ 20 - 4
PicView/Library/Utilities.cs

@@ -1,5 +1,8 @@
-using System.Configuration;
+using System;
+using System.Configuration;
+using System.Diagnostics;
 using System.IO;
+using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows.Input;
 
@@ -7,7 +10,6 @@ namespace PicView.Library
 {
     internal static class Utilities
     {
-        #region static helpers
 
         /// <summary>
         /// Greatest Common Divisor
@@ -29,8 +31,6 @@ namespace PicView.Library
             return element.PointToScreen(Mouse.GetPosition(element));
         }
 
-        #endregion static helpers
-
         public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel)
         {
             try
@@ -48,5 +48,21 @@ namespace PicView.Library
         {
             return Path.GetDirectoryName(GetDefaultExeConfigPath(ConfigurationUserLevel.PerUserRoamingAndLocal));
         }
+
+        internal static string GetURL(string value)
+        {
+            try
+            {
+                var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
+                return linkParser.Match(value).ToString();
+            }
+            catch (Exception e)
+            {
+#if DEBUG
+                Trace.WriteLine(e.Message);
+#endif
+                return string.Empty;
+            }
+        }
     }
 }

+ 2 - 2
PicView/Shortcuts/MainShortcuts.cs

@@ -43,7 +43,7 @@ namespace PicView.Shortcuts
                     {
                         if (Pics.Count == 0)
                         {
-                            SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, "Custom image");
+                            SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height);
                         }
                         else
                         {
@@ -59,7 +59,7 @@ namespace PicView.Shortcuts
                     {
                         if (Pics.Count == 0)
                         {
-                            SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, "Custom image");
+                            SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height);
                         }
                         else
                         {

+ 1 - 14
PicView/SystemIntegration/Wallpaper.cs

@@ -29,20 +29,7 @@ namespace PicView.SystemIntegration
         /// <param name="style"></param>
         internal static void SetWallpaper(WallpaperStyle style)
         {
-            string wallpaper;
-
-            try
-            {
-                var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
-                wallpaper = linkParser.Match(mainWindow.Bar.Text).ToString();
-            }
-            catch (Exception e)
-            {
-#if DEBUG
-                Trace.WriteLine(e.Message);
-#endif
-                return;
-            }
+            string wallpaper = Library.Utilities.GetURL(mainWindow.Bar.Text);
 
             if (Uri.IsWellFormedUriString(wallpaper, UriKind.Absolute)) // Check if from web
                 {

+ 24 - 2
PicView/UI/SetTitle.cs

@@ -16,7 +16,7 @@ namespace PicView.UI
         /// <param name="height"></param>
         /// <param name="index"></param>
         /// <returns></returns>
-        internal static string[] TitleString(int width, int height, int index)
+        private static string[] TitleString(int width, int height, int index)
         {
             var s1 = new StringBuilder(90);
             s1.Append(Path.GetFileName(Pics[index])).Append(" ").Append(index + 1).Append("/").Append(Pics.Count).Append(" files")
@@ -62,7 +62,7 @@ namespace PicView.UI
         /// <param name="height"></param>
         /// <param name="path"></param>
         /// <returns></returns>
-        internal static string[] TitleString(int width, int height, string path)
+        private static string[] TitleString(int width, int height, string path)
         {
             var s1 = new StringBuilder();
             s1.Append(path).Append(" (").Append(width).Append(" x ").Append(height).Append(StringAspect(width, height));
@@ -96,5 +96,27 @@ namespace PicView.UI
             mainWindow.Bar.Text = titleString[1];
             mainWindow.Bar.ToolTip = titleString[1];
         }
+
+        /// <summary>
+        /// Use name from title bar to set title string with,
+        /// zoom, aspect ratio and resolution
+        /// </summary>
+        /// <param name="width"></param>
+        /// <param name="height"></param>
+        internal static void SetTitleString(int width, int height)
+        {
+            string path = Library.Utilities.GetURL(mainWindow.Bar.Text);
+
+            path = string.IsNullOrWhiteSpace(path) ? "Custom image" : path;
+
+            var titleString = TitleString(width, height, path);
+            mainWindow.Title = titleString[0];
+            mainWindow.Bar.Text = titleString[1];
+            mainWindow.Bar.ToolTip = titleString[1];
+        }
+
+
+
+
     }
 }

+ 8 - 32
PicView/UI/TransformImage/Zoom.cs

@@ -256,26 +256,14 @@ namespace PicView.UI.TransformImage
             ScaleImage.TryFitImage();
 
             // Display non-zoomed values
-            if (CanNavigate)
+            if (Pics.Count == 0)
             {
-                SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, FolderIndex);
+                /// Display values from web
+                SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height);
             }
             else
             {
-                // Display values from web
-                try
-                {
-                    var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
-                    var txt = linkParser.Match(mainWindow.Bar.Text).ToString();
-                    SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, txt);
-                }
-                catch (Exception e)
-                {
-                    SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, "Custom image");
-#if DEBUG
-                    Trace.WriteLine(e.Message);
-#endif
-                }
+                SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, FolderIndex);
             }
 
             IsZoomed = false;
@@ -367,26 +355,14 @@ namespace PicView.UI.TransformImage
             }
 
             /// Display updated values
-            if (CanNavigate)
+            if (Pics.Count == 0)
             {
-                SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, FolderIndex);
+                /// Display values from web
+                SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height);
             }
             else
             {
-                /// Display values from web
-                try
-                {
-                    var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
-                    var txt = linkParser.Match(mainWindow.Bar.Text).ToString();
-                    SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, txt);
-                }
-                catch (Exception e)
-                {
-                    SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, "Custom image");
-#if DEBUG
-                    Trace.WriteLine(e.Message);
-#endif
-                }
+                SetTitle.SetTitleString((int)mainWindow.img.Source.Width, (int)mainWindow.img.Source.Height, FolderIndex);
             }
         }
     }