Skip to content

Commit

Permalink
Update screenshot, bug fixes, quick filter context menu for negative …
Browse files Browse the repository at this point in the history
…search
  • Loading branch information
thgossler committed Nov 24, 2024
1 parent bae28ec commit 8d79fdf
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 23 deletions.
6 changes: 3 additions & 3 deletions AzTagger/AzTagger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows7.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<Version>1.0.7.0</Version>
<Version>1.0.8.0</Version>
<Authors>Thomas Gossler</Authors>
<Description>
A Windows Desktop GUI application for fast and flexible querying of Azure resources
Expand All @@ -18,8 +18,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<ApplicationIcon>images\icon.ico</ApplicationIcon>
<AssemblyVersion>1.0.7.0</AssemblyVersion>
<FileVersion>1.0.7.0</FileVersion>
<AssemblyVersion>1.0.8.0</AssemblyVersion>
<FileVersion>1.0.8.0</FileVersion>
</PropertyGroup>


Expand Down
26 changes: 21 additions & 5 deletions AzTagger/MainForm.Designer.cs

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

105 changes: 90 additions & 15 deletions AzTagger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Serilog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
Expand All @@ -33,7 +34,7 @@ public partial class MainForm : Form
private AzureService _azureService;

private List<Resource> _resources;
private ContextMenuStrip _contextMenu;
private ContextMenuStrip _resultsDataGridViewContextMenu;
private DataGridViewCell _contextMenuClickedCell;
private string _fullQuery = string.Empty;
private CancellationTokenSource _queryCancellationTokenSource;
Expand All @@ -49,6 +50,10 @@ public partial class MainForm : Form
private Timer _tooltipTimer;
private DataGridViewCellEventArgs _currentCellEventArgs;

private ContextMenuStrip _quickFilterContextMenu;
private ToolStripMenuItem _quickFilterExcludeCurrentTextMenuItem;
private ToolStripMenuItem _quickFilterExcludeTextRegExMenuItem;

private List<TagTemplate> _tagTemplates;
private List<string> _tagsToRemove = new List<string>();

Expand Down Expand Up @@ -157,7 +162,8 @@ public MainForm(Settings settings)
_lblQueryMode.Text = string.Empty;
InitializeResultsDataGridView();
InitializeTagsDataGridView();
InitializeContextMenu();
InitializeResultsDataGridViewContextMenu();
InitializeQuickFilterTextBoxContextMenus();
InitializeResizeTimer();
InitializeQuickFilterComboBoxes();
InitializeDebounceTimers();
Expand All @@ -171,35 +177,53 @@ public MainForm(Settings settings)
_tooltipTimer.Tick += ToolTipTimer_Tick;
}

private void InitializeContextMenu()
private void InitializeResultsDataGridViewContextMenu()
{
_contextMenu = new ContextMenuStrip();
_resultsDataGridViewContextMenu = new ContextMenuStrip();

var openInAzurePortalMenuItem = new ToolStripMenuItem("Open in Azure Portal");
openInAzurePortalMenuItem.Click += MenuItem_OpenInAzurePortal_Click;
_contextMenu.Items.Add(openInAzurePortalMenuItem);
_resultsDataGridViewContextMenu.Items.Add(openInAzurePortalMenuItem);

var openUrlsInTagValuesMenuItem = new ToolStripMenuItem("Open URLs in tags");
openUrlsInTagValuesMenuItem.Click += MenuItem_OpenUrlsInTagValues_Click;
_contextMenu.Items.Add(openUrlsInTagValuesMenuItem);
_resultsDataGridViewContextMenu.Items.Add(openUrlsInTagValuesMenuItem);

var copyCellValueMenuItem = new ToolStripMenuItem("Copy cell value");
copyCellValueMenuItem.Click += MenuItem_CopyCellValue_Click;
_contextMenu.Items.Add(copyCellValueMenuItem);
_resultsDataGridViewContextMenu.Items.Add(copyCellValueMenuItem);

var addToFilterQueryMenuItem = new ToolStripMenuItem("Add to filter query");
addToFilterQueryMenuItem.Name = "AddToFilterQueryMenuItem";
addToFilterQueryMenuItem.Click += MenuItem_AddToFilterQuery_Click;
_contextMenu.Items.Add(addToFilterQueryMenuItem);
_resultsDataGridViewContextMenu.Items.Add(addToFilterQueryMenuItem);

var excludeInFilterQueryMenuItem = new ToolStripMenuItem("Exclude in filter query");
excludeInFilterQueryMenuItem.Name = "ExcludeInFilterQueryMenuItem";
excludeInFilterQueryMenuItem.Click += MenuItem_AddToFilterQuery_Click;
_contextMenu.Items.Add(excludeInFilterQueryMenuItem);
_resultsDataGridViewContextMenu.Items.Add(excludeInFilterQueryMenuItem);

var refreshTagsMenuItem = new ToolStripMenuItem("Refresh tags from Azure");
refreshTagsMenuItem.Click += MenuItem_RefreshTags_Click;
_contextMenu.Items.Add(refreshTagsMenuItem);
_resultsDataGridViewContextMenu.Items.Add(refreshTagsMenuItem);
}

private void InitializeQuickFilterTextBoxContextMenus()
{
_quickFilterContextMenu = new ContextMenuStrip();

_quickFilterExcludeTextRegExMenuItem = new ToolStripMenuItem("Replace with RegEx to exclude text");
_quickFilterExcludeTextRegExMenuItem.Click += MenuItem_QuickFilterExcludeTextRegEx_Click;
_quickFilterContextMenu.Items.Add(_quickFilterExcludeTextRegExMenuItem);

_quickFilterExcludeCurrentTextMenuItem = new ToolStripMenuItem("Convert to RegEx excluding the current search text");
_quickFilterExcludeCurrentTextMenuItem.Click += MenuItem_QuickFilterExcludeCurrentText_Click;
_quickFilterContextMenu.Items.Add(_quickFilterExcludeCurrentTextMenuItem);

_quickFilterContextMenu.Opening += ContextMenu_QuickFilter_Opening;

_txtQuickFilter1Text.ContextMenuStrip = _quickFilterContextMenu;
_txtQuickFilter2Text.ContextMenuStrip = _quickFilterContextMenu;
}

private void InitializeResultsDataGridView()
Expand Down Expand Up @@ -590,6 +614,47 @@ private async void MenuItem_RefreshTags_Click(object sender, EventArgs e)
}
}

private void ContextMenu_QuickFilter_Opening(object sender, CancelEventArgs e)
{
if (sender is ContextMenuStrip cms && cms.SourceControl is TextBox tb)
{
string text = tb.Text;

char[] forbiddenChars = ['!', '?', '.', ':', '+', '*', '(', ')', '[', ']', '{', '}', '\\', '^', '<', '>'];
_quickFilterExcludeCurrentTextMenuItem.Enabled = !text.Any(c => forbiddenChars.Contains(c)) && text.Trim().Length > 0;

_quickFilterExcludeTextRegExMenuItem.Enabled = text.Trim().Length == 0;
}
}

private void MenuItem_QuickFilterExcludeCurrentText_Click(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem)
{
var cms = ((ToolStripMenuItem)sender).Owner as ContextMenuStrip;
if (cms?.SourceControl is TextBox tb)
{
string searchText = tb.Text;
string newRegex = $"^(?!.*{searchText}).+$";
tb.Text = newRegex;
}
}
}

private void MenuItem_QuickFilterExcludeTextRegEx_Click(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem)
{
var cms = ((ToolStripMenuItem)sender).Owner as ContextMenuStrip;
if (cms?.SourceControl is TextBox tb)
{
string searchText = "TEXT";
string newRegex = $"^(?!.*{searchText}).+$";
tb.Text = newRegex;
}
}
}

private void DataGridView_Results_SelectionChanged(object sender, EventArgs e)
{
_gvwTags.Rows.Clear();
Expand Down Expand Up @@ -658,7 +723,7 @@ private void DataGridView_Results_CellMouseClick(object sender, DataGridViewCell
_gvwResults.ClearSelection();
_gvwResults.Rows[e.RowIndex].Selected = true;
_contextMenuClickedCell = _gvwResults.Rows[e.RowIndex].Cells[e.ColumnIndex];
_contextMenu.Show(Cursor.Position);
_resultsDataGridViewContextMenu.Show(Cursor.Position);
}
}

Expand Down Expand Up @@ -1237,9 +1302,9 @@ private void SaveRecentSearch(string queryText)
{
_cboRecentSearches.Items.Remove(item);
}
_cboRecentSearches.Items.Insert(0, new RecentSearchItem(queryText));
_cboRecentSearches.Items.Insert(1, new RecentSearchItem(queryText));

if (_cboRecentSearches.Items.Count > 10)
if (_cboRecentSearches.Items.Count > 11)
{
_cboRecentSearches.Items.RemoveAt(_cboRecentSearches.Items.Count - 1);
}
Expand Down Expand Up @@ -1284,13 +1349,18 @@ private List<Resource> ApplyQuickFilters(List<Resource> resources)
var isMatch = regex1.IsMatch(value);
return isMatch;
}).ToList();
errorProvider1.SetError(_txtQuickFilter1Text, string.Empty);
}
catch (Exception ex)
{
Log.Error(ex, "Invalid regex pattern in Quick Filter 1.");
MessageBox.Show(this, "Invalid regex pattern in Quick Filter 1.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
errorProvider1.SetError(_txtQuickFilter1Text, "Invalid regex pattern");
}
}
else
{
errorProvider1.SetError(_txtQuickFilter1Text, string.Empty);
}

if (_cboQuickFilter2Column.SelectedItem != null &&
_cboQuickFilter2Column.SelectedItem.ToString() != string.Empty &&
Expand All @@ -1308,13 +1378,18 @@ private List<Resource> ApplyQuickFilters(List<Resource> resources)
var value = GetPropertyValue(r, column2)?.ToString() ?? string.Empty;
return regex2.IsMatch(value);
}).ToList();
errorProvider2.SetError(_txtQuickFilter2Text, string.Empty);
}
catch (Exception ex)
{
Log.Error(ex, "Invalid regex pattern in Quick Filter 2.");
MessageBox.Show(this, "Invalid regex pattern in Quick Filter 2.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
errorProvider2.SetError(_txtQuickFilter2Text, "Invalid regex pattern");
}
}
else
{
errorProvider2.SetError(_txtQuickFilter2Text, string.Empty);
}

return filtered;
}
Expand Down
6 changes: 6 additions & 0 deletions AzTagger/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<metadata name="Value.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="errorProvider1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>131, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down Expand Up @@ -989,4 +992,7 @@
/////////////////////////////w==
</value>
</data>
<metadata name="errorProvider2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>286, 17</value>
</metadata>
</root>
Binary file modified AzTagger/images/screenshot.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 8d79fdf

Please sign in to comment.