Skip to content

Commit 90951db

Browse files
committed
Rework filter
A major clean up of all filter related functionality in RevisionGrid control. * Move all filter-related info into a dedicated filter class FilterInfo * Move all filter-related AppSettings from RevisionGrid into FilterInfo * Move calculations of RefFilterOptions from RevisionGrid into FilterInfo Clean up FilterToolbar to react to FilterChanged events, and update its state from the event payload. Relates to gitextensions#9553
1 parent 4a8ad8d commit 90951db

28 files changed

+1438
-661
lines changed

GitCommands/RevisionReader.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ private async Task ExecuteAsync(
127127

128128
using (var process = module.GitCommandRunner.RunDetached(arguments, redirectOutput: true, outputEncoding: GitModule.LosslessEncoding))
129129
{
130+
#if DEBUG
131+
Debug.WriteLine($"git {arguments}");
132+
#endif
130133
token.ThrowIfCancellationRequested();
131134

132135
var buffer = new byte[4096];

GitExtensionsTest.ruleset

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
<Rules AnalyzerId="Microsoft.VisualStudio.Threading.Analyzers" RuleNamespace="Microsoft.VisualStudio.Threading.Analyzers">
55
<Rule Id="VSTHRD200" Action="None" />
66
</Rules>
7+
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
8+
<Rule Id="SA1515" Action="Hidden" />
9+
</Rules>
710
</RuleSet>

GitUI/BranchTreePanel/RepoObjectsTree.ContextActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private ToolStripItem[] CreateCopyContextMenuItems()
339339

340340
private void FilterInRevisionGrid(BaseBranchNode branch)
341341
{
342-
_branchFilterAction(branch.FullPath, true);
342+
_branchFilterAction(branch.FullPath);
343343
}
344344

345345
private void contextMenu_Opening(object sender, CancelEventArgs e)

GitUI/BranchTreePanel/RepoObjectsTree.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public partial class RepoObjectsTree : GitModuleControl
3737
private TagTree _tagTree;
3838
private SubmoduleTree _submoduleTree;
3939
private List<TreeNode>? _searchResult;
40-
private Action<string?, bool> _branchFilterAction;
40+
private Action<string?> _branchFilterAction;
4141
private IAheadBehindDataProvider? _aheadBehindDataProvider;
4242
private bool _searchCriteriaChanged;
4343
private ICheckRefs _refsSource;
@@ -231,7 +231,7 @@ bool IsOverride(MethodInfo m)
231231
}
232232
}
233233

234-
public void Initialize(IAheadBehindDataProvider? aheadBehindDataProvider, Action<string?, bool> branchFilterAction, ICheckRefs refsSource, IScriptHostControl scriptHost, IRunScript scriptRunner)
234+
public void Initialize(IAheadBehindDataProvider? aheadBehindDataProvider, Action<string?> branchFilterAction, ICheckRefs refsSource, IScriptHostControl scriptHost, IRunScript scriptRunner)
235235
{
236236
_aheadBehindDataProvider = aheadBehindDataProvider;
237237
_branchFilterAction = branchFilterAction;

GitUI/CommandsDialogs/FormBrowse.InitMenusAndToolbars.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ private void InitMenusAndToolbars(string? revFilter, string? pathFilter)
2121
{
2222
commandsToolStripMenuItem.DropDownOpening += CommandsToolStripMenuItem_DropDownOpening;
2323

24+
InitFilters();
25+
2426
toolPanel.TopToolStripPanel.MouseClick += (s, e) =>
2527
{
2628
if (e.Button == MouseButtons.Right)
@@ -75,16 +77,6 @@ private void InitMenusAndToolbars(string? revFilter, string? pathFilter)
7577

7678
WorkaroundToolbarLocationBug();
7779

78-
if (!string.IsNullOrWhiteSpace(revFilter))
79-
{
80-
ToolStripFilters.SetRevisionFilter(revFilter);
81-
}
82-
83-
if (!string.IsNullOrWhiteSpace(pathFilter))
84-
{
85-
SetPathFilter(pathFilter);
86-
}
87-
8880
return;
8981

9082
void InitToolStripStyles(Color toolForeColor, Color toolBackColor)
@@ -105,6 +97,21 @@ void InitToolStripStyles(Color toolForeColor, Color toolBackColor)
10597
ToolStripScripts.ForeColor = toolForeColor;
10698
}
10799

100+
void InitFilters()
101+
{
102+
ToolStripFilters.UpdateBranchFilterItems();
103+
104+
if (!string.IsNullOrWhiteSpace(revFilter))
105+
{
106+
ToolStripFilters.SetRevisionFilter(revFilter);
107+
}
108+
109+
if (!string.IsNullOrWhiteSpace(pathFilter))
110+
{
111+
SetPathFilter(pathFilter);
112+
}
113+
}
114+
108115
void WorkaroundToolbarLocationBug()
109116
{
110117
// Layout engine bug (?) which may change the order of toolbars

GitUI/CommandsDialogs/FormBrowse.InitRevisionGrid.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ private void InitRevisionGrid(ObjectId? selectedId, ObjectId? firstId)
2323
.FileAndForget();
2424
};
2525
RevisionGrid.MenuCommands.MenuChanged += (sender, e) => _formBrowseMenus.OnMenuCommandsPropertyChanged();
26-
RevisionGrid.PathFilterChanged += revisionGrid_PathFilterChanged;
27-
RevisionGrid.RefFilterOptionsChanged += (sender, e) =>
26+
RevisionGrid.FilterChanged += (sender, e) =>
2827
{
29-
if (e.RefFilterOptions.HasFlag(RefFilterOptions.All | RefFilterOptions.Boundary))
30-
{
31-
// This means show all branches
32-
ToolStripFilters.ClearFilters();
33-
AppSettings.BranchFilterEnabled =
34-
AppSettings.ShowCurrentBranchOnly = false;
35-
}
28+
Text = _appTitleGenerator.Generate(Module.WorkingDir, Module.IsValidGitWorkingDir(), branchSelect.Text, TranslatedStrings.NoBranch, e.PathFilter);
3629
};
3730
RevisionGrid.RevisionGraphLoaded += (sender, e) =>
3831
{

GitUI/CommandsDialogs/FormBrowse.cs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ public FormBrowse(GitUICommands commands, BrowseArguments args)
261261
_appTitleGenerator = ManagedExtensibility.GetExport<IAppTitleGenerator>().Value;
262262
_windowsJumpListManager = ManagedExtensibility.GetExport<IWindowsJumpListManager>().Value;
263263

264-
_appTitleGenerator = ManagedExtensibility.GetExport<IAppTitleGenerator>().Value;
265-
_windowsJumpListManager = ManagedExtensibility.GetExport<IWindowsJumpListManager>().Value;
266-
267264
_formBrowseDiagnosticsReporter = new FormBrowseDiagnosticsReporter(this);
268265

269266
MainSplitContainer.Visible = false;
@@ -280,6 +277,10 @@ public FormBrowse(GitUICommands commands, BrowseArguments args)
280277
InitCountArtificial(out _gitStatusMonitor);
281278

282279
_formBrowseMenus = new FormBrowseMenus(mainMenuStrip);
280+
281+
RevisionGrid.SuspendRefreshRevisions();
282+
283+
ToolStripFilters.Bind(() => Module, RevisionGrid);
283284
InitMenusAndToolbars(args.RevFilter, args.PathFilter);
284285

285286
InitRevisionGrid(args.SelectedId, args.FirstId);
@@ -309,8 +310,6 @@ public FormBrowse(GitUICommands commands, BrowseArguments args)
309310
control.DragDrop += FormBrowse_DragDrop;
310311
}
311312

312-
ToolStripFilters.Bind(() => Module, RevisionGrid);
313-
314313
_aheadBehindDataProvider = GitVersion.Current.SupportAheadBehindData ? new AheadBehindDataProvider(() => Module.GitExecutable) : null;
315314

316315
toolStripButtonPush.Initialize(_aheadBehindDataProvider);
@@ -321,6 +320,8 @@ public FormBrowse(GitUICommands commands, BrowseArguments args)
321320
// We're launching the main form, and whilst the module has been set for us we still need to formally switch to it
322321
SetGitModule(this, new GitModuleEventArgs(new GitModule(Module.WorkingDir)));
323322

323+
RevisionGrid.ResumeRefreshRevisions();
324+
324325
return;
325326

326327
void ManageWorktreeSupport()
@@ -557,7 +558,7 @@ public override void CancelButtonClick(object sender, EventArgs e)
557558
else if (RevisionGrid.FilterIsApplied(true) || AppSettings.BranchFilterEnabled)
558559
{
559560
// Clear branch filter
560-
ToolStripFilters.SetBranchFilter(string.Empty, refresh: true);
561+
ToolStripFilters.SetBranchFilter(string.Empty);
561562

562563
// Execute the "Show all branches" menu option
563564
RevisionGrid.ShowAllBranches();
@@ -571,10 +572,9 @@ private bool NeedsGitStatusMonitor()
571572

572573
private void UICommands_PostRepositoryChanged(object sender, GitUIEventArgs e)
573574
{
574-
ToolStripFilters.UpdateBranchFilterItems();
575-
576575
this.InvokeAsync(RefreshRevisions).FileAndForget();
577576

577+
ToolStripFilters.UpdateBranchFilterItems();
578578
UpdateSubmodulesStructure();
579579
UpdateStashCount();
580580

@@ -608,7 +608,7 @@ private void RefreshRevisions()
608608
private void RefreshSelection()
609609
{
610610
var selectedRevisions = RevisionGrid.GetSelectedRevisions();
611-
var selectedRevision = RevisionGrid.GetSelectedRevisions().FirstOrDefault();
611+
var selectedRevision = selectedRevisions.FirstOrDefault();
612612

613613
FillFileTree(selectedRevision);
614614
FillDiff(selectedRevisions);
@@ -627,11 +627,6 @@ private void RefreshSelection()
627627
repoObjectsTree.SelectionChanged(selectedRevisions);
628628
}
629629

630-
private void revisionGrid_PathFilterChanged(object? sender, EventArgs e)
631-
{
632-
Text = _appTitleGenerator.Generate(Module.WorkingDir, Module.IsValidGitWorkingDir(), branchSelect.Text, TranslatedStrings.NoBranch, RevisionGrid.GetPathFilter());
633-
}
634-
635630
#region IBrowseRepo
636631

637632
public void GoToRef(string refName, bool showNoRevisionMsg, bool toggleSelection = false)
@@ -646,11 +641,9 @@ public void GoToRef(string refName, bool showNoRevisionMsg, bool toggleSelection
646641

647642
public void SetPathFilter(string pathFilter)
648643
{
649-
RevisionGrid.SetPathFilter(pathFilter.QuoteNE());
650644
revisionDiff.FallbackFollowedFile = pathFilter;
651645
fileTree.FallbackFollowedFile = pathFilter;
652-
Text = _appTitleGenerator.Generate(Module.WorkingDir, Module.IsValidGitWorkingDir(), branchSelect.Text, TranslatedStrings.NoBranch, RevisionGrid.GetPathFilter());
653-
RevisionGrid.ForceRefreshRevisions();
646+
RevisionGrid.SetAndApplyPathFilter(pathFilter.QuoteNE());
654647
}
655648

656649
private void ShowDashboard()
@@ -894,7 +887,6 @@ private void InternalInitialize(bool hard)
894887
}
895888

896889
RefreshWorkingDirComboText();
897-
Text = _appTitleGenerator.Generate(Module.WorkingDir, validBrowseDir, branchSelect.Text, TranslatedStrings.NoBranch, RevisionGrid.GetPathFilter());
898890

899891
OnActivate();
900892

@@ -1796,12 +1788,6 @@ private void SetGitModule(object sender, GitModuleEventArgs e)
17961788
_gitStatusMonitor.InvalidateGitWorkingDirectoryStatus();
17971789
_submoduleStatusProvider.Init();
17981790

1799-
// If we're applying custom branch or revision filters - reset them
1800-
ToolStripFilters.ClearFilters();
1801-
AppSettings.BranchFilterEnabled = AppSettings.BranchFilterEnabled && AppSettings.ShowCurrentBranchOnly;
1802-
1803-
RevisionGrid.DisableFilters();
1804-
18051791
UICommands = new GitUICommands(module);
18061792
if (Module.IsValidGitWorkingDir())
18071793
{
@@ -1814,6 +1800,7 @@ private void SetGitModule(object sender, GitModuleEventArgs e)
18141800
if (!string.Equals(originalWorkingDir, Module.WorkingDir, StringComparison.Ordinal))
18151801
{
18161802
ChangeTerminalActiveFolder(Module.WorkingDir);
1803+
18171804
#if DEBUG
18181805
// Current encodings
18191806
Debug.WriteLine($"Encodings for {Module.WorkingDir}");
@@ -2482,7 +2469,7 @@ private void RevisionInfo_CommandClicked(object sender, ResourceManager.CommandE
24822469
// and to make it possible we add explicit branch filter and refresh.
24832470
if (AppSettings.ShowFirstParent && !found)
24842471
{
2485-
ToolStripFilters.SetBranchFilter(revision?.ToString(), refresh: true);
2472+
ToolStripFilters.SetBranchFilter(revision?.ToString());
24862473
RevisionGrid.SetSelectedRevision(revision);
24872474
}
24882475

GitUI/CommandsDialogs/FormFileHistory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private void LoadFileHistory()
234234
// browse dialog.
235235
FileName = FileName.ToPosixPath();
236236

237-
RevisionGrid.SetPathFilter(FileName.QuoteNE());
237+
RevisionGrid.SetAndApplyPathFilter(FileName);
238238
RevisionGrid.Load();
239239
}
240240

GitUI/CommandsDialogs/RevisionDiffControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void DisplayDiffTab(IReadOnlyList<GitRevision> revisions)
225225
/// When switching commits, the last selected file is "followed" if available in the new commit,
226226
/// this file is used as a fallback.
227227
/// </summary>
228-
public string? FallbackFollowedFile { private get; set; } = null;
228+
public string? FallbackFollowedFile { get; set; } = null;
229229

230230
private void SetDiffs(IReadOnlyList<GitRevision> revisions)
231231
{

GitUI/CommandsDialogs/RevisionFileTreeControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void InvokeFindFileDialog()
155155
/// When switching commits, the last selected file is "followed" if available in the new commit,
156156
/// this file is used as a fallback.
157157
/// </summary>
158-
public string? FallbackFollowedFile { private get; set; } = null;
158+
public string? FallbackFollowedFile { get; set; } = null;
159159

160160
public void LoadRevision(GitRevision? revision)
161161
{

GitUI/CommandsDialogs/SettingsDialog/Pages/GeneralSettingsPage.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GitUI/Translation/English.xlf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7408,7 +7408,7 @@ Do you want to use this custom merge script?</source>
74087408
<target />
74097409
</trans-unit>
74107410
<trans-unit id="label8.Text">
7411-
<source>File filter</source>
7411+
<source>Path filter</source>
74127412
<target />
74137413
</trans-unit>
74147414
<trans-unit id="label9.Text">
@@ -9783,10 +9783,6 @@ See the changes in the commit form.</source>
97839783
<source>For you own protection dropping more than 10 patch files at once is blocked!</source>
97849784
<target />
97859785
</trans-unit>
9786-
<trans-unit id="_formRevisionFilter.Text">
9787-
<source>Filter</source>
9788-
<target />
9789-
</trans-unit>
97909786
<trans-unit id="_invalidDiffContainsFilter.Text">
97919787
<source>Filter text '{0}' not valid for "Diff contains" filter.</source>
97929788
<target />

0 commit comments

Comments
 (0)