/// <summary> /// Provides access to the entities of the layout with the given name. /// </summary> /// <param name="name">The name of the layout.</param> /// <returns>An EntityContainer to access the layout's entities.</returns> public EntityContainer PaperSpace(string name) { Require.NotDisposed(Database.IsDisposed, nameof(AcadDatabase)); Require.ParameterNotNull(name, nameof(name)); Require.NameExists <Layout>(Layouts.Contains(name), nameof(name)); var layout = Layouts.Element(name); Require.IsTrue(layout.ModelType, $"{name} is not a paper space layout"); return(new EntityContainer(Database, transaction, layout.BlockTableRecordId)); }
internal void RenameWindowLayout(WindowLayout layout) { Debug.Assert(layout != null); Debug.Assert(Layouts.Contains(layout)); string oldLayoutName = layout.Name; Logger.Info("Renaming window layout \"{0}\".", oldLayoutName); ShowSaveLayoutDialog: var saveLayoutDialog = new SaveLayoutViewModel { DisplayName = "Rename Window Layout", LayoutName = oldLayoutName }; string newLayoutName = null; WindowLayout existingLayout = null; var result = _windowService.ShowDialog(saveLayoutDialog); if (result.HasValue && result.Value && saveLayoutDialog.LayoutName != oldLayoutName) { Debug.Assert(!string.IsNullOrEmpty(saveLayoutDialog.LayoutName), "The layout name must not be null or empty."); Debug.Assert(saveLayoutDialog.LayoutName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1, "The layout name must not contain invalid characters."); newLayoutName = saveLayoutDialog.LayoutName; // Overwrite existing file? existingLayout = Layouts.FirstOrDefault(l => l.Name == newLayoutName); if (existingLayout != null) { if (existingLayout.IsFactoryPreset) { MessageBox.Show( $"\"{newLayoutName}\" is a factory preset. Factory presets cannot be overwritten.", Editor.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Exclamation); // Try again. goto ShowSaveLayoutDialog; } else { var messageBoxResult = MessageBox.Show( $"The layout \"{newLayoutName}\" already exists. Overwrite existing?", Editor.ApplicationName, MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation); if (messageBoxResult == MessageBoxResult.No) { // Try again. goto ShowSaveLayoutDialog; } if (messageBoxResult == MessageBoxResult.Cancel) { // Abort. newLayoutName = null; } } } } if (!string.IsNullOrEmpty(newLayoutName)) { try { // Rename window layout. RenameUserSession(layout.Name, newLayoutName); RenameUserPreset(layout.Name, newLayoutName); if (existingLayout != null) { Layouts.Remove(existingLayout); } layout.Name = newLayoutName; UpdateWindowLayoutItem(); } catch (Exception exception) { Logger.Error(exception, "Could not rename window layout (old name: \"{0}\", new name: \"{1}\").", oldLayoutName, newLayoutName); string message = $"Could not rename window layout.\n\n{exception.Message}"; MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }