From 414235ecdd65b4abd651e94d0d4a7d9258c17cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Fri, 7 Jan 2022 11:41:30 +0100 Subject: [PATCH] Rename Pane to Tab --- .../{Pane/PaneItem.cs => Tab/TabItem.cs} | 6 +- .../{Pane/PaneState.cs => Tab/TabState.cs} | 34 ++++---- .../Application.CommandHandlers.cs | 78 +++++++++---------- src/FileTime.ConsoleUI.App/Application.cs | 26 +++---- .../Command/Commands.cs | 2 +- src/FileTime.ConsoleUI.App/UI/Render.cs | 48 ++++++------ .../Components/{Pane.cs => Tab.cs} | 4 +- 7 files changed, 99 insertions(+), 99 deletions(-) rename src/FileTime.App.Core/{Pane/PaneItem.cs => Tab/TabItem.cs} (64%) rename src/FileTime.App.Core/{Pane/PaneState.cs => Tab/TabState.cs} (64%) rename src/FileTime.Core/Components/{Pane.cs => Tab.cs} (98%) diff --git a/src/FileTime.App.Core/Pane/PaneItem.cs b/src/FileTime.App.Core/Tab/TabItem.cs similarity index 64% rename from src/FileTime.App.Core/Pane/PaneItem.cs rename to src/FileTime.App.Core/Tab/TabItem.cs index 85de585..b98cda9 100644 --- a/src/FileTime.App.Core/Pane/PaneItem.cs +++ b/src/FileTime.App.Core/Tab/TabItem.cs @@ -1,14 +1,14 @@ using FileTime.Core.Models; using FileTime.Core.Providers; -namespace FileTime.App.Core.Pane +namespace FileTime.App.Core.Tab { - public class PaneItem : IAbsolutePath + public class TabItem : IAbsolutePath { public IContentProvider ContentProvider { get; } public string Path { get; } - public PaneItem(IContentProvider contentProvider, string path) + public TabItem(IContentProvider contentProvider, string path) { ContentProvider = contentProvider; Path = path; diff --git a/src/FileTime.App.Core/Pane/PaneState.cs b/src/FileTime.App.Core/Tab/TabState.cs similarity index 64% rename from src/FileTime.App.Core/Pane/PaneState.cs rename to src/FileTime.App.Core/Tab/TabState.cs index 37c3e95..a16f7ae 100644 --- a/src/FileTime.App.Core/Pane/PaneState.cs +++ b/src/FileTime.App.Core/Tab/TabState.cs @@ -2,30 +2,30 @@ using System.Collections.ObjectModel; using FileTime.Core.Models; using FileTime.Core.Providers; -namespace FileTime.App.Core.Pane +namespace FileTime.App.Core.Tab { - public class PaneState + public class TabState { - private readonly Dictionary> _selectedItems; - private readonly Dictionary> _selectedItemsReadOnly; - public IReadOnlyDictionary> SelectedItems { get; } + private readonly Dictionary> _selectedItems; + private readonly Dictionary> _selectedItemsReadOnly; + public IReadOnlyDictionary> SelectedItems { get; } - public FileTime.Core.Components.Pane Pane { get; } + public FileTime.Core.Components.Tab Tab { get; } - public PaneState(FileTime.Core.Components.Pane pane) + public TabState(FileTime.Core.Components.Tab pane) { - Pane = pane; + Tab = pane; - _selectedItems = new Dictionary>(); - _selectedItemsReadOnly = new Dictionary>(); - SelectedItems = new ReadOnlyDictionary>(_selectedItemsReadOnly); + _selectedItems = new Dictionary>(); + _selectedItemsReadOnly = new Dictionary>(); + SelectedItems = new ReadOnlyDictionary>(_selectedItemsReadOnly); } public void AddSelectedItem(IContentProvider contentProvider, IContainer container, string path) { if (!_selectedItems.ContainsKey(container)) { - var val = new List(); + var val = new List(); _selectedItems.Add(container, val); _selectedItemsReadOnly.Add(container, val.AsReadOnly()); } @@ -35,7 +35,7 @@ namespace FileTime.App.Core.Pane if (content.ContentProvider == contentProvider && content.Path == path) return; } - _selectedItems[container].Add(new PaneItem(contentProvider, path)); + _selectedItems[container].Add(new TabItem(contentProvider, path)); } public void RemoveSelectedItem(IContentProvider contentProvider, IContainer container, string path) @@ -65,9 +65,9 @@ namespace FileTime.App.Core.Pane return false; } - public IReadOnlyList GetCurrentSelectedItems() => - SelectedItems.ContainsKey(Pane.CurrentLocation) - ? SelectedItems[Pane.CurrentLocation] - : new List().AsReadOnly(); + public IReadOnlyList GetCurrentSelectedItems() => + SelectedItems.ContainsKey(Tab.CurrentLocation) + ? SelectedItems[Tab.CurrentLocation] + : new List().AsReadOnly(); } } \ No newline at end of file diff --git a/src/FileTime.ConsoleUI.App/Application.CommandHandlers.cs b/src/FileTime.ConsoleUI.App/Application.CommandHandlers.cs index fca57c2..31ac03f 100644 --- a/src/FileTime.ConsoleUI.App/Application.CommandHandlers.cs +++ b/src/FileTime.ConsoleUI.App/Application.CommandHandlers.cs @@ -6,50 +6,50 @@ namespace FileTime.ConsoleUI.App { public partial class Application { - private void ClosePane() + private void CloseTab() { - var currentPaneIndex = _panes.IndexOf(_selectedPane!); - RemovePane(_selectedPane!); + var currentTabIndex = _panes.IndexOf(_selectedTab!); + RemoveTab(_selectedTab!); if (_panes.Count > 0) { - _selectedPane = _panes[currentPaneIndex == 0 ? 0 : currentPaneIndex - 1]; + _selectedTab = _panes[currentTabIndex == 0 ? 0 : currentTabIndex - 1]; } else { - _selectedPane = null; + _selectedTab = null; IsRunning = false; } } - private void MoveCursorUp() => _selectedPane!.SelectPreviousItem(); - private void MoveCursorDown() => _selectedPane!.SelectNextItem(); - private void GoUp() => _selectedPane!.GoUp(); - private void Open() => _selectedPane!.Open(); + private void MoveCursorUp() => _selectedTab!.SelectPreviousItem(); + private void MoveCursorDown() => _selectedTab!.SelectNextItem(); + private void GoUp() => _selectedTab!.GoUp(); + private void Open() => _selectedTab!.Open(); - private void MoveCursorUpPage() => _selectedPane!.SelectPreviousItem(_renderers[_selectedPane].PageSize); - private void MoveCursorDownPage() => _selectedPane!.SelectNextItem(_renderers[_selectedPane].PageSize); - private void MoveCursorToTop() => _selectedPane!.SelectFirstItem(); - private void MoveCursorToBottom() => _selectedPane!.SelectLastItem(); + private void MoveCursorUpPage() => _selectedTab!.SelectPreviousItem(_renderers[_selectedTab].PageSize); + private void MoveCursorDownPage() => _selectedTab!.SelectNextItem(_renderers[_selectedTab].PageSize); + private void MoveCursorToTop() => _selectedTab!.SelectFirstItem(); + private void MoveCursorToBottom() => _selectedTab!.SelectLastItem(); private void ToggleHidden() { const string hiddenFilterName = "filter_showhiddenelements"; - IContainer containerToOpen = _selectedPane!.CurrentLocation; + IContainer containerToOpen = _selectedTab!.CurrentLocation; - if (_selectedPane.CurrentLocation is VirtualContainer oldVirtualContainer) + if (_selectedTab.CurrentLocation is VirtualContainer oldVirtualContainer) { containerToOpen = oldVirtualContainer.HasWithName(hiddenFilterName) ? oldVirtualContainer.ExceptWithName(hiddenFilterName) - : GenerateHiddenFilterVirtualContainer(_selectedPane.CurrentLocation); + : GenerateHiddenFilterVirtualContainer(_selectedTab.CurrentLocation); } else { - containerToOpen = GenerateHiddenFilterVirtualContainer(_selectedPane.CurrentLocation); + containerToOpen = GenerateHiddenFilterVirtualContainer(_selectedTab.CurrentLocation); } - _selectedPane.OpenContainer(containerToOpen); + _selectedTab.OpenContainer(containerToOpen); static VirtualContainer GenerateHiddenFilterVirtualContainer(IContainer container) { @@ -72,19 +72,19 @@ namespace FileTime.ConsoleUI.App public void Select() { - if (_selectedPane!.CurrentSelectedItem != null) + if (_selectedTab!.CurrentSelectedItem != null) { - var currentSelectedItem = _selectedPane.CurrentSelectedItem; - if (_paneStates[_selectedPane].ContainsSelectedItem(currentSelectedItem.Provider, _selectedPane.CurrentLocation, currentSelectedItem.FullName!)) + var currentSelectedItem = _selectedTab.CurrentSelectedItem; + if (_paneStates[_selectedTab].ContainsSelectedItem(currentSelectedItem.Provider, _selectedTab.CurrentLocation, currentSelectedItem.FullName!)) { - _paneStates[_selectedPane].RemoveSelectedItem(currentSelectedItem.Provider, _selectedPane.CurrentLocation, currentSelectedItem.FullName!); + _paneStates[_selectedTab].RemoveSelectedItem(currentSelectedItem.Provider, _selectedTab.CurrentLocation, currentSelectedItem.FullName!); } else { - _paneStates[_selectedPane].AddSelectedItem(currentSelectedItem.Provider, _selectedPane.CurrentLocation, currentSelectedItem.FullName!); + _paneStates[_selectedTab].AddSelectedItem(currentSelectedItem.Provider, _selectedTab.CurrentLocation, currentSelectedItem.FullName!); } - _selectedPane.SelectNextItem(); + _selectedTab.SelectNextItem(); } } @@ -93,16 +93,16 @@ namespace FileTime.ConsoleUI.App _clipboard.Clear(); _clipboard.SetCommand(); - if (_paneStates[_selectedPane!].GetCurrentSelectedItems().Count > 0) + if (_paneStates[_selectedTab!].GetCurrentSelectedItems().Count > 0) { - foreach (var selectedItem in _paneStates[_selectedPane!].GetCurrentSelectedItems()) + foreach (var selectedItem in _paneStates[_selectedTab!].GetCurrentSelectedItems()) { _clipboard.AddContent(selectedItem.ContentProvider, selectedItem.Path); } } else { - _clipboard.AddContent(_selectedPane!.CurrentSelectedItem!.Provider, _selectedPane.CurrentSelectedItem.FullName!); + _clipboard.AddContent(_selectedTab!.CurrentSelectedItem!.Provider, _selectedTab.CurrentSelectedItem.FullName!); } } @@ -140,9 +140,9 @@ namespace FileTime.ConsoleUI.App command.Sources.Add(item); } - command.Target = _selectedPane.CurrentLocation is VirtualContainer virtualContainer + command.Target = _selectedTab.CurrentLocation is VirtualContainer virtualContainer ? virtualContainer.BaseContainer - : _selectedPane.CurrentLocation; + : _selectedTab.CurrentLocation; _commandExecutor.ExecuteCommand(command); @@ -152,7 +152,7 @@ namespace FileTime.ConsoleUI.App private void CreateContainer() { - if (_selectedPane?.CurrentLocation != null) + if (_selectedTab?.CurrentLocation != null) { _coloredConsoleRenderer.ResetColor(); MoveToIOLine(2); @@ -161,13 +161,13 @@ namespace FileTime.ConsoleUI.App if (!string.IsNullOrWhiteSpace(newContainerName)) { - _selectedPane.CurrentLocation.CreateContainer(newContainerName); + _selectedTab.CurrentLocation.CreateContainer(newContainerName); } } void Validator(string newPath) { - if (_selectedPane!.CurrentLocation.IsExists(newPath)) + if (_selectedTab!.CurrentLocation.IsExists(newPath)) { _coloredConsoleRenderer.ForegroundColor = _styles.ErrorColor; } @@ -182,12 +182,12 @@ namespace FileTime.ConsoleUI.App { IList itemsToDelete = null; - if (_paneStates[_selectedPane!].GetCurrentSelectedItems().Count > 0) + if (_paneStates[_selectedTab!].GetCurrentSelectedItems().Count > 0) { var delete = true; - if (_paneStates[_selectedPane!].GetCurrentSelectedItems().Count == 1 - && _paneStates[_selectedPane!].GetCurrentSelectedItems()[0] is IContainer container + if (_paneStates[_selectedTab!].GetCurrentSelectedItems().Count == 1 + && _paneStates[_selectedTab!].GetCurrentSelectedItems()[0] is IContainer container && container.Items.Count > 0) { delete = AskForApprove($"The container '{container.Name}' is not empty."); @@ -195,13 +195,13 @@ namespace FileTime.ConsoleUI.App if (delete) { - itemsToDelete = _paneStates[_selectedPane].GetCurrentSelectedItems().Cast().ToList(); + itemsToDelete = _paneStates[_selectedTab].GetCurrentSelectedItems().Cast().ToList(); } } - else if (_selectedPane?.CurrentSelectedItem != null) + else if (_selectedTab?.CurrentSelectedItem != null) { bool delete = true; - if (_selectedPane?.CurrentSelectedItem is IContainer container && container.Items.Count > 0) + if (_selectedTab?.CurrentSelectedItem is IContainer container && container.Items.Count > 0) { delete = AskForApprove($"The container '{container.Name}' is not empty."); } @@ -210,7 +210,7 @@ namespace FileTime.ConsoleUI.App { itemsToDelete = new List() { - new AbsolutePath(_selectedPane.CurrentSelectedItem.Provider, _selectedPane.CurrentSelectedItem.FullName!) + new AbsolutePath(_selectedTab.CurrentSelectedItem.Provider, _selectedTab.CurrentSelectedItem.FullName!) }; } } diff --git a/src/FileTime.ConsoleUI.App/Application.cs b/src/FileTime.ConsoleUI.App/Application.cs index 0f48187..21a3b44 100644 --- a/src/FileTime.ConsoleUI.App/Application.cs +++ b/src/FileTime.ConsoleUI.App/Application.cs @@ -6,7 +6,7 @@ using FileTime.Core.Extensions; using FileTime.App.Core.Clipboard; using Microsoft.Extensions.DependencyInjection; -using FileTime.App.Core.Pane; +using FileTime.App.Core.Tab; using FileTime.ConsoleUI.App.UI.Color; using FileTime.Core.Command; @@ -14,10 +14,10 @@ namespace FileTime.ConsoleUI.App { public partial class Application { - private readonly List _panes = new(); - private readonly Dictionary _renderers = new(); - private readonly Dictionary _paneStates = new(); - private Pane? _selectedPane; + private readonly List _panes = new(); + private readonly Dictionary _renderers = new(); + private readonly Dictionary _paneStates = new(); + private Tab? _selectedTab; private readonly List _commandBindings = new(); private readonly IServiceProvider _serviceProvider; @@ -49,15 +49,15 @@ namespace FileTime.ConsoleUI.App public void SetContainer(IContainer currentPath) { - _selectedPane = CreatePane(currentPath); + _selectedTab = CreateTab(currentPath); } - private Pane CreatePane(IContainer container) + private Tab CreateTab(IContainer container) { - var pane = new Pane(container); + var pane = new Tab(container); _panes.Add(pane); - var paneState = new PaneState(pane); + var paneState = new TabState(pane); _paneStates.Add(pane, paneState); var renderer = _serviceProvider.GetService()!; @@ -67,7 +67,7 @@ namespace FileTime.ConsoleUI.App return pane; } - private void RemovePane(Pane pane) + private void RemoveTab(Tab pane) { _panes.Remove(pane); _renderers.Remove(pane); @@ -78,7 +78,7 @@ namespace FileTime.ConsoleUI.App { var commandBindings = new List() { - new CommandBinding("close pane", Commands.ClosePane, new[] { new ConsoleKeyInfo('q', ConsoleKey.Q, false, false, false) }, ClosePane), + new CommandBinding("close pane", Commands.CloseTab, new[] { new ConsoleKeyInfo('q', ConsoleKey.Q, false, false, false) }, CloseTab), new CommandBinding("cursor up", Commands.MoveCursorUp, new[] { new ConsoleKeyInfo('↑', ConsoleKey.UpArrow, false, false, false) }, MoveCursorUp), new CommandBinding("cursor down", Commands.MoveCursorDown, new[] { new ConsoleKeyInfo('↓', ConsoleKey.DownArrow, false, false, false) }, MoveCursorDown), new CommandBinding("cursor page up", Commands.MoveCursorUpPage, new[] { new ConsoleKeyInfo(' ', ConsoleKey.PageUp, false, false, false) }, MoveCursorUpPage), @@ -182,9 +182,9 @@ namespace FileTime.ConsoleUI.App public void PrintUI() { - if (_selectedPane != null) + if (_selectedTab != null) { - _renderers[_selectedPane].PrintUI(); + _renderers[_selectedTab].PrintUI(); } } diff --git a/src/FileTime.ConsoleUI.App/Command/Commands.cs b/src/FileTime.ConsoleUI.App/Command/Commands.cs index b28dc4c..8c60be2 100644 --- a/src/FileTime.ConsoleUI.App/Command/Commands.cs +++ b/src/FileTime.ConsoleUI.App/Command/Commands.cs @@ -2,7 +2,7 @@ namespace FileTime.ConsoleUI.App.Command { public enum Commands { - ClosePane, + CloseTab, Copy, Cut, GoUp, diff --git a/src/FileTime.ConsoleUI.App/UI/Render.cs b/src/FileTime.ConsoleUI.App/UI/Render.cs index 5c96df3..d9048e4 100644 --- a/src/FileTime.ConsoleUI.App/UI/Render.cs +++ b/src/FileTime.ConsoleUI.App/UI/Render.cs @@ -1,4 +1,4 @@ -using FileTime.App.Core.Pane; +using FileTime.App.Core.Tab; using FileTime.ConsoleUI.App.UI.Color; using FileTime.ConsoleUI.UI.App; using FileTime.Core.Components; @@ -23,8 +23,8 @@ namespace FileTime.ConsoleUI.App.UI private readonly string _paddingLeft; private readonly string _paddingRight; - public Pane Pane { get; private set; } - public PaneState PaneState { get; private set; } + public Tab Tab { get; private set; } + public TabState TabState { get; private set; } public int PageSize => Console.WindowHeight - _contentPaddingTop - _contentPaddingBottom; public Render(IColoredConsoleRenderer coloredRenderer, IStyles appStyle) @@ -37,34 +37,34 @@ namespace FileTime.ConsoleUI.App.UI _contentRowCount = Console.WindowHeight - _contentPaddingTop - _contentPaddingBottom; } - public void Init(Pane pane, PaneState paneState) + public void Init(Tab pane, TabState paneState) { if (pane == null) throw new Exception($"{nameof(pane)} can not be null"); if (paneState == null) throw new Exception($"{nameof(paneState)} can not be null"); - Pane = pane; - Pane.CurrentLocationChanged += (o, e) => _currentDisplayStartY = 0; + Tab = pane; + Tab.CurrentLocationChanged += (o, e) => _currentDisplayStartY = 0; - PaneState = paneState; + TabState = paneState; } public void PrintUI() { - if (Pane != null) + if (Tab != null) { PrintPrompt(); - PrintPanes(); + PrintTabs(); } } - private void PrintPanes() + private void PrintTabs() { var previousColumnWidth = (int)Math.Floor(Console.WindowWidth * 0.15) - 1; var currentColumnWidth = (int)Math.Floor(Console.WindowWidth * 0.4) - 1; var nextColumnWidth = Console.WindowWidth - currentColumnWidth - previousColumnWidth - 2; - var currentVirtualContainer = Pane!.CurrentLocation as VirtualContainer; + var currentVirtualContainer = Tab!.CurrentLocation as VirtualContainer; - if (Pane.CurrentLocation.GetParent() is var parentContainer && parentContainer is not null) + if (Tab.CurrentLocation.GetParent() is var parentContainer && parentContainer is not null) { parentContainer.Refresh(); @@ -74,7 +74,7 @@ namespace FileTime.ConsoleUI.App.UI : parentContainer, currentVirtualContainer != null ? currentVirtualContainer.GetRealContainer() - : Pane.CurrentLocation, + : Tab.CurrentLocation, PrintMode.Previous, 0, _contentPaddingTop, @@ -90,19 +90,19 @@ namespace FileTime.ConsoleUI.App.UI _contentRowCount); } - Pane.CurrentLocation.Refresh(); + Tab.CurrentLocation.Refresh(); CheckAndSetCurrentDisplayStartY(); PrintColumn( - Pane.CurrentLocation, - Pane.CurrentSelectedItem, + Tab.CurrentLocation, + Tab.CurrentSelectedItem, PrintMode.Current, previousColumnWidth + 1, _contentPaddingTop, currentColumnWidth, _contentRowCount); - if (Pane.CurrentSelectedItem is IContainer selectedContainer) + if (Tab.CurrentSelectedItem is IContainer selectedContainer) { selectedContainer.Refresh(); @@ -140,13 +140,13 @@ namespace FileTime.ConsoleUI.App.UI _coloredRenderer.Write(' '); _coloredRenderer.ForegroundColor = _appStyle.ContainerForeground; - var path = Pane!.CurrentLocation.FullName + "/"; + var path = Tab!.CurrentLocation.FullName + "/"; _coloredRenderer.Write(path); - if (Pane.CurrentSelectedItem?.Name != null) + if (Tab.CurrentSelectedItem?.Name != null) { _coloredRenderer.ResetColor(); - _coloredRenderer.Write($"{{0,-{300 - path.Length}}}", Pane.CurrentSelectedItem.Name); + _coloredRenderer.Write($"{{0,-{300 - path.Length}}}", Tab.CurrentSelectedItem.Name); } } @@ -205,7 +205,7 @@ namespace FileTime.ConsoleUI.App.UI } } - var isSelected = PaneState.ContainsSelectedItem(item.Provider, currentContainer, item.FullName!); + var isSelected = TabState.ContainsSelectedItem(item.Provider, currentContainer, item.FullName!); if (isSelected) { backgroundColor = _appStyle.SelectedItemBackground; @@ -266,14 +266,14 @@ namespace FileTime.ConsoleUI.App.UI { const int padding = 5; - while (Pane.CurrentSelectedIndex < _currentDisplayStartY + padding + while (Tab.CurrentSelectedIndex < _currentDisplayStartY + padding && _currentDisplayStartY > 0) { _currentDisplayStartY--; } - while (Pane.CurrentSelectedIndex > _currentDisplayStartY + _contentRowCount - padding - && _currentDisplayStartY < Pane.CurrentLocation.Items.Count - _contentRowCount) + while (Tab.CurrentSelectedIndex > _currentDisplayStartY + _contentRowCount - padding + && _currentDisplayStartY < Tab.CurrentLocation.Items.Count - _contentRowCount) { _currentDisplayStartY++; } diff --git a/src/FileTime.Core/Components/Pane.cs b/src/FileTime.Core/Components/Tab.cs similarity index 98% rename from src/FileTime.Core/Components/Pane.cs rename to src/FileTime.Core/Components/Tab.cs index 500e9d1..4e0c516 100644 --- a/src/FileTime.Core/Components/Pane.cs +++ b/src/FileTime.Core/Components/Tab.cs @@ -2,7 +2,7 @@ using FileTime.Core.Models; namespace FileTime.Core.Components { - public class Pane + public class Tab { private IItem? currentSelectedItem; private IContainer currentLocation; @@ -42,7 +42,7 @@ namespace FileTime.Core.Components public event EventHandler CurrentLocationChanged; - public Pane(IContainer currentPath) + public Tab(IContainer currentPath) { CurrentLocation = currentPath; CurrentSelectedItem = CurrentLocation.Items.Count > 0 ? CurrentLocation.Items[0] : null;