Skip to content

Commit

Permalink
feature: updated the library filter to not clear the directory listin…
Browse files Browse the repository at this point in the history
…g and switch folders.
  • Loading branch information
MetalHexx committed Mar 9, 2024
1 parent b0a1fbe commit 5b34bd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,21 @@ public static string[] ToPathArray(this string path)
}
return path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
}

public static string GetCommonBasePath(this IEnumerable<string> directories)
{
if (!directories.Any()) return string.Empty;

string commonPath = directories.First();

foreach (string path in directories)
{
while (!path.StartsWith(commonPath, StringComparison.OrdinalIgnoreCase))
{
commonPath = commonPath.Substring(0, commonPath.LastIndexOf(Path.DirectorySeparatorChar));
}
}
return commonPath;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,14 @@ public async Task LoadDirectory(string path, string? filePathToSelect = null)

_directoryState.Value.ClearSelection();
_directoryState.Value.LoadDirectory(cacheItem.ToList(), cacheItem.Path, filePathToSelect);
_currentPath = cacheItem.Path;

_currentPath = cacheItem.Path;

Application.Current.Dispatcher.Invoke(() =>
{
_tree.Insert(cacheItem.Directories);
_tree.SelectDirectory(cacheItem.Path);
});

_directoryState.OnNext(_directoryState.Value);
}
public Task RefreshDirectory(bool bustCache = true)
Expand Down Expand Up @@ -374,9 +373,7 @@ public virtual Unit SetPageSize(int pageSize)
public Task SwitchLibrary(TeensyLibrary library)
{
_currentLibrary = library;
_directoryState.Value.ClearSelection();
_tree.ResetDirectoryTree(library.Path);
return LoadDirectory(library.Path);
return Task.CompletedTask;
}

public TeensyFileType[] GetFileTypes()
Expand All @@ -394,7 +391,7 @@ public TeensyFileType[] GetFileTypes()

public async Task StoreFiles(IEnumerable<FileCopyItem> files)
{
var commonParent = GetCommonBasePath(files.Select(i => i.Path));
var commonParent = files.Select(i => i.Path).GetCommonBasePath();
var directoryOnly = files.All(i => i.InSubdirectory);

foreach (var file in files)
Expand All @@ -417,24 +414,6 @@ public async Task StoreFiles(IEnumerable<FileCopyItem> files)
await _storage.SaveFile(fileInfo);
}
await RefreshDirectory(bustCache: false);
}

private static string GetCommonBasePath(IEnumerable<string> directories)
{
if (!directories.Any()) return string.Empty;

string commonPath = directories.First();

foreach (string path in directories)
{
while (!path.StartsWith(commonPath, StringComparison.OrdinalIgnoreCase))
{
commonPath = commonPath.Substring(0, commonPath.LastIndexOf(Path.DirectorySeparatorChar));
}
}
return commonPath;
}


}
}
}

0 comments on commit 5b34bd7

Please sign in to comment.