diff --git a/src/Stowage.Terminal/AppTopLevel.cs b/src/Stowage.Terminal/AppTopLevel.cs index 2210be8..f8c5aad 100644 --- a/src/Stowage.Terminal/AppTopLevel.cs +++ b/src/Stowage.Terminal/AppTopLevel.cs @@ -13,21 +13,21 @@ class AppTopLevel : Toplevel { public AppTopLevel(IFileStorage fs) { _fs = fs; - ColorScheme = Colors.Base; - - MenuBar = new MenuBar(new MenuBarItem[] { - new MenuBarItem("_File", new MenuItem[] { - new MenuItem("_Quit", "", () => Application.RequestStop()), - }), - new MenuBarItem("_Help", new MenuItem[] { - new MenuItem("_About", "", () => MessageBox.Query(50, 7, "About", "Stowage.Terminal", "Ok")), - }), - }); - MenuBar.Visible = true; + //ColorScheme = Colors.Base; + + //MenuBar = new MenuBar(new MenuBarItem[] { + // new MenuBarItem("_File", new MenuItem[] { + // new MenuItem("_Quit", "", () => Application.RequestStop()), + // }), + // new MenuBarItem("_Help", new MenuItem[] { + // new MenuItem("_About", "", () => MessageBox.Query(50, 7, "About", "Stowage.Terminal", "Ok")), + // }), + //}); + //MenuBar.Visible = true; _fsView1 = new FSView(_fs) { X = 0, - Y = 1, + Y = 0, Width = Dim.Percent(50), Height = Dim.Fill() - 1 }; diff --git a/src/Stowage.Terminal/FileCopyDialog.cs b/src/Stowage.Terminal/FileCopyDialog.cs index 9b0af4a..bfd18f8 100644 --- a/src/Stowage.Terminal/FileCopyDialog.cs +++ b/src/Stowage.Terminal/FileCopyDialog.cs @@ -22,7 +22,7 @@ class FileCopyDialog { private readonly ProgressBar _progressTotal; private readonly ProgressBar _progressCurrent; private readonly Label _labelTotal; - private readonly Label _labelCurrent; + //private readonly Label _labelCurrent; private long _copiedTotal = 0; private long _sizeTotal = 0; @@ -37,7 +37,7 @@ public FileCopyDialog(View parent, FSView from, FSView to) { _cts.Cancel(); }; - _dialog = new Dialog("Copy files", width / 2, 10, cancel); + _dialog = new Dialog("Copy files", width / 2, 7, cancel); var lbl = new Label(" total: ") { X = 0, Y = 0 }; _dialog.Add(lbl); @@ -50,21 +50,24 @@ public FileCopyDialog(View parent, FSView from, FSView to) { }; _dialog.Add(_progressTotal); - _labelTotal = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) }; - _dialog.Add(_labelTotal); + //_labelTotal = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) }; + //_dialog.Add(_labelTotal); - lbl = new Label("current: ") { X = 0, Y = Pos.Bottom(_labelTotal) }; + lbl = new Label("current: ") { X = 0, Y = Pos.Bottom(lbl) }; _dialog.Add(lbl); _progressCurrent = new ProgressBar() { X = Pos.Right(lbl), - Y = Pos.Bottom(_progressTotal), + Y = 1, Width = Dim.Fill(), Height = 1 }; _dialog.Add(_progressCurrent); - _labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) }; - _dialog.Add(_labelCurrent); + //_labelCurrent = new Label("0 / 0") { X = 0, Y = Pos.Bottom(lbl) }; + //_dialog.Add(_labelCurrent); + + _labelTotal = new Label("?") { X = 0, Y = Pos.Bottom(lbl) }; + _dialog.Add(_labelTotal); } public void Start() { @@ -98,15 +101,21 @@ private async Task Copy(IFileStorage fsFrom, IFileStorage fsTo, IOPath pathFrom, byte[] buffer = ArrayPool.Shared.Rent(DefaultCopyBufferSize); try { int bytesRead; + long totalRead = 0; while((bytesRead = await streamFrom.ReadAsync(new Memory(buffer), _cts.Token)) != 0) { await streamTo.WriteAsync(new ReadOnlyMemory(buffer, 0, bytesRead), _cts.Token); - float fraction = streamFrom.Position / (float)streamFrom.Length; + + _copiedTotal += bytesRead; + totalRead += bytesRead; + float fracCurrent = totalRead / (float)streamFrom.Length; + float fracTotal = _copiedTotal / (float)_sizeTotal; + string status = $"{_copiedTotal.Bytes()} / {_sizeTotal.Bytes()}"; Application.MainLoop.Invoke(() => { - _progressCurrent.Fraction = fraction; - _copiedTotal += bytesRead; - _labelCurrent.Text = $"{streamFrom.Position.Bytes()} / {streamFrom.Length.Bytes()}"; - _labelTotal.Text = $"{_copiedTotal.Bytes()} / {_sizeTotal.Bytes()}"; + + _progressCurrent.Fraction = fracCurrent; + _progressTotal.Fraction = fracTotal; + _labelTotal.Text = status; }); } @@ -127,14 +136,8 @@ private void RunCopy() { IReadOnlyCollection sourceEntries = await Explode(_from.Fs, _from.SelectedEntry!); _sizeTotal = sourceEntries.Sum(e => e.Size!.Value); - int i = 0; foreach(IOEntry entry in sourceEntries) { - await Copy(_from.Fs, _to.Fs, entry.Path, _to.CurrentPath.Combine(entry.Path.Name)); - - Application.MainLoop.Invoke(() => { - _progressTotal.Fraction = i++ * 100.0f / sourceEntries.Count; - }); } } catch(Exception ex1) { ex = ex1; @@ -143,8 +146,10 @@ private void RunCopy() { Application.MainLoop.Invoke(() => { if(ex != null) { MessageBox.ErrorQuery(60, 10, "Error", ex.ToString(), "Ok"); + } else { + MessageBox.Query(60, 5, "Done", "Files copied.", "Ok"); + Application.RequestStop(); } - Application.RequestStop(); }); }); } diff --git a/src/Stowage.Terminal/TextFileEditorWindow.cs b/src/Stowage.Terminal/TextFileEditorWindow.cs index 23fef66..6681537 100644 --- a/src/Stowage.Terminal/TextFileEditorWindow.cs +++ b/src/Stowage.Terminal/TextFileEditorWindow.cs @@ -49,8 +49,7 @@ public TextFileEditorWindow(IFileStorage fs, IOEntry entry) : base("Quick Edit", _statusBar = new StatusBar(new StatusItem[] { new StatusItem(Key.F2, "~F2~ Save", SaveContent), _statusSize, - _statusCursorPos, - new StatusItem(Key.F10, "~F10~ Close", () => Application.RequestStop()) + _statusCursorPos }); Add(_textView);