2018-07-16 00:48:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
using System.Windows.Forms;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class SAV_FolderList : Form
|
|
|
|
|
{
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private readonly Action<SaveFile> OpenSaveFile;
|
2018-07-21 17:23:15 +00:00
|
|
|
|
private readonly List<CustomFolderPath> Paths;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private readonly SortableBindingList<SavePreview> Recent;
|
|
|
|
|
private readonly SortableBindingList<SavePreview> Backup;
|
2018-07-18 04:02:01 +00:00
|
|
|
|
private readonly List<Label> TempTranslationLabels = new List<Label>();
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
public SAV_FolderList(Action<SaveFile> openSaveFile)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-07-16 00:48:31 +00:00
|
|
|
|
OpenSaveFile = openSaveFile;
|
2018-07-21 17:23:15 +00:00
|
|
|
|
|
|
|
|
|
var drives = Environment.GetLogicalDrives();
|
|
|
|
|
Paths = GetPathList(drives);
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent);
|
|
|
|
|
dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup);
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var recent = SaveFinder.GetSaveFiles(drives, false, Paths.Select(z => z.Path).Where(z => z != Main.BackupPath));
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Recent = PopulateData(dgDataRecent, recent);
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var backup = SaveFinder.GetSaveFiles(drives, false, Main.BackupPath);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Backup = PopulateData(dgDataBackup, backup);
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
CB_FilterColumn.Items.Add(MsgAny);
|
|
|
|
|
var dgv = Recent.Count >= 1 ? dgDataRecent : dgDataBackup;
|
|
|
|
|
int count = dgv.ColumnCount;
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2018-07-18 04:02:01 +00:00
|
|
|
|
{
|
|
|
|
|
var text = dgv.Columns[i].HeaderText;
|
|
|
|
|
CB_FilterColumn.Items.Add(text);
|
|
|
|
|
var tempLabel = new Label {Name = "DGV_" + text, Text = text, Visible = false};
|
|
|
|
|
Controls.Add(tempLabel);
|
|
|
|
|
TempTranslationLabels.Add(tempLabel);
|
|
|
|
|
}
|
2018-07-18 03:52:08 +00:00
|
|
|
|
CB_FilterColumn.SelectedIndex = 0;
|
|
|
|
|
|
2018-07-18 04:02:01 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
|
|
|
|
|
// Update Translated headers
|
|
|
|
|
for (int i = 0; i < TempTranslationLabels.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var text = TempTranslationLabels[i].Text;
|
2018-07-19 02:32:57 +00:00
|
|
|
|
if (i < dgDataRecent.ColumnCount)
|
|
|
|
|
dgDataRecent.Columns[i].HeaderText = text;
|
|
|
|
|
if (i < dgDataBackup.ColumnCount)
|
|
|
|
|
dgDataBackup.Columns[i].HeaderText = text;
|
2018-07-18 04:02:01 +00:00
|
|
|
|
CB_FilterColumn.Items[i+1] = text;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
// Preprogrammed folders
|
|
|
|
|
foreach (var loc in Paths)
|
|
|
|
|
AddButton(loc.DisplayText, loc.Path);
|
2018-07-22 21:27:48 +00:00
|
|
|
|
AddCustomizeButton();
|
2018-07-16 00:48:31 +00:00
|
|
|
|
|
|
|
|
|
dgDataRecent.DoubleBuffered(true);
|
|
|
|
|
dgDataBackup.DoubleBuffered(true);
|
|
|
|
|
|
|
|
|
|
CenterToParent();
|
2018-07-18 03:52:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-21 17:23:15 +00:00
|
|
|
|
private static List<CustomFolderPath> GetPathList(IReadOnlyList<string> drives)
|
2018-07-18 03:52:08 +00:00
|
|
|
|
{
|
|
|
|
|
var locs = new List<CustomFolderPath>
|
|
|
|
|
{
|
|
|
|
|
new CustomFolderPath(Main.BackupPath, "PKHeX Backups")
|
|
|
|
|
};
|
|
|
|
|
locs.AddRange(GetUserPaths());
|
2018-07-21 17:23:15 +00:00
|
|
|
|
locs.AddRange(GetConsolePaths(drives));
|
|
|
|
|
locs.AddRange(GetSwitchPaths(drives));
|
2018-07-18 03:52:08 +00:00
|
|
|
|
return locs.GroupBy(z => z.Path).Select(z => z.First())
|
|
|
|
|
.OrderByDescending(z => Directory.Exists(z.Path)).ToList();
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
private const int ButtonHeight = 30;
|
|
|
|
|
private const int ButtonWidth = 130;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddButton(string name, string path)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Button button = GetCustomButton(name);
|
|
|
|
|
button.Enabled = new DirectoryInfo(path).Exists;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
{
|
2018-07-25 14:26:29 +00:00
|
|
|
|
if (!Directory.Exists(path))
|
2017-05-18 01:25:48 +00:00
|
|
|
|
{
|
2018-07-25 14:26:29 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgFolderNotFound, path);
|
|
|
|
|
return;
|
2017-05-18 01:25:48 +00:00
|
|
|
|
}
|
2018-07-25 14:26:29 +00:00
|
|
|
|
Process.Start("explorer.exe", path);
|
|
|
|
|
Close();
|
2017-05-16 23:27:43 +00:00
|
|
|
|
};
|
|
|
|
|
FLP_Buttons.Controls.Add(button);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
private void AddCustomizeButton()
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2018-07-22 21:27:48 +00:00
|
|
|
|
const string name = "Customize";
|
|
|
|
|
Button button = GetCustomButton(name);
|
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
{
|
2018-09-03 17:30:35 +00:00
|
|
|
|
var loc = Main.SAVPaths;
|
2018-07-22 21:27:48 +00:00
|
|
|
|
if (!File.Exists(loc))
|
|
|
|
|
{
|
|
|
|
|
var custom = Paths.Where(z => z.Custom).ToList();
|
|
|
|
|
if (custom.Count == 0)
|
|
|
|
|
Paths.Add(new CustomFolderPath("DISPLAY_TEXT", "FOLDER_PATH", true));
|
|
|
|
|
var lines = custom.Select(z => z.Write());
|
|
|
|
|
File.WriteAllLines(loc, lines);
|
|
|
|
|
}
|
|
|
|
|
Process.Start(loc);
|
|
|
|
|
Close();
|
|
|
|
|
};
|
|
|
|
|
FLP_Buttons.Controls.Add(button);
|
|
|
|
|
}
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
private static Button GetCustomButton(string name)
|
|
|
|
|
{
|
|
|
|
|
return new Button
|
|
|
|
|
{
|
|
|
|
|
Size = new Size { Height = ButtonHeight, Width = ButtonWidth },
|
|
|
|
|
Text = name,
|
|
|
|
|
Name = $"B_{name}",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<CustomFolderPath> GetUserPaths()
|
|
|
|
|
{
|
2018-09-03 17:30:35 +00:00
|
|
|
|
string loc = Main.SAVPaths;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
if (!File.Exists(loc))
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return Enumerable.Empty<CustomFolderPath>();
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2018-02-20 07:34:07 +00:00
|
|
|
|
var lines = File.ReadLines(loc);
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return lines.Select(z => z.Split('\t'))
|
|
|
|
|
.Where(a => a.Length == 2)
|
2018-07-22 21:27:48 +00:00
|
|
|
|
.Select(x => new CustomFolderPath(x, true));
|
2017-05-17 04:44:02 +00:00
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-21 17:23:15 +00:00
|
|
|
|
private static IEnumerable<CustomFolderPath> GetConsolePaths(IEnumerable<string> drives)
|
2017-05-17 04:44:02 +00:00
|
|
|
|
{
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var path3DS = SaveFinder.Get3DSLocation(drives);
|
2018-07-21 17:23:15 +00:00
|
|
|
|
if (path3DS == null)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return Enumerable.Empty<CustomFolderPath>();
|
|
|
|
|
var root = Path.GetPathRoot(path3DS);
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var paths = SaveFinder.Get3DSBackupPaths(root);
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return paths.Select(z => new CustomFolderPath(z));
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-21 17:23:15 +00:00
|
|
|
|
private static IEnumerable<CustomFolderPath> GetSwitchPaths(IEnumerable<string> drives)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var pathNX = SaveFinder.GetSwitchLocation(drives);
|
2018-07-21 17:23:15 +00:00
|
|
|
|
if (pathNX == null)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return Enumerable.Empty<CustomFolderPath>();
|
|
|
|
|
var root = Path.GetPathRoot(pathNX);
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var paths = SaveFinder.GetSwitchBackupPaths(root);
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return paths.Select(z => new CustomFolderPath(z));
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private class CustomFolderPath
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
|
|
|
|
public readonly string Path;
|
|
|
|
|
public readonly string DisplayText;
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public readonly bool Custom;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public CustomFolderPath(string z, bool custom = false)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2017-05-17 04:44:02 +00:00
|
|
|
|
var di = new DirectoryInfo(z);
|
|
|
|
|
var root = di.Root.Name;
|
|
|
|
|
var folder = di.Parent.Name;
|
|
|
|
|
if (root == folder)
|
|
|
|
|
folder = di.Name;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
|
|
|
|
|
Path = z;
|
|
|
|
|
DisplayText = folder;
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Custom = custom;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public CustomFolderPath(IReadOnlyList<string> arr, bool custom = false)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
|
|
|
|
Path = arr[1];
|
|
|
|
|
DisplayText = arr[0];
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Custom = custom;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public CustomFolderPath(string path, string display, bool custom = false)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
|
|
|
|
Path = path;
|
|
|
|
|
DisplayText = display;
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Custom = custom;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
|
|
|
|
public string Write() => $"{DisplayText}\t{Path}";
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
2018-07-16 00:48:31 +00:00
|
|
|
|
|
|
|
|
|
private string GetParentFolderName(SaveFile first)
|
|
|
|
|
{
|
2018-07-17 04:00:43 +00:00
|
|
|
|
var parent = Paths.Find(z => first.FileFolder.StartsWith(z.Path));
|
2018-07-21 17:23:15 +00:00
|
|
|
|
return parent?.DisplayText ?? "???";
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class SaveList<T> : SortableBindingList<T> { }
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private sealed class SavePreview
|
|
|
|
|
{
|
|
|
|
|
public readonly SaveFile Save;
|
|
|
|
|
|
|
|
|
|
public SavePreview(SaveFile sav, string parent)
|
|
|
|
|
{
|
|
|
|
|
Save = sav;
|
|
|
|
|
Folder = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string OT => Save.OT;
|
|
|
|
|
public int G => Save.Generation;
|
|
|
|
|
public GameVersion Game => Save.Version;
|
|
|
|
|
|
|
|
|
|
public string Played => Save.PlayTimeString.PadLeft(9, '0');
|
2019-04-06 01:45:59 +00:00
|
|
|
|
public string FileTime => File.GetLastWriteTimeUtc(Save.FilePath).ToString("yyyy.MM.dd:hh:mm:ss");
|
2018-07-16 00:48:31 +00:00
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
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");
|
2018-07-16 00:48:31 +00:00
|
|
|
|
|
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Local
|
|
|
|
|
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
|
|
|
|
public string Folder { get; }
|
2018-07-16 04:28:27 +00:00
|
|
|
|
|
|
|
|
|
public string Name => Path.GetFileName(Save.FilePath);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ContextMenuStrip GetContextMenu(DataGridView dgv)
|
|
|
|
|
{
|
|
|
|
|
var mnuOpen = new ToolStripMenuItem
|
|
|
|
|
{
|
|
|
|
|
Name = "mnuOpen",
|
|
|
|
|
Text = "Open",
|
|
|
|
|
Image = Resources.open,
|
|
|
|
|
};
|
|
|
|
|
mnuOpen.Click += (sender, e) => ClickOpenFile(dgv);
|
|
|
|
|
|
|
|
|
|
var mnuBrowseAt = new ToolStripMenuItem
|
|
|
|
|
{
|
|
|
|
|
Name = "mnuBrowseAt",
|
|
|
|
|
Text = "Browse...",
|
|
|
|
|
Image = Resources.folder,
|
|
|
|
|
};
|
|
|
|
|
mnuBrowseAt.Click += (sender, e) => ClickOpenFolder(dgv);
|
|
|
|
|
|
|
|
|
|
ContextMenuStrip mnu = new ContextMenuStrip();
|
|
|
|
|
mnu.Items.Add(mnuOpen);
|
|
|
|
|
mnu.Items.Add(mnuBrowseAt);
|
|
|
|
|
return mnu;
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private void ClickOpenFile(DataGridView dgv)
|
|
|
|
|
{
|
|
|
|
|
var sav = GetSaveFile(dgv);
|
|
|
|
|
if (sav == null)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(MsgFileLoadFail);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenSaveFile(sav.Save);
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private void ClickOpenFolder(DataGridView dgv)
|
|
|
|
|
{
|
|
|
|
|
var sav = GetSaveFile(dgv);
|
|
|
|
|
if (sav == null)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(MsgFileLoadFail);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var path = sav.Save.FilePath;
|
|
|
|
|
Process.Start("explorer.exe", $"/select, \"{path}\"");
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private SavePreview GetSaveFile(DataGridView dgData)
|
|
|
|
|
{
|
|
|
|
|
var c = dgData.SelectedCells;
|
|
|
|
|
if (c.Count != 1)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var item = c[0].RowIndex;
|
|
|
|
|
var parent = dgData == dgDataRecent ? Recent : Backup;
|
|
|
|
|
return parent[item];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DataGridCellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ColumnIndex == -1 || e.RowIndex == -1 || e.Button != MouseButtons.Right)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var c = ((DataGridView) sender)[e.ColumnIndex, e.RowIndex];
|
|
|
|
|
c.DataGridView.ClearSelection();
|
|
|
|
|
c.DataGridView.CurrentCell = c;
|
|
|
|
|
c.Selected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SaveList<SavePreview> PopulateData(DataGridView dgData, IEnumerable<SaveFile> saves)
|
|
|
|
|
{
|
|
|
|
|
var list = new SaveList<SavePreview>();
|
|
|
|
|
|
|
|
|
|
var enumerator = saves.GetEnumerator();
|
|
|
|
|
while (enumerator.Current == null)
|
|
|
|
|
{
|
|
|
|
|
if (!enumerator.MoveNext())
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var first = enumerator.Current;
|
|
|
|
|
var sav1 = new SavePreview(first, GetParentFolderName(first));
|
|
|
|
|
LoadEntryInitial(dgData, list, sav1);
|
2018-07-28 03:41:49 +00:00
|
|
|
|
|
|
|
|
|
int ctr = 1; // refresh every 7 until 15+ are loaded
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Task.Run(async () => // load the rest async
|
|
|
|
|
{
|
2018-07-16 22:31:23 +00:00
|
|
|
|
while (!dgData.IsHandleCreated)
|
|
|
|
|
await Task.Delay(15).ConfigureAwait(false);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
while (enumerator.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
var next = enumerator.Current;
|
|
|
|
|
if (next == null)
|
|
|
|
|
continue;
|
|
|
|
|
var sav = new SavePreview(next, GetParentFolderName(next));
|
|
|
|
|
dgData.Invoke(new Action(() => LoadEntry(dgData, list, sav)));
|
2018-07-28 03:41:49 +00:00
|
|
|
|
ctr++;
|
|
|
|
|
if (ctr < 15 && ctr % 7 == 0)
|
|
|
|
|
dgData.Invoke(new Action(() => Refresh(dgData)));
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
2018-07-28 03:41:49 +00:00
|
|
|
|
dgData.Invoke(new Action(() => Refresh(dgData)));
|
2018-07-16 00:48:31 +00:00
|
|
|
|
enumerator.Dispose();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-28 03:41:49 +00:00
|
|
|
|
private static void Refresh(DataGridView dgData)
|
|
|
|
|
{
|
|
|
|
|
dgData.SuspendLayout();
|
|
|
|
|
dgData.AutoResizeColumns();
|
|
|
|
|
dgData.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-23 22:58:48 +00:00
|
|
|
|
private static void LoadEntryInitial(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(sav);
|
|
|
|
|
dgData.DataSource = list;
|
|
|
|
|
dgData.AutoGenerateColumns = true;
|
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
|
|
|
|
|
dgData.AutoResizeColumns(); // Trigger Resizing
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
private void LoadEntry(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(sav);
|
2018-07-18 03:52:08 +00:00
|
|
|
|
int count = list.Count;
|
|
|
|
|
if (CB_FilterColumn.SelectedIndex != 0)
|
|
|
|
|
ToggleRowVisibility(dgData, CB_FilterColumn.SelectedIndex - 1, TB_FilterTextContains.Text, count - 1);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
2018-07-18 03:52:08 +00:00
|
|
|
|
|
|
|
|
|
private void ChangeFilterIndex(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TB_FilterTextContains.Enabled = CB_FilterColumn.SelectedIndex != 0;
|
|
|
|
|
SetRowFilter();
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2018-07-19 02:32:57 +00:00
|
|
|
|
if (dg.RowCount == 0)
|
|
|
|
|
return;
|
2018-07-18 03:52:08 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|