This commit is contained in:
2022-01-20 13:36:25 +01:00
parent c2e64226a0
commit 6b1dc6724f
5 changed files with 52 additions and 20 deletions

View File

@@ -16,7 +16,12 @@ namespace FileTime.App.Core.Command
CreateElement, CreateElement,
MoveCursorUpPage, MoveCursorUpPage,
MoveCursorDownPage, MoveCursorDownPage,
GoToTop, MoveToTop,
GoToBottom, MoveToBottom,
MoveToFirst,
MoveToLast,
GoToRoot,
GoToProvider,
GoToHome,
} }
} }

View File

@@ -88,7 +88,7 @@ namespace FileTime.ConsoleUI.App
new CommandBinding("open", Commands.Open, new[] { new ConsoleKeyInfo('→', ConsoleKey.RightArrow, false, false, false) }, Open), new CommandBinding("open", Commands.Open, new[] { new ConsoleKeyInfo('→', ConsoleKey.RightArrow, false, false, false) }, Open),
new CommandBinding( new CommandBinding(
"go to top", "go to top",
Commands.GoToTop, Commands.MoveToTop,
new[] new[]
{ {
new ConsoleKeyInfo('g', ConsoleKey.G, false, false, false), new ConsoleKeyInfo('g', ConsoleKey.G, false, false, false),
@@ -97,7 +97,7 @@ namespace FileTime.ConsoleUI.App
MoveCursorToTop), MoveCursorToTop),
new CommandBinding( new CommandBinding(
"go to bottom", "go to bottom",
Commands.GoToBottom, Commands.MoveToBottom,
new[] new[]
{ {
new ConsoleKeyInfo('G', ConsoleKey.G, true, false, false) new ConsoleKeyInfo('G', ConsoleKey.G, true, false, false)
@@ -194,7 +194,7 @@ namespace FileTime.ConsoleUI.App
var key = keyinfo.Key; var key = keyinfo.Key;
_previousKeys.Add(keyinfo); _previousKeys.Add(keyinfo);
CommandBinding? selectedCommandBinding = _commandBindings.Find(c => AreKeysEqual(c.Keys, _previousKeys)); var selectedCommandBinding = _commandBindings.Find(c => AreKeysEqual(c.Keys, _previousKeys));
if (keyinfo.Key == ConsoleKey.Escape) if (keyinfo.Key == ConsoleKey.Escape)
{ {

View File

@@ -4,43 +4,45 @@ namespace FileTime.Core.Components
{ {
public class Tab public class Tab
{ {
private IItem? currentSelectedItem; private IItem? _currentSelectedItem;
private IContainer currentLocation; private IContainer _currentLocation;
public IContainer CurrentLocation public IContainer CurrentLocation
{ {
get => currentLocation; get => _currentLocation;
private set private set
{ {
if (currentLocation != value) if (_currentLocation != value)
{ {
if (currentLocation != null) if (_currentLocation != null)
{ {
currentLocation.Refreshed -= HandleCurrentLocationRefresh; _currentLocation.Refreshed -= HandleCurrentLocationRefresh;
} }
currentLocation = value; _currentLocation = value;
CurrentLocationChanged?.Invoke(this, EventArgs.Empty); CurrentLocationChanged?.Invoke(this, EventArgs.Empty);
CurrentSelectedItem = CurrentLocation.Items.Count > 0 ? CurrentLocation.Items[0] : null; CurrentSelectedItem = CurrentLocation.Items.Count > 0 ? CurrentLocation.Items[0] : null;
currentLocation.Refreshed += HandleCurrentLocationRefresh; _currentLocation.Refreshed += HandleCurrentLocationRefresh;
} }
} }
} }
public IItem? CurrentSelectedItem public IItem? CurrentSelectedItem
{ {
get => currentSelectedItem; get => _currentSelectedItem;
private set set
{ {
if (currentSelectedItem != value && (currentLocation.Items.Contains(value) || value == null)) if (_currentSelectedItem != value && (_currentLocation.Items.Contains(value) || value == null))
{ {
currentSelectedItem = value; _currentSelectedItem = value;
CurrentSelectedIndex = GetItemIndex(value); CurrentSelectedIndex = GetItemIndex(value);
CurrentSelectedItemChanged?.Invoke(this, EventArgs.Empty);
} }
} }
} }
public int CurrentSelectedIndex { get; private set; } public int CurrentSelectedIndex { get; private set; }
public event EventHandler CurrentLocationChanged; public event EventHandler CurrentLocationChanged;
public event EventHandler CurrentSelectedItemChanged;
public Tab(IContainer currentPath) public Tab(IContainer currentPath)
{ {
@@ -53,7 +55,7 @@ namespace FileTime.Core.Components
var currentSelectedName = CurrentSelectedItem?.FullName; var currentSelectedName = CurrentSelectedItem?.FullName;
if (currentSelectedName != null) if (currentSelectedName != null)
{ {
CurrentSelectedItem = CurrentLocation.Items.FirstOrDefault(i => i.FullName == currentSelectedName) ?? currentLocation.Items.FirstOrDefault(); CurrentSelectedItem = CurrentLocation.Items.FirstOrDefault(i => i.FullName == currentSelectedName) ?? _currentLocation.Items.FirstOrDefault();
} }
else if (CurrentLocation.Items.Count > 0) else if (CurrentLocation.Items.Count > 0)
{ {
@@ -120,6 +122,26 @@ namespace FileTime.Core.Components
} }
} }
public void GoToProvider()
{
if (CurrentLocation == null) return;
CurrentLocation = CurrentLocation.Provider;
}
public void GoToRoot()
{
if (CurrentLocation == null) return;
var root = CurrentLocation;
while (root!.GetParent() != null)
{
root = root.GetParent();
}
CurrentLocation = root;
}
public void GoUp() public void GoUp()
{ {
var lastCurrentLocation = CurrentLocation; var lastCurrentLocation = CurrentLocation;
@@ -142,7 +164,7 @@ namespace FileTime.Core.Components
public void Open() public void Open()
{ {
if (currentSelectedItem is IContainer childContainer) if (_currentSelectedItem is IContainer childContainer)
{ {
if (CurrentLocation is VirtualContainer currentVirtuakContainer) if (CurrentLocation is VirtualContainer currentVirtuakContainer)
{ {

View File

@@ -19,7 +19,10 @@ namespace FileTime.Providers.Local.Extensions
_ => (fileSizeD, "B") _ => (fileSizeD, "B")
}; };
return string.Format("{0:N" + precision + "}", size).TrimEnd('0').Replace(',', '.').TrimEnd('.') + " " + suffix; var result = string.Format("{0:N" + precision + "}", size).Replace(',', '.');
if (result.Contains('.')) result = result.TrimEnd('0').TrimEnd('.');
return result + " " + suffix;
} }
} }
} }

View File

@@ -10,6 +10,8 @@ namespace FileTime.Providers.Local
{ {
private readonly FileInfo _file; private readonly FileInfo _file;
public FileInfo File => _file;
public string Name { get; } public string Name { get; }
public string FullName { get; } public string FullName { get; }