Ejemplo n.º 1
0
        public MainWindow(Builder builder, IntPtr handle) : base(handle)
        {
            try
            {
                this._builder = builder;
                builder.Autoconnect(this);
                this.Title         = Names.ApplicationName;
                _progressbar1.Text = Names.ApplicationName;
                CodeWidget.Initialize();
                Box box = new Box(Orientation.Vertical, 0);
                _dock                 = new Dock();
                this._master          = (DockMaster)this._dock.Master;
                _master.SwitcherStyle = SwitcherStyle.Tabs;
                this._layout          = new DockLayout(this._dock);
                _layout.Master        = _master;
                this._bar             = new DockBar(this._dock);
                Box box2 = new Box(Orientation.Horizontal, 5);
                box.PackStart(box2, true, true, 0u);
                box2.PackStart(this._bar, false, false, 0u);
                box2.PackEnd(this._dock, true, true, 0u);
                DockItem dockItem = new DockItem("code1", "Code", Stock.Edit, DockItemBehavior.CantClose);
                dockItem.Grip.Hide();
                this._dock.AddItem(dockItem, DockPlacement.Center);
                this._dock.BorderWidth = 2u;
                CodeWidget.AddWelcomeTab(string.Format("Welcome to {0} !", Names.ApplicationName));
                dockItem.Add(this.GetCodePane());
                dockItem.ShowAll();

                DockItem dockItem4 = new DockItem("outputConsole", "Output", Stock.Execute, 0);
                this._dock.AddItem(dockItem4, DockPlacement.Bottom);
                dockItem4.Add(_outputWidget);
                dockItem4.ShowAll();

                DockItem dockItem2 = new DockItem("projectExplorer", "Project Explorer", Stock.Harddisk, 0);
                this._dock.AddItem(dockItem2, DockPlacement.Left);
                dockItem2.Add(this.CreateProjectExplorerPane());
                dockItem2.ShowAll();

                DockItem dockItem3 = new DockItem("properties", "Properties", Stock.Properties, 0);
                this._dock.AddItem(dockItem3, DockPlacement.Right);
                dockItem3.Add(this.CreatePropertiesPane());
                dockItem3.ShowAll();

                this.DeleteEvent += OnDeleteEvent;
                this.Add(box);
                this.Icon = Pixbuf.LoadFromResource("iCode.resources.images.icon.png");
                this._buildProjectAction.Activated += (sender, e) =>
                {
                    Task.Factory.StartNew(() =>
                    {
                        if (ProjectManager.BuildProject())
                        {
                            StateLabel.Text = "Build succeeded.";
                        }
                        else
                        {
                            StateLabel.Text = "Build failed.";
                        }
                    });
                };
                this._aboutICodeAction.Activated += (sender, e) => { AboutWindow.Create().ShowAll(); };

                ProjectManager.AddSensitiveWidget(_buildProjectAction);
                ProjectManager.AddSensitiveWidget(_button6);
                ProjectManager.AddSensitiveWidget(_button7);

                _label1.Text = Names.ApplicationName;

                this._button6.Clicked += (sender, e) => { ProjectManager.RunProject(); };
                Gtk.CssProvider nopad = new CssProvider();
                nopad.LoadFromData(@"
                widget
                { 
                    border-radius: 4px;
                    background: @borders;
                }
                progress, trough 
                {
                    border-bottom-right-radius: 4px;
                    border-bottom-left-radius: 4px;
                    min-height: 4px;
                }
                ");
                var layoutFile = System.IO.Path.Combine(Program.ConfigPath, "Layouts.xml");

                if (!File.Exists(layoutFile))
                {
                    _layout.SaveLayout("default_layout");
                    _layout.SaveToFile(layoutFile);
                }

                _layout.LoadFromFile(layoutFile);

                XDocument xdoc       = XDocument.Load(layoutFile);
                var       layoutList = xdoc.Elements().First().Elements().ToList();
                Dictionary <MenuItem, string> names = new Dictionary <MenuItem, string>();
                Menu menu = new Menu();

                var saveItem = new MenuItem();
                saveItem.Label      = "Save actual layout...";
                saveItem.Activated += (o, a) =>
                {
                    InputWindow input = InputWindow.Create();
                    input.Title = "Select name for the layout";
                    input.Run();
                    if (string.IsNullOrWhiteSpace(input.Text))
                    {
                        return;
                    }
                    Console.WriteLine($"Saving layout \"{input.Text}\"");
                    _layout.SaveLayout(input.Text);
                    var menuItem = new MenuItem();
                    menuItem.Label      = input.Text;
                    menuItem.Activated += (o, a) => { _layout.LoadLayout(input.Text); };
                    menu.Append(menuItem);
                };
                menu.Append(saveItem);

                foreach (var a in layoutList)
                {
                    var menuItem = new MenuItem();
                    var name     = a.Attributes().First(x => x.Name == "name").Value;
                    names.Add(menuItem, name);
                    menuItem.Label      = name;
                    menuItem.Activated += (o, a) =>
                    {
                        Console.WriteLine($"Loading layout {names[menuItem]}");
                        _layout.LoadLayout(names[menuItem]);
                    };
                    menu.Append(menuItem);

                    if (name == "__default_")
                    {
                        this.ShowAll();
                        _layout.LoadLayout(name);
                    }
                }

                _layoutAction.Submenu = menu;

                if (Program.UpdateAvailable)
                {
                    var updateMenu = new MenuItem();
                    var itemMenu   = new Menu();
                    var item       = new MenuItem();

                    updateMenu.Label      = "Update iCode in background";
                    updateMenu.Activated += (sender, args) =>
                    {
                        Gtk.Application.Invoke((o, a) =>
                        {
                            itemMenu.Remove(updateMenu);
                            item.Label = "Update in progress...";
                        });

                        Task.Factory.StartNew(() =>
                        {
                            var outp = iCode.Utils.Extensions.LaunchProcess(
                                System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                       "Updater"), $"\"{Program.AppImagePath}\"", out int ret);
                            if (ret == 0)
                            {
                                Gtk.Application.Invoke((o, a) =>
                                {
                                    item.Label = "Update completed.";
                                });
                            }
                            else
                            {
                                Gtk.Application.Invoke((o, a) =>
                                {
                                    item.Label = "Update failed.";
                                });
                            }
                        });
                    };

                    itemMenu.Append(updateMenu);
                    item.Label = "Update available";

                    item.Submenu = itemMenu;
                    _menuBar.Append(item);
                }

                _statusBox.ButtonPressEvent += (o, args) =>
                {
                    // Here it will redirect to the future error pane, but I need to fix signing first
                };

                _statusBox.StyleContext.AddProvider(nopad, 1);
                _progressbar1.StyleContext.AddProvider(nopad, 1);
                _createProjectAction.Activated += CreateProject;
                _openProjectAction.Activated   += LoadProjectActivated;
                // var b = layout.LoadFromFile(System.IO.Path.Combine(Program.ConfigPath, "layouts/saved.layout"));
                // Console.WriteLine("Fail or success ? It's " + b + " !");
            }
            catch (Exception e)
            {
                ExceptionWindow.Create(e, this).ShowAll();
            }
        }
		protected virtual void Build()
		{
			global::Stetic.Gui.Initialize(this);
			// Widget OpenGraal.LevelEditor.MainWindow
			this.UIManager = new global::Gtk.UIManager();
			global::Gtk.ActionGroup w1 = new global::Gtk.ActionGroup("Default");
			this.UIManager.InsertActionGroup(w1, 0);
			this.AddAccelGroup(this.UIManager.AccelGroup);
			this.Name = "OpenGraal.LevelEditor.MainWindow";
			this.Title = global::Mono.Unix.Catalog.GetString("MainWindow");
			this.WindowPosition = ((global::Gtk.WindowPosition)(4));
			// Container child OpenGraal.LevelEditor.MainWindow.Gtk.Container+ContainerChild
			this.vbox1 = new global::Gtk.VBox();
			this.vbox1.Name = "vbox1";
			this.vbox1.Spacing = 6;
			// Container child vbox1.Gtk.Box+BoxChild
			this.UIManager.AddUiFromString("<ui><menubar name=\'menubar1\'/></ui>");
			this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget("/menubar1")));
			this.menubar1.Name = "menubar1";
			this.vbox1.Add(this.menubar1);

			Gtk.MenuItem fileMenu = new Gtk.MenuItem ("File");

			Gtk.ImageMenuItem fileMenuNew = new Gtk.ImageMenuItem (Gtk.Stock.New);
			fileMenu.Add (fileMenuNew);

			menubar1.Append (fileMenu);

			global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.menubar1]));
			w2.Position = 0;
			w2.Expand = false;
			w2.Fill = false;
			// Container child vbox1.Gtk.Box+BoxChild
			this.hpaned1 = new global::Gtk.HPaned();
			this.hpaned1.CanFocus = true;
			this.hpaned1.Name = "hpaned1";
			this.hpaned1.Position = 597;
			// Container child hpaned1.Gtk.Paned+PanedChild
			this._levelScrollPane = new global::Gtk.ScrolledWindow();
			this._levelScrollPane.CanFocus = true;
			this._levelScrollPane.Name = "levelScrollPane";
			this._levelScrollPane.ShadowType = ((global::Gtk.ShadowType)(1));
			// Container child _levelScrollPane.Gtk.Container+ContainerChild
			global::Gtk.Viewport w3 = new global::Gtk.Viewport();
			w3.ShadowType = ((global::Gtk.ShadowType)(0));
			// Container child GtkViewport.Gtk.Container+ContainerChild
			this.levelDrawPane = new global::Gtk.Image();
			this.levelDrawPane.Name = "levelDrawPane";

			_levelEventBox = new Gtk.EventBox ();
			_levelEventBox.Add (levelDrawPane);

			w3.Add(_levelEventBox);
			this._levelScrollPane.Add(w3);
			this.hpaned1.Add(this._levelScrollPane);

			_levelEventBox.ButtonPressEvent += new Gtk.ButtonPressEventHandler (onLevelClick);
			_levelEventBox.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler (onLevelRelease);
			_levelEventBox.MotionNotifyEvent += new Gtk.MotionNotifyEventHandler (onLevelMove);

			global::Gtk.Paned.PanedChild w6 = ((global::Gtk.Paned.PanedChild)(this.hpaned1[this._levelScrollPane]));
			w6.Resize = false;
			// Container child hpaned1.Gtk.Paned+PanedChild
			this.notebook1 = new global::Gtk.Notebook();
			this.notebook1.CanFocus = true;
			this.notebook1.Name = "notebook1";
			this.notebook1.CurrentPage = 0;
			// Container child notebook1.Gtk.Notebook+NotebookChild
			this._tilesetScrollPane = new global::Gtk.ScrolledWindow();
			this._tilesetScrollPane.CanFocus = true;
			this._tilesetScrollPane.Name = "tilesetScrollPane";
			this._tilesetScrollPane.ShadowType = ((global::Gtk.ShadowType)(1));
			// Container child scrolledwindow2.Gtk.Container+ContainerChild
			global::Gtk.Viewport w7 = new global::Gtk.Viewport();
			w7.ShadowType = ((global::Gtk.ShadowType)(0));
			// Container child GtkViewport1.Gtk.Container+ContainerChild
			this.tilesetDrawPane = new global::Gtk.Image();
			this.tilesetDrawPane.Name = "tilesetDrawPane";
			this._tilesetEventBox = new global::Gtk.EventBox();
			this._tilesetEventBox.Add(tilesetDrawPane);
			this._tilesetEventBox.ButtonPressEvent += new Gtk.ButtonPressEventHandler (onTilesetClick);
			this._tilesetEventBox.MotionNotifyEvent += new Gtk.MotionNotifyEventHandler (onTilesetDrag);
			this._tilesetEventBox.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler (onTilesetRelease);
			w7.Add(this._tilesetEventBox);
			this._tilesetScrollPane.Add(w7);
			this.notebook1.Add(this._tilesetScrollPane);

			// Notebook tab
			this.tilesetLbl = new global::Gtk.Label();
			this.tilesetLbl.Name = "tilesetLbl";
			this.tilesetLbl.LabelProp = global::Mono.Unix.Catalog.GetString("Tileset");
			this.notebook1.SetTabLabel(this._tilesetScrollPane, this.tilesetLbl);
			this.tilesetLbl.ShowAll();
			// Notebook tab
			global::Gtk.Label w11 = new global::Gtk.Label();
			w11.Visible = true;
			this.notebook1.Add(w11);
			this.layersLbl = new global::Gtk.Label();
			this.layersLbl.Name = "layersLbl";
			this.layersLbl.LabelProp = global::Mono.Unix.Catalog.GetString("Layers");
			this.notebook1.SetTabLabel(w11, this.layersLbl);
			this.layersLbl.ShowAll();
			this.hpaned1.Add(this.notebook1);
			this.vbox1.Add(this.hpaned1);
			global::Gtk.Box.BoxChild w13 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hpaned1]));
			w13.Position = 1;
			// Container child vbox1.Gtk.Box+BoxChild
			this.reportLbl = new global::Gtk.Label();
			this.reportLbl.Name = "reportLbl";
			this.reportLbl.LabelProp = global::Mono.Unix.Catalog.GetString("label1");
			this.reportLbl.Justify = ((global::Gtk.Justification)(1));
			this.vbox1.Add(this.reportLbl);
			global::Gtk.Box.BoxChild w14 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.reportLbl]));
			w14.Position = 2;
			w14.Expand = false;
			w14.Fill = false;
			this.Add(this.vbox1);
			if ((this.Child != null))
			{
				this.Child.ShowAll();
			}
			this.DefaultWidth = 850;
			this.DefaultHeight = 434;
			this.Show();
			this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);

			tilesetDrawPane.GdkWindow = notebook1.GdkWindow;
		}