Ejemplo n.º 1
0
        public void SetupMenu()
        {
            // --- Create the command structure that represents the main menu
            var aboutGroup = new UiMenuItem()
                             .Append(new AboutCommand());

            var preferencesGroup = new UiMenuItem()
                                   .Append(new OptionsCommand());

            var servicesGroup = new UiMenuItem()
                                .Append(new ElectronShellMenuItem(MenuRole.services));

            var appWindowGroup = new UiMenuItem()
                                 .Append(new ElectronShellMenuItem(MenuRole.hide))
                                 .Append(new ElectronShellMenuItem(MenuRole.hideothers))
                                 .Append(new ElectronShellMenuItem(MenuRole.unhide));

            var quitGroup = new UiMenuItem()
                            .Append(new ElectronShellMenuItem(MenuRole.quit, "E&xit"));

            var darwinMenu = new UiMenuItem("darwin", "ZX Spectrum IDE")
                             .Append(aboutGroup)
                             .Append(preferencesGroup)
                             .Append(servicesGroup)
                             .Append(appWindowGroup)
                             .Append(quitGroup);

            var createGroup = new UiMenuItem()
                              .Append(new NewProjectCommand())
                              .Append(new OpenProjectCommand());

            var closeGroup = new UiMenuItem()
                             .Append(new CloseProjectCommand());

            var fileGroup = new UiMenuItem("file", PlatformHelper.IsDarwin ? "File" : "&File")
                            .Append(createGroup)
                            .Append(closeGroup);

            if (!PlatformHelper.IsDarwin)
            {
                fileGroup.Append(preferencesGroup);
            }
            fileGroup.Append(quitGroup);

            var explorerGroup = new UiMenuItem()
                                .Append(new ShowExplorerCommand())
                                .Append(new ShowSpectrumEmulatorCommand());

            var spectrumWindowsGroup = new UiMenuItem()
                                       .Append(new ShowRegistersCommand())
                                       .Append(new ShowDisassemblyCommand())
                                       .Append(new ShowMemoryCommand());

            var devToolsGroup = new UiMenuItem()
                                .Append(new ShowDevToolsCommand());

            var viewGroup = new UiMenuItem("view", PlatformHelper.IsDarwin ? "View" : "&View")
                            .Append(explorerGroup)
                            .Append(spectrumWindowsGroup)
                            .Append(devToolsGroup);

            var help1Group = new UiMenuItem()
                             .Append(new UiMenuItem("help-topic-1", "Help topic #1"))
                             .Append(new UiMenuItem("help-topic-2", "Help topic #2").Enable(false));

            var help3SubGroup = new UiMenuItem("help-topic-3", "Help topic #&3")
                                .Append(new UiMenuItem("help-topic-31", "Help topic #31"))
                                .Append(new UiMenuItem("help-topic-32", "Help topic #32"))
                                .Append(new UiMenuItem("help-topic-33", "Help topic #33"));

            var help4SubGroup = new UiMenuItem("help-topic-4", "Help topic #4").Enable(false)
                                .Append(new UiMenuItem("help-topic-41", "Help topic #41"))
                                .Append(new UiMenuItem("help-topic-42", "Help topic #42"))
                                .Append(new UiMenuItem("help-topic-43", "Help topic #43"));

            var help2Group = new UiMenuItem()
                             .Append(help3SubGroup)
                             .Append(help4SubGroup);

            var helpMenu = new UiMenuItem("help", "H&elp")
                           .Append(help1Group)
                           .Append(help2Group);

            AppMenu = new UiMenuItem();
            if (PlatformHelper.IsDarwin)
            {
                AppMenu.Append(darwinMenu);
            }
            AppMenu
            .Append(fileGroup)
            .Append(viewGroup)
            .Append(helpMenu);

            // --- Convert the command structure into Electron menu
            BuildDefaultMenuFromCommands();

            // --- Now, set the menu
            try
            {
                Electron.Menu.SetApplicationMenu(_appMenu);
                Console.WriteLine("Electron menu set");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"App Menu Error: {ex}");
            }

            // --- Set the menu state
            Console.WriteLine("Setting app menu");
            StateStore.Dispatch(new SetAppMenuAction(AppMenu));
        }
Ejemplo n.º 2
0
 public SetAppMenuAction(UiMenuItem appMenu)
 {
     AppMenu = appMenu;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a menu pane from the specified command group
        /// </summary>
        /// <param name="menuGroup"></param>
        /// <returns></returns>
        private MenuItem BuildMenuPaneFromCommands(UiMenuItem menuGroup)
        {
            var separator = new MenuItem {
                Type = MenuType.separator
            };
            var pane             = new List <MenuItem>();
            var lastItemWasGroup = false;
            var groupJustEnded   = false;

            for (var i = 0; i < menuGroup.Items.Count; i++)
            {
                var subitem = menuGroup.Items[i];

                // --- Provide separator between groups
                if (i > 0 && subitem.HasSubitems != lastItemWasGroup || groupJustEnded)
                {
                    pane.Add(separator);
                }
                lastItemWasGroup = subitem.HasSubitems;
                groupJustEnded   = false;
                if (subitem.HasSubitems)
                {
                    // --- We are about to process a command group
                    foreach (var item in subitem.Items)
                    {
                        if (item.HasSubitems)
                        {
                            // --- This is a submenu to render
                            var submenu = BuildMenuPaneFromCommands(item);
                            pane.Add(submenu);
                        }
                        else if (item.Role != null)
                        {
                            // --- An Electron Shell predefined role
                            pane.Add(new MenuItem
                            {
                                Type = MenuType.normal,
                                Role = item.Role.Value
                            });
                        }
                        else
                        {
                            // --- Normal menu item
                            pane.Add(new MenuItem
                            {
                                Label       = item.Label,
                                Accelerator = item.Accelerator,
                                Click       = () => item.OnExecute(Window)
                            });

                            // --- Let's map this item by its ID
                            _commandMap[item.Id] = item;
                        }
                    }
                    groupJustEnded = true;
                }
                else
                {
                    // --- Normal menu item
                    pane.Add(new MenuItem
                    {
                        Label       = subitem.Label,
                        Accelerator = subitem.Accelerator,
                        Click       = () => subitem.OnExecute(Window)
                    });

                    // --- Let's map this item by its ID
                    _commandMap[subitem.Id] = subitem;
                }
            }

            // --- Done
            var newMenuItem = new MenuItem
            {
                Label   = menuGroup.Label,
                Submenu = pane.ToArray()
            };

            menuGroup.MenuItem = newMenuItem;
            return(newMenuItem);
        }