From 323f7ac7e833ac80fe0c3a3ca7dc940acd0c4f8d Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 2 Mar 2016 02:02:08 +0200 Subject: [PATCH] Image history performance improvements --- ShareX.HelpersLib/Enums.cs | 12 ------ ShareX.HelpersLib/Helpers/Helpers.cs | 11 +++-- .../ImageHistoryForm.Designer.cs | 32 ++++++++------- ShareX.HistoryLib/ImageHistoryForm.cs | 21 ++++++---- ShareX.HistoryLib/ImageHistoryForm.resx | 40 +++++++++---------- ShareX/TaskSettings.cs | 4 +- 6 files changed, 60 insertions(+), 60 deletions(-) diff --git a/ShareX.HelpersLib/Enums.cs b/ShareX.HelpersLib/Enums.cs index 05ce153cf..853a54633 100644 --- a/ShareX.HelpersLib/Enums.cs +++ b/ShareX.HelpersLib/Enums.cs @@ -27,18 +27,6 @@ namespace ShareX.HelpersLib { - // http://en.wikipedia.org/wiki/List_of_file_formats - - public enum ImageFileExtensions - { - jpg, jpeg, png, gif, bmp, ico, tif, tiff - } - - public enum TextFileExtensions - { - txt, log, nfo, c, cpp, cc, cxx, h, hpp, hxx, cs, vb, html, htm, xhtml, xht, xml, css, js, php, bat, java, lua, py, pl, cfg, ini - } - public enum EDataType { Default, diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index f340b4feb..706d9d4d4 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -62,6 +62,9 @@ public static class Helpers public const string URLPathCharacters = URLCharacters + "/"; // 47 public const string ValidURLCharacters = URLPathCharacters + ":?#[]@!$&'()*+,;= "; + public static readonly string[] ImageFileExtensions = new string[] { "jpg", "jpeg", "png", "gif", "bmp", "ico", "tif", "tiff" }; + public static readonly string[] TextFileExtensions = new string[] { "txt", "log", "nfo", "c", "cpp", "cc", "cxx", "h", "hpp", "hxx", "cs", "vb", "html", "htm", "xhtml", "xht", "xml", "css", "js", "php", "bat", "java", "lua", "py", "pl", "cfg", "ini" }; + public static readonly Version OSVersion = Environment.OSVersion.Version; // Extension without dot @@ -110,13 +113,13 @@ public static string AppendExtension(string filePath, string extension) return filePath.TrimEnd('.') + '.' + extension.TrimStart('.'); } - private static bool IsValidFile(string filePath, Type enumType) + private static bool IsValidFile(string filePath, string[] extensionList) { string ext = GetFilenameExtension(filePath); if (!string.IsNullOrEmpty(ext)) { - return Enum.GetNames(enumType).Any(x => ext.Equals(x, StringComparison.InvariantCultureIgnoreCase)); + return extensionList.Any(x => ext.Equals(x, StringComparison.InvariantCultureIgnoreCase)); } return false; @@ -124,12 +127,12 @@ private static bool IsValidFile(string filePath, Type enumType) public static bool IsImageFile(string filePath) { - return IsValidFile(filePath, typeof(ImageFileExtensions)); + return IsValidFile(filePath, ImageFileExtensions); } public static bool IsTextFile(string filePath) { - return IsValidFile(filePath, typeof(TextFileExtensions)); + return IsValidFile(filePath, TextFileExtensions); } public static EDataType FindDataType(string filePath) diff --git a/ShareX.HistoryLib/ImageHistoryForm.Designer.cs b/ShareX.HistoryLib/ImageHistoryForm.Designer.cs index 96cd721eb..da82fe8ad 100644 --- a/ShareX.HistoryLib/ImageHistoryForm.Designer.cs +++ b/ShareX.HistoryLib/ImageHistoryForm.Designer.cs @@ -29,8 +29,8 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageHistoryForm)); - this.ilvImages = new Manina.Windows.Forms.ImageListView(); this.tscMain = new System.Windows.Forms.ToolStripContainer(); + this.ilvImages = new Manina.Windows.Forms.ImageListView(); this.tsMain = new System.Windows.Forms.ToolStrip(); this.tsddbViewMode = new System.Windows.Forms.ToolStripDropDownButton(); this.tsmiViewModeThumbnails = new System.Windows.Forms.ToolStripMenuItem(); @@ -49,6 +49,20 @@ private void InitializeComponent() this.tsMain.SuspendLayout(); this.SuspendLayout(); // + // tscMain + // + // + // tscMain.ContentPanel + // + this.tscMain.ContentPanel.Controls.Add(this.ilvImages); + resources.ApplyResources(this.tscMain.ContentPanel, "tscMain.ContentPanel"); + resources.ApplyResources(this.tscMain, "tscMain"); + this.tscMain.Name = "tscMain"; + // + // tscMain.TopToolStripPanel + // + this.tscMain.TopToolStripPanel.Controls.Add(this.tsMain); + // // ilvImages // this.ilvImages.AllowDuplicateFileNames = true; @@ -66,20 +80,6 @@ private void InitializeComponent() this.ilvImages.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ilvImages_KeyDown); this.ilvImages.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ilvImages_MouseUp); // - // tscMain - // - // - // tscMain.ContentPanel - // - this.tscMain.ContentPanel.Controls.Add(this.ilvImages); - resources.ApplyResources(this.tscMain.ContentPanel, "tscMain.ContentPanel"); - resources.ApplyResources(this.tscMain, "tscMain"); - this.tscMain.Name = "tscMain"; - // - // tscMain.TopToolStripPanel - // - this.tscMain.TopToolStripPanel.Controls.Add(this.tsMain); - // // tsMain // resources.ApplyResources(this.tsMain, "tsMain"); @@ -127,6 +127,7 @@ private void InitializeComponent() this.tsmiThumbnailSize150, this.tsmiThumbnailSize200, this.tsmiThumbnailSize250}); + this.tsddbThumbnailSize.Margin = new System.Windows.Forms.Padding(5, 1, 0, 2); this.tsddbThumbnailSize.Name = "tsddbThumbnailSize"; resources.ApplyResources(this.tsddbThumbnailSize, "tsddbThumbnailSize"); // @@ -164,6 +165,7 @@ private void InitializeComponent() // this.tsbQuickList.CheckOnClick = true; this.tsbQuickList.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.tsbQuickList.Margin = new System.Windows.Forms.Padding(5, 1, 0, 2); this.tsbQuickList.Name = "tsbQuickList"; resources.ApplyResources(this.tsbQuickList, "tsbQuickList"); this.tsbQuickList.Click += new System.EventHandler(this.tsbQuickList_Click); diff --git a/ShareX.HistoryLib/ImageHistoryForm.cs b/ShareX.HistoryLib/ImageHistoryForm.cs index 5eb30ee32..4e1f7d6fb 100644 --- a/ShareX.HistoryLib/ImageHistoryForm.cs +++ b/ShareX.HistoryLib/ImageHistoryForm.cs @@ -75,7 +75,8 @@ public ImageHistoryForm(string historyPath, int viewMode, Size thumbnailSize, in { InitializeComponent(); Icon = ShareXResources.Icon; - Text = "ShareX - " + string.Format("Image history: {0}", historyPath); + // TODO: Translate + Text = "ShareX - Image history"; HistoryPath = historyPath; MaxItemCount = maxItemCount; @@ -104,15 +105,21 @@ private void RefreshHistoryItems() private HistoryItem[] GetHistoryItems() { - IEnumerable tempHistoryItems = history.GetHistoryItems().Where(x => !string.IsNullOrEmpty(x.Filepath) && Helpers.IsImageFile(x.Filepath) && File.Exists(x.Filepath)); + List tempHistoryItems = new List(); - if (MaxItemCount > -1) + int itemCount = 0; + + foreach (HistoryItem hi in history.GetHistoryItems()) { - int skip = tempHistoryItems.Count() - MaxItemCount; - - if (skip > 0) + if (!string.IsNullOrEmpty(hi.Filepath) && Helpers.IsImageFile(hi.Filepath) && File.Exists(hi.Filepath)) { - tempHistoryItems = tempHistoryItems.Skip(skip); + tempHistoryItems.Add(hi); + itemCount++; + } + + if (MaxItemCount > -1 && itemCount >= MaxItemCount) + { + break; } } diff --git a/ShareX.HistoryLib/ImageHistoryForm.resx b/ShareX.HistoryLib/ImageHistoryForm.resx index 7eff5d4d1..4e4f8c3a6 100644 --- a/ShareX.HistoryLib/ImageHistoryForm.resx +++ b/ShareX.HistoryLib/ImageHistoryForm.resx @@ -117,6 +117,18 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tscMain.BottomToolStripPanel + + + System.Windows.Forms.ToolStripPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tscMain + + + 4 + Fill @@ -136,7 +148,7 @@ ilvImages - Manina.Windows.Forms.ImageListView, ImageListView, Version=11.0.0.0, Culture=neutral, PublicKeyToken=null + Manina.Windows.Forms.ImageListView, ImageListView, Version=11.0.4.0, Culture=neutral, PublicKeyToken=null tscMain.ContentPanel @@ -144,18 +156,6 @@ 0 - - tscMain.BottomToolStripPanel - - - System.Windows.Forms.ToolStripPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tscMain - - - 4 - 804, 587 @@ -238,31 +238,31 @@ View mode - 121, 22 + 152, 22 75 x 75 @Invariant - 121, 22 + 152, 22 100 x 100 @Invariant - 121, 22 + 152, 22 150 x 150 @Invariant - 121, 22 + 152, 22 200 x 200 @Invariant - 121, 22 + 152, 22 250 x 250 @@ -274,7 +274,7 @@ Thumbnail size - 174, 20 + 150, 20 Only show last 100 images @@ -286,7 +286,7 @@ 3, 1, 3, 1 - 361, 25 + 347, 25 0 diff --git a/ShareX/TaskSettings.cs b/ShareX/TaskSettings.cs index b10668963..7b4b35483 100644 --- a/ShareX/TaskSettings.cs +++ b/ShareX/TaskSettings.cs @@ -509,8 +509,8 @@ public Size ToastWindowSize public TaskSettingsAdvanced() { this.ApplyDefaultPropertyValues(); - ImageExtensions = Enum.GetNames(typeof(ImageFileExtensions)).ToList(); - TextExtensions = Enum.GetNames(typeof(TextFileExtensions)).ToList(); + ImageExtensions = Helpers.ImageFileExtensions.ToList(); + TextExtensions = Helpers.TextFileExtensions.ToList(); } } } \ No newline at end of file