Ejemplo n.º 1
0
        public static void Initialize()
        {
            MenuItem[] mainItems =
            {
                new MenuItem("File",
                             new MenuItem("Dump",                                            () =>          {
                    Exit();
                    InfoPanel.Message("Dumping...");
                    Dumper.Dump(FilePanel.File.FullName,                                     MainApp.BytesPerRow, MainApp.OffsetView);
                    InfoPanel.Message("Done");
                }),
                             new MenuItem(),
                             new MenuItem("Exit",                                            () =>          {
                    inMenu = false; MainApp.Exit();
                })
                             ),                                                              /*
                                                                                              * new MenuItem("Edit", null,
                                                                                              * new MenuItem("Test")
                                                                                              * ),*/
                new MenuItem("Search",
                             new MenuItem("Find byte...",                                    () =>          {
                    Exit();
                    Dialog.PromptFindByte();
                }),
                             new MenuItem("Find ASCII string...",                            () =>          {
                    Exit();
                    Dialog.PromptSearchString();
                }),
                             new MenuItem(),
                             new MenuItem("Goto...",                                         () =>          {
                    Exit();
                    Dialog.PromptGoto();
                })
                             ),
                new MenuItem("View",
                             new MenuItem("Offset view...",                                  () =>          {
                    Exit();
                    Dialog.PromptOffset();
                }),
                             new MenuItem(),
                             new MenuItem("File info",                                       () =>          {
                    Exit();
                    InfoPanel.DisplayFileInfo();
                }),
                             new MenuItem(),
                             new MenuItem("Refresh",                                         () =>          {
                    Exit();
                    FilePanel.Refresh();
                })
                             ),                                                              /*
                                                                                              * new MenuItem("Tools", null,
                                                                                              * new MenuItem("Test")
                                                                                              * ),*/
#if DEBUG
                new MenuItem("Debug",
                             new MenuItem("Show Test Window",                                () =>          {
                    Exit();
                    new Window("Test",                                                       new Control[]  {
                        new Label("Hello World!")
                    }).Show();
                }),
                             new MenuItem("Goto",                                            () =>          {
                    Exit();
                    new Window("Goto",                                                       new Control[]  {
                        new Label("Hello World!",                                                      1, 1),
                        new Button("OK",                                               12, 3, action: () => { MainApp.Goto(0xdd);})
                    }).Show();
                }),
                             new MenuItem("Preferences...",                                  () =>          {
                    Exit();
                    new Window("Test",                                                 50, 6, new Control[] {
                        new Label("Setting 1:",                                                      1, 1),
                        new Button("OK",                                                               12, 3)
                    }).Show();
                })
                             ),
#endif
                new MenuItem("?",
                             new MenuItem("About",                                           () =>          {
                    Exit();
                    Dialog.GenerateWindow(
                        title: "About",
                        text:
                        $"{Program.Name} v{Program.Version}\nCopyright (c)  2015-2017 dd86k",
                        width: 36,
                        height: 5
                        );
                })
                             )
            };

            // Make an array for each, remember that arrays are REFERENCED.
            _pos = new int[mainItems.Length];
            _miw = new int[mainItems.Length];

            MenuItems = new List <MenuItem>(mainItems.Length);
            MenuItems.AddRange(mainItems);

            _barlength = 0;
            // Get menubar's length with items
            for (int i = 0; i < MenuItems.Count; ++i)
            {
                MenuItem item = MenuItems[i];

                _pos[i] = _barlength;

                _barlength += item.Text.Length + 2;

                int max = 0; // Get longuest string in each submenus
                for (int si = 0; si < item.Items.Count; si++)
                {
                    MenuItem subitem = MenuItems[i].Items[si];

                    if (!subitem.IsSeparator)
                    {
                        int len = subitem.Text.Length;

                        if (len > max)
                        {
                            max = len;
                        }
                    }
                }
                _miw[i] = max;
            }

            Draw();
        }