2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using ShareX.HistoryLib.Properties;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-10-21 11:46:23 +13:00
|
|
|
|
using System.IO;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2022-01-01 11:36:47 +13:00
|
|
|
|
using System.Threading.Tasks;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HistoryLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-02-26 09:55:54 +13:00
|
|
|
|
public partial class HistoryForm : Form
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
public string HistoryPath { get; private set; }
|
2018-08-02 01:52:10 +12:00
|
|
|
|
public HistorySettings Settings { get; private set; }
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
private HistoryItemManager him;
|
|
|
|
|
private HistoryItem[] allHistoryItems;
|
2022-01-01 10:18:40 +13:00
|
|
|
|
private HistoryItem[] filteredHistoryItems;
|
2016-03-20 04:40:59 +13:00
|
|
|
|
private string defaultTitle;
|
2021-09-08 18:44:34 +12:00
|
|
|
|
private Dictionary<string, string> typeNamesLocaleLookup;
|
2021-09-09 20:34:03 +12:00
|
|
|
|
private string[] allTypeNames;
|
2022-01-01 10:18:40 +13:00
|
|
|
|
private ListViewItem[] listViewCache;
|
2022-01-03 16:40:20 +13:00
|
|
|
|
private int listViewCacheStartIndex;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2018-08-02 01:52:10 +12:00
|
|
|
|
public HistoryForm(string historyPath, HistorySettings settings, Action<string> uploadFile = null, Action<string> editImage = null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-03-01 22:03:19 +13:00
|
|
|
|
HistoryPath = historyPath;
|
2018-08-02 01:52:10 +12:00
|
|
|
|
Settings = settings;
|
2016-03-01 22:03:19 +13:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
InitializeComponent();
|
2021-07-29 16:05:20 +12:00
|
|
|
|
tsHistory.Renderer = new ToolStripRoundedEdgeRenderer();
|
2019-06-17 19:43:13 +12:00
|
|
|
|
|
2016-03-20 04:44:24 +13:00
|
|
|
|
defaultTitle = Text;
|
2021-09-08 18:44:34 +12:00
|
|
|
|
|
|
|
|
|
string[] typeNames = Enum.GetNames(typeof(EDataType));
|
|
|
|
|
string[] typeTranslations = Helpers.GetLocalizedEnumDescriptions<EDataType>();
|
2021-09-09 20:34:03 +12:00
|
|
|
|
typeNamesLocaleLookup = typeNames.Zip(typeTranslations, (key, val) => new { key, val }).ToDictionary(e => e.key, e => e.val);
|
2021-09-08 18:44:34 +12:00
|
|
|
|
|
2019-06-17 18:02:16 +12:00
|
|
|
|
UpdateTitle();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-03-01 15:03:39 +13:00
|
|
|
|
ImageList il = new ImageList();
|
|
|
|
|
il.ColorDepth = ColorDepth.Depth32Bit;
|
|
|
|
|
il.Images.Add(Resources.image);
|
|
|
|
|
il.Images.Add(Resources.notebook);
|
|
|
|
|
il.Images.Add(Resources.application_block);
|
|
|
|
|
il.Images.Add(Resources.globe);
|
|
|
|
|
lvHistory.SmallImageList = il;
|
|
|
|
|
|
2021-08-08 05:23:34 +12:00
|
|
|
|
him = new HistoryItemManager(uploadFile, editImage, true);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
him.GetHistoryItems += him_GetHistoryItems;
|
2019-06-25 07:33:17 +12:00
|
|
|
|
lvHistory.ContextMenuStrip = him.cmsHistory;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
pbThumbnail.Reset();
|
|
|
|
|
lvHistory.FillLastColumn();
|
2021-08-04 11:18:48 +12:00
|
|
|
|
scHistoryItemInfo.SplitterWidth = 7; // Because of bug must be assigned here again
|
|
|
|
|
scHistoryItemInfo.Panel2Collapsed = true;
|
2016-03-01 22:25:38 +13:00
|
|
|
|
|
2021-08-10 09:06:56 +12:00
|
|
|
|
tstbSearch.TextBox.HandleCreated += (sender, e) => tstbSearch.TextBox.SetWatermark(Resources.HistoryForm_Search_Watermark, true);
|
|
|
|
|
|
2021-07-27 17:27:40 +12:00
|
|
|
|
if (Settings.RememberSearchText)
|
|
|
|
|
{
|
|
|
|
|
tstbSearch.Text = Settings.SearchText;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 07:33:17 +12:00
|
|
|
|
ShareXResources.ApplyTheme(this);
|
|
|
|
|
|
2021-08-03 03:21:09 +12:00
|
|
|
|
if (Settings.RememberWindowState)
|
|
|
|
|
{
|
|
|
|
|
Settings.WindowState.ApplyFormState(this);
|
|
|
|
|
|
|
|
|
|
if (Settings.SplitterDistance > 0)
|
|
|
|
|
{
|
|
|
|
|
scMain.SplitterDistance = Settings.SplitterDistance;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 12:18:50 +12:00
|
|
|
|
private void ResetFilters()
|
|
|
|
|
{
|
|
|
|
|
txtFilenameFilter.ResetText();
|
|
|
|
|
txtURLFilter.ResetText();
|
|
|
|
|
cbDateFilter.Checked = false;
|
|
|
|
|
dtpFilterFrom.ResetText();
|
|
|
|
|
dtpFilterTo.ResetText();
|
|
|
|
|
cbTypeFilter.Checked = false;
|
|
|
|
|
if (cbTypeFilterSelection.Items.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
cbTypeFilterSelection.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
cbHostFilter.Checked = false;
|
|
|
|
|
cbHostFilterSelection.ResetText();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 11:36:47 +13:00
|
|
|
|
private async Task RefreshHistoryItems(bool mockData = false)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2022-01-01 11:36:47 +13:00
|
|
|
|
allHistoryItems = await GetHistoryItems(mockData);
|
|
|
|
|
|
2021-07-25 16:34:02 +12:00
|
|
|
|
ApplyFilterSimple();
|
2021-09-08 18:44:34 +12:00
|
|
|
|
|
2021-09-09 20:34:03 +12:00
|
|
|
|
cbTypeFilterSelection.Items.Clear();
|
|
|
|
|
cbHostFilterSelection.Items.Clear();
|
|
|
|
|
|
|
|
|
|
if (allHistoryItems.Length > 0)
|
2021-09-08 18:44:34 +12:00
|
|
|
|
{
|
2021-09-09 20:34:03 +12:00
|
|
|
|
allTypeNames = allHistoryItems.Select(x => x.Type).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray();
|
|
|
|
|
cbTypeFilterSelection.Items.AddRange(allTypeNames.Select(x => typeNamesLocaleLookup.TryGetValue(x, out string value) ? value : x).ToArray());
|
2021-09-08 18:44:34 +12:00
|
|
|
|
cbHostFilterSelection.Items.AddRange(allHistoryItems.Select(x => x.Host).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray());
|
|
|
|
|
}
|
2021-09-09 20:34:03 +12:00
|
|
|
|
|
|
|
|
|
ResetFilters();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HistoryItem[] him_GetHistoryItems()
|
|
|
|
|
{
|
2022-01-01 10:18:40 +13:00
|
|
|
|
return lvHistory.SelectedIndices.Cast<int>().Select(i => filteredHistoryItems[i]).ToArray();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 11:36:47 +13:00
|
|
|
|
private async Task<HistoryItem[]> GetHistoryItems(bool mockData = false)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2021-08-03 06:58:47 +12:00
|
|
|
|
HistoryManager history;
|
|
|
|
|
|
2021-07-26 11:39:35 +12:00
|
|
|
|
if (mockData)
|
|
|
|
|
{
|
|
|
|
|
history = new HistoryManagerMock(HistoryPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
2018-08-02 01:12:18 +12:00
|
|
|
|
{
|
2019-10-26 01:42:17 +13:00
|
|
|
|
history = new HistoryManagerJSON(HistoryPath);
|
2018-08-02 01:12:18 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 11:36:47 +13:00
|
|
|
|
List<HistoryItem> historyItems = await history.GetHistoryItemsAsync();
|
2020-09-28 01:39:38 +13:00
|
|
|
|
historyItems.Reverse();
|
|
|
|
|
return historyItems.ToArray();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 14:55:01 +12:00
|
|
|
|
private void ApplyFilter(HistoryFilter filter)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2021-07-25 14:55:01 +12:00
|
|
|
|
if (allHistoryItems != null && allHistoryItems.Length > 0)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2021-07-25 14:55:01 +12:00
|
|
|
|
IEnumerable<HistoryItem> historyItems = filter.ApplyFilter(allHistoryItems);
|
2022-01-01 10:18:40 +13:00
|
|
|
|
filteredHistoryItems = historyItems.ToArray();
|
2021-07-25 14:00:36 +12:00
|
|
|
|
|
2022-01-01 10:18:40 +13:00
|
|
|
|
UpdateTitle(filteredHistoryItems);
|
|
|
|
|
|
|
|
|
|
listViewCache = null;
|
2022-01-03 16:40:20 +13:00
|
|
|
|
listViewCacheStartIndex = 0;
|
2022-01-01 10:18:40 +13:00
|
|
|
|
lvHistory.VirtualListSize = 0;
|
2022-01-01 18:26:26 +13:00
|
|
|
|
|
|
|
|
|
if (filteredHistoryItems.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
lvHistory.VirtualListSize = filteredHistoryItems.Length;
|
|
|
|
|
lvHistory.SelectedIndices.Add(0);
|
|
|
|
|
}
|
2021-07-25 14:55:01 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 14:00:36 +12:00
|
|
|
|
private void ApplyFilterSimple()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2021-07-27 17:27:40 +12:00
|
|
|
|
string searchText = tstbSearch.Text;
|
|
|
|
|
|
|
|
|
|
if (Settings.RememberSearchText)
|
|
|
|
|
{
|
|
|
|
|
Settings.SearchText = searchText;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Settings.SearchText = "";
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 14:55:01 +12:00
|
|
|
|
HistoryFilter filter = new HistoryFilter()
|
|
|
|
|
{
|
2022-01-01 10:41:20 +13:00
|
|
|
|
Filename = searchText
|
2021-07-25 14:55:01 +12:00
|
|
|
|
};
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2021-07-25 14:00:36 +12:00
|
|
|
|
ApplyFilter(filter);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2021-07-25 14:55:01 +12:00
|
|
|
|
private void ApplyFilterAdvanced()
|
2021-07-25 14:00:36 +12:00
|
|
|
|
{
|
2021-07-25 14:55:01 +12:00
|
|
|
|
HistoryFilter filter = new HistoryFilter()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2021-07-25 16:17:10 +12:00
|
|
|
|
Filename = txtFilenameFilter.Text,
|
2021-07-25 14:55:01 +12:00
|
|
|
|
URL = txtURLFilter.Text,
|
|
|
|
|
FilterDate = cbDateFilter.Checked,
|
|
|
|
|
FromDate = dtpFilterFrom.Value.Date,
|
|
|
|
|
ToDate = dtpFilterTo.Value.Date,
|
|
|
|
|
FilterHost = cbHostFilter.Checked,
|
2022-01-01 10:41:20 +13:00
|
|
|
|
Host = cbHostFilterSelection.Text
|
2021-07-25 14:55:01 +12:00
|
|
|
|
};
|
2021-09-09 20:34:03 +12:00
|
|
|
|
|
|
|
|
|
if (cbTypeFilter.Checked && allTypeNames.IsValidIndex(cbTypeFilterSelection.SelectedIndex))
|
|
|
|
|
{
|
|
|
|
|
filter.FilterType = true;
|
|
|
|
|
filter.Type = allTypeNames[cbTypeFilterSelection.SelectedIndex];
|
|
|
|
|
}
|
2018-10-02 08:56:37 +13:00
|
|
|
|
|
2021-07-25 14:55:01 +12:00
|
|
|
|
ApplyFilter(filter);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 10:18:40 +13:00
|
|
|
|
private ListViewItem CreateListViewItem(int index)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2022-01-01 10:18:40 +13:00
|
|
|
|
HistoryItem hi = filteredHistoryItems[index];
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2022-01-01 10:18:40 +13:00
|
|
|
|
ListViewItem lvi = new ListViewItem();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2022-01-01 10:18:40 +13:00
|
|
|
|
if (hi.Type.Equals("Image", StringComparison.InvariantCultureIgnoreCase))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2022-01-01 10:18:40 +13:00
|
|
|
|
lvi.ImageIndex = 0;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2022-01-01 10:18:40 +13:00
|
|
|
|
else if (hi.Type.Equals("Text", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
lvi.ImageIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
else if (hi.Type.Equals("File", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
lvi.ImageIndex = 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-07-25 15:07:12 +12:00
|
|
|
|
{
|
2022-01-01 10:18:40 +13:00
|
|
|
|
lvi.ImageIndex = 3;
|
2021-07-25 15:07:12 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 18:26:26 +13:00
|
|
|
|
lvi.SubItems.Add(hi.DateTime.ToString());
|
2022-01-01 10:18:40 +13:00
|
|
|
|
lvi.SubItems.Add(hi.FileName);
|
|
|
|
|
lvi.SubItems.Add(hi.URL);
|
|
|
|
|
|
|
|
|
|
return lvi;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 22:03:19 +13:00
|
|
|
|
private void UpdateTitle(HistoryItem[] historyItems = null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-03-20 04:40:59 +13:00
|
|
|
|
string title = defaultTitle;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-03-01 22:03:19 +13:00
|
|
|
|
if (historyItems != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-03-01 22:03:19 +13:00
|
|
|
|
StringBuilder status = new StringBuilder();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-03-02 02:05:53 +13:00
|
|
|
|
status.Append(" (");
|
2016-03-01 22:03:19 +13:00
|
|
|
|
status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Length.ToString("N0"));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-03-01 22:03:19 +13:00
|
|
|
|
if (allHistoryItems.Length > historyItems.Length)
|
|
|
|
|
{
|
|
|
|
|
status.AppendFormat(" - " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length.ToString("N0"));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-17 18:02:16 +12:00
|
|
|
|
IEnumerable<string> types = historyItems.
|
|
|
|
|
GroupBy(x => x.Type).
|
|
|
|
|
OrderByDescending(x => x.Count()).
|
2021-09-08 18:44:34 +12:00
|
|
|
|
Select(x => string.Format(" - {0}: {1}", typeNamesLocaleLookup.TryGetValue(x.Key, out string value) ? value : x.Key, x.Count()));
|
2016-03-01 22:03:19 +13:00
|
|
|
|
|
|
|
|
|
foreach (string type in types)
|
|
|
|
|
{
|
|
|
|
|
status.Append(type);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 02:05:53 +13:00
|
|
|
|
status.Append(")");
|
2016-03-01 22:03:19 +13:00
|
|
|
|
title += status.ToString();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 22:03:19 +13:00
|
|
|
|
Text = title;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateControls()
|
|
|
|
|
{
|
2019-10-27 05:36:24 +13:00
|
|
|
|
HistoryItem previousHistoryItem = him.HistoryItem;
|
|
|
|
|
HistoryItem historyItem = him.UpdateSelectedHistoryItem();
|
|
|
|
|
|
|
|
|
|
if (historyItem == null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-10-27 05:36:24 +13:00
|
|
|
|
pbThumbnail.Reset();
|
2019-10-21 19:36:30 +13:00
|
|
|
|
}
|
2019-10-27 05:36:24 +13:00
|
|
|
|
else if (historyItem != previousHistoryItem)
|
2019-10-21 19:36:30 +13:00
|
|
|
|
{
|
2019-10-27 05:36:24 +13:00
|
|
|
|
UpdatePictureBox();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2021-08-04 11:18:48 +12:00
|
|
|
|
|
2021-08-04 11:26:25 +12:00
|
|
|
|
pgHistoryItemInfo.SelectedObject = historyItem;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePictureBox()
|
|
|
|
|
{
|
|
|
|
|
pbThumbnail.Reset();
|
|
|
|
|
|
|
|
|
|
if (him != null)
|
|
|
|
|
{
|
|
|
|
|
if (him.IsImageFile)
|
|
|
|
|
{
|
2019-10-22 00:20:21 +13:00
|
|
|
|
pbThumbnail.LoadImageFromFileAsync(him.HistoryItem.FilePath);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
else if (him.IsImageURL)
|
|
|
|
|
{
|
|
|
|
|
pbThumbnail.LoadImageFromURLAsync(him.HistoryItem.URL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 15:22:06 +12:00
|
|
|
|
private string OutputStats(HistoryItem[] historyItems)
|
|
|
|
|
{
|
2021-12-13 00:33:14 +13:00
|
|
|
|
string empty = "(empty)";
|
|
|
|
|
|
2021-07-25 15:22:06 +12:00
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
sb.AppendLine(Resources.HistoryItemCounts);
|
|
|
|
|
sb.AppendLine(Resources.HistoryStats_Total + " " + historyItems.Length);
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> types = historyItems.
|
|
|
|
|
GroupBy(x => x.Type).
|
|
|
|
|
OrderByDescending(x => x.Count()).
|
|
|
|
|
Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine(string.Join(Environment.NewLine, types));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine(Resources.HistoryStats_YearlyUsages);
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> yearlyUsages = historyItems.
|
|
|
|
|
GroupBy(x => x.DateTime.Year).
|
|
|
|
|
OrderByDescending(x => x.Key).
|
|
|
|
|
Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine(string.Join(Environment.NewLine, yearlyUsages));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine(Resources.HistoryStats_FileExtensions);
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> fileExtensions = historyItems.
|
|
|
|
|
Where(x => !string.IsNullOrEmpty(x.FileName) && !x.FileName.EndsWith(")")).
|
2022-05-03 18:34:18 +12:00
|
|
|
|
Select(x => FileHelpers.GetFileNameExtension(x.FileName)).
|
2021-12-13 00:33:14 +13:00
|
|
|
|
GroupBy(x => string.IsNullOrWhiteSpace(x) ? empty : x).
|
2021-07-25 15:22:06 +12:00
|
|
|
|
OrderByDescending(x => x.Count()).
|
2021-12-13 00:33:14 +13:00
|
|
|
|
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
2021-07-25 15:22:06 +12:00
|
|
|
|
|
|
|
|
|
sb.AppendLine(string.Join(Environment.NewLine, fileExtensions));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine(Resources.HistoryStats_Hosts);
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> hosts = historyItems.
|
2021-12-13 00:33:14 +13:00
|
|
|
|
GroupBy(x => string.IsNullOrWhiteSpace(x.Host) ? empty : x.Host).
|
|
|
|
|
OrderByDescending(x => x.Count()).
|
|
|
|
|
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine(string.Join(Environment.NewLine, hosts));
|
|
|
|
|
|
|
|
|
|
sb.AppendLine();
|
2021-12-15 04:51:54 +13:00
|
|
|
|
sb.AppendLine(Resources.ProcessNames);
|
2021-12-13 00:33:14 +13:00
|
|
|
|
|
|
|
|
|
IEnumerable<string> processNames = historyItems.
|
|
|
|
|
GroupBy(x => string.IsNullOrWhiteSpace(x.TagsProcessName) ? empty : x.TagsProcessName).
|
2021-07-25 15:22:06 +12:00
|
|
|
|
OrderByDescending(x => x.Count()).
|
2021-12-13 00:33:14 +13:00
|
|
|
|
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
2021-07-25 15:22:06 +12:00
|
|
|
|
|
2021-12-13 00:33:14 +13:00
|
|
|
|
sb.Append(string.Join(Environment.NewLine, processNames));
|
2021-07-25 15:22:06 +12:00
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
#region Form events
|
|
|
|
|
|
2022-01-01 11:36:47 +13:00
|
|
|
|
private async void HistoryForm_Shown(object sender, EventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-03-10 05:37:54 +13:00
|
|
|
|
this.ForceActivate();
|
2022-01-01 11:36:47 +13:00
|
|
|
|
|
|
|
|
|
await RefreshHistoryItems();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 22:03:19 +13:00
|
|
|
|
private void HistoryForm_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-03 03:21:09 +12:00
|
|
|
|
private void HistoryForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Settings.RememberWindowState)
|
|
|
|
|
{
|
|
|
|
|
Settings.WindowState.UpdateFormState(this);
|
2021-08-03 06:33:06 +12:00
|
|
|
|
Settings.SplitterDistance = scMain.SplitterDistance;
|
2021-08-03 03:21:09 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 11:36:47 +13:00
|
|
|
|
private async void HistoryForm_KeyDown(object sender, KeyEventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
switch (e.KeyData)
|
|
|
|
|
{
|
|
|
|
|
case Keys.F5:
|
|
|
|
|
e.Handled = true;
|
2022-01-01 11:36:47 +13:00
|
|
|
|
await RefreshHistoryItems();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
2021-08-23 11:09:34 +12:00
|
|
|
|
case Keys.Control | Keys.F5 when HelpersOptions.DevMode:
|
2021-07-26 11:39:35 +12:00
|
|
|
|
e.Handled = true;
|
2022-01-01 11:36:47 +13:00
|
|
|
|
await RefreshHistoryItems(true);
|
2021-07-26 11:39:35 +12:00
|
|
|
|
break;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 10:28:06 +13:00
|
|
|
|
private void tstbSearch_TextChanged(object sender, EventArgs e)
|
2021-07-25 14:00:36 +12:00
|
|
|
|
{
|
2022-01-01 10:28:06 +13:00
|
|
|
|
ApplyFilterSimple();
|
2021-07-25 14:00:36 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsbSearch_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ApplyFilterSimple();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 12:00:12 +12:00
|
|
|
|
private void tsbAdvancedSearch_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-08-09 15:05:22 +12:00
|
|
|
|
bool isPanelVisible = gbAdvancedSearch.Visible;
|
|
|
|
|
gbAdvancedSearch.Visible = !isPanelVisible;
|
|
|
|
|
tsbAdvancedSearch.Checked = !isPanelVisible;
|
2021-07-26 12:00:12 +12:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 05:23:34 +12:00
|
|
|
|
private void tsbToggleMoreInfo_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-08-09 15:05:22 +12:00
|
|
|
|
bool isPanelVisible = !scHistoryItemInfo.Panel2Collapsed;
|
|
|
|
|
scHistoryItemInfo.Panel2Collapsed = isPanelVisible;
|
|
|
|
|
tsbToggleMoreInfo.Checked = !isPanelVisible;
|
2021-08-08 05:23:34 +12:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 06:02:44 +13:00
|
|
|
|
private void tsbShowStats_Click(object sender, EventArgs e)
|
2021-07-26 12:00:12 +12:00
|
|
|
|
{
|
|
|
|
|
string stats = OutputStats(allHistoryItems);
|
2021-12-15 04:51:54 +13:00
|
|
|
|
OutputBox.Show(stats, Resources.HistoryStats);
|
2021-07-26 12:00:12 +12:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 16:17:10 +12:00
|
|
|
|
private void tsbSettings_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (HistorySettingsForm form = new HistorySettingsForm(Settings))
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 12:48:41 +13:00
|
|
|
|
private void AdvancedFilter_ValueChanged(object sender, EventArgs e)
|
2021-05-26 14:05:11 +12:00
|
|
|
|
{
|
2021-07-25 14:55:01 +12:00
|
|
|
|
ApplyFilterAdvanced();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-25 17:46:33 +12:00
|
|
|
|
private void btnAdvancedSearchReset_Click(object sender, EventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2021-07-26 12:18:50 +12:00
|
|
|
|
ResetFilters();
|
|
|
|
|
ApplyFilterAdvanced();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 13:05:51 +13:00
|
|
|
|
private void btnAdvancedSearchClose_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
gbAdvancedSearch.Visible = false;
|
|
|
|
|
tsbAdvancedSearch.Checked = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-01 10:18:40 +13:00
|
|
|
|
private void lvHistory_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
|
|
|
|
|
{
|
2022-01-03 16:40:20 +13:00
|
|
|
|
if (listViewCache != null && e.ItemIndex >= listViewCacheStartIndex && e.ItemIndex < listViewCacheStartIndex + listViewCache.Length)
|
2022-01-01 10:18:40 +13:00
|
|
|
|
{
|
2022-01-03 16:40:20 +13:00
|
|
|
|
e.Item = listViewCache[e.ItemIndex - listViewCacheStartIndex];
|
2022-01-01 10:18:40 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Item = CreateListViewItem(e.ItemIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lvHistory_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
|
|
|
|
|
{
|
2022-01-03 16:40:20 +13:00
|
|
|
|
if (listViewCache != null && e.StartIndex >= listViewCacheStartIndex && e.EndIndex <= listViewCacheStartIndex + listViewCache.Length)
|
2022-01-01 10:18:40 +13:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 16:40:20 +13:00
|
|
|
|
listViewCacheStartIndex = e.StartIndex;
|
2022-01-01 10:18:40 +13:00
|
|
|
|
int length = e.EndIndex - e.StartIndex + 1;
|
|
|
|
|
listViewCache = new ListViewItem[length];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
listViewCache[i] = CreateListViewItem(e.StartIndex + i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
private void lvHistory_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
|
|
|
|
{
|
2020-01-04 02:15:50 +13:00
|
|
|
|
UpdateControls();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lvHistory_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (him != null && e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
him.TryOpen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lvHistory_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
2021-08-11 14:34:45 +12:00
|
|
|
|
e.Handled = e.SuppressKeyPress = him.HandleKeyInput(e);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 11:46:23 +13:00
|
|
|
|
private void lvHistory_ItemDrag(object sender, ItemDragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
List<string> selection = new List<string>();
|
|
|
|
|
|
2022-01-01 10:18:40 +13:00
|
|
|
|
foreach (int index in lvHistory.SelectedIndices)
|
2017-10-21 11:46:23 +13:00
|
|
|
|
{
|
2022-01-01 10:18:40 +13:00
|
|
|
|
HistoryItem hi = filteredHistoryItems[index];
|
|
|
|
|
|
2019-10-22 00:20:21 +13:00
|
|
|
|
if (File.Exists(hi.FilePath))
|
2017-10-24 08:04:19 +13:00
|
|
|
|
{
|
2019-10-22 00:20:21 +13:00
|
|
|
|
selection.Add(hi.FilePath);
|
2017-10-24 08:04:19 +13:00
|
|
|
|
}
|
2017-10-21 11:46:23 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 08:04:19 +13:00
|
|
|
|
if (selection.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
DataObject data = new DataObject(DataFormats.FileDrop, selection.ToArray());
|
|
|
|
|
DoDragDrop(data, DragDropEffects.Copy);
|
|
|
|
|
}
|
2017-10-21 11:46:23 +13:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 09:53:19 +13:00
|
|
|
|
private void pbThumbnail_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
pbThumbnail.Enabled = false;
|
|
|
|
|
|
|
|
|
|
int currentImageIndex = lvHistory.SelectedIndex;
|
|
|
|
|
int modifiedImageIndex = 0;
|
|
|
|
|
int halfRange = 100;
|
|
|
|
|
int startIndex = Math.Max(currentImageIndex - halfRange, 0);
|
|
|
|
|
int endIndex = Math.Min(startIndex + (halfRange * 2) + 1, filteredHistoryItems.Length);
|
|
|
|
|
|
|
|
|
|
List<string> filteredImages = new List<string>();
|
|
|
|
|
|
|
|
|
|
for (int i = startIndex; i < endIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
string imageFilePath = filteredHistoryItems[i].FilePath;
|
|
|
|
|
|
|
|
|
|
if (i == currentImageIndex)
|
|
|
|
|
{
|
|
|
|
|
modifiedImageIndex = filteredImages.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filteredImages.Add(imageFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageViewer.ShowImage(filteredImages.ToArray(), modifiedImageIndex);
|
|
|
|
|
|
|
|
|
|
pbThumbnail.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
#endregion Form events
|
|
|
|
|
}
|
|
|
|
|
}
|