Exemple #1
0
        static MenuBar CreateMenuBar()
        {
            MenuBar bar = new MenuBar();

            MenuItem file = new MenuItem("File");

            file.AddEvents((int)Gdk.EventMask.AllEventsMask);
            bar.Append(file);
            Menu fileMenu = new Menu();

            file.Submenu = fileMenu;
            fileMenu.Append(new MenuItem("Open..."));

            // FIXME: Hook up callbacks

            // FIXME: On windows (and Mac) there should be no delay
            // on the ability to close the menu when you've opened it.
            // Atm there is a delay after opening the menu and when
            // you can close it...

            return(bar);
        }
Exemple #2
0
        static MenuBar CreateMenuBar(Window parent)
        {
            MenuItem open = new MenuItem("Open...");

            open.Activated += (object?sender, EventArgs e) =>
            {
                FileChooserDialog fcd = new FileChooserDialog("Open Project", parent, FileChooserAction.Open,
                                                              Stock.Open, ResponseType.Ok,
                                                              Stock.Cancel, ResponseType.Cancel);
                fcd.SelectMultiple = false;
                AddFilters(fcd);

                if (fcd.Run() == (int)ResponseType.Ok)
                {
                    try
                    {
                        FileManager.Load(fcd.Filename);

                        Console.WriteLine($"Successfully read and parsed project file { fcd.Filename }.");
                        Console.WriteLine($"- wires: { FileManager.Wires }");
                        Console.WriteLine($"- components: { FileManager.Components }");
                        Console.WriteLine($"- labels: { FileManager.Labels }");
                    }
                    catch (Exception err)
                    {
                        // FIXME: Do something if parse fails?

                        Output.WriteError($"Failed to read and parse project file { fcd.Filename }.", err);
                    }
                }

                fcd.Dispose();
            };

            MenuItem saveAs = new MenuItem("Save As...");

            saveAs.Activated += (object?sender, EventArgs e) =>
            {
                FileChooserDialog fcd = new FileChooserDialog("Save Project", parent, FileChooserAction.Open,
                                                              Stock.Save, ResponseType.Ok,
                                                              Stock.Cancel, ResponseType.Cancel);
                AddFilters(fcd);

                if (fcd.Run() == (int)ResponseType.Ok)
                {
                    try
                    {
                        FileManager.Save(fcd.Filename);

                        Console.WriteLine($"Successfully saved and parsed project file { fcd.Filename }.");
                        Console.WriteLine($"- wires: { FileManager.Wires }");
                        Console.WriteLine($"- components: { FileManager.Components }");
                        Console.WriteLine($"- labels: { FileManager.Labels }");
                    }
                    catch (Exception err)
                    {
                        // FIXME: Do something if parse fails?

                        Output.WriteError($"Failed to write and parse project file { fcd.Filename }.", err);
                    }
                }

                fcd.Dispose();
            };

            MenuItem save = new MenuItem("Save...");

            save.Activated += (object?sender, EventArgs e) =>
            {
                if (FileManager.IsNew)
                {
                    saveAs.Activate();
                }
                else
                {
                    FileManager.Save();
                }
            };

            Menu fileMenu = new Menu();

            fileMenu.Append(open);
            fileMenu.Append(save);
            fileMenu.Append(saveAs);

            MenuItem file = new MenuItem("File");

            file.AddEvents((int)Gdk.EventMask.AllEventsMask);
            file.Submenu = fileMenu;

            // FIXME: Hook up callbacks

            // FIXME: On windows (and Mac) there should be no delay
            // on the ability to close the menu when you've opened it.
            // Atm there is a delay after opening the menu and when
            // you can close it...

            MenuBar bar = new MenuBar();

            bar.Append(file);

            return(bar);
        }