[Feature] Refresh root folder on change of contents (#330), version 1.2.9.23
This commit is contained in:
parent
1ec1842bb0
commit
7211e4dff1
|
@ -31,7 +31,7 @@ namespace SystemTrayMenu.Business
|
|||
private readonly WaitToLoadMenu waitToOpenMenu = new();
|
||||
private readonly KeyboardInput keyboardInput;
|
||||
private readonly List<FileSystemWatcher> watchers = new();
|
||||
private readonly List<FileSystemEventArgs> watcherHistory = new();
|
||||
private readonly List<EventArgs> watcherHistory = new();
|
||||
private readonly Timer timerShowProcessStartedAsLoadingIcon = new();
|
||||
private readonly Timer timerStillActiveCheck = new();
|
||||
private readonly WaitLeave waitLeave = new(Properties.Settings.Default.TimeUntilCloses);
|
||||
|
@ -313,7 +313,7 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
try
|
||||
{
|
||||
FileSystemWatcher watcher = new FileSystemWatcher();
|
||||
FileSystemWatcher watcher = new();
|
||||
watcher.Path = path;
|
||||
watcher.NotifyFilter = NotifyFilters.Attributes |
|
||||
NotifyFilters.DirectoryName |
|
||||
|
@ -322,8 +322,8 @@ namespace SystemTrayMenu.Business
|
|||
watcher.Filter = "*.*";
|
||||
watcher.Created += WatcherProcessItem;
|
||||
watcher.Deleted += WatcherProcessItem;
|
||||
watcher.Renamed += WatcherRenamed;
|
||||
watcher.Changed += WatcherChanged;
|
||||
watcher.Renamed += WatcherProcessItem;
|
||||
watcher.Changed += WatcherProcessItem;
|
||||
watcher.IncludeSubdirectories = recursiv;
|
||||
watcher.EnableRaisingEvents = true;
|
||||
watchers.Add(watcher);
|
||||
|
@ -370,8 +370,8 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
watcher.Created -= WatcherProcessItem;
|
||||
watcher.Deleted -= WatcherProcessItem;
|
||||
watcher.Renamed -= WatcherRenamed;
|
||||
watcher.Changed -= WatcherChanged;
|
||||
watcher.Renamed -= WatcherProcessItem;
|
||||
watcher.Changed -= WatcherProcessItem;
|
||||
watcher.Dispose();
|
||||
}
|
||||
}
|
||||
|
@ -1300,19 +1300,7 @@ namespace SystemTrayMenu.Business
|
|||
watcherHistory.Clear();
|
||||
}
|
||||
|
||||
private void WatcherRenamed(object sender, RenamedEventArgs e)
|
||||
{
|
||||
WatcherProcessItem(sender, new FileSystemEventArgs(WatcherChangeTypes.Deleted, Path.GetDirectoryName(e.OldFullPath), e.OldName));
|
||||
WatcherProcessItem(sender, new FileSystemEventArgs(WatcherChangeTypes.Created, Path.GetDirectoryName(e.FullPath), e.Name));
|
||||
}
|
||||
|
||||
private void WatcherChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
WatcherProcessItem(sender, new FileSystemEventArgs(WatcherChangeTypes.Deleted, Path.GetDirectoryName(e.FullPath), e.Name));
|
||||
WatcherProcessItem(sender, new FileSystemEventArgs(WatcherChangeTypes.Created, Path.GetDirectoryName(e.FullPath), e.Name));
|
||||
}
|
||||
|
||||
private void WatcherProcessItem(object sender, FileSystemEventArgs e)
|
||||
private void WatcherProcessItem(object sender, EventArgs e)
|
||||
{
|
||||
if (menus[0] == null || !menus[0].IsHandleCreated)
|
||||
{
|
||||
|
@ -1320,13 +1308,85 @@ namespace SystemTrayMenu.Business
|
|||
return;
|
||||
}
|
||||
|
||||
if (e.ChangeType == WatcherChangeTypes.Deleted)
|
||||
if (e is RenamedEventArgs renamedEventArgs)
|
||||
{
|
||||
menus[0].Invoke(() => DeleteItem(e));
|
||||
menus[0].Invoke(() => RenameItem(renamedEventArgs));
|
||||
}
|
||||
else if (e.ChangeType == WatcherChangeTypes.Created)
|
||||
else
|
||||
{
|
||||
menus[0].Invoke(() => CreateItem(e));
|
||||
FileSystemEventArgs fileSystemEventArgs = (FileSystemEventArgs)e;
|
||||
if (fileSystemEventArgs.ChangeType == WatcherChangeTypes.Deleted)
|
||||
{
|
||||
menus[0].Invoke(() => DeleteItem(e as FileSystemEventArgs));
|
||||
}
|
||||
else if (fileSystemEventArgs.ChangeType == WatcherChangeTypes.Created)
|
||||
{
|
||||
menus[0].Invoke(() => CreateItem(e as FileSystemEventArgs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RenameItem(RenamedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<RowData> rowDatas = new();
|
||||
DataTable dataTable = (DataTable)menus[0].GetDataGridView().DataSource;
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
RowData rowData = (RowData)row[2];
|
||||
if (rowData.Path.StartsWith($"{e.OldFullPath}"))
|
||||
{
|
||||
bool isAddionalPathRenamed = false;
|
||||
string oldPath = rowData.Path;
|
||||
string path = rowData.Path.Replace(e.OldFullPath, e.FullPath);
|
||||
foreach (var pathAndFlags in MenusHelpers.GetAddionalPathsForMainMenu())
|
||||
{
|
||||
if (oldPath.StartsWith($"{pathAndFlags.Path}\\") &&
|
||||
!path.StartsWith($"{pathAndFlags.Path}\\"))
|
||||
{
|
||||
isAddionalPathRenamed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isAddionalPathRenamed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FileAttributes attr = File.GetAttributes(path);
|
||||
bool isFolder = (attr & FileAttributes.Directory) == FileAttributes.Directory;
|
||||
bool isAddionalItem = Path.GetDirectoryName(path) != Config.Path;
|
||||
RowData rowDataRenamed = new(isFolder, isAddionalItem, false, 0, path);
|
||||
if (FolderOptions.IsHidden(rowDataRenamed))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IconReader.RemoveIconFromCache(rowData.Path);
|
||||
rowDataRenamed.ReadIcon(true);
|
||||
rowDatas.Add(rowDataRenamed);
|
||||
}
|
||||
else
|
||||
{
|
||||
rowDatas.Add(rowData);
|
||||
}
|
||||
}
|
||||
|
||||
rowDatas = MenusHelpers.SortItems(rowDatas);
|
||||
keyboardInput.ClearIsSelectedByKey();
|
||||
AddItemsToMenu(rowDatas, menus[0], out _, out _);
|
||||
|
||||
hideSubmenuDuringRefreshSearch = false;
|
||||
menus[0].RefreshSearchText();
|
||||
hideSubmenuDuringRefreshSearch = true;
|
||||
|
||||
menus[0].TimerUpdateIconsStart();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warn($"Failed to {nameof(RenameItem)}: {e.OldFullPath} {e.FullPath}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1334,7 +1394,7 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
try
|
||||
{
|
||||
List<DataRow> rowsToRemove = new List<DataRow>();
|
||||
List<DataRow> rowsToRemove = new();
|
||||
DataGridView dgv = menus[0].GetDataGridView();
|
||||
DataTable dataTable = (DataTable)dgv.DataSource;
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace SystemTrayMenu.DllImports
|
|||
if (handle != IntPtr.Zero)
|
||||
{
|
||||
region = System.Drawing.Region.FromHrgn(handle);
|
||||
DeleteObject(handle);
|
||||
_ = DeleteObject(handle);
|
||||
success = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.2.9.22")]
|
||||
[assembly: AssemblyFileVersion("1.2.9.22")]
|
||||
[assembly: AssemblyVersion("1.2.9.23")]
|
||||
[assembly: AssemblyFileVersion("1.2.9.23")]
|
||||
|
|
|
@ -392,7 +392,7 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
return "* " + keyString;
|
||||
}
|
||||
|
||||
keyString = keyString.Substring(0, 1).ToUpperInvariant() + keyString[1..].ToLowerInvariant();
|
||||
keyString = keyString[..1].ToUpperInvariant() + keyString[1..].ToLowerInvariant();
|
||||
}
|
||||
|
||||
return keyString + " *";
|
||||
|
@ -405,7 +405,7 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
return "/ " + keyString;
|
||||
}
|
||||
|
||||
keyString = keyString.Substring(0, 1).ToUpperInvariant() + keyString[1..].ToLowerInvariant();
|
||||
keyString = keyString[..1].ToUpperInvariant() + keyString[1..].ToLowerInvariant();
|
||||
}
|
||||
|
||||
return keyString + " /";
|
||||
|
@ -443,7 +443,7 @@ namespace SystemTrayMenu.UserInterface.HotkeyTextboxControl
|
|||
string visibleName = keyName.ToString();
|
||||
if (visibleName.Length > 1)
|
||||
{
|
||||
visibleName = visibleName.Substring(0, 1) + visibleName[1..].ToLowerInvariant();
|
||||
visibleName = visibleName[..1] + visibleName[1..].ToLowerInvariant();
|
||||
}
|
||||
|
||||
return visibleName;
|
||||
|
|
|
@ -747,9 +747,8 @@ namespace SystemTrayMenu.UserInterface
|
|||
row.Height = dgv.RowTemplate.Height;
|
||||
}
|
||||
|
||||
DataTable data = (DataTable)dgv.DataSource;
|
||||
int dgvHeightNew = dgv.Rows.GetRowsHeight(DataGridViewElementStates.None); // Height of all rows
|
||||
int dgvHeightMax = screenHeightMax - (Height - dgv.Height); // except dgv
|
||||
int dgvHeightNew = dgv.Rows.GetRowsHeight(DataGridViewElementStates.None);
|
||||
int dgvHeightMax = screenHeightMax - (Height - dgv.Height);
|
||||
|
||||
if (dgvHeightMax > Properties.Settings.Default.MaximumMenuHeight)
|
||||
{
|
||||
|
|
|
@ -20,8 +20,6 @@ namespace SystemTrayMenu.Utilities
|
|||
/// <param name="dgv">datagridview.</param>
|
||||
internal static void FastAutoSizeColumns(this DataGridView dgv)
|
||||
{
|
||||
System.Collections.Generic.IEnumerable<DataGridViewRow> rows =
|
||||
dgv.Rows.Cast<DataGridViewRow>();
|
||||
using Graphics gfx = dgv.CreateGraphics();
|
||||
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
||||
float widthMax = WidthMin;
|
||||
|
|
Loading…
Reference in New Issue