Added "Show stats" button to history form

This commit is contained in:
Jaex 2019-06-17 04:14:04 +03:00
parent f937a5d093
commit 1f9bcaf902
5 changed files with 197 additions and 19 deletions

View file

@ -694,5 +694,20 @@ public static void DoubleBuffered(this DataGridView dgv, bool value)
PropertyInfo pi = dgv.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, value, null);
}
public static void AppendLine(this RichTextBox rtb, string value = "")
{
rtb.AppendText(value + Environment.NewLine);
}
public static void SetFontRegular(this RichTextBox rtb)
{
rtb.SelectionFont = new Font(rtb.Font, FontStyle.Regular);
}
public static void SetFontBold(this RichTextBox rtb)
{
rtb.SelectionFont = new Font(rtb.Font, FontStyle.Bold);
}
}
}

View file

@ -31,12 +31,14 @@ private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HistoryForm));
this.scMain = new ShareX.HelpersLib.SplitContainerCustomSplitter();
this.rtbStats = new System.Windows.Forms.RichTextBox();
this.lvHistory = new ShareX.HelpersLib.MyListView();
this.chIcon = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chDateTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chFilename = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chURL = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.panel1 = new System.Windows.Forms.Panel();
this.btnShowStats = new System.Windows.Forms.Button();
this.pbThumbnail = new ShareX.HelpersLib.MyPictureBox();
this.gbFilters = new System.Windows.Forms.GroupBox();
this.lblURLFilter = new System.Windows.Forms.Label();
@ -70,13 +72,22 @@ private void InitializeComponent()
//
// scMain.Panel1
//
this.scMain.Panel1.Controls.Add(this.rtbStats);
this.scMain.Panel1.Controls.Add(this.lvHistory);
//
// scMain.Panel2
//
this.scMain.Panel2.Controls.Add(this.panel1);
this.scMain.SplitterColor = System.Drawing.Color.White;
this.scMain.SplitterLineColor = System.Drawing.Color.FromArgb(((int)(((byte)(189)))), ((int)(((byte)(189)))), ((int)(((byte)(189)))));
this.scMain.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.scMain_SplitterMoved);
//
// rtbStats
//
this.rtbStats.BorderStyle = System.Windows.Forms.BorderStyle.None;
resources.ApplyResources(this.rtbStats, "rtbStats");
this.rtbStats.Name = "rtbStats";
//
// lvHistory
//
this.lvHistory.AllowColumnSort = true;
@ -117,11 +128,19 @@ private void InitializeComponent()
//
// panel1
//
this.panel1.Controls.Add(this.btnShowStats);
this.panel1.Controls.Add(this.pbThumbnail);
this.panel1.Controls.Add(this.gbFilters);
resources.ApplyResources(this.panel1, "panel1");
this.panel1.Name = "panel1";
//
// btnShowStats
//
resources.ApplyResources(this.btnShowStats, "btnShowStats");
this.btnShowStats.Name = "btnShowStats";
this.btnShowStats.UseVisualStyleBackColor = true;
this.btnShowStats.Click += new System.EventHandler(this.BtnShowStats_Click);
//
// pbThumbnail
//
resources.ApplyResources(this.pbThumbnail, "pbThumbnail");
@ -130,6 +149,7 @@ private void InitializeComponent()
this.pbThumbnail.DrawCheckeredBackground = true;
this.pbThumbnail.FullscreenOnClick = true;
this.pbThumbnail.Name = "pbThumbnail";
this.pbThumbnail.PictureBoxBackColor = System.Drawing.SystemColors.Control;
this.pbThumbnail.ShowImageSizeLabel = true;
//
// gbFilters
@ -286,5 +306,7 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblFilenameFilter;
private System.Windows.Forms.Label lblURLFilter;
private System.Windows.Forms.TextBox txtURLFilter;
private System.Windows.Forms.Button btnShowStats;
private System.Windows.Forms.RichTextBox rtbStats;
}
}

View file

@ -44,6 +44,7 @@ public partial class HistoryForm : Form
private HistoryItemManager him;
private HistoryItem[] allHistoryItems;
private string defaultTitle;
private bool showingStats;
public HistoryForm(string historyPath, HistorySettings settings, Action<string> uploadFile = null, Action<string> editImage = null)
{
@ -53,7 +54,7 @@ public HistoryForm(string historyPath, HistorySettings settings, Action<string>
InitializeComponent();
Icon = ShareXResources.Icon;
defaultTitle = Text;
UpdateTitle();
//UpdateTitle();
// Mark the Date column as having a date; used for sorting
chDateTime.Tag = new DateTime();
@ -86,6 +87,63 @@ private void RefreshHistoryItems()
ApplyFiltersAndAdd();
}
private void OutputStats(HistoryItem[] historyItems)
{
rtbStats.ResetText();
rtbStats.SetFontBold();
rtbStats.AppendLine("History item counts:");
rtbStats.SetFontRegular();
rtbStats.AppendLine("Total: " + historyItems.Length);
IEnumerable<string> types = historyItems.
Select(x => x.Type).
GroupBy(x => x).
OrderByDescending(x => x.Count()).
Select(x => string.Format("{0}: {1}", x.Key, x.Count()));
rtbStats.AppendLine(string.Join(Environment.NewLine, types));
rtbStats.AppendLine();
rtbStats.SetFontBold();
rtbStats.AppendLine("Yearly usages:");
rtbStats.SetFontRegular();
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));
rtbStats.AppendLine(string.Join(Environment.NewLine, yearlyUsages));
rtbStats.AppendLine();
rtbStats.SetFontBold();
rtbStats.AppendLine("File extensions:");
rtbStats.SetFontRegular();
IEnumerable<string> fileExtensions = historyItems.
Where(x => !string.IsNullOrEmpty(x.Filename) && !x.Filename.EndsWith(")")).
Select(x => Helpers.GetFilenameExtension(x.Filename)).
GroupBy(x => x).
OrderByDescending(x => x.Count()).
Select(x => string.Format("{0} ({1})", x.Key, x.Count()));
rtbStats.AppendLine(string.Join(Environment.NewLine, fileExtensions));
rtbStats.AppendLine();
rtbStats.SetFontBold();
rtbStats.AppendLine("Hosts:");
rtbStats.SetFontRegular();
IEnumerable<string> hosts = historyItems.
Select(x => x.Host).
GroupBy(x => x).
OrderByDescending(x => x.Count()).
Select(x => string.Format("{0} ({1})", x.Key, x.Count()));
rtbStats.AppendLine(string.Join(Environment.NewLine, hosts));
}
private HistoryItem[] him_GetHistoryItems()
{
return lvHistory.SelectedItems.Cast<ListViewItem>().Select(x => x.Tag as HistoryItem).ToArray();
@ -177,7 +235,7 @@ private void AddHistoryItems(HistoryItem[] historyItems)
{
Cursor = Cursors.WaitCursor;
UpdateTitle(historyItems);
//UpdateTitle(historyItems);
lvHistory.Items.Clear();
@ -340,6 +398,29 @@ private void btnRemoveFilters_Click(object sender, EventArgs e)
AddHistoryItems(allHistoryItems);
}
private void BtnShowStats_Click(object sender, EventArgs e)
{
if (showingStats)
{
lvHistory.Visible = true;
rtbStats.Visible = false;
// TODO: Translate
btnShowStats.Text = "Show stats";
showingStats = false;
}
else
{
rtbStats.Visible = true;
lvHistory.Visible = false;
// TODO: Translate
btnShowStats.Text = "Hide stats";
Cursor = Cursors.WaitCursor;
OutputStats(allHistoryItems);
Cursor = Cursors.Default;
showingStats = true;
}
}
private void lvHistory_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (e.IsSelected)

View file

@ -125,10 +125,43 @@
<data name="scMain.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
<data name="rtbStats.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="rtbStats.Font" type="System.Drawing.Font, System.Drawing">
<value>Arial, 9.75pt</value>
</data>
<data name="rtbStats.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
<data name="rtbStats.Size" type="System.Drawing.Size, System.Drawing">
<value>550, 641</value>
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="rtbStats.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="rtbStats.Text" xml:space="preserve">
<value />
</data>
<data name="rtbStats.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;rtbStats.Name" xml:space="preserve">
<value>rtbStats</value>
</data>
<data name="&gt;&gt;rtbStats.Type" xml:space="preserve">
<value>System.Windows.Forms.RichTextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;rtbStats.Parent" xml:space="preserve">
<value>scMain.Panel1</value>
</data>
<data name="&gt;&gt;rtbStats.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="chIcon.Text" xml:space="preserve">
<value />
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="chIcon.Width" type="System.Int32, mscorlib">
<value>24</value>
</data>
@ -166,13 +199,13 @@
<value>lvHistory</value>
</data>
<data name="&gt;&gt;lvHistory.Type" xml:space="preserve">
<value>ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=12.3.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;lvHistory.Parent" xml:space="preserve">
<value>scMain.Panel1</value>
</data>
<data name="&gt;&gt;lvHistory.ZOrder" xml:space="preserve">
<value>0</value>
<value>1</value>
</data>
<data name="&gt;&gt;scMain.Panel1.Name" xml:space="preserve">
<value>scMain.Panel1</value>
@ -189,6 +222,33 @@
<data name="scMain.Panel1MinSize" type="System.Int32, mscorlib">
<value>100</value>
</data>
<data name="btnShowStats.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="btnShowStats.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 608</value>
</data>
<data name="btnShowStats.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 24</value>
</data>
<data name="btnShowStats.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="btnShowStats.Text" xml:space="preserve">
<value>Show stats</value>
</data>
<data name="&gt;&gt;btnShowStats.Name" xml:space="preserve">
<value>btnShowStats</value>
</data>
<data name="&gt;&gt;btnShowStats.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnShowStats.Parent" xml:space="preserve">
<value>panel1</value>
</data>
<data name="&gt;&gt;btnShowStats.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="pbThumbnail.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value>
</data>
@ -196,7 +256,7 @@
<value>8, 8</value>
</data>
<data name="pbThumbnail.Size" type="System.Drawing.Size, System.Drawing">
<value>408, 384</value>
<value>408, 352</value>
</data>
<data name="pbThumbnail.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
@ -205,13 +265,13 @@
<value>pbThumbnail</value>
</data>
<data name="&gt;&gt;pbThumbnail.Type" xml:space="preserve">
<value>ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=12.3.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;pbThumbnail.Parent" xml:space="preserve">
<value>panel1</value>
</data>
<data name="&gt;&gt;pbThumbnail.ZOrder" xml:space="preserve">
<value>0</value>
<value>1</value>
</data>
<data name="gbFilters.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left, Right</value>
@ -601,7 +661,7 @@
<value>14</value>
</data>
<data name="gbFilters.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 400</value>
<value>8, 368</value>
</data>
<data name="gbFilters.Size" type="System.Drawing.Size, System.Drawing">
<value>408, 234</value>
@ -622,7 +682,7 @@
<value>panel1</value>
</data>
<data name="&gt;&gt;gbFilters.ZOrder" xml:space="preserve">
<value>1</value>
<value>2</value>
</data>
<data name="panel1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
@ -679,7 +739,7 @@
<value>scMain</value>
</data>
<data name="&gt;&gt;scMain.Type" xml:space="preserve">
<value>ShareX.HelpersLib.SplitContainerCustomSplitter, ShareX.HelpersLib, Version=12.3.0.0, Culture=neutral, PublicKeyToken=null</value>
<value>ShareX.HelpersLib.SplitContainerCustomSplitter, ShareX.HelpersLib, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;scMain.Parent" xml:space="preserve">
<value>$this</value>

View file

@ -768,32 +768,32 @@ private void UpdateResponseInfoTextBox(ResponseInfo responseInfo, bool includeRe
{
rtbResponseInfo.ResetText();
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Bold);
rtbResponseInfo.SetFontBold();
rtbResponseInfo.AppendText("Status code:\r\n");
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Regular);
rtbResponseInfo.SetFontRegular();
rtbResponseInfo.AppendText($"({(int)responseInfo.StatusCode}) {responseInfo.StatusDescription}");
if (!string.IsNullOrEmpty(responseInfo.ResponseURL))
{
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Bold);
rtbResponseInfo.SetFontBold();
rtbResponseInfo.AppendText("\r\n\r\nResponse URL:\r\n");
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Regular);
rtbResponseInfo.SetFontRegular();
rtbResponseInfo.AppendText(responseInfo.ResponseURL);
}
if (responseInfo.Headers != null && responseInfo.Headers.Count > 0)
{
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Bold);
rtbResponseInfo.SetFontBold();
rtbResponseInfo.AppendText("\r\n\r\nHeaders:\r\n");
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Regular);
rtbResponseInfo.SetFontRegular();
rtbResponseInfo.AppendText(responseInfo.Headers.ToString().TrimEnd('\r', '\n'));
}
if (includeResponseText && !string.IsNullOrEmpty(responseInfo.ResponseText))
{
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Bold);
rtbResponseInfo.SetFontBold();
rtbResponseInfo.AppendText("\r\n\r\nResponse text:\r\n");
rtbResponseInfo.SelectionFont = new Font(rtbResponseInfo.Font, FontStyle.Regular);
rtbResponseInfo.SetFontRegular();
rtbResponseInfo.AppendText(responseInfo.ResponseText);
}
}