From 705ee05c54842c72e0fbf9ab51ac8e5183830b77 Mon Sep 17 00:00:00 2001 From: codeimp Date: Thu, 14 Jun 2007 15:35:37 +0000 Subject: [PATCH] mainwindow now saves position/size/state. also changed path seperater in configuration. --- Build/Builder.cfg | 10 ++++ Source/General/General.cs | 19 ++++++- Source/IO/Configuration.cs | 3 +- Source/Interface/MainForm.Designer.cs | 23 +++++--- Source/Interface/MainForm.cs | 80 +++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 11 deletions(-) diff --git a/Build/Builder.cfg b/Build/Builder.cfg index e69de29b..2ff6b575 100644 --- a/Build/Builder.cfg +++ b/Build/Builder.cfg @@ -0,0 +1,10 @@ + +mainwindow +{ + positionx = 27; + windowstate = 2; + sizeheight = 586; + sizewidth = 750; + positiony = 15; +} + diff --git a/Source/General/General.cs b/Source/General/General.cs index 452d1fc3..ee5cca7b 100644 --- a/Source/General/General.cs +++ b/Source/General/General.cs @@ -83,7 +83,7 @@ namespace CodeImp.DoomBuilder // Create main window mainwindow = new MainForm(); - + // Show main window mainwindow.Show(); mainwindow.Update(); @@ -147,5 +147,22 @@ namespace CodeImp.DoomBuilder } #endregion + + #region ================== Terminate + + // This terminates the program + public static void Terminate() + { + // Clean up + mainwindow.Dispose(); + + // Save settings configuration + settings.SaveConfiguration(Path.Combine(apppath, SETTINGS_CONFIG_FILE)); + + // Application ends here and now + Application.Exit(); + } + + #endregion } } diff --git a/Source/IO/Configuration.cs b/Source/IO/Configuration.cs index ec609571..4b2fa815 100644 --- a/Source/IO/Configuration.cs +++ b/Source/IO/Configuration.cs @@ -138,7 +138,7 @@ namespace CodeImp.DoomBuilder.IO #region ================== Constants // Path seperator - public const string DEFAULT_SEPERATOR = "/"; + public const string DEFAULT_SEPERATOR = "."; // Parse mode constants private const int PM_NOTHING = 0; @@ -1208,6 +1208,7 @@ namespace CodeImp.DoomBuilder.IO string data = OutputConfiguration(newline, whitespace); byte[] baData= Encoding.ASCII.GetBytes(data); fstream.Write(baData, 0, baData.Length); + fstream.Flush(); fstream.Close(); // Return true when done, false when errors occurred diff --git a/Source/Interface/MainForm.Designer.cs b/Source/Interface/MainForm.Designer.cs index 1bbe2b74..e0ba3c14 100644 --- a/Source/Interface/MainForm.Designer.cs +++ b/Source/Interface/MainForm.Designer.cs @@ -55,7 +55,7 @@ namespace CodeImp.DoomBuilder.Interface this.menufile}); this.menumain.Location = new System.Drawing.Point(0, 0); this.menumain.Name = "menumain"; - this.menumain.Size = new System.Drawing.Size(619, 24); + this.menumain.Size = new System.Drawing.Size(731, 24); this.menumain.TabIndex = 0; this.menumain.Text = "menuStrip1"; // @@ -125,7 +125,7 @@ namespace CodeImp.DoomBuilder.Interface this.toolbar.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; this.toolbar.Location = new System.Drawing.Point(0, 24); this.toolbar.Name = "toolbar"; - this.toolbar.Size = new System.Drawing.Size(619, 25); + this.toolbar.Size = new System.Drawing.Size(731, 25); this.toolbar.TabIndex = 1; this.toolbar.Text = "toolStrip1"; // @@ -134,16 +134,16 @@ namespace CodeImp.DoomBuilder.Interface this.statusbar.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.statusbar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.statuslabel}); - this.statusbar.Location = new System.Drawing.Point(0, 471); + this.statusbar.Location = new System.Drawing.Point(0, 523); this.statusbar.Name = "statusbar"; - this.statusbar.Size = new System.Drawing.Size(619, 22); + this.statusbar.Size = new System.Drawing.Size(731, 22); this.statusbar.TabIndex = 2; // // statuslabel // this.statuslabel.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.statuslabel.Name = "statuslabel"; - this.statuslabel.Size = new System.Drawing.Size(573, 17); + this.statuslabel.Size = new System.Drawing.Size(716, 17); this.statuslabel.Spring = true; this.statuslabel.Text = "Initializing user interface..."; this.statuslabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -151,9 +151,9 @@ namespace CodeImp.DoomBuilder.Interface // panelinfo // this.panelinfo.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panelinfo.Location = new System.Drawing.Point(0, 370); + this.panelinfo.Location = new System.Drawing.Point(0, 422); this.panelinfo.Name = "panelinfo"; - this.panelinfo.Size = new System.Drawing.Size(619, 101); + this.panelinfo.Size = new System.Drawing.Size(731, 101); this.panelinfo.TabIndex = 4; // // display @@ -167,14 +167,14 @@ namespace CodeImp.DoomBuilder.Interface this.display.InitialImage = null; this.display.Location = new System.Drawing.Point(0, 49); this.display.Name = "display"; - this.display.Size = new System.Drawing.Size(619, 321); + this.display.Size = new System.Drawing.Size(731, 373); this.display.TabIndex = 5; this.display.TabStop = false; // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.ClientSize = new System.Drawing.Size(619, 493); + this.ClientSize = new System.Drawing.Size(731, 545); this.Controls.Add(this.display); this.Controls.Add(this.panelinfo); this.Controls.Add(this.statusbar); @@ -186,7 +186,12 @@ namespace CodeImp.DoomBuilder.Interface this.KeyPreview = true; this.MainMenuStrip = this.menumain; this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "Doom Builder"; + this.Move += new System.EventHandler(this.MainForm_Move); + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); + this.ResizeEnd += new System.EventHandler(this.MainForm_ResizeEnd); + this.Load += new System.EventHandler(this.MainForm_Load); this.menumain.ResumeLayout(false); this.menumain.PerformLayout(); this.statusbar.ResumeLayout(false); diff --git a/Source/Interface/MainForm.cs b/Source/Interface/MainForm.cs index b3ce14a0..5b6179a4 100644 --- a/Source/Interface/MainForm.cs +++ b/Source/Interface/MainForm.cs @@ -15,6 +15,14 @@ namespace CodeImp.DoomBuilder.Interface #endregion + #region ================== Variables + + // Position/size + private Point lastposition; + private Size lastsize; + + #endregion + #region ================== Constructor / Disposer // Constructor @@ -22,6 +30,78 @@ namespace CodeImp.DoomBuilder.Interface { // Setup controls InitializeComponent(); + + // Keep last position and size + lastposition = this.Location; + lastsize = this.Size; + } + + #endregion + + #region ================== Window + + // Window is loaded + private void MainForm_Load(object sender, EventArgs e) + { + // Position window from configuration settings + this.SuspendLayout(); + this.Location = new Point(General.Settings.ReadSetting("mainwindow.positionx", this.Location.X), + General.Settings.ReadSetting("mainwindow.positiony", this.Location.Y)); + this.Size = new Size(General.Settings.ReadSetting("mainwindow.sizewidth", this.Size.Width), + General.Settings.ReadSetting("mainwindow.sizeheight", this.Size.Height)); + this.WindowState = (FormWindowState)General.Settings.ReadSetting("mainwindow.windowstate", (int)FormWindowState.Maximized); + this.ResumeLayout(true); + + // Normal windowstate? + if(this.WindowState == FormWindowState.Normal) + { + // Keep last position and size + lastposition = this.Location; + lastsize = this.Size; + } + } + + // Window is moved + private void MainForm_Move(object sender, EventArgs e) + { + // Normal windowstate? + if(this.WindowState == FormWindowState.Normal) + { + // Keep last position and size + lastposition = this.Location; + lastsize = this.Size; + } + } + + // Window was resized + private void MainForm_ResizeEnd(object sender, EventArgs e) + { + // Normal windowstate? + if(this.WindowState == FormWindowState.Normal) + { + // Keep last position and size + lastposition = this.Location; + lastsize = this.Size; + } + } + + // Window is being closed + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) + { + int windowstate; + + // Determine window state to save + if(this.WindowState != FormWindowState.Minimized) windowstate = (int)this.WindowState; else windowstate = (int)FormWindowState.Normal; + + // Save settings to configuration + General.Settings.WriteSetting("mainwindow.positionx", lastposition.X); + General.Settings.WriteSetting("mainwindow.positiony", lastposition.Y); + General.Settings.WriteSetting("mainwindow.sizewidth", lastsize.Width); + General.Settings.WriteSetting("mainwindow.sizeheight", lastsize.Height); + General.Settings.WriteSetting("mainwindow.windowstate", windowstate); + + // Terminate the program + General.Terminate(); } #endregion