This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
UpTool2/UpTool2/TaskPreview.cs

32 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using UpToolLib.v2.TaskQueue;
namespace UpTool2
{
internal static class TaskPreview
{
public static bool Show(ref List<AppTask> tasks, bool showOk)
{
bool ok = false;
using Form tmp = new Form {Size = new Size(600, 300), MinimumSize = new Size(300, showOk ? 138 : 133)};
using CheckedListBox list = new CheckedListBox {Dock = DockStyle.Fill};
using Button okButton = new Button {Dock = DockStyle.Bottom, Text = "OK"};
list.Items.AddRange(tasks.ToArray());
for (int i = 0; i < tasks.Count; i++)
list.SetItemChecked(i, true);
tmp.Controls.Add(list);
okButton.Click += (sender, args) =>
{
ok = true;
tmp.Close();
};
if (showOk) tmp.Controls.Add(okButton);
tmp.ShowDialog();
tasks = list.Items.OfType<AppTask>().Where((s, i) => list.GetItemChecked(i)).ToList();
return !showOk || ok;
}
}
}