From 2fe4fa4592523a4a4d70c0ae8b49c9bc84cfe5b1 Mon Sep 17 00:00:00 2001 From: JFronny <33260128+jfronny@users.noreply.github.com> Date: Sun, 14 Feb 2021 16:29:09 +0100 Subject: [PATCH] Implement queue management UI and app upload for eto --- UpToolEto/UpToolEto/Controls/AppControls.cs | 41 +++++++++++++++-- UpToolEto/UpToolEto/Controls/AppList.cs | 5 +- .../Controls/AppListSearchProvider.cs | 2 +- UpToolEto/UpToolEto/Controls/AppPanel.cs | 21 +++++++-- UpToolEto/UpToolEto/Controls/UTMenuBar.cs | 27 +++++++++-- UpToolEto/UpToolEto/Forms/DownloadDialog.cs | 9 ++-- UpToolEto/UpToolEto/Forms/MainForm.cs | 8 ++-- UpToolEto/UpToolEto/Forms/QueueOverview.cs | 46 +++++++++++++++++++ UpToolEto/UpToolEto/Forms/RepoForm.cs | 2 +- UpToolEto/UpToolEto/Forms/StringDialog.cs | 20 ++++++++ UpToolEto/UpToolEto/UTLibFunctions.cs | 2 +- 11 files changed, 159 insertions(+), 24 deletions(-) create mode 100644 UpToolEto/UpToolEto/Forms/QueueOverview.cs create mode 100644 UpToolEto/UpToolEto/Forms/StringDialog.cs diff --git a/UpToolEto/UpToolEto/Controls/AppControls.cs b/UpToolEto/UpToolEto/Controls/AppControls.cs index a45629c..729cd8a 100644 --- a/UpToolEto/UpToolEto/Controls/AppControls.cs +++ b/UpToolEto/UpToolEto/Controls/AppControls.cs @@ -1,6 +1,9 @@ +using System; using System.Collections.Generic; +using System.Linq; using Eto.Drawing; using Eto.Forms; +using UpToolEto.Forms; using UpToolLib.DataStructures; using UpToolLib.v2; using UpToolLib.v2.TaskQueue; @@ -9,9 +12,12 @@ namespace UpToolEto.Controls { public class AppControls : StackLayout { + private readonly IList _tasks; private readonly List _buttons; - public AppControls(TaskFactory factory, IList tasks) + private readonly Button _applyButton; + public AppControls(TaskFactory factory, IList tasks, IExternalFunctionality platform, Action update) { + _tasks = tasks; _buttons = new List { new AppControlButton("Install", factory.CreateInstall, tasks, ReloadState, @@ -21,7 +27,37 @@ namespace UpToolEto.Controls new AppControlButton("Remove", factory.CreateRemove, tasks, ReloadState, app => app.Status.Contains(Status.Installed)) }; + _applyButton = new Button((_, _) => + { + try + { + QueueOverview overview = new(tasks); + overview.ShowModal(); + if (!overview.Cancelled) + { + foreach (AppTask task in overview.TasksResulting) + { + task.Run(); + _tasks.RemoveAt(0); + } + } + } + catch (Exception e) + { + platform.OkDialog("Failed to complete queue:\r\n" + e); + } + finally + { + ReloadState(); + update(); + } + }) + { + Text = "Apply", + Enabled = false + }; foreach (AppControlButton button in _buttons) Items.Add(button); + Items.Add(new StackLayoutItem(_applyButton, HorizontalAlignment.Right)); if (Main.DebugColors) BackgroundColor = Colors.Yellow; Orientation = Orientation.Horizontal; @@ -29,20 +65,19 @@ namespace UpToolEto.Controls public void SetApp(App app) { - Visible = true; foreach (AppControlButton button in _buttons) button.SetApp(app); ReloadState(); } public void Clear() { - Visible = false; foreach (AppControlButton button in _buttons) button.Clear(); } private void ReloadState() { foreach (AppControlButton button in _buttons) button.ReloadState(); + _applyButton.Enabled = _tasks.Any(); } } } diff --git a/UpToolEto/UpToolEto/Controls/AppList.cs b/UpToolEto/UpToolEto/Controls/AppList.cs index 15863d6..c9ae3b0 100644 --- a/UpToolEto/UpToolEto/Controls/AppList.cs +++ b/UpToolEto/UpToolEto/Controls/AppList.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; +using System.Linq; using Eto.Drawing; using Eto.Forms; +using UpToolEto.Forms; using UpToolLib.v1.Tool; using UpToolLib.v2; +using UpToolLib.v2.TaskQueue; namespace UpToolEto.Controls { @@ -14,7 +17,7 @@ namespace UpToolEto.Controls private readonly StackLayout _layout; private readonly AppListSearchProvider _searchProvider; - public AppList(AppExtras extras, Action itemClickEvent, bool online) + public AppList(AppExtras extras, Action itemClickEvent, bool online, TaskFactory factory, IList tasks) { _extras = extras; _itemClickEvent = itemClickEvent; diff --git a/UpToolEto/UpToolEto/Controls/AppListSearchProvider.cs b/UpToolEto/UpToolEto/Controls/AppListSearchProvider.cs index b164f95..b0da0f8 100644 --- a/UpToolEto/UpToolEto/Controls/AppListSearchProvider.cs +++ b/UpToolEto/UpToolEto/Controls/AppListSearchProvider.cs @@ -3,7 +3,6 @@ using Eto.Forms; using UpToolLib.DataStructures; using UpToolLib.v2; -//TODO implement namespace UpToolEto.Controls { public class AppListSearchProvider : StackLayout @@ -11,6 +10,7 @@ namespace UpToolEto.Controls private readonly bool _online; private readonly TextBox _search; private readonly EnumDropDown _state; + public AppListSearchProvider(bool online, Action refresh) { _online = online; diff --git a/UpToolEto/UpToolEto/Controls/AppPanel.cs b/UpToolEto/UpToolEto/Controls/AppPanel.cs index 51082e5..7aead14 100644 --- a/UpToolEto/UpToolEto/Controls/AppPanel.cs +++ b/UpToolEto/UpToolEto/Controls/AppPanel.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Eto.Drawing; using Eto.Forms; @@ -14,12 +15,26 @@ namespace UpToolEto.Controls private readonly Label _appDescriptionLabel; private readonly AppControls _appControls; private App _app; - public AppPanel(TaskFactory factory, AppExtras extras, IList tasks) + public AppPanel(TaskFactory factory, AppExtras extras, IList tasks, IExternalFunctionality platform, Action updateAppList) { _appDescriptionLabel = new Label(); - _appNameLabel = new Button((_, _) => extras.RunApp(_app)); + _appNameLabel = new Button((_, _) => + { + try + { + extras.RunApp(_app); + } + catch (Exception e) + { + platform.OkDialog("Failed to start\r\n" + e); + } + }); _appNameLabel.Font = new Font(_appNameLabel.Font.Family, _appNameLabel.Font.Size * 2); - _appControls = new AppControls(factory, tasks); + _appControls = new AppControls(factory, tasks, platform, () => + { + updateAppList(); + SetApp(_app); + }); Content = new StackLayout { Items = diff --git a/UpToolEto/UpToolEto/Controls/UTMenuBar.cs b/UpToolEto/UpToolEto/Controls/UTMenuBar.cs index 9b8fbbc..bcab04f 100644 --- a/UpToolEto/UpToolEto/Controls/UTMenuBar.cs +++ b/UpToolEto/UpToolEto/Controls/UTMenuBar.cs @@ -1,13 +1,16 @@ +using System.Collections.Generic; +using System.Linq; using Eto.Forms; using UpToolEto.Forms; using UpToolLib.DataStructures; using UpToolLib.v2; +using UpToolLib.v2.TaskQueue; namespace UpToolEto.Controls { public class UTMenuBar : MenuBar { - public UTMenuBar(MainForm mainForm, RepoManagement repoManagement, AppList appList, IExternalFunctionality platform) + public UTMenuBar(MainForm mainForm, RepoManagement repoManagement, TaskFactory factory, IList tasks, AppList appList, IExternalFunctionality platform) { Command reloadRepos = new() {MenuText = "Reload", ToolBarText = "Reload"}; reloadRepos.Executed += (_, _) => @@ -20,8 +23,23 @@ namespace UpToolEto.Controls } }; - Command openSettings = new() {MenuText = "Sources", ToolBarText = "Sources"}; - openSettings.Executed += (_, _) => new RepoForm(repoManagement).Show(); + Command editSources = new() {MenuText = "Sources", ToolBarText = "Sources"}; + editSources.Executed += (_, _) => new RepoForm(repoManagement).ShowModal(); + + Command addPackage = new() {MenuText = "Add Package", ToolBarText = "Add Package"}; + addPackage.Executed += (_, _) => + { + OpenFileDialog dialog = new() {MultiSelect = false, CheckFileExists = true, Filters = { new FileFilter("App package", ".zip")}}; + if (dialog.ShowDialog(mainForm) == DialogResult.Ok) + { + if (!tasks.Any(s => s is UploadTask t && t.ZipFile == dialog.FileName)) + { + StringDialog sd = new("Package name") {Text = "New package"}; + sd.ShowModal(); + tasks.Add(factory.CreateUpload(dialog.FileName, sd.Text)); + } + } + }; Command quitCommand = new() {MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q}; quitCommand.Executed += (_, _) => Application.Instance.Quit(); @@ -34,7 +52,8 @@ namespace UpToolEto.Controls Text = "&File", Items = { reloadRepos, - openSettings + editSources, + addPackage } }); // File submenu diff --git a/UpToolEto/UpToolEto/Forms/DownloadDialog.cs b/UpToolEto/UpToolEto/Forms/DownloadDialog.cs index 3c617a5..895659b 100644 --- a/UpToolEto/UpToolEto/Forms/DownloadDialog.cs +++ b/UpToolEto/UpToolEto/Forms/DownloadDialog.cs @@ -7,7 +7,7 @@ using UpToolLib.DataStructures; namespace UpToolEto.Forms { - public class DownloadDialog : Form + public class DownloadDialog : Dialog { private readonly Uri _url; private readonly Application _application; @@ -47,12 +47,11 @@ namespace UpToolEto.Forms try { WebClient client = new(); - client.DownloadProgressChanged += (_, args) => + client.DownloadProgressChanged += (_, args) => _application.Invoke(() => { - _platform.Log($"{args.BytesReceived}/{args.TotalBytesToReceive}"); - _application.Invoke(() => _bar.Value = args.ProgressPercentage); + _bar.Value = args.ProgressPercentage; _application.RunIteration(); - }; + }); client.DownloadDataCompleted += (_, args) => { CurrentState = State.Success; diff --git a/UpToolEto/UpToolEto/Forms/MainForm.cs b/UpToolEto/UpToolEto/Forms/MainForm.cs index 93745ff..6ac08fe 100644 --- a/UpToolEto/UpToolEto/Forms/MainForm.cs +++ b/UpToolEto/UpToolEto/Forms/MainForm.cs @@ -6,8 +6,6 @@ using UpToolLib; using UpToolLib.DataStructures; using UpToolLib.v2.TaskQueue; -//TODO implement tasks queue UI and add control to execute queue, also needs to clear AppPanel and reload AppList -//TODO add control_upload namespace UpToolEto.Forms { public partial class MainForm : Form @@ -19,8 +17,8 @@ namespace UpToolEto.Forms _tasks = new List(); Title = "UpTool2"; MinimumSize = new Size(600, 100); - AppList appList = new(lib.V1.AppExtras, (_, app) => _appPanel.SetApp(app), online); - _appPanel = new AppPanel(lib.V2.TaskFactory, lib.V1.AppExtras, _tasks); + AppList appList = new(lib.V1.AppExtras, (_, app) => _appPanel.SetApp(app), online, lib.V2.TaskFactory, _tasks); + _appPanel = new AppPanel(lib.V2.TaskFactory, lib.V1.AppExtras, _tasks, platform, appList.Update); Content = new StackLayout { @@ -32,7 +30,7 @@ namespace UpToolEto.Forms }, Orientation = Orientation.Horizontal }; - Menu = new UTMenuBar(this, lib.V2.RepoManagement, appList, platform); + Menu = new UTMenuBar(this, lib.V2.RepoManagement, lib.V2.TaskFactory, _tasks, appList, platform); Shown += (_, _) => init.Close(); } } diff --git a/UpToolEto/UpToolEto/Forms/QueueOverview.cs b/UpToolEto/UpToolEto/Forms/QueueOverview.cs new file mode 100644 index 0000000..8890074 --- /dev/null +++ b/UpToolEto/UpToolEto/Forms/QueueOverview.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Linq; +using Eto.Forms; +using UpToolLib.v2.TaskQueue; + +namespace UpToolEto.Forms +{ + public class QueueOverview : Dialog + { + private readonly IList _tasks; + public bool Cancelled; + CheckBoxList cbl; + public List TasksResulting => cbl.SelectedValues.Select(s => (AppTask) s).ToList(); + + public QueueOverview(IList tasks) + { + _tasks = tasks; + StackLayout layout = new(); + layout.Items.Add(new StackLayoutItem(new StackLayout() + { + Items = + { + new StackLayoutItem(new Button((_, _) => + { + Cancelled = true; + Close(); + }) + { + Text = "Cancel" + }, HorizontalAlignment.Stretch), + new StackLayoutItem(new Button((_, _) => + { + Close(); + }) + { + Text = "OK" + }, HorizontalAlignment.Stretch) + }, + Orientation = Orientation.Horizontal + }, HorizontalAlignment.Stretch)); + cbl = new CheckBoxList {DataStore = tasks, SelectedValues = tasks}; + layout.Items.Add(cbl); + Content = layout; + } + } +} diff --git a/UpToolEto/UpToolEto/Forms/RepoForm.cs b/UpToolEto/UpToolEto/Forms/RepoForm.cs index d6446b3..1b5bb45 100644 --- a/UpToolEto/UpToolEto/Forms/RepoForm.cs +++ b/UpToolEto/UpToolEto/Forms/RepoForm.cs @@ -7,7 +7,7 @@ using UpToolLib.v2; namespace UpToolEto.Forms { - public class RepoForm : Form + public class RepoForm : Dialog { private readonly RepoManagement _management; private List _repos = new(); diff --git a/UpToolEto/UpToolEto/Forms/StringDialog.cs b/UpToolEto/UpToolEto/Forms/StringDialog.cs new file mode 100644 index 0000000..9976419 --- /dev/null +++ b/UpToolEto/UpToolEto/Forms/StringDialog.cs @@ -0,0 +1,20 @@ +using Eto.Forms; + +namespace UpToolEto.Forms +{ + public class StringDialog : Dialog + { + private readonly TextBox _tb; + public string Text + { + get => _tb.Text; + set => _tb.Text = value; + } + public StringDialog(string title) + { + _tb = new TextBox(); + Content = _tb; + Title = title; + } + } +} \ No newline at end of file diff --git a/UpToolEto/UpToolEto/UTLibFunctions.cs b/UpToolEto/UpToolEto/UTLibFunctions.cs index 9c5106b..8e7bfe5 100644 --- a/UpToolEto/UpToolEto/UTLibFunctions.cs +++ b/UpToolEto/UpToolEto/UTLibFunctions.cs @@ -17,7 +17,7 @@ namespace UpToolEto public Tuple Download(Uri link) { DownloadDialog dlg = new(link, _application, this); - _application.AsyncInvoke(() => dlg.Show()); + _application.AsyncInvoke(() => dlg.ShowModal()); dlg.StartDownload(); Log("Downloading " + link); while (dlg.CurrentState == DownloadDialog.State.Downloading) Thread.Sleep(20);