71 lines
2.8 KiB
C#
71 lines
2.8 KiB
C#
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, TaskFactory factory, IList<AppTask> tasks, AppList appList, IExternalFunctionality platform)
|
|
{
|
|
Command reloadRepos = new() {MenuText = "Reload", ToolBarText = "Reload"};
|
|
reloadRepos.Executed += (_, _) =>
|
|
{
|
|
if (platform.YesNoDialog("This may take some time. Are you sure?", true))
|
|
{
|
|
repoManagement.FetchRepos();
|
|
repoManagement.GetReposFromDisk();
|
|
appList.Update();
|
|
}
|
|
};
|
|
|
|
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();
|
|
|
|
Command aboutCommand = new() {MenuText = "About Eto..."};
|
|
aboutCommand.Executed += (_, _) => new AboutDialog().ShowDialog(mainForm);
|
|
|
|
Items.Add(new ButtonMenuItem
|
|
{
|
|
Text = "&File", Items =
|
|
{
|
|
reloadRepos,
|
|
editSources,
|
|
addPackage
|
|
}
|
|
});
|
|
// File submenu
|
|
// new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } },
|
|
// new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } },
|
|
/*ApplicationItems =
|
|
{
|
|
// application (OS X) or file menu (others)
|
|
new ButtonMenuItem {Text = "&Preferences..."},
|
|
},*/
|
|
QuitItem = quitCommand;
|
|
AboutItem = aboutCommand;
|
|
}
|
|
}
|
|
} |