From ab28c9d66be1eaec3dde27f8ebfb1527d8590038 Mon Sep 17 00:00:00 2001 From: codeimp Date: Wed, 8 Oct 2008 15:14:02 +0000 Subject: [PATCH] better way to cancel editing mode --- Source/BuilderModes/General/BuilderPlug.cs | 6 +- Source/General/MapManager.cs | 84 ++++++++++------------ Source/Plugins/Plug.cs | 4 +- Source/Plugins/PluginManager.cs | 6 +- 4 files changed, 49 insertions(+), 51 deletions(-) diff --git a/Source/BuilderModes/General/BuilderPlug.cs b/Source/BuilderModes/General/BuilderPlug.cs index de2b381e..cfa4d4fc 100644 --- a/Source/BuilderModes/General/BuilderPlug.cs +++ b/Source/BuilderModes/General/BuilderPlug.cs @@ -110,12 +110,14 @@ namespace CodeImp.DoomBuilder.BuilderModes #endregion #region ================== Events - + // When the editing mode changes - public override void OnModeChange(EditMode oldmode, EditMode newmode) + public override bool OnModeChange(EditMode oldmode, EditMode newmode) { // Show the correct menu for the new mode menusform.ShowEditingModeMenu(newmode); + + return base.OnModeChange(oldmode, newmode); } #endregion diff --git a/Source/General/MapManager.cs b/Source/General/MapManager.cs index 40132290..d55f2d8c 100644 --- a/Source/General/MapManager.cs +++ b/Source/General/MapManager.cs @@ -65,7 +65,6 @@ namespace CodeImp.DoomBuilder private string filetitle; private string filepathname; private string temppath; - private bool cancelmodechange; // Main objects private MapSet map; @@ -98,7 +97,6 @@ namespace CodeImp.DoomBuilder public string FilePathName { get { return filepathname; } } public string FileTitle { get { return filetitle; } } public string TempPath { get { return temppath; } } - public bool CancelModeChange { get { return cancelmodechange; } set { cancelmodechange |= value; } } internal MapOptions Options { get { return options; } } public MapSet Map { get { return map; } } public EditMode Mode { get { return mode; } } @@ -865,10 +863,10 @@ namespace CodeImp.DoomBuilder // - Engage of new mode is called // - Dispose of old mode is called // - public void ChangeMode(EditMode nextmode) + // Returns false when cancelled + public bool ChangeMode(EditMode nextmode) { EditMode oldmode = mode; - cancelmodechange = false; // Log info if(newmode != null) @@ -889,56 +887,50 @@ namespace CodeImp.DoomBuilder prevstablemode = null; } - // Let the plugins know beforehand - General.Plugins.ModeChanges(oldmode, newmode); - - // Change cancelled? - if(cancelmodechange) + // Let the plugins know beforehand and check if not cancelled + if(General.Plugins.ModeChanges(oldmode, newmode)) { - General.WriteLogLine("Edit mode change cancelled."); - return; - } - - // Disenagage old mode - if(oldmode != null) oldmode.OnDisengage(); + // Disenagage old mode + if(oldmode != null) oldmode.OnDisengage(); - // Change cancelled? - if(cancelmodechange) - { - General.WriteLogLine("Edit mode change cancelled."); - return; - } + // Reset cursor + General.Interface.SetCursor(Cursors.Default); + + // Apply new mode + mode = newmode; + + // Engage new mode + if(newmode != null) newmode.OnEngage(); - // Reset cursor - General.Interface.SetCursor(Cursors.Default); - - // Apply new mode - mode = newmode; - - // Engage new mode - if(newmode != null) newmode.OnEngage(); + // Check appropriate button on interface + // And show the mode name + if(mode != null) + { + General.MainWindow.CheckEditModeButton(mode.EditModeButtonName); + General.MainWindow.DisplayModeName(mode.Attributes.DisplayName); + } + else + { + General.MainWindow.CheckEditModeButton(""); + General.MainWindow.DisplayModeName(""); + } - // Check appropriate button on interface - // And show the mode name - if(mode != null) - { - General.MainWindow.CheckEditModeButton(mode.EditModeButtonName); - General.MainWindow.DisplayModeName(mode.Attributes.DisplayName); + // Dispose old mode + if(oldmode != null) oldmode.Dispose(); + + // Done switching + newmode = null; + + // Redraw the display + General.MainWindow.RedrawDisplay(); + return true; } else { - General.MainWindow.CheckEditModeButton(""); - General.MainWindow.DisplayModeName(""); + // Cancelled + General.WriteLogLine("Edit mode change cancelled."); + return false; } - - // Dispose old mode - if(oldmode != null) oldmode.Dispose(); - - // Done switching - newmode = null; - - // Redraw the display - General.MainWindow.RedrawDisplay(); } // This changes mode by class name and optionally with arguments diff --git a/Source/Plugins/Plug.cs b/Source/Plugins/Plug.cs index 1715a795..34908f2d 100644 --- a/Source/Plugins/Plug.cs +++ b/Source/Plugins/Plug.cs @@ -115,11 +115,13 @@ namespace CodeImp.DoomBuilder.Plugins /// /// This is called by the Doom Builder core when the editing mode changes. + /// Return false to abort the mode change. /// /// The previous editing mode /// The new editing mode - public virtual void OnModeChange(EditMode oldmode, EditMode newmode) + public virtual bool OnModeChange(EditMode oldmode, EditMode newmode) { + return true; } /// diff --git a/Source/Plugins/PluginManager.cs b/Source/Plugins/PluginManager.cs index 3c151f0b..87f5a8ec 100644 --- a/Source/Plugins/PluginManager.cs +++ b/Source/Plugins/PluginManager.cs @@ -208,9 +208,11 @@ namespace CodeImp.DoomBuilder.Plugins } - public void ModeChanges(EditMode oldmode, EditMode newmode) + public bool ModeChanges(EditMode oldmode, EditMode newmode) { - foreach(Plugin p in plugins) p.Plug.OnModeChange(oldmode, newmode); + bool result = true; + foreach(Plugin p in plugins) result &= p.Plug.OnModeChange(oldmode, newmode); + return result; }