240 lines
9 KiB
C#
240 lines
9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using TeaBox.Macros;
|
|
using TeaBox.Macros.Gui.Runner;
|
|
using TeaBox.Code;
|
|
using TeaBox.SourceControl;
|
|
using DataObject = System.Windows.Forms.DataObject;
|
|
|
|
namespace TeaBox.UAF
|
|
{
|
|
/// <summary>
|
|
/// Lists all the JustDance maps.
|
|
/// </summary>
|
|
public class QuickRunTool : IQuickRunItemProvider
|
|
{
|
|
private IQuickOpenItem[] _toolsRoot;
|
|
|
|
public IEnumerable<IQuickOpenItem> QuickRunItems
|
|
{
|
|
get
|
|
{
|
|
_toolsRoot = _toolsRoot ?? ToolsRoot().ToArray();
|
|
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = " Tools",
|
|
Hint = "Press tab to see tool list",
|
|
ChildrenProvider = () => _toolsRoot,
|
|
Image = ImageService.Load("tools.png")
|
|
};
|
|
foreach (var quickRunItem in _toolsRoot)
|
|
{
|
|
yield return quickRunItem;
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerable<IQuickOpenItem> ToolsRoot()
|
|
{
|
|
foreach (Tool tool in Enum.GetValues(typeof(Tool)))
|
|
{
|
|
if (tool == Tool.GearStudio)
|
|
continue;
|
|
|
|
string solution = tool.Paths().Solution;
|
|
string toolsSolution = UAFConstants.ToolsSolution;
|
|
if (solution != null && solution != toolsSolution)
|
|
{
|
|
yield return solution.ToQuickRunItem();
|
|
}
|
|
|
|
yield return new ToolQuickRunItem(tool);
|
|
}
|
|
}
|
|
|
|
private class ToolQuickRunItem : IQuickOpenItem
|
|
{
|
|
private readonly Tool _tool;
|
|
private readonly IAsyncImage _image;
|
|
|
|
public ToolQuickRunItem(Tool tool)
|
|
{
|
|
_tool = tool;
|
|
_image = ImageService.LoadIconFromToolAsync(_tool);
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return _tool.ToString(); }
|
|
}
|
|
|
|
public string Hint
|
|
{
|
|
get { return "Press enter to run tool, or tab to see options"; }
|
|
}
|
|
|
|
public Image Image
|
|
{
|
|
get { return _image.Image; }
|
|
}
|
|
|
|
public IEnumerable<IQuickOpenItem> Children
|
|
{
|
|
get { return ToolOptions(_tool); }
|
|
}
|
|
|
|
public IEnumerable<string> SearchText
|
|
{
|
|
get { return null; }
|
|
}
|
|
|
|
public Func<DataObject> DragDropData
|
|
{
|
|
get{ return () => null; }
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
MacroRunnerPad.Instance.Schedule(RunPlaylist(_tool));
|
|
}
|
|
|
|
private static Playlist RunPlaylist(Tool tool, ToolPath? toolPath = null)
|
|
{
|
|
var playlist = new Playlist();
|
|
if (toolPath == ToolPath.Debug || toolPath == ToolPath.Release)
|
|
{
|
|
var buildMacro = new MethodMacro(typeof(BuildMacros).GetMethod("Build_tool"));
|
|
var buildEntry = new Playlist.Entry(buildMacro);
|
|
buildEntry.Arguments.Set(buildMacro.Definition.Parameters[1], tool);
|
|
playlist.Entries.Add(buildEntry);
|
|
}
|
|
|
|
var launchMacro = new MethodMacro(typeof(LaunchMacros).GetMethod("LaunchTool"));
|
|
var launchEntry = new Playlist.Entry(launchMacro);
|
|
launchEntry.Arguments.Set(launchMacro.Definition.Parameters[1], tool);
|
|
launchEntry.Arguments.Set(launchMacro.Definition.Parameters[2], toolPath);
|
|
playlist.Entries.Add(launchEntry);
|
|
return playlist;
|
|
}
|
|
|
|
private static IEnumerable<IQuickOpenItem> ToolOptions(Tool tool)
|
|
{
|
|
string solution = tool.Paths().Solution;
|
|
if (solution != null)
|
|
{
|
|
yield return solution.ToQuickRunItem();
|
|
}
|
|
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "(Debug)",
|
|
Image = ImageService.LoadIconFromToolAsync(tool),
|
|
ActivateAction = () => MacroRunnerPad.Instance.Schedule(RunPlaylist(tool)),
|
|
ChildrenProvider = () => ToolPathOptions(tool, ToolPath.Debug),
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "(Release)",
|
|
Image = ImageService.LoadIconFromToolAsync(tool),
|
|
ActivateAction = () => MacroRunnerPad.Instance.Schedule(RunPlaylist(tool)),
|
|
ChildrenProvider = () => ToolPathOptions(tool, ToolPath.Release),
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "(Delivery)",
|
|
Image = ImageService.LoadIconFromToolAsync(tool),
|
|
ActivateAction = () => MacroRunnerPad.Instance.Schedule(RunPlaylist(tool)),
|
|
ChildrenProvider = () => ToolPathOptions(tool, ToolPath.Delivery),
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "(Beta)",
|
|
Image = ImageService.LoadIconFromToolAsync(tool),
|
|
ActivateAction = () => MacroRunnerPad.Instance.Schedule(RunPlaylist(tool, ToolPath.Beta)),
|
|
ChildrenProvider = () => ToolPathOptions(tool, ToolPath.Beta),
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "Publish",
|
|
Image = ImageService.Load("publish.png"),
|
|
ActivateAction = () =>
|
|
{
|
|
var macro = new MethodMacro(typeof(PublishMacros).GetMethod("Publish_Tool_ToDelivery"));
|
|
var entry = new Playlist.Entry(macro);
|
|
entry.Arguments.Set(macro.Definition.Parameters[1], tool);
|
|
MacroRunnerPad.Instance.Schedule(entry);
|
|
},
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "Publish to beta",
|
|
Image = ImageService.Load("beta.png"),
|
|
ActivateAction = () =>
|
|
{
|
|
var macro = new MethodMacro(typeof(PublishMacros).GetMethod("Publish_Tool_ToBeta"));
|
|
var entry = new Playlist.Entry(macro);
|
|
entry.Arguments.Set(macro.Definition.Parameters[1], tool);
|
|
MacroRunnerPad.Instance.Schedule(entry);
|
|
},
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "Build&Run",
|
|
Image = ImageService.Load("run.png"),
|
|
ActivateAction = () => MacroRunnerPad.Instance.Schedule(RunPlaylist(tool)),
|
|
};
|
|
|
|
if (tool.Paths().AdditionalQuickOpenItems != null)
|
|
{
|
|
foreach (var item in tool.Paths().AdditionalQuickOpenItems())
|
|
{
|
|
yield return item;
|
|
}
|
|
}
|
|
|
|
if (tool == Tool.Sharpmake)
|
|
{
|
|
var macro = new MethodMacro(typeof(BuildMacros).GetMethod("Generate_solutions"));
|
|
var entry = new Playlist.Entry(macro);
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "Generate solutions",
|
|
Image = ImageService.Load("build.png"),
|
|
ActivateAction = () => MacroRunnerPad.Instance.Schedule(entry),
|
|
};
|
|
}
|
|
}
|
|
|
|
private static IEnumerable<IQuickOpenItem> ToolPathOptions(Tool tool, ToolPath toolPath)
|
|
{
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "(Copy Path to clipboard)",
|
|
ActivateAction = () => Clipboard.SetText(tool.Paths().ExeFile(toolPath)),
|
|
Image = ImageService.Load("open.png")
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = "(Show in explorer)",
|
|
ActivateAction = () => Process.Start(tool.Paths().ExeDirectory(toolPath)),
|
|
Image = ImageService.Load("open.png")
|
|
};
|
|
yield return new QuickOpenItem
|
|
{
|
|
Name = (toolPath == ToolPath.Debug || toolPath == ToolPath.Release) ? "Build & Run" : "Run",
|
|
ActivateAction = () =>
|
|
{
|
|
MacroRunnerPad.Instance.Schedule(RunPlaylist(tool, toolPath));
|
|
},
|
|
Image = ImageService.Load("run.png"),
|
|
};
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|