private void ToolbarButton_Click(object sender, RoutedEventArgs e) { try { switch ((sender as FrameworkElement).Tag.ToString().Replace("toolbar.", "")) { case "new": NewFileCommand.Execute(null); break; case "open": OpenFileCommand.Execute(null); break; case "save": SaveFileCommand.Execute(null); break; case "cut": CutCommand.Execute(null); break; case "copy": CopyCommand.Execute(null); break; case "paste": PasteCommand.Execute(null); break; case "build": BuildRunCommand.Execute(false); break; case "buildrun": BuildRunCommand.Execute(true); break; case "close": CloseTabCommand.Execute(null); break; } } catch (Exception ex) { Debug.Fail(ex.Message); } }
/// <summary> /// Cut selected items /// </summary> /// <returns> /// true if at least one object is cut /// </returns> public void CutSelection() { int i; int n = _graphicsList.Count; _inMemoryList.Clear(); for (i = n - 1; i >= 0; i--) { if (((DrawObject)_graphicsList[i]).Selected) { _inMemoryList.Add(_graphicsList[i]); } } _isCut = true; var cmd = new CutCommand(_graphicsList, _inMemoryList); cmd.Execute(); _undoRedo.AddCommand(cmd); }
private void _cutButton_Click(object sender, EventArgs e) { _cutCommand.Execute(); }
void WpfKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Z && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { UndoBuff.UndoCommand(); //SelectionManager.SelectObject(null); } else if (e.Key == System.Windows.Input.Key.Y && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { UndoBuff.RedoCommand(); //SelectionManager.SelectObject(null); } else if (e.Key == System.Windows.Input.Key.X && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { if (_activeTool is SelectionTool && SelectionManager.SelectedObjects.Count > 0) { var cmd = new CutCommand(this); cmd.CheckApplicability(); cmd.Execute(); cmd.Dispose(); } } else if (e.Key == System.Windows.Input.Key.C && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { if (_activeTool is SelectionTool && SelectionManager.SelectedObjects.Count > 0) { var cmd = new CopyCommand(this); cmd.Execute(); cmd.Dispose(); } } else if (e.Key == System.Windows.Input.Key.V && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { if (_activeTool is SelectionTool) { var cmd = new PasteCommand(this); cmd.Execute(); cmd.Dispose(); } } else if (e.Key == System.Windows.Input.Key.Delete) { if (SelectionManager.SelectedObjects.Count > 0) { UndoBuff.AddCommand(new DeleteGraphicsObject(SelectionManager.SelectedObjects.Cast <FrameworkElement>().FirstOrDefault())); } else if (_activeTool is SelectionTool && SelectionManager.SelectedObjects.Count > 0) { foreach (var el in SelectionManager.SelectedObjects.Cast <FrameworkElement>()) { UndoBuff.AddCommand(new DeleteGraphicsObject(el)); } } SelectionManager.SelectObject(null); } else if (e.Key == System.Windows.Input.Key.Add && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { DocumentCommands.First(c => c.command is ZoomInCommand).command.Execute(); } else if (e.Key == System.Windows.Input.Key.Subtract && (System.Windows.Input.Keyboard.Modifiers & System.Windows.Input.ModifierKeys.Control) != System.Windows.Input.ModifierKeys.None) { DocumentCommands.First(c => c.command is ZoomOutCommand).command.Execute(); } else if (e.Key == System.Windows.Input.Key.Escape) { //NotifySetCurrentTool(toolsList[0]); } else if (e.Key == System.Windows.Input.Key.F5) { UpdateCanvasByXaml(); } else if (_activeTool is SelectionTool) { if (e.Key == System.Windows.Input.Key.Left) { (_activeTool as SelectionTool).MoveHelper(-1, 0); } if (e.Key == System.Windows.Input.Key.Right) { (_activeTool as SelectionTool).MoveHelper(1, 0); } if (e.Key == System.Windows.Input.Key.Up) { (_activeTool as SelectionTool).MoveHelper(0, -1); } if (e.Key == System.Windows.Input.Key.Down) { (_activeTool as SelectionTool).MoveHelper(0, 1); } } MainPanel.UpdateLayout(); }