private void PrintCards() { AppMode = AppModes.PrintCards; if (Layouts != null) { SelectedLayout = Layouts.FirstOrDefault(); } }
private void OnEditorActivated(object sender, ActivationEventArgs eventArgs) { if (eventArgs.Opened) { Editor.Activated -= OnEditorActivated; // Load EditorWindow state. LoadEditorWindowState(); // Check if a layout was requested using the --layout command line parameter. var layoutName = GetLayoutNameFromCommandLine(); WindowLayout layout = null; if (layoutName != null) { layout = Layouts.FirstOrDefault(l => l.Name == layoutName); if (layout == null) { Logger.Error(Invariant($"The layout \"{layoutName}\" was not found. This layout was requested using a command line parameter.")); } } if (layout == null) { // Load previous window layout. layout = Layouts.FirstOrDefault(l => l.Name == Settings.Default.ActiveWindowLayout) ?? Layouts.FirstOrDefault(); } SwitchLayout(layout); if (Editor.Window != null) { // Save EditorWindow state and window layout before window is closed. Editor.Window.Closing += (s, e) => { SaveEditorWindowState(); SaveLayouts(); }; } } }
private void UserStateItemClick(object sender, EventArgs e) { editor.AcceptLayoutForControl(Layouts.FirstOrDefault(state => state.Id == Convert.ToInt32(((DXMenuItem)sender).Tag))); }
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); } } }
private void SavePresetAs() { Logger.Info("Saving window layout as new preset."); ShowSaveLayoutDialog: var saveLayoutDialog = new SaveLayoutViewModel { DisplayName = "Save Window Layout", LayoutName = "New layout" }; string layoutName = null; WindowLayout existingLayout = null; var result = _windowService.ShowDialog(saveLayoutDialog); if (result.HasValue && result.Value) { 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."); layoutName = saveLayoutDialog.LayoutName; // Overwrite existing window layout? existingLayout = Layouts.FirstOrDefault(l => string.Compare(l.Name, layoutName, StringComparison.OrdinalIgnoreCase) == 0); if (existingLayout != null) { if (existingLayout.IsFactoryPreset) { MessageBox.Show( $"\"{layoutName}\" 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 \"{layoutName}\" already exists. Overwrite existing?", Editor.ApplicationName, MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation); if (messageBoxResult == MessageBoxResult.No) { // Try again. goto ShowSaveLayoutDialog; } if (messageBoxResult == MessageBoxResult.Cancel) { // Abort. layoutName = null; } } } } if (!string.IsNullOrEmpty(layoutName)) { try { // Save window layout as new preset. var serializedLayout = Editor.SaveLayout(true); var layout = new WindowLayout(layoutName, false) { SerializedLayout = serializedLayout }; SaveUserPreset(layout); if (existingLayout != null) { Layouts.Remove(existingLayout); } Layouts.Add(layout); ActiveLayout = layout; UpdateWindowLayoutItem(); } catch (Exception exception) { Logger.Error(exception, "Could not save window layout as new preset \"{0}\".", layoutName); string message = $"Could not save window layout as new preset \"{layoutName}\".\n\n{exception.Message}"; MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }