// This switches to the mode by user command (when user presses shortcut key) public void UserSwitchToMode() { // Only when a map is opened if (General.Map != null) { //mxd. Not the same mode? if (type != General.Editing.Mode.GetType()) { // Switching from volatile mode to a different volatile mode? if ((General.Editing.Mode != null) && General.Editing.Mode.Attributes.Volatile && this.attribs.Volatile) { // First cancel previous volatile mode General.Editing.CancelVolatileMode(); } // Create instance EditMode newmode = plugin.CreateObject <EditMode>(type); //mxd. Switch mode? if (newmode != null) { General.Editing.ChangeMode(newmode); } } // When in VisualMode and switching to the same VisualMode, switch back to the previous classic mode else if (General.Editing.Mode is VisualMode) { // Switch back to last classic mode General.Editing.ChangeMode(General.Editing.PreviousClassicMode.Name); } //mxd. Switch between view floor and view ceiling textures? else if (General.Editing.Mode is ClassicMode && General.Settings.SwitchViewModes) { ClassicMode.SetViewMode(General.Map.Renderer2D.ViewMode == ViewMode.FloorTextures ? ViewMode.CeilingTextures : ViewMode.FloorTextures); } } }
// // This changes the editing mode. // Order in which events occur for the old and new modes: // // - Constructor of new mode is called // - Disengage of old mode is called // ----- Mode switches ----- // - Engage of new mode is called // - Dispose of old mode is called // // Returns false when cancelled public bool ChangeMode(EditMode nextmode) { EditMode oldmode = mode; if (nextmode != null) { // Verify that this mode is usable bool allowuse = false; foreach (EditModeInfo emi in usedmodes) { if (emi.Type.FullName == nextmode.GetType().FullName) { allowuse = true; break; } } if (!allowuse) { General.Interface.MessageBeep(MessageBeepType.Error); General.WriteLogLine("Attempt to switch to an invalid edit mode " + nextmode.GetType().Name + "!"); return(false); } else { General.WriteLogLine("Preparing to change editing mode to " + nextmode.GetType().Name + "..."); } } else { General.WriteLogLine("Stopping editing mode..."); } // Remember previous mode newmode = nextmode; if (mode != null) { prevmode = mode.GetType(); if (!mode.Attributes.Volatile) { prevstablemode = prevmode; if (mode is ClassicMode) { prevclassicmode = prevmode; } } } else { prevmode = null; prevstablemode = null; prevclassicmode = null; } // Let the plugins know beforehand and check if not cancelled if (General.Plugins.ModeChanges(oldmode, newmode)) { // Disenagage old mode disengaging = true; if (oldmode != null) { General.Plugins.OnEditDisengage(oldmode, newmode); oldmode.OnDisengage(); } // Reset cursor General.Interface.SetCursor(Cursors.Default); // Apply new mode General.WriteLogLine("Editing mode changes from " + TypeNameOrNull(oldmode) + " to " + TypeNameOrNull(nextmode)); General.WriteLogLine("Previous stable mode is " + TypeNameOrNull(prevstablemode) + ", previous classic mode is " + TypeNameOrNull(prevclassicmode)); mode = newmode; disengaging = false; // Engage new mode if (newmode != null) { newmode.OnEngage(); General.Plugins.OnEditEngage(oldmode, newmode); } // Bind new switch actions UnbindSwitchActions(); BindAvailableSwitchActions(); // Update the interface General.MainWindow.EditModeChanged(); // Dispose old mode if (oldmode != null) { oldmode.Dispose(); } // Done switching General.WriteLogLine("Editing mode change complete."); newmode = null; // Redraw the display General.MainWindow.RedrawDisplay(); return(true); } else { // Cancelled General.WriteLogLine("Editing mode change cancelled."); return(false); } }