From 51d56016f3a1f82fd7a62d6b81e0d2e932f4b1a8 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 28 Dec 2022 13:10:04 +0100 Subject: [PATCH] Refactor the code that open edit forms, to make it easier to add different forms in the future --- Source/Core/Builder.csproj | 3 + Source/Core/BuilderMono.csproj | 3 + Source/Core/Windows/ILinedefEditForm.cs | 23 +++ Source/Core/Windows/ISectorEditForm.cs | 23 +++ Source/Core/Windows/IThingEditForm.cs | 23 +++ Source/Core/Windows/LinedefEditForm.cs | 4 +- Source/Core/Windows/LinedefEditFormUDMF.cs | 2 +- Source/Core/Windows/MainForm.cs | 216 +++++++++------------ Source/Core/Windows/SectorEditForm.cs | 2 +- Source/Core/Windows/SectorEditFormUDMF.cs | 2 +- Source/Core/Windows/ThingEditForm.cs | 2 +- Source/Core/Windows/ThingEditFormUDMF.cs | 2 +- 12 files changed, 169 insertions(+), 136 deletions(-) create mode 100644 Source/Core/Windows/ILinedefEditForm.cs create mode 100644 Source/Core/Windows/ISectorEditForm.cs create mode 100644 Source/Core/Windows/IThingEditForm.cs diff --git a/Source/Core/Builder.csproj b/Source/Core/Builder.csproj index 28070d03..5e67fb8d 100644 --- a/Source/Core/Builder.csproj +++ b/Source/Core/Builder.csproj @@ -274,6 +274,9 @@ + + + Form diff --git a/Source/Core/BuilderMono.csproj b/Source/Core/BuilderMono.csproj index 66d5d4db..2214f426 100644 --- a/Source/Core/BuilderMono.csproj +++ b/Source/Core/BuilderMono.csproj @@ -266,6 +266,9 @@ + + + Form diff --git a/Source/Core/Windows/ILinedefEditForm.cs b/Source/Core/Windows/ILinedefEditForm.cs new file mode 100644 index 00000000..49ee90ab --- /dev/null +++ b/Source/Core/Windows/ILinedefEditForm.cs @@ -0,0 +1,23 @@ +#region ================== Namespaces + +using CodeImp.DoomBuilder.Map; +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +#endregion + +namespace CodeImp.DoomBuilder.Windows +{ + public interface ILinedefEditForm + { + //Events + event EventHandler OnValuesChanged; + event EventHandler Closed; + + // Methods + void Setup(ICollection lines, bool selectfront, bool selectback); + DialogResult ShowDialog(IWin32Window owner); + void Dispose(); + } +} diff --git a/Source/Core/Windows/ISectorEditForm.cs b/Source/Core/Windows/ISectorEditForm.cs new file mode 100644 index 00000000..c4f801a4 --- /dev/null +++ b/Source/Core/Windows/ISectorEditForm.cs @@ -0,0 +1,23 @@ +#region ================== Namespaces + +using CodeImp.DoomBuilder.Map; +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +#endregion + +namespace CodeImp.DoomBuilder.Windows +{ + public interface ISectorEditForm + { + //Events + event EventHandler OnValuesChanged; + event EventHandler Closed; + + // Methods + void Setup(ICollection sectors); + DialogResult ShowDialog(IWin32Window owner); + void Dispose(); + } +} diff --git a/Source/Core/Windows/IThingEditForm.cs b/Source/Core/Windows/IThingEditForm.cs new file mode 100644 index 00000000..6f23fa34 --- /dev/null +++ b/Source/Core/Windows/IThingEditForm.cs @@ -0,0 +1,23 @@ +#region ================== Namespaces + +using CodeImp.DoomBuilder.Map; +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +#endregion + +namespace CodeImp.DoomBuilder.Windows +{ + public interface IThingEditForm + { + //Events + event EventHandler OnValuesChanged; + event EventHandler Closed; + + // Methods + void Setup(ICollection things); + DialogResult ShowDialog(IWin32Window owner); + void Dispose(); + } +} diff --git a/Source/Core/Windows/LinedefEditForm.cs b/Source/Core/Windows/LinedefEditForm.cs index c47c002c..00b1ad16 100755 --- a/Source/Core/Windows/LinedefEditForm.cs +++ b/Source/Core/Windows/LinedefEditForm.cs @@ -28,7 +28,7 @@ using CodeImp.DoomBuilder.Types; namespace CodeImp.DoomBuilder.Windows { - internal partial class LinedefEditForm : DelayedForm + internal partial class LinedefEditForm : DelayedForm, ILinedefEditForm { #region ================== Events @@ -149,7 +149,7 @@ namespace CodeImp.DoomBuilder.Windows #region ================== Methods // This sets up the form to edit the given lines - public void Setup(ICollection lines) + public void Setup(ICollection lines, bool selectfront, bool selectback) { preventchanges = true; oldmapischanged = General.Map.IsChanged; diff --git a/Source/Core/Windows/LinedefEditFormUDMF.cs b/Source/Core/Windows/LinedefEditFormUDMF.cs index a24f1977..b96615d4 100755 --- a/Source/Core/Windows/LinedefEditFormUDMF.cs +++ b/Source/Core/Windows/LinedefEditFormUDMF.cs @@ -29,7 +29,7 @@ using CodeImp.DoomBuilder.Types; namespace CodeImp.DoomBuilder.Windows { - internal partial class LinedefEditFormUDMF : DelayedForm + internal partial class LinedefEditFormUDMF : DelayedForm, ILinedefEditForm { #region ================== Events diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 63080077..37cd3bc4 100755 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -4144,159 +4144,117 @@ namespace CodeImp.DoomBuilder.Windows // This shows the dialog to edit lines public DialogResult ShowEditLinedefs(ICollection lines, bool selectfront, bool selectback) { - DialogResult result; - // Show line edit dialog - if(General.Map.UDMF) //mxd + ILinedefEditForm f = GetLinedefEditForm(selectfront, selectback); + DisableProcessing(); //mxd + #if NO_WIN32 + BreakExclusiveMouseInput(); + f.Closed += (object sender, EventArgs e) => { + ResumeExclusiveMouseInput(); + EnableProcessing(); //mxd + }; + #endif + f.Setup(lines, selectfront, selectback); + #if !NO_WIN32 + EnableProcessing(); + #endif + f.OnValuesChanged += EditForm_OnValuesChanged; + editformopen = true; //mxd + DialogResult result = f.ShowDialog(this); + editformopen = false; //mxd + f.Dispose(); + + return result; + } + + private ILinedefEditForm GetLinedefEditForm(bool selectfront, bool selectback) + { + if (General.Map.UDMF) { - LinedefEditFormUDMF f = new LinedefEditFormUDMF(selectfront, selectback); - DisableProcessing(); //mxd - #if NO_WIN32 - BreakExclusiveMouseInput(); - f.Closed += (object sender, EventArgs e) => { - ResumeExclusiveMouseInput(); - EnableProcessing(); //mxd - }; - #endif - f.Setup(lines, selectfront, selectback); - #if !NO_WIN32 - EnableProcessing(); - #endif - f.OnValuesChanged += EditForm_OnValuesChanged; - editformopen = true; //mxd - result = f.ShowDialog(this); - editformopen = false; //mxd - f.Dispose(); + return new LinedefEditFormUDMF(selectfront, selectback); } else { - LinedefEditForm f = new LinedefEditForm(); - DisableProcessing(); //mxd - #if NO_WIN32 - BreakExclusiveMouseInput(); - f.Closed += (object sender, EventArgs e) => { - ResumeExclusiveMouseInput(); - EnableProcessing(); //mxd - }; - #endif - f.Setup(lines); - #if !NO_WIN32 - EnableProcessing(); - #endif - f.OnValuesChanged += EditForm_OnValuesChanged; - editformopen = true; //mxd - result = f.ShowDialog(this); - editformopen = false; //mxd - f.Dispose(); + return new LinedefEditForm(); } - - return result; } // This shows the dialog to edit sectors public DialogResult ShowEditSectors(ICollection sectors) { - DialogResult result; - // Show sector edit dialog - if(General.Map.UDMF) //mxd - { - SectorEditFormUDMF f = new SectorEditFormUDMF(); - DisableProcessing(); //mxd - #if NO_WIN32 - BreakExclusiveMouseInput(); - f.Closed += (object sender, EventArgs e) => { - ResumeExclusiveMouseInput(); - EnableProcessing(); //mxd - }; - #endif - f.Setup(sectors); - #if !NO_WIN32 + ISectorEditForm f = GetSectorEditForm(); + DisableProcessing(); //mxd + #if NO_WIN32 + BreakExclusiveMouseInput(); + f.Closed += (object sender, EventArgs e) => { + ResumeExclusiveMouseInput(); EnableProcessing(); //mxd - #endif - f.OnValuesChanged += EditForm_OnValuesChanged; - editformopen = true; //mxd - result = f.ShowDialog(this); - editformopen = false; //mxd - f.Dispose(); - } - else - { - SectorEditForm f = new SectorEditForm(); - DisableProcessing(); //mxd - #if NO_WIN32 - BreakExclusiveMouseInput(); - f.Closed += (object sender, EventArgs e) => { - ResumeExclusiveMouseInput(); - EnableProcessing(); //mxd - }; - #endif - f.Setup(sectors); - #if !NO_WIN32 - EnableProcessing(); //mxd - #endif - f.OnValuesChanged += EditForm_OnValuesChanged; - editformopen = true; //mxd - result = f.ShowDialog(this); - editformopen = false; //mxd - f.Dispose(); - } + }; + #endif + f.Setup(sectors); + #if !NO_WIN32 + EnableProcessing(); //mxd + #endif + f.OnValuesChanged += EditForm_OnValuesChanged; + editformopen = true; //mxd + DialogResult result = f.ShowDialog(this); + editformopen = false; //mxd + f.Dispose(); return result; } - // This shows the dialog to edit things - public DialogResult ShowEditThings(ICollection things) + private ISectorEditForm GetSectorEditForm() { - DialogResult result; - - // Show thing edit dialog - if(General.Map.UDMF) + if (General.Map.UDMF) { - ThingEditFormUDMF f = new ThingEditFormUDMF(); - DisableProcessing(); //mxd - #if NO_WIN32 - BreakExclusiveMouseInput(); - f.Closed += (object sender, EventArgs e) => { - ResumeExclusiveMouseInput(); - EnableProcessing(); //mxd - }; - #endif - f.Setup(things); - #if !NO_WIN32 - EnableProcessing(); //mxd - #endif - f.OnValuesChanged += EditForm_OnValuesChanged; - editformopen = true; //mxd - result = f.ShowDialog(this); - editformopen = false; //mxd - f.Dispose(); - } - else - { - ThingEditForm f = new ThingEditForm(); - DisableProcessing(); //mxd - #if NO_WIN32 - BreakExclusiveMouseInput(); - f.Closed += (object sender, EventArgs e) => { - ResumeExclusiveMouseInput(); - EnableProcessing(); //mxd - }; - #endif - f.Setup(things); - #if !NO_WIN32 - EnableProcessing(); //mxd - #endif - f.OnValuesChanged += EditForm_OnValuesChanged; - editformopen = true; //mxd - result = f.ShowDialog(this); - editformopen = false; //mxd - f.Dispose(); + return new SectorEditFormUDMF(); } + else + { + return new SectorEditForm(); + } + } + + // This shows the dialog to edit things + public DialogResult ShowEditThings(ICollection things) + { + // Show thing edit dialog + IThingEditForm f = GetThingEditForm(); + DisableProcessing(); //mxd + #if NO_WIN32 + BreakExclusiveMouseInput(); + f.Closed += (object sender, EventArgs e) => { + ResumeExclusiveMouseInput(); + EnableProcessing(); //mxd + }; + #endif + f.Setup(things); + #if !NO_WIN32 + EnableProcessing(); //mxd + #endif + f.OnValuesChanged += EditForm_OnValuesChanged; + editformopen = true; //mxd + DialogResult result = f.ShowDialog(this); + editformopen = false; //mxd + f.Dispose(); return result; } + private IThingEditForm GetThingEditForm() + { + if (General.Map.UDMF) + { + return new ThingEditFormUDMF(); + } + else + { + return new ThingEditForm(); + } + } + //mxd private void EditForm_OnValuesChanged(object sender, EventArgs e) { diff --git a/Source/Core/Windows/SectorEditForm.cs b/Source/Core/Windows/SectorEditForm.cs index 989b9d12..7e4608d6 100755 --- a/Source/Core/Windows/SectorEditForm.cs +++ b/Source/Core/Windows/SectorEditForm.cs @@ -27,7 +27,7 @@ using CodeImp.DoomBuilder.Types; namespace CodeImp.DoomBuilder.Windows { - internal partial class SectorEditForm : DelayedForm + internal partial class SectorEditForm : DelayedForm, ISectorEditForm { #region ================== Events diff --git a/Source/Core/Windows/SectorEditFormUDMF.cs b/Source/Core/Windows/SectorEditFormUDMF.cs index 5fd8839b..c331c01a 100755 --- a/Source/Core/Windows/SectorEditFormUDMF.cs +++ b/Source/Core/Windows/SectorEditFormUDMF.cs @@ -13,7 +13,7 @@ using CodeImp.DoomBuilder.Types; namespace CodeImp.DoomBuilder.Windows { - internal partial class SectorEditFormUDMF : DelayedForm + internal partial class SectorEditFormUDMF : DelayedForm, ISectorEditForm { #region ================== Events diff --git a/Source/Core/Windows/ThingEditForm.cs b/Source/Core/Windows/ThingEditForm.cs index 9fb98327..f0f5ce21 100755 --- a/Source/Core/Windows/ThingEditForm.cs +++ b/Source/Core/Windows/ThingEditForm.cs @@ -33,7 +33,7 @@ namespace CodeImp.DoomBuilder.Windows /// /// Dialog window that allows viewing and editing of Thing properties. /// - internal partial class ThingEditForm : DelayedForm + internal partial class ThingEditForm : DelayedForm, IThingEditForm { #region ================== Events diff --git a/Source/Core/Windows/ThingEditFormUDMF.cs b/Source/Core/Windows/ThingEditFormUDMF.cs index f3b3c37b..5dfaf4ac 100755 --- a/Source/Core/Windows/ThingEditFormUDMF.cs +++ b/Source/Core/Windows/ThingEditFormUDMF.cs @@ -33,7 +33,7 @@ namespace CodeImp.DoomBuilder.Windows /// /// Dialog window that allows viewing and editing of Thing properties. /// - internal partial class ThingEditFormUDMF : DelayedForm + internal partial class ThingEditFormUDMF : DelayedForm, IThingEditForm { #region ================== Events