PlotDirector/PlotLine/Services/ApplicationRibbon.cs

59 lines
4.4 KiB
C#

using PlotLine.ViewModels;
namespace PlotLine.Services;
public sealed record RibbonCommand(string Label, string IconKey, string Controller, string Action,
string Scope = "project", bool OwnerOnly = false, string? ToolbarKey = null, bool Post = false)
{
public bool Available(ApplicationNavigationViewModel model) => (Scope == "global" || model.Project is not null)
&& (Scope != "book" && Scope != "chapter" || model.Book is not null) && (!OwnerOnly || model.Project?.IsOwner == true);
public object Values(ApplicationNavigationViewModel model) => Scope switch
{
"global" => new { }, "id" => new { id = model.Project?.ProjectID },
"book" => new { id = model.Book?.BookID }, "chapter" => new { bookId = model.Book?.BookID },
_ => new { projectId = model.Project?.ProjectID }
};
public static RibbonCommand Shortcut(string key)
{
var command = ToolbarCommands.All.Single(x => x.Key == key);
return new(command.Label, key, command.Controller, command.Action, ToolbarKey: key);
}
}
public sealed record RibbonGroup(string Label, params RibbonCommand[] Commands);
public sealed record RibbonCategory(string Key, string Label, params RibbonGroup[] Groups);
public static class ApplicationRibbon
{
private static RibbonCommand S(string key) => RibbonCommand.Shortcut(key);
public static IReadOnlyList<RibbonCategory> Categories { get; } = [
new("project", "Project",
new("Workspace", S("overview"), S("projects"), S("writer"), new("Import a manuscript", "assets", "Onboarding", "StartImport", "global", Post: true)),
new("Project", new("Edit project", "writer", "Projects", "Edit", "id"), new("Add book", "bible", "Books", "Create"), new("Activity", "metrics", "Projects", "Activity", "id")),
new("Manage", new("Collaborators", "characters", "ProjectCollaborators", "Index", OwnerOnly: true), new("Back up books", "backup", "BookRecovery", "Backup", OwnerOnly: true), new("Restore books", "restore", "BookRecovery", "Restore", "global"), new("Rewind project", "restore", "ProjectRestorePoints", "Index", OwnerOnly: true))),
new("book", "Book",
new("Selected book", new("Book overview", "bible", "Books", "Details", "book"), new("Edit book", "writer", "Books", "Edit", "book"), new("Add chapter", "threads", "Chapters", "Create", "chapter")),
new("Manuscript review", S("review")), new("Library", S("overview"), new("Add book", "bible", "Books", "Create"))),
new("story", "Story", new("Story structure", S("timeline"), S("plotlines"), S("threads"), S("calendar"), S("point")), new("Analysis & planning", S("review"), S("scenarios"), S("continuity")), new("Writing", S("writer"))),
new("characters", "Characters", new("Cast", S("characters"), S("names")), new("Connections", S("relationships"))),
new("world", "World", new("Setting", S("locations"), S("maps"), S("floorplans")), new("Story world", S("assets"))),
new("tools", "Tools", new("Reference", S("bible")), new("Insights", S("metrics"), S("health"), S("warnings")), new("Organisation", S("archive"))),
new("help", "Help", new RibbonGroup("Support", new("Help Centre", "bible", "Help", "Index", "global"), new("Feature Requests", "review", "FeatureRequests", "Index", "global")))
];
public static string ActiveCategory(string controller, string section) => controller switch
{
"Books" or "Chapters" or "Scenes" => "book", "Help" or "FeatureRequests" => "help",
"Onboarding" => "story",
_ => section switch
{
"Timeline" or "Calendar" or "At This Point" or "Plot Lines" or "Threads" or "Scenarios" or "Continuity Explorer" => "story",
"Characters" or "Names" or "Relationships" => "characters",
"Locations" or "Assets" or "Maps" or "Floor Plans" => "world",
"Story Bible" or "Metrics" or "Health" or "Warnings" or "Archive" => "tools", _ => "project"
}
};
public static RibbonIcon Icon(string key) => RibbonPresentation.Icons.Single(x => x.Key == key);
public static string Tone(string key) => key switch
{
"calendar" or "point" => "calendar", "characters" or "names" => "characters", "locations" or "maps" or "floorplans" => "locations",
"relationships" => "relationships", "warnings" => "warning", "review" => "review", "bible" or "overview" or "projects" => "books", _ => "planning"
};
}