[GUI] Improve asset list filtering

- Added filter history
- Added more filtering modes: Include, Exclude, Regex (Name/Container)
This commit is contained in:
VaDiM 2023-05-18 23:35:14 +03:00
parent b0bf5e0cfd
commit 02e46eaa0d
4 changed files with 158 additions and 64 deletions

View File

@ -83,14 +83,16 @@
this.sceneTreeView = new AssetStudioGUI.GOHierarchy();
this.treeSearch = new System.Windows.Forms.TextBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.filterExcludeMode = new System.Windows.Forms.CheckBox();
this.assetListView = new System.Windows.Forms.ListView();
this.columnHeaderName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderContainer = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderPathID = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderSize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.listSearch = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.listSearch = new System.Windows.Forms.RichTextBox();
this.listSearchHistory = new System.Windows.Forms.ComboBox();
this.listSearchFilterMode = new System.Windows.Forms.ComboBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.classesListView = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@ -143,6 +145,7 @@
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.panel1.SuspendLayout();
this.tabPage3.SuspendLayout();
this.progressbarPanel.SuspendLayout();
this.tabControl2.SuspendLayout();
@ -619,9 +622,8 @@
//
// tabPage2
//
this.tabPage2.Controls.Add(this.filterExcludeMode);
this.tabPage2.Controls.Add(this.assetListView);
this.tabPage2.Controls.Add(this.listSearch);
this.tabPage2.Controls.Add(this.panel1);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(472, 607);
@ -629,24 +631,6 @@
this.tabPage2.Text = "Asset List";
this.tabPage2.UseVisualStyleBackColor = true;
//
// filterExcludeMode
//
this.filterExcludeMode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.filterExcludeMode.AutoSize = true;
this.filterExcludeMode.BackColor = System.Drawing.Color.WhiteSmoke;
this.filterExcludeMode.Enabled = false;
this.filterExcludeMode.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.filterExcludeMode.ForeColor = System.Drawing.SystemColors.ControlText;
this.filterExcludeMode.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.filterExcludeMode.Location = new System.Drawing.Point(409, 2);
this.filterExcludeMode.Name = "filterExcludeMode";
this.filterExcludeMode.Size = new System.Drawing.Size(61, 17);
this.filterExcludeMode.TabIndex = 2;
this.filterExcludeMode.Text = "Exclude";
this.filterExcludeMode.TextAlign = System.Drawing.ContentAlignment.BottomRight;
this.filterExcludeMode.UseVisualStyleBackColor = false;
this.filterExcludeMode.CheckedChanged += new System.EventHandler(this.filterExcludeMode_CheckedChanged);
//
// assetListView
//
this.assetListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@ -659,9 +643,9 @@
this.assetListView.FullRowSelect = true;
this.assetListView.GridLines = true;
this.assetListView.HideSelection = false;
this.assetListView.Location = new System.Drawing.Point(0, 20);
this.assetListView.Location = new System.Drawing.Point(0, 23);
this.assetListView.Name = "assetListView";
this.assetListView.Size = new System.Drawing.Size(472, 587);
this.assetListView.Size = new System.Drawing.Size(472, 584);
this.assetListView.TabIndex = 1;
this.assetListView.UseCompatibleStateImageBehavior = false;
this.assetListView.View = System.Windows.Forms.View.Details;
@ -697,19 +681,66 @@
this.columnHeaderSize.Text = "Size";
this.columnHeaderSize.Width = 50;
//
// panel1
//
this.panel1.Controls.Add(this.listSearch);
this.panel1.Controls.Add(this.listSearchHistory);
this.panel1.Controls.Add(this.listSearchFilterMode);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(472, 23);
this.panel1.TabIndex = 2;
//
// listSearch
//
this.listSearch.Dock = System.Windows.Forms.DockStyle.Top;
this.listSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listSearch.BackColor = System.Drawing.Color.White;
this.listSearch.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.listSearch.DetectUrls = false;
this.listSearch.ForeColor = System.Drawing.SystemColors.GrayText;
this.listSearch.Location = new System.Drawing.Point(0, 0);
this.listSearch.Location = new System.Drawing.Point(3, 3);
this.listSearch.Multiline = false;
this.listSearch.Name = "listSearch";
this.listSearch.Size = new System.Drawing.Size(472, 20);
this.listSearch.TabIndex = 0;
this.listSearch.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.listSearch.Size = new System.Drawing.Size(331, 16);
this.listSearch.TabIndex = 3;
this.listSearch.Text = " Filter ";
this.listSearch.WordWrap = false;
this.listSearch.TextChanged += new System.EventHandler(this.ListSearchTextChanged);
this.listSearch.Enter += new System.EventHandler(this.listSearch_Enter);
this.listSearch.Leave += new System.EventHandler(this.listSearch_Leave);
//
// listSearchHistory
//
this.listSearchHistory.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.listSearchHistory.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.listSearchHistory.Dock = System.Windows.Forms.DockStyle.Fill;
this.listSearchHistory.Location = new System.Drawing.Point(0, 0);
this.listSearchHistory.Name = "listSearchHistory";
this.listSearchHistory.Size = new System.Drawing.Size(351, 21);
this.listSearchHistory.TabIndex = 2;
this.listSearchHistory.TabStop = false;
this.listSearchHistory.TextChanged += new System.EventHandler(this.listSearchHistory_TextChanged);
//
// listSearchFilterMode
//
this.listSearchFilterMode.Dock = System.Windows.Forms.DockStyle.Right;
this.listSearchFilterMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.listSearchFilterMode.DropDownWidth = 150;
this.listSearchFilterMode.Items.AddRange(new object[] {
"Include",
"Exclude",
"Regex (Name)",
"Regex (Container)"});
this.listSearchFilterMode.Location = new System.Drawing.Point(351, 0);
this.listSearchFilterMode.Name = "listSearchFilterMode";
this.listSearchFilterMode.Size = new System.Drawing.Size(121, 21);
this.listSearchFilterMode.TabIndex = 3;
this.listSearchFilterMode.SelectedIndexChanged += new System.EventHandler(this.listSearchFilterMode_SelectedIndexChanged);
//
// tabPage3
//
this.tabPage3.Controls.Add(this.classesListView);
@ -1194,7 +1225,7 @@
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.panel1.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
this.progressbarPanel.ResumeLayout(false);
this.tabControl2.ResumeLayout(false);
@ -1225,7 +1256,6 @@
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TextBox treeSearch;
private System.Windows.Forms.TextBox listSearch;
private System.Windows.Forms.ToolStripMenuItem loadFileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem loadFolderToolStripMenuItem;
private System.Windows.Forms.ListView assetListView;
@ -1315,7 +1345,6 @@
private System.Windows.Forms.ToolStripTextBox specifyUnityVersion;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem15;
private System.Windows.Forms.ToolStripMenuItem dumpSelectedAssetsToolStripMenuItem;
private System.Windows.Forms.CheckBox filterExcludeMode;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip2;
private System.Windows.Forms.ToolStripMenuItem selectAllToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem clearSelectionToolStripMenuItem;
@ -1323,6 +1352,10 @@
private System.Windows.Forms.ToolStripMenuItem collapseAllToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem expandAllToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ComboBox listSearchFilterMode;
private System.Windows.Forms.ComboBox listSearchHistory;
private System.Windows.Forms.RichTextBox listSearch;
}
}

View File

@ -12,6 +12,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
@ -119,6 +120,7 @@ namespace AssetStudioGUI
displayInfo.Checked = Properties.Settings.Default.displayInfo;
enablePreview.Checked = Properties.Settings.Default.enablePreview;
FMODinit();
listSearchFilterMode.SelectedIndex = 0;
logger = new GUILogger(StatusStripUpdate);
Logger.Default = logger;
@ -217,7 +219,6 @@ namespace AssetStudioGUI
{
if (assetsManager.assetsFileList.Count == 0)
{
filterExcludeModeCheck(assetsManager.assetsFileList.Count);
Logger.Info("No Unity file can be loaded.");
return;
}
@ -256,8 +257,6 @@ namespace AssetStudioGUI
typeMap.Clear();
classesListView.EndUpdate();
filterExcludeModeCheck(exportableAssets.Count);
var types = exportableAssets.Select(x => x.Type).Distinct().OrderBy(x => x.ToString()).ToArray();
foreach (var type in types)
{
@ -616,7 +615,7 @@ namespace AssetStudioGUI
{
listSearch.Text = "";
listSearch.ForeColor = SystemColors.WindowText;
enableFiltering = true;
BeginInvoke(new Action(() => enableFiltering = true));
}
}
@ -627,6 +626,7 @@ namespace AssetStudioGUI
enableFiltering = false;
listSearch.Text = " Filter ";
listSearch.ForeColor = SystemColors.GrayText;
listSearch.BackColor = System.Drawing.Color.White;
}
}
@ -649,9 +649,25 @@ namespace AssetStudioGUI
private void delayTimer_Elapsed(object sender, ElapsedEventArgs e)
{
delayTimer.Stop();
ListSearchHistoryAdd();
Invoke(new Action(FilterAssetList));
}
private void ListSearchHistoryAdd()
{
BeginInvoke(new Action(() =>
{
if (listSearch.Text != "")
{
if (listSearchHistory.Items.Count == listSearchHistory.MaxDropDownItems)
{
listSearchHistory.Items.RemoveAt(listSearchHistory.MaxDropDownItems - 1);
}
listSearchHistory.Items.Insert(0, listSearch.Text);
}
}));
}
private void assetListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (sortColumn != e.Column)
@ -1335,6 +1351,8 @@ namespace AssetStudioGUI
reverseSort = false;
enableFiltering = false;
listSearch.Text = " Filter ";
listSearch.ForeColor = SystemColors.GrayText;
listSearch.BackColor = System.Drawing.Color.White;
if (tabControl1.SelectedIndex == 1)
assetListView.Select();
@ -1634,22 +1652,11 @@ namespace AssetStudioGUI
return selectedAssets;
}
private void filterExcludeMode_CheckedChanged(object sender, EventArgs e)
{
FilterAssetList();
}
private void filterExcludeModeCheck(int itemCount)
{
filterExcludeMode.Enabled = itemCount > 0;
if (!filterExcludeMode.Enabled)
{
filterExcludeMode.Checked = false;
}
}
private void FilterAssetList()
{
if (exportableAssets.Count < 1)
return;
assetListView.BeginUpdate();
assetListView.SelectedIndices.Clear();
var show = new List<ClassIDType>();
@ -1671,19 +1678,49 @@ namespace AssetStudioGUI
}
if (listSearch.Text != " Filter ")
{
if (filterExcludeMode.Checked)
var mode = (ListSearchFilterMode)listSearchFilterMode.SelectedIndex;
switch (mode)
{
visibleAssets = visibleAssets.FindAll(
x => x.Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) <= 0 &&
x.SubItems[1].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) <= 0 &&
x.SubItems[3].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) <= 0);
}
else
{
visibleAssets = visibleAssets.FindAll(
x => x.Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0 ||
x.SubItems[1].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0 ||
x.SubItems[3].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0);
case ListSearchFilterMode.Include:
visibleAssets = visibleAssets.FindAll(
x => x.Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0 ||
x.SubItems[1].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0 ||
x.SubItems[3].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0);
break;
case ListSearchFilterMode.Exclude:
visibleAssets = visibleAssets.FindAll(
x => x.Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) <= 0 &&
x.SubItems[1].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) <= 0 &&
x.SubItems[3].Text.IndexOf(listSearch.Text, StringComparison.OrdinalIgnoreCase) <= 0);
break;
case ListSearchFilterMode.RegexName:
case ListSearchFilterMode.RegexContainer:
StatusStripUpdate("");
var pattern = listSearch.Text;
var regexOptions = RegexOptions.IgnoreCase | RegexOptions.Singleline;
try
{
if (mode == ListSearchFilterMode.RegexName)
{
visibleAssets = visibleAssets.FindAll(x => Regex.IsMatch(x.Text, pattern, regexOptions));
}
else
{
visibleAssets = visibleAssets.FindAll(x => Regex.IsMatch(x.SubItems[1].Text, pattern, regexOptions));
}
listSearch.BackColor = System.Drawing.Color.PaleGreen;
}
catch (ArgumentException e)
{
listSearch.BackColor = System.Drawing.Color.FromArgb(255, 160, 160);
StatusStripUpdate($"Regex error: {e.Message}");
}
catch (RegexMatchTimeoutException)
{
listSearch.BackColor = System.Drawing.Color.FromArgb(255, 160, 160);
StatusStripUpdate($"Timeout error");
}
break;
}
}
assetListView.VirtualListSize = visibleAssets.Count;
@ -1821,6 +1858,22 @@ namespace AssetStudioGUI
aboutForm.ShowDialog(this);
}
private void listSearchFilterMode_SelectedIndexChanged(object sender, EventArgs e)
{
listSearch.BackColor = System.Drawing.Color.White;
if (listSearch.Text != " Filter ")
{
FilterAssetList();
}
}
private void listSearchHistory_TextChanged(object sender, EventArgs e)
{
listSearch.Text = listSearchHistory.Text;
listSearch.Focus();
listSearch.SelectionStart = listSearch.Text.Length;
}
#region FMOD
private void FMODinit()
{

View File

@ -120,6 +120,9 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>312, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>432, 17</value>
</metadata>
<data name="fontPreviewBox.Text" xml:space="preserve">
<value>abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ
1234567890.:,;'\"(!?)+-*/=
@ -138,9 +141,6 @@ The quick brown fox jumps over the lazy dog. 1234567890
The quick brown fox jumps over the lazy dog. 1234567890</value>
</data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>432, 17</value>
</metadata>
<metadata name="contextMenuStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>775, 21</value>
</metadata>

View File

@ -32,6 +32,14 @@ namespace AssetStudioGUI
XML
}
internal enum ListSearchFilterMode
{
Include,
Exclude,
RegexName,
RegexContainer,
}
internal static class Studio
{
public static AssetsManager assetsManager = new AssetsManager();