mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-01 18:08:31 -05:00
Add datagrid filtering for folderlist view
can be a little silly if the tab hasn't been viewed yet, but works fine
This commit is contained in:
24
PKHeX.WinForms/Subforms/SAV_FolderList.Designer.cs
generated
24
PKHeX.WinForms/Subforms/SAV_FolderList.Designer.cs
generated
@@ -38,6 +38,8 @@ private void InitializeComponent()
|
||||
this.Tab_Backup = new System.Windows.Forms.TabPage();
|
||||
this.dgDataBackup = new System.Windows.Forms.DataGridView();
|
||||
this.Tab_Folders = new System.Windows.Forms.TabPage();
|
||||
this.CB_FilterColumn = new System.Windows.Forms.ComboBox();
|
||||
this.TB_FilterTextContains = new System.Windows.Forms.TextBox();
|
||||
this.TC_Tabs.SuspendLayout();
|
||||
this.Tab_Recent.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgDataRecent)).BeginInit();
|
||||
@@ -137,11 +139,30 @@ private void InitializeComponent()
|
||||
this.Tab_Folders.Text = "Folders";
|
||||
this.Tab_Folders.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// CB_FilterColumn
|
||||
//
|
||||
this.CB_FilterColumn.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.CB_FilterColumn.Location = new System.Drawing.Point(327, 0);
|
||||
this.CB_FilterColumn.Name = "CB_FilterColumn";
|
||||
this.CB_FilterColumn.Size = new System.Drawing.Size(121, 21);
|
||||
this.CB_FilterColumn.TabIndex = 0;
|
||||
this.CB_FilterColumn.SelectedIndexChanged += new System.EventHandler(this.ChangeFilterIndex);
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this.TB_FilterTextContains.Location = new System.Drawing.Point(449, 0);
|
||||
this.TB_FilterTextContains.Name = "TB_FilterTextContains";
|
||||
this.TB_FilterTextContains.Size = new System.Drawing.Size(160, 20);
|
||||
this.TB_FilterTextContains.TabIndex = 2;
|
||||
this.TB_FilterTextContains.TextChanged += new System.EventHandler(this.ChangeFilterText);
|
||||
//
|
||||
// SAV_FolderList
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(609, 361);
|
||||
this.Controls.Add(this.TB_FilterTextContains);
|
||||
this.Controls.Add(this.CB_FilterColumn);
|
||||
this.Controls.Add(this.TC_Tabs);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
@@ -156,6 +177,7 @@ private void InitializeComponent()
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgDataBackup)).EndInit();
|
||||
this.Tab_Folders.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@@ -168,5 +190,7 @@ private void InitializeComponent()
|
||||
private System.Windows.Forms.TabPage Tab_Backup;
|
||||
private System.Windows.Forms.DataGridView dgDataBackup;
|
||||
private System.Windows.Forms.DataGridView dgDataRecent;
|
||||
private System.Windows.Forms.ComboBox CB_FilterColumn;
|
||||
private System.Windows.Forms.TextBox TB_FilterTextContains;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace PKHeX.WinForms
|
||||
public partial class SAV_FolderList : Form
|
||||
{
|
||||
private readonly Action<SaveFile> OpenSaveFile;
|
||||
private readonly List<CustomFolderPath> Paths;
|
||||
private readonly List<CustomFolderPath> Paths = GetPathList();
|
||||
private readonly SortableBindingList<SavePreview> Recent;
|
||||
private readonly SortableBindingList<SavePreview> Backup;
|
||||
|
||||
@@ -23,8 +23,36 @@ public SAV_FolderList(Action<SaveFile> openSaveFile)
|
||||
{
|
||||
InitializeComponent();
|
||||
OpenSaveFile = openSaveFile;
|
||||
dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent);
|
||||
dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup);
|
||||
|
||||
var recent = PathUtilWindows.GetSaveFiles(Paths.Select(z => z.Path).Where(z => z != Main.BackupPath));
|
||||
Recent = PopulateData(dgDataRecent, recent);
|
||||
var backup = PathUtilWindows.GetSaveFiles(Main.BackupPath);
|
||||
Backup = PopulateData(dgDataBackup, backup);
|
||||
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
|
||||
CB_FilterColumn.Items.Add(MsgAny);
|
||||
var dgv = Recent.Count >= 1 ? dgDataRecent : dgDataBackup;
|
||||
int count = dgv.ColumnCount;
|
||||
for (int i = 0; i < count; i++)
|
||||
CB_FilterColumn.Items.Add(dgv.Columns[i].HeaderText);
|
||||
CB_FilterColumn.SelectedIndex = 0;
|
||||
|
||||
// Preprogrammed folders
|
||||
foreach (var loc in Paths)
|
||||
AddButton(loc.DisplayText, loc.Path);
|
||||
|
||||
dgDataRecent.DoubleBuffered(true);
|
||||
dgDataBackup.DoubleBuffered(true);
|
||||
|
||||
CenterToParent();
|
||||
|
||||
}
|
||||
|
||||
private static List<CustomFolderPath> GetPathList()
|
||||
{
|
||||
var locs = new List<CustomFolderPath>
|
||||
{
|
||||
new CustomFolderPath(Main.BackupPath, "PKHeX Backups")
|
||||
@@ -34,31 +62,13 @@ public SAV_FolderList(Action<SaveFile> openSaveFile)
|
||||
locs.AddRange(GetSwitchPaths());
|
||||
addIfExists(CyberGadgetUtil.GetCacheFolder(), "CGSE Cache");
|
||||
addIfExists(CyberGadgetUtil.GetTempFolder(), "CGSE Temp");
|
||||
|
||||
Paths = locs.GroupBy(z => z.Path).Select(z => z.First())
|
||||
.OrderByDescending(z => Directory.Exists(z.Path)).ToList();
|
||||
foreach (var loc in Paths)
|
||||
AddButton(loc.DisplayText, loc.Path);
|
||||
|
||||
var recent = PathUtilWindows.GetSaveFiles(Paths.Select(z => z.Path).Where(z => z != Main.BackupPath));
|
||||
Recent = PopulateData(dgDataRecent, recent);
|
||||
var backup = PathUtilWindows.GetSaveFiles(Main.BackupPath);
|
||||
Backup = PopulateData(dgDataBackup, backup);
|
||||
|
||||
dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent);
|
||||
dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup);
|
||||
|
||||
dgDataRecent.DoubleBuffered(true);
|
||||
dgDataBackup.DoubleBuffered(true);
|
||||
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
CenterToParent();
|
||||
|
||||
void addIfExists(string path, string text)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
locs.Add(new CustomFolderPath(path, text));
|
||||
}
|
||||
return locs.GroupBy(z => z.Path).Select(z => z.First())
|
||||
.OrderByDescending(z => Directory.Exists(z.Path)).ToList();
|
||||
}
|
||||
|
||||
private void AddButton(string name, string path)
|
||||
@@ -168,8 +178,8 @@ public SavePreview(SaveFile sav, string parent)
|
||||
public string Played => Save.PlayTimeString.PadLeft(9, '0');
|
||||
public string FileTime => new FileInfo(Save.FilePath).LastWriteTime.ToString("yyyy.MM.dd:hh:mm:ss");
|
||||
|
||||
public int TID => Save.Generation >= 7 ? Save.TrainerID7 : Save.TID;
|
||||
public int SID => Save.Generation >= 7 ? Save.TrainerSID7 : Save.SID;
|
||||
public string TID => Save.Generation >= 7 ? Save.TrainerID7.ToString("000000") : Save.TID.ToString("00000");
|
||||
public string SID => Save.Generation >= 7 ? Save.TrainerSID7.ToString("0000") : Save.SID.ToString("00000");
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Local
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||
@@ -288,12 +298,57 @@ private static void LoadEntryInitial(DataGridView dgData, SaveList<SavePreview>
|
||||
dgData.AutoResizeColumns(); // Trigger Resizing
|
||||
}
|
||||
|
||||
private static void LoadEntry(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
||||
private void LoadEntry(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
||||
{
|
||||
dgData.SuspendLayout();
|
||||
list.Add(sav);
|
||||
int count = list.Count;
|
||||
if (CB_FilterColumn.SelectedIndex != 0)
|
||||
ToggleRowVisibility(dgData, CB_FilterColumn.SelectedIndex - 1, TB_FilterTextContains.Text, count - 1);
|
||||
dgData.AutoResizeColumns();
|
||||
dgData.ResumeLayout();
|
||||
}
|
||||
|
||||
private void ChangeFilterIndex(object sender, EventArgs e)
|
||||
{
|
||||
TB_FilterTextContains.Enabled = CB_FilterColumn.SelectedIndex != 0;
|
||||
SetRowFilter();
|
||||
}
|
||||
private void ChangeFilterText(object sender, EventArgs e)
|
||||
{
|
||||
if (CB_FilterColumn.SelectedIndex != 0)
|
||||
SetRowFilter();
|
||||
}
|
||||
|
||||
private void SetRowFilter()
|
||||
{
|
||||
GetFilterText(dgDataRecent);
|
||||
GetFilterText(dgDataBackup);
|
||||
}
|
||||
|
||||
private void GetFilterText(DataGridView dg)
|
||||
{
|
||||
var cm = (CurrencyManager)BindingContext[dg.DataSource];
|
||||
cm.SuspendBinding();
|
||||
int column = CB_FilterColumn.SelectedIndex - 1;
|
||||
var text = TB_FilterTextContains.Text;
|
||||
|
||||
for (int i = 0; i < dg.RowCount; i++)
|
||||
ToggleRowVisibility(dg, column, text, i);
|
||||
cm.ResumeBinding();
|
||||
}
|
||||
|
||||
private static void ToggleRowVisibility(DataGridView dg, int column, string text, int i)
|
||||
{
|
||||
var row = dg.Rows[i];
|
||||
if (text.Length == 0 || column < 0)
|
||||
{
|
||||
row.Visible = true;
|
||||
return;
|
||||
}
|
||||
var cell = row.Cells[column];
|
||||
var value = cell.Value.ToString();
|
||||
row.Visible = value.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0; // case insensitive contains
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user