Skip to content

Commit

Permalink
Added grid view tab to history tab
Browse files Browse the repository at this point in the history
Added grid view tab which shows a tabulated ("spreadsheet") form of the history data which allows for more elaborate selection and copy actions on the data. From this view, the existing functionality for removing from imgur, removing from history, or opening links in a browser are still supported.
  • Loading branch information
bkeiren committed Dec 4, 2022
1 parent a3f913c commit 2065770
Show file tree
Hide file tree
Showing 14 changed files with 2,353 additions and 1,682 deletions.
7 changes: 7 additions & 0 deletions EasyImgur/EasyImgur.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="Resources\SelectRows.png" />
<None Include="Resources\SelectColumns.png" />
<None Include="Resources\SelectAll.png" />
<None Include="Resources\OpenLink.png" />
<None Include="Resources\RemoveFromCollection.png" />
<None Include="Resources\Delete.png" />
<None Include="Resources\Copy.png" />
<EmbeddedResource Include="Newtonsoft.Json.dll" />
<None Include="ei_logo.png" />
<Content Include="icon.ico" />
Expand Down
3,759 changes: 2,087 additions & 1,672 deletions EasyImgur/Form1.Designer.cs

Large diffs are not rendered by default.

148 changes: 144 additions & 4 deletions EasyImgur/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,55 @@ private string GetDescriptionString(FormattingHelper.FormattingContext _Formatti
return FormatInfoString(textBoxDescriptionFormat.Text, _FormattingContext);
}

private void buttonRemoveFromImgur_Click(object sender, EventArgs e)
private SortedSet<int> getSelectedRowIndicesFromHistoryGridView()
{
SortedSet<int> unique_row_indices = new SortedSet<int>();

// Generate a sorted set of unique row indices. This accomplishes multiple goals:
// - We want the set to be sorted
// - We want to only output a given row index once, even if multiple cells are selected for a given row/column (DataGridView.SelectedRows and DataGridView.SelectedColumns are empty unless an entire row/column is selected)
foreach (DataGridViewCell cell in dataGridViewHistory.SelectedCells)
unique_row_indices.Add(cell.RowIndex);

return unique_row_indices;
}
private SortedSet<int> getSelectedColumnIndicesFromHistoryGridView()
{
int count = listBoxHistory.SelectedItems.Count;
SortedSet<int> unique_col_indices = new SortedSet<int>();

// Generate a sorted set of unique column indices. This accomplishes multiple goals:
// - We want the set to be sorted
// - We want to only output a given column index once, even if multiple cells are selected for a given row/column (DataGridView.SelectedRows and DataGridView.SelectedColumns are empty unless an entire row/column is selected)
foreach (DataGridViewCell cell in dataGridViewHistory.SelectedCells)
unique_col_indices.Add(cell.ColumnIndex);

return unique_col_indices;
}


// Get a list of HistoryItems that are currently considered to be selected in the history gridview
// This method works even if only partial rows are selected. The returned list is always sorted
// based on the row index of each item in the history grid, and contains no null entries.
private List<HistoryItem> getSelectedHistoryItemsFromHistoryGridView()
{
List<HistoryItem> selected_items = new List<HistoryItem>();
foreach (int row_index in getSelectedRowIndicesFromHistoryGridView())
if (dataGridViewHistory.Rows[row_index].DataBoundItem is HistoryItem item)
selected_items.Add(item);

return selected_items;
}

private void removeItemsFromImgur(List<HistoryItem> itemsToRemove)
{
int count = itemsToRemove.Count;
bool isMultipleImages = count > 1;
int currentCount = 0;

listBoxHistory.BeginUpdate();
List<HistoryItem> selectedItems = new List<HistoryItem>(listBoxHistory.SelectedItems.Cast<HistoryItem>());
foreach(HistoryItem item in selectedItems)
dataGridViewHistory.Enabled = false;

foreach(HistoryItem item in itemsToRemove)
{
++currentCount;

Expand All @@ -783,11 +823,19 @@ private void buttonRemoveFromImgur_Click(object sender, EventArgs e)
else
ShowBalloonTip(2000, "Failed", "Failed to remove " + (item.Album ? "album" : "image") + " " + balloon_image_counter_text + " from Imgur", ToolTipIcon.Error);
}

dataGridViewHistory.Enabled = true;
listBoxHistory.EndUpdate();

Statistics.GatherAndSend();
}

private void buttonRemoveFromImgur_Click(object sender, EventArgs e)
{
List<HistoryItem> selectedItems = new List<HistoryItem>(listBoxHistory.SelectedItems.Cast<HistoryItem>());
removeItemsFromImgur(selectedItems);
}

private void buttonForceTokenRefresh_Click(object sender, EventArgs e)
{
ImgurAPI.ForceRefreshTokens();
Expand Down Expand Up @@ -916,5 +964,97 @@ private void buttonViewLog_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(Log.LogFile);
}

private void dataGridViewHistory_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
// If a link cell or the thumbnail cell double-clicked, open the link in a browser window
if (e.ColumnIndex == linkDataGridViewTextBoxColumn.Index ||
e.ColumnIndex == thumbnailDataGridViewImageColumn.Index)
{
if (dataGridViewHistory.Rows[e.RowIndex].DataBoundItem is HistoryItem item)
System.Diagnostics.Process.Start(item.Link);
}
}

private void toolStripButtonHistoryGridCopy_Click(object sender, EventArgs e)
{
// Copy the contents of all selected cells
Clipboard.SetDataObject(dataGridViewHistory.GetClipboardContent());
}

private void toolStripButtonHistoryGridOpenLink_Click(object sender, EventArgs e)
{
foreach (HistoryItem item in getSelectedHistoryItemsFromHistoryGridView())
System.Diagnostics.Process.Start(item.Link);
}

private void toolStripButtonHistoryGridSelectAll_Click(object sender, EventArgs e)
{
dataGridViewHistory.SelectAll();
}

private void toolStripButtonHistoryGridSelectColumn_Click(object sender, EventArgs e)
{
// Cache the selected rows before changing the selection mode, because that action will reset the selection.
SortedSet<int> selected_cols = getSelectedColumnIndicesFromHistoryGridView();

dataGridViewHistory.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;

foreach (int col_index in selected_cols)
dataGridViewHistory.Columns[col_index].Selected = true;
}

private void toolStripButtonHistoryGridSelectRow_Click(object sender, EventArgs e)
{
// Cache the selected rows before changing the selection mode, because that action will reset the selection.
SortedSet<int> selected_rows = getSelectedRowIndicesFromHistoryGridView();

dataGridViewHistory.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;

foreach (int row_index in selected_rows)
dataGridViewHistory.Rows[row_index].Selected = true;
}

private void dataGridViewHistory_MouseDown(object sender, MouseEventArgs e)
{
// In this callback we have to manually simulate the behavior that selecting a header cell will select
// an entire column, because the DataGridView class only allows *either* the selection mode of RowHeaderSelect
// or the selection mode of ColumnHeaderSelect. Both modes at the same time is not supported, but we
// can fake it here by manually hit testing for row/column index -1 (i.e. the header row/column)
// and then changing the selection mode accordingly.
// This approach was copied from https://social.msdn.microsoft.com/Forums/windows/en-US/570a032e-75d6-4f36-8cf0-9553dc1f46d2/datagridview-with-columnheaderselect-and-rowheaderselect

System.Windows.Forms.DataGridView.HitTestInfo hti = dataGridViewHistory.HitTest(e.X, e.Y);

if (hti.ColumnIndex == -1 && hti.RowIndex >= 0)
{
// row header click
if (dataGridViewHistory.SelectionMode != DataGridViewSelectionMode.RowHeaderSelect)
dataGridViewHistory.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
}
else if (hti.RowIndex == -1 && hti.ColumnIndex >= 0)
{
// column header click
if (dataGridViewHistory.SelectionMode != DataGridViewSelectionMode.ColumnHeaderSelect)
dataGridViewHistory.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
}
}

private void clearFromHistoryToolStripMenuItem_Click(object sender, EventArgs e)
{
// Disable updates while we're modifying the data source
dataGridViewHistory.Enabled = false;

List<HistoryItem> selectedItems = getSelectedHistoryItemsFromHistoryGridView();
foreach(HistoryItem item in selectedItems)
History.RemoveHistoryItem(item);

dataGridViewHistory.Enabled = true;
}

private void deleteFromImgurToolStripMenuItem_Click(object sender, EventArgs e)
{
removeItemsFromImgur(getSelectedHistoryItemsFromHistoryGridView());
}
}
}
18 changes: 18 additions & 0 deletions EasyImgur/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5226,6 +5226,24 @@ To revoke authorization of any tokens this application has, visit:</value>
<metadata name="historyItemBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>368, 17</value>
</metadata>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>560, 17</value>
</metadata>
<data name="toolStripDropDownButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="trayMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>264, 17</value>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions EasyImgur/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1")]
[assembly: AssemblyFileVersion("0.4.1")]
[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]

72 changes: 71 additions & 1 deletion EasyImgur/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions EasyImgur/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,34 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Copy" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Copy.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ei_logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\ei_logo.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="OpenLink" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\OpenLink.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="RemoveFromCollection" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\RemoveFromCollection.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SelectAll" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SelectAll.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SelectColumns" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SelectColumns.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SelectRows" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SelectRows.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added EasyImgur/Resources/Copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyImgur/Resources/Delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyImgur/Resources/OpenLink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyImgur/Resources/RemoveFromCollection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyImgur/Resources/SelectAll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyImgur/Resources/SelectColumns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyImgur/Resources/SelectRows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2065770

Please sign in to comment.