Image history performance improvements

This commit is contained in:
Jaex 2016-03-02 02:02:08 +02:00
parent 2d1fc1e0b6
commit 323f7ac7e8
6 changed files with 60 additions and 60 deletions

View file

@ -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,

View file

@ -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)

View file

@ -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);

View file

@ -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<HistoryItem> tempHistoryItems = history.GetHistoryItems().Where(x => !string.IsNullOrEmpty(x.Filepath) && Helpers.IsImageFile(x.Filepath) && File.Exists(x.Filepath));
List<HistoryItem> tempHistoryItems = new List<HistoryItem>();
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;
}
}

View file

@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.Name" xml:space="preserve">
<value>tscMain.BottomToolStripPanel</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.Parent" xml:space="preserve">
<value>tscMain</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ilvImages.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
@ -136,7 +148,7 @@
<value>ilvImages</value>
</data>
<data name="&gt;&gt;ilvImages.Type" xml:space="preserve">
<value>Manina.Windows.Forms.ImageListView, ImageListView, Version=11.0.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>Manina.Windows.Forms.ImageListView, ImageListView, Version=11.0.4.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;ilvImages.Parent" xml:space="preserve">
<value>tscMain.ContentPanel</value>
@ -144,18 +156,6 @@
<data name="&gt;&gt;ilvImages.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.Name" xml:space="preserve">
<value>tscMain.BottomToolStripPanel</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.Parent" xml:space="preserve">
<value>tscMain</value>
</data>
<data name="&gt;&gt;tscMain.BottomToolStripPanel.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="tscMain.ContentPanel.Size" type="System.Drawing.Size, System.Drawing">
<value>804, 587</value>
</data>
@ -238,31 +238,31 @@
<value>View mode</value>
</data>
<data name="tsmiThumbnailSize75.Size" type="System.Drawing.Size, System.Drawing">
<value>121, 22</value>
<value>152, 22</value>
</data>
<data name="tsmiThumbnailSize75.Text" xml:space="preserve">
<value>75 x 75</value>
<comment>@Invariant</comment></data>
<data name="tsmiThumbnailSize100.Size" type="System.Drawing.Size, System.Drawing">
<value>121, 22</value>
<value>152, 22</value>
</data>
<data name="tsmiThumbnailSize100.Text" xml:space="preserve">
<value>100 x 100</value>
<comment>@Invariant</comment></data>
<data name="tsmiThumbnailSize150.Size" type="System.Drawing.Size, System.Drawing">
<value>121, 22</value>
<value>152, 22</value>
</data>
<data name="tsmiThumbnailSize150.Text" xml:space="preserve">
<value>150 x 150</value>
<comment>@Invariant</comment></data>
<data name="tsmiThumbnailSize200.Size" type="System.Drawing.Size, System.Drawing">
<value>121, 22</value>
<value>152, 22</value>
</data>
<data name="tsmiThumbnailSize200.Text" xml:space="preserve">
<value>200 x 200</value>
<comment>@Invariant</comment></data>
<data name="tsmiThumbnailSize250.Size" type="System.Drawing.Size, System.Drawing">
<value>121, 22</value>
<value>152, 22</value>
</data>
<data name="tsmiThumbnailSize250.Text" xml:space="preserve">
<value>250 x 250</value>
@ -274,7 +274,7 @@
<value>Thumbnail size</value>
</data>
<data name="tsbQuickList.Size" type="System.Drawing.Size, System.Drawing">
<value>174, 20</value>
<value>150, 20</value>
</data>
<data name="tsbQuickList.Text" xml:space="preserve">
<value>Only show last 100 images</value>
@ -286,7 +286,7 @@
<value>3, 1, 3, 1</value>
</data>
<data name="tsMain.Size" type="System.Drawing.Size, System.Drawing">
<value>361, 25</value>
<value>347, 25</value>
</data>
<data name="tsMain.TabIndex" type="System.Int32, mscorlib">
<value>0</value>

View file

@ -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();
}
}
}