/// <summary>Change the name of the tab.</summary> /// <param name="newTabName">New name of the tab.</param> public void ChangeTabText(string newTabName) { TabbedExplorerView ownerview = Owner as TabbedExplorerView; if (Owner != null) { ownerview.SetTabLabelText(this.MainWidget, newTabName); } }
/// <summary>Ask the user if they wish to save the simulation.</summary> /// <returns>Choice for saving the simulation</returns> public Int32 AskToSave() { TabbedExplorerView owner = Owner as TabbedExplorerView; if (owner != null) { Notebook notebook = owner.MainWidget as Notebook; string name = notebook.GetMenuLabelText(notebook.CurrentPageWidget); string message = "Do you want to save changes for " + name + " ?"; MessageDialog md = new MessageDialog(MainWidget.Toplevel as Window, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, message); md.Title = "Save changes"; int result = md.Run(); md.Destroy(); switch ((Gtk.ResponseType)result) { case Gtk.ResponseType.Yes: return(0); case Gtk.ResponseType.No: return(1); default: return(-1); } } return(-1); }
/// <summary> /// A helper function that asks user for a SaveAs name and returns their new choice. /// </summary> /// <param name="oldFilename">The old filename.</param> /// <returns> /// Returns the new file name or null if action cancelled by user. /// </returns> public string SaveAs(string oldFilename) { TabbedExplorerView parentView = this.Parent.Parent.Parent as TabbedExplorerView; return(parentView.AskUserForSaveFileName(oldFilename)); }
/// <summary> /// Constructor /// </summary> public MainForm(string[] args) : base(null) { commandLineArguments = args; // Gtk.Settings.Default.SetLongProperty("gtk-button-images", 1, ""); // Gtk.Settings.Default.ThemeName = "Raleigh"; // The following code for changing theme settings comes from https://github.com/picoe/Eto/issues/442 // The XftRgba setting makes a big difference on Windows // Get the Global Settings //Settings setts = Gtk.Settings.Default; // This enables clear text on Win32, makes the text look a lot less crappy //setts.XftRgba = "rgb"; // This enlarges the size of the controls based on the dpi //setts.XftDpi = 96; // By Default Anti-aliasing is enabled, if you want to disable it for any reason set this value to 0 // setts.XftAntialias = 0; // Enable text hinting // setts.XftHinting = 1; // setts.XftHintstyle = "hintslight"; // setts.XftHintstyle = "hintfull"; // Load the Theme // Gtk.CssProvider css_provider = new Gtk.CssProvider(); // css_provider.LoadFromPath("themes/DeLorean-3.14/gtk-3.0/gtk.css"); // css_provider.LoadFromPath("themes/DeLorean-Dark-3.14/gtk-3.0/gtk.css"); // Gtk.StyleContext.AddProviderForScreen(Gdk.Screen.Default, css_provider, 800) // Glade can generate files in two different formats: libglade or GtkBuilder. // libglade is the older format; GtkBuilder is intended to eventually replace it. // However, in the GtkSharp layer (well, version 2 anyway), the support for // GtkBuilder lacks the ability to autoconnect widgets and events contained // in the glade descriptions. The connections must be done manually. // In GtkSharp version 3, though, Builder does have an Autoconnect member for // event connections. // What is the better way to add resources to a .NET assembly? // Should we use the .resx mechanism, or just add things and // set their Build Action to "Embedded Resource"? // Depending on how the resources are added, they are read in // slightly different ways, apparently. So we might instead have: // Builder Gui = new Builder(); // Gui.AddFromString(ApsimNG.Properties.Resources.MainForm); // Here's how we load the form description using an embedded GtkBuilder file // Builder Gui = new Builder("ApsimNG.Resources.Glade.MainForm.glade"); // window1 = (Window)Gui.GetObject("window1"); // hpaned1 = (HPaned)Gui.GetObject("hpaned1"); // And here's part of how it works with libglade format. // The "[Widget]" attributes are part of the libglade // autoconnection stuff, replacing the need for the .GetObject // calls used with GtkBuilder. //Console.WriteLine("") //Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApsimNG.Resources.Glade.MainForm.glade"); //Glade.XML gxmla = new Glade.XML(s, "mainWindow", null); Glade.XML gxml = new Glade.XML("ApsimNG.Resources.Glade.MainForm.glade", "mainWindow"); gxml.Autoconnect(this); _mainWidget = mainWindow; mainWindow.Icon = new Gdk.Pixbuf(null, "ApsimNG.Resources.apsim logo32.png"); Presenter1 = new Presenters.TabbedExplorerPresenter(); Presenter2 = new Presenters.TabbedExplorerPresenter(); TabbedExplorerView ExplorerView1 = new TabbedExplorerView(this); TabbedExplorerView ExplorerView2 = new TabbedExplorerView(this); Presenter1.Attach(ExplorerView1); Presenter2.Attach(ExplorerView2); hpaned1.Pack1(ExplorerView1.MainWidget, true, true); hpaned1.Pack2(ExplorerView2.MainWidget, true, true); hpaned1.PositionSet = true; hpaned1.Child2.Hide(); hpaned1.Child2.NoShowAll = true; Console.WriteLine("Getting assembly version"); // Get the version of the current assembly. Version version = Assembly.GetExecutingAssembly().GetName().Version; if (version.Major == 0) mainWindow.Title = "APSIM (Custom Build)"; else mainWindow.Title = "APSIM " + version.ToString(); try { if (Utility.Configuration.Settings.MainFormMaximized) mainWindow.GdkWindow.Maximize(); else { System.Drawing.Point location = Utility.Configuration.Settings.MainFormLocation; System.Drawing.Size size = Utility.Configuration.Settings.MainFormSize; mainWindow.Move(location.X, location.Y); mainWindow.Resize(size.Width, size.Height); } } catch (System.Exception) { mainWindow.GdkWindow.Maximize(); } // Look for a script specified on the command line. if (commandLineArguments != null && commandLineArguments.Length > 0) { if (commandLineArguments[0].EndsWith(".cs")) { try { ProcessStartupScript(commandLineArguments[0]); } catch (Exception err) { ErrorMessage = err.Message; if (err.InnerException != null) ErrorMessage += "\r\n" + err.InnerException.Message; ErrorMessage += "\r\n" + err.StackTrace; queryClose = false; mainWindow.Destroy(); // Is this right? } } else if (commandLineArguments[0].EndsWith(".apsimx")) { Presenter1.OpenApsimXFileInTab(commandLineArguments[0]); } } }