public static MenuItem AddMenuChild( ItemCollection parent, string locString, RelayCommand command, object commandParameter = null, string icon = null) { var item = new MenuItem { Command = command, CommandParameter = commandParameter, InputGestureText = command?.GestureText }; if (locString.StartsWith("LOC")) { item.SetResourceReference(MenuItem.HeaderProperty, locString); } else { item.Header = locString; } var iconObj = MenuHelpers.GetIcon(icon); if (iconObj != null) { item.Icon = iconObj; } parent.Add(item); return(item); }
public void InitializeItems() { if (settings == null) { return; } Items.Clear(); // Sort By var sortItem = new MenuItem { Header = ResourceProvider.GetString("LOCMenuSortByTitle") }; GenerateSortMenu(sortItem.Items, settings); // Group By var groupItem = new MenuItem { Header = ResourceProvider.GetString("LOCMenuGroupByTitle") }; GenerateGroupMenu(groupItem.Items, settings); Items.Add(sortItem); Items.Add(groupItem); Items.Add(new Separator()); // View Type MenuHelpers.PopulateEnumOptions <ViewType>(Items, nameof(settings.ViewSettings.GamesViewType), settings.ViewSettings); Items.Add(new Separator()); // View var filterItem = MainMenu.AddMenuChild(Items, "LOCMenuViewFilterPanel", null); filterItem.IsCheckable = true; BindingOperations.SetBinding(filterItem, MenuItem.IsCheckedProperty, new Binding { Source = settings, Path = new PropertyPath(nameof(PlayniteSettings.FilterPanelVisible)) }); var explorerItem = MainMenu.AddMenuChild(Items, "LOCMenuViewExplorerPanel", null); explorerItem.IsCheckable = true; BindingOperations.SetBinding(explorerItem, MenuItem.IsCheckedProperty, new Binding { Source = settings, Path = new PropertyPath(nameof(PlayniteSettings.ExplorerPanelVisible)) }); }
public static void GenerateGroupMenu(ItemCollection itemsRoot, PlayniteSettings settings) { var dontGroupItem = MainMenu.AddMenuChild(itemsRoot, GroupableField.None.GetDescription(), null); dontGroupItem.IsCheckable = true; MenuHelpers.SetEnumBinding(dontGroupItem, nameof(settings.ViewSettings.GroupingOrder), settings.ViewSettings, GroupableField.None); itemsRoot.Add(new Separator()); MenuHelpers.PopulateEnumOptions <GroupableField>(itemsRoot, nameof(settings.ViewSettings.GroupingOrder), settings.ViewSettings, true, new List <GroupableField> { GroupableField.None }); }
public void InitializeItems() { if (settings == null) { return; } Items.Clear(); // Sort By var sortItem = new MenuItem { Header = ResourceProvider.GetString("LOCMenuSortByTitle") }; MenuHelpers.PopulateEnumOptions <SortOrderDirection>(sortItem.Items, nameof(settings.ViewSettings.SortingOrderDirection), settings.ViewSettings); sortItem.Items.Add(new Separator()); MenuHelpers.PopulateEnumOptions <SortOrder>(sortItem.Items, nameof(settings.ViewSettings.SortingOrder), settings.ViewSettings, true); // Group By var groupItem = new MenuItem { Header = ResourceProvider.GetString("LOCMenuGroupByTitle") }; var dontGroupItem = MainMenu.AddMenuChild(groupItem.Items, GroupableField.None.GetDescription(), null); dontGroupItem.IsCheckable = true; MenuHelpers.SetEnumBinding(dontGroupItem, nameof(settings.ViewSettings.GroupingOrder), settings.ViewSettings, GroupableField.None); groupItem.Items.Add(new Separator()); MenuHelpers.PopulateEnumOptions <GroupableField>(groupItem.Items, nameof(settings.ViewSettings.GroupingOrder), settings.ViewSettings, true, new List <GroupableField> { GroupableField.None }); Items.Add(sortItem); Items.Add(groupItem); Items.Add(new Separator()); // View Type MenuHelpers.PopulateEnumOptions <ViewType>(Items, nameof(settings.ViewSettings.GamesViewType), settings.ViewSettings); Items.Add(new Separator()); // View var filterItem = MainMenu.AddMenuChild(Items, "LOCMenuViewFilterPanel", null); filterItem.IsCheckable = true; BindingOperations.SetBinding(filterItem, MenuItem.IsCheckedProperty, new Binding { Source = settings, Path = new PropertyPath(nameof(PlayniteSettings.FilterPanelVisible)) }); var explorerItem = MainMenu.AddMenuChild(Items, "LOCMenuViewExplorerPanel", null); explorerItem.IsCheckable = true; BindingOperations.SetBinding(explorerItem, MenuItem.IsCheckedProperty, new Binding { Source = settings, Path = new PropertyPath(nameof(PlayniteSettings.ExplorerPanelVisible)) }); }
public void InitializeItems() { // Add Game var addGameItem = AddMenuChild(Items, "LOCMenuAddGame", null, null, "AddGameIcon"); AddMenuChild(addGameItem.Items, "LOCMenuAddGameManual", mainModel.AddCustomGameCommand); AddMenuChild(addGameItem.Items, "LOCMenuAddGameInstalled", mainModel.AddInstalledGamesCommand); AddMenuChild(addGameItem.Items, "LOCMenuAddGameEmulated", mainModel.AddEmulatedGamesCommand); if (Computer.WindowsVersion == WindowsVersion.Win10) { AddMenuChild(addGameItem.Items, "LOCMenuAddWindowsStore", mainModel.AddWindowsStoreGamesCommand); } Items.Add(new Separator()); // Library var libraryItem = AddMenuChild(Items, "LOCLibrary", null); AddMenuChild(libraryItem.Items, "LOCMenuConfigureIntegrations", mainModel.OpenLibraryIntegrationsConfigCommand); AddMenuChild(libraryItem.Items, "LOCMenuLibraryManagerTitle", mainModel.OpenDbFieldsManagerCommand); AddMenuChild(libraryItem.Items, "LOCMenuConfigureEmulatorsMenuTitle", mainModel.OpenEmulatorsCommand); AddMenuChild(libraryItem.Items, "LOCMenuDownloadMetadata", mainModel.DownloadMetadataCommand); AddMenuChild(libraryItem.Items, "LOCMenuSoftwareTools", mainModel.OpenSoftwareToolsCommand); // Update Library var updateItem = AddMenuChild(Items, "LOCMenuReloadLibrary", null, null, "UpdateDbIcon"); AddMenuChild(updateItem.Items, "LOCUpdateAll", mainModel.UpdateGamesCommand); updateItem.Items.Add(new Separator()); foreach (var plugin in mainModel.Extensions.LibraryPlugins) { var item = new MenuItem { Header = plugin.Name, Command = mainModel.UpdateLibraryCommand, CommandParameter = plugin }; updateItem.Items.Add(item); } // Random game select AddMenuChild(Items, "LOCMenuSelectRandomGame", mainModel.SelectRandomGameCommand, null, "DiceIcon"); // Settings AddMenuChild(Items, "LOCMenuPlayniteSettingsTitle", mainModel.OpenSettingsCommand, null, "SettingsIcon"); // View var viewItem = AddMenuChild(Items, LOC.MenuView, null, null, null); var sideBarItem = AddMenuChild(viewItem.Items, LOC.Sidebar, null, null, null); var sideBarEnableItem = AddMenuChild(sideBarItem.Items, LOC.EnabledTitle, null); sideBarEnableItem.IsCheckable = true; BindingOperations.SetBinding(sideBarEnableItem, MenuItem.IsCheckedProperty, new Binding { Source = mainModel.AppSettings, Path = new PropertyPath(nameof(PlayniteSettings.SidebarVisible)) }); sideBarItem.Items.Add(new Separator()); MenuHelpers.PopulateEnumOptions <Dock>(sideBarItem.Items, nameof(PlayniteSettings.SidebarPosition), mainModel.AppSettings); viewItem.Items.Add(new Separator()); var librarySideItem = MainMenu.AddMenuChild(viewItem.Items, LOC.Library, null); librarySideItem.IsCheckable = true; MenuHelpers.SetEnumBinding(librarySideItem, nameof(mainModel.AppSettings.CurrentApplicationView), mainModel.AppSettings, ApplicationView.Library); var statsSideItem = MainMenu.AddMenuChild(viewItem.Items, LOC.Statistics, null); statsSideItem.IsCheckable = true; MenuHelpers.SetEnumBinding(statsSideItem, nameof(mainModel.AppSettings.CurrentApplicationView), mainModel.AppSettings, ApplicationView.Statistics); Items.Add(new Separator()); // Open Client var openClientItem = AddMenuChild(Items, "LOCMenuClients", null); foreach (var tool in mainModel.ThirdPartyTools) { var item = new MenuItem { Header = tool.Name, Command = mainModel.ThirdPartyToolOpenCommand, CommandParameter = tool, Icon = tool.Icon }; openClientItem.Items.Add(item); } // Tools toolsItem = AddMenuChild(Items, "LOCMenuTools", null); // Extensions extensionsItem = AddMenuChild(Items, "LOCExtensions", null); // FullScreen extensionsEndItem = new Separator(); Items.Add(extensionsEndItem); AddMenuChild(Items, "LOCMenuOpenFullscreen", mainModel.OpenFullScreenCommand, null, "FullscreenModeIcon"); Items.Add(new Separator()); // Links var linksItem = AddMenuChild(Items, "LOCMenuLinksTitle", null); AddMenuChild(linksItem.Items, "LOCCommonLinksForum", GlobalCommands.NavigateUrlCommand, UrlConstants.Forum, "Images/applogo.png"); AddMenuChild(linksItem.Items, "Discord", GlobalCommands.NavigateUrlCommand, UrlConstants.Discord, "Images/discord.png"); AddMenuChild(linksItem.Items, "Twitter", GlobalCommands.NavigateUrlCommand, UrlConstants.Twitter, "Images/twitter.png"); AddMenuChild(linksItem.Items, "Reddit", GlobalCommands.NavigateUrlCommand, UrlConstants.Reddit, "Images/reddit.png"); // Help var helpItem = AddMenuChild(Items, "LOCMenuHelpTitle", null); AddMenuChild(helpItem.Items, "Wiki / FAQ", GlobalCommands.NavigateUrlCommand, UrlConstants.Wiki); AddMenuChild(helpItem.Items, "LOCMenuIssues", mainModel.ReportIssueCommand); AddMenuChild(helpItem.Items, "LOCSDKDocumentation", GlobalCommands.NavigateUrlCommand, UrlConstants.SdkDocs); helpItem.Items.Add(new Separator()); AddMenuChild(helpItem.Items, "LOCCrashRestartSafe", mainModel.RestartInSafeMode); AddMenuChild(helpItem.Items, "LOCCheckForUpdates", mainModel.CheckForUpdateCommand); // Patreon AddMenuChild(Items, "LOCMenuPatreonSupport", GlobalCommands.NavigateUrlCommand, UrlConstants.Patreon, "Images/patreon.png"); // About AddMenuChild(Items, "LOCMenuAbout", mainModel.OpenAboutCommand, null, "AboutPlayniteIcon"); Items.Add(new Separator()); // Exit AddMenuChild(Items, "LOCExitAppLabel", mainModel.ShutdownCommand, null, "ExitIcon"); }
private void AddExtensionItems() { extensionsItem.Items.Clear(); AddMenuChild(extensionsItem.Items, "LOCReloadScripts", mainModel.ReloadScriptsCommand); extensionsItem.Items.Add(new Separator()); foreach (var function in mainModel.Extensions.ExportedFunctions) { var item = new MenuItem { Header = function.Name, Command = mainModel.InvokeExtensionFunctionCommand, CommandParameter = function }; extensionsItem.Items.Add(item); } var args = new GetMainMenuItemsArgs(); var toAdd = new List <MainMenuItem>(); foreach (var plugin in mainModel.Extensions.Plugins.Values) { try { var items = plugin.Plugin.GetMainMenuItems(args); if (items.HasItems()) { toAdd.AddRange(items); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, $"Failed to get menu items from plugin {plugin.Description.Name}"); } } foreach (var script in mainModel.Extensions.Scripts) { if (script.SupportedMenus.Contains(Scripting.SupportedMenuMethods.MainMenu)) { try { var items = script.GetMainMenuItems(args); if (items.HasItems()) { foreach (var item in items) { var newItem = MainMenuItem.FromScriptMainMenuItem(item); newItem.Action = (a) => { script.InvokeFunction(item.FunctionName, new List <object> { new ScriptMainMenuItemActionArgs() }); }; toAdd.Add(newItem); } } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, $"Failed to get menu items from script {script.Name}"); } } } if (toAdd.Count > 0) { var menuItems = new Dictionary <string, MenuItem>(); var menuExtensionItems = new Dictionary <string, MenuItem>(); foreach (var item in toAdd) { var newItem = new MenuItem() { Header = item.Description, Icon = MenuHelpers.GetIcon(item.Icon) }; if (item.Action != null) { newItem.Click += (_, __) => { try { item.Action(new MainMenuItemActionArgs()); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Main menu extension action failed."); Dialogs.ShowErrorMessage( ResourceProvider.GetString("LOCMenuActionExecError") + Environment.NewLine + Environment.NewLine + e.Message, ""); } }; } var startIndex = Items.IndexOf(extensionsItem) + 1; if (item.MenuSection.IsNullOrEmpty()) { Items.Insert(startIndex, newItem); } else { if (item.MenuSection == "@") { extensionsItem.Items.Add(newItem); } else if (item.MenuSection.StartsWith("@")) { var parent = MenuHelpers.GenerateMenuParents(menuExtensionItems, item.MenuSection.Substring(1), extensionsItem.Items); parent?.Items.Add(newItem); } else { var parent = MenuHelpers.GenerateMenuParents(menuItems, item.MenuSection, Items, startIndex); parent?.Items.Add(newItem); } } } } }
private void AddExtensionItems() { var args = new GetGameMenuItemsArgs(); var toAdd = new List <GameMenuItem>(); if (Games != null) { args.Games = Games; } else { args.Games = new List <Game>(1) { Game }; } foreach (var plugin in model.Extensions.Plugins.Values) { try { var items = plugin.Plugin.GetGameMenuItems(args); if (items.HasItems()) { toAdd.AddRange(items); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, $"Failed to get menu items from plugin {plugin.Description.Name}"); } } foreach (var script in model.Extensions.Scripts) { if (script.SupportedMenus.Contains(Scripting.SupportedMenuMethods.GameMenu)) { try { var items = script.GetGameMenuItems(args); if (items.HasItems()) { foreach (var item in items) { var newItem = GameMenuItem.FromScriptGameMenuItem(item); newItem.Action = (a) => { script.InvokeFunction(item.FunctionName, new List <object> { new ScriptGameMenuItemActionArgs { Games = a.Games, SourceItem = item } }); }; toAdd.Add(newItem); } } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, $"Failed to get menu items from script {script.Name}"); } } } if (toAdd.Count > 0) { Items.Add(new Separator()); var menuItems = new Dictionary <string, MenuItem>(); foreach (var item in toAdd) { object newItem = null; if (item.Description == "-") { newItem = new Separator(); } else { newItem = new MenuItem() { Header = item.Description, Icon = MenuHelpers.GetIcon(item.Icon) }; if (item.Action != null) { ((MenuItem)newItem).Click += (_, __) => { try { item.Action(new GameMenuItemActionArgs { Games = args.Games, SourceItem = item }); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Game menu extension action failed."); Dialogs.ShowErrorMessage( ResourceProvider.GetString("LOCMenuActionExecError") + Environment.NewLine + Environment.NewLine + e.Message, ""); } }; } } if (item.MenuSection.IsNullOrEmpty()) { Items.Add(newItem); } else { var parent = MenuHelpers.GenerateMenuParents(menuItems, item.MenuSection, Items); parent?.Items.Add(newItem); } } } }
public void InitializeItems() { // Have to load icons as late as possible to make sure ovewritten theme resources are loaded. if (!iconsLoaded) { startIcon = MenuHelpers.GetIcon("PlayIcon"); removeIcon = MenuHelpers.GetIcon("RemoveGameIcon"); linksIcon = MenuHelpers.GetIcon("LinksIcon"); favoriteIcon = MenuHelpers.GetIcon("AddFavoritesIcon"); unFavoriteIcon = MenuHelpers.GetIcon("RemoveFavoritesIcon"); hideIcon = MenuHelpers.GetIcon("HideIcon"); unHideIcon = MenuHelpers.GetIcon("UnHideIcon"); browseIcon = MenuHelpers.GetIcon("OpenFolderIcon"); shortcutIcon = MenuHelpers.GetIcon("DesktopShortcutIcon"); installIcon = MenuHelpers.GetIcon("InstallIcon"); editIcon = MenuHelpers.GetIcon("EditGameIcon"); manualIcon = MenuHelpers.GetIcon("ManualIcon"); iconsLoaded = true; } Items.Clear(); if (Games?.Count == 0 && Game == null) { return; } if (Games != null) { // Create Desktop Shortcut var shortcutItem = new MenuItem() { Header = resources.GetString("LOCCreateDesktopShortcut"), Icon = shortcutIcon, Command = model.CreateDesktopShortcutsCommand, CommandParameter = Games }; Items.Add(shortcutItem); // Set Favorites var favoriteItem = new MenuItem() { Header = resources.GetString("LOCFavoriteGame"), Icon = favoriteIcon, Command = model.SetAsFavoritesCommand, CommandParameter = Games }; Items.Add(favoriteItem); var unFavoriteItem = new MenuItem() { Header = resources.GetString("LOCRemoveFavoriteGame"), Icon = unFavoriteIcon, Command = model.RemoveAsFavoritesCommand, CommandParameter = Games }; Items.Add(unFavoriteItem); // Set Hide var hideItem = new MenuItem() { Header = resources.GetString("LOCHideGame"), Icon = hideIcon, Command = model.SetAsHiddensCommand, CommandParameter = Games }; Items.Add(hideItem); var unHideItem = new MenuItem() { Header = resources.GetString("LOCUnHideGame"), Icon = unHideIcon, Command = model.RemoveAsHiddensCommand, CommandParameter = Games }; Items.Add(unHideItem); // Edit var editItem = new MenuItem() { Header = resources.GetString("LOCEditGame"), Icon = editIcon, Command = model.EditGamesCommand, CommandParameter = Games, InputGestureText = model.EditSelectedGamesCommand.GestureText }; Items.Add(editItem); // Set Category var categoryItem = new MenuItem() { Header = resources.GetString("LOCSetGameCategory"), //Icon = Images.GetEmptyImage(), Command = model.AssignGamesCategoryCommand, CommandParameter = Games }; Items.Add(categoryItem); // Set Completion Status Items.Add(LoadCompletionStatusItem()); // Extensions items AddExtensionItems(); Items.Add(new Separator()); // Remove var removeItem = new MenuItem() { Header = resources.GetString("LOCRemoveGame"), Icon = removeIcon, Command = model.RemoveGamesCommand, CommandParameter = Games, InputGestureText = model.RemoveSelectedGamesCommand.GestureText }; Items.Add(removeItem); } else if (Game != null) { // Play / Install if (ShowStartSection) { bool added = false; if (Game.IsInstalled) { var playItem = new MenuItem() { Header = resources.GetString("LOCPlayGame"), Icon = startIcon, FontWeight = FontWeights.Bold, Command = model.StartGameCommand, CommandParameter = Game, InputGestureText = model.StartSelectedGameCommand.GestureText }; Items.Add(playItem); added = true; } else if (!Game.IsCustomGame) { var installItem = new MenuItem() { Header = resources.GetString("LOCInstallGame"), Icon = installIcon, FontWeight = FontWeights.Bold, Command = model.InstallGameCommand, CommandParameter = Game }; Items.Add(installItem); added = true; } if (added) { Items.Add(new Separator()); } } // Custom Actions var otherActions = Game.GameActions?.Where(a => !a.IsPlayAction).ToList(); if (otherActions.HasItems()) { foreach (var task in otherActions) { var taskItem = new MenuItem() { Header = task.Name }; taskItem.Click += (s, e) => { model.GamesEditor.ActivateAction(Game, task); }; Items.Add(taskItem); } Items.Add(new Separator()); } // Links if (Game.Links?.Any() == true) { var linksItem = new MenuItem() { Header = resources.GetString("LOCLinksLabel"), Icon = linksIcon }; foreach (var link in Game.Links) { if (link != null) { linksItem.Items.Add(new MenuItem() { Header = link.Name, Command = new RelayCommand <Link>((_) => { try { GlobalCommands.NavigateUrl(Game.ExpandVariables(link.Url)); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to open url."); } }) }); } } Items.Add(linksItem); Items.Add(new Separator()); } // Open Game Location if (Game.IsInstalled) { var locationItem = new MenuItem() { Header = resources.GetString("LOCOpenGameLocation"), Icon = browseIcon, Command = model.OpenGameLocationCommand, CommandParameter = Game }; Items.Add(locationItem); } // Create Desktop Shortcut var shortcutItem = new MenuItem() { Header = resources.GetString("LOCCreateDesktopShortcut"), Icon = shortcutIcon, Command = model.CreateDesktopShortcutCommand, CommandParameter = Game }; Items.Add(shortcutItem); // Manual if (!Game.Manual.IsNullOrEmpty()) { Items.Add(new MenuItem() { Header = resources.GetString("LOCOpenGameManual"), Icon = manualIcon, Command = model.OpenManualCommand, CommandParameter = Game }); } Items.Add(new Separator()); // Toggle Favorites var favoriteItem = new MenuItem() { Header = Game.Favorite ? resources.GetString("LOCRemoveFavoriteGame") : resources.GetString("LOCFavoriteGame"), Icon = Game.Favorite ? unFavoriteIcon : favoriteIcon, Command = model.ToggleFavoritesCommand, CommandParameter = Game }; Items.Add(favoriteItem); // Toggle Hide var hideItem = new MenuItem() { Header = Game.Hidden ? resources.GetString("LOCUnHideGame") : resources.GetString("LOCHideGame"), Icon = Game.Hidden ? unHideIcon : hideIcon, Command = model.ToggleVisibilityCommand, CommandParameter = Game }; Items.Add(hideItem); // Edit var editItem = new MenuItem() { Header = resources.GetString("LOCEditGame"), Icon = editIcon, Command = model.EditGameCommand, CommandParameter = Game, InputGestureText = model.EditSelectedGamesCommand.GestureText }; Items.Add(editItem); // Set Category var categoryItem = new MenuItem() { Header = resources.GetString("LOCSetGameCategory"), //Icon = Images.GetEmptyImage(), Command = model.AssignGameCategoryCommand, CommandParameter = Game }; Items.Add(categoryItem); // Set Completion Status Items.Add(LoadCompletionStatusItem()); // Extensions items AddExtensionItems(); Items.Add(new Separator()); // Remove var removeItem = new MenuItem() { Header = resources.GetString("LOCRemoveGame"), Icon = removeIcon, Command = model.RemoveGameCommand, CommandParameter = Game, InputGestureText = model.RemoveGameCommand.GestureText }; Items.Add(removeItem); // Uninstall if (!Game.IsCustomGame && Game.IsInstalled) { var uninstallItem = new MenuItem() { Header = resources.GetString("LOCUninstallGame"), //Icon = Images.GetEmptyImage(), Command = model.UninstallGameCommand, CommandParameter = Game }; Items.Add(uninstallItem); } } }
public static void GenerateSortMenu(ItemCollection itemsRoot, PlayniteSettings settings) { MenuHelpers.PopulateEnumOptions <SortOrderDirection>(itemsRoot, nameof(settings.ViewSettings.SortingOrderDirection), settings.ViewSettings); itemsRoot.Add(new Separator()); MenuHelpers.PopulateEnumOptions <SortOrder>(itemsRoot, nameof(settings.ViewSettings.SortingOrder), settings.ViewSettings, true); }