コード例 #1
0
        /// <summary>
        /// Paste selected items
        /// </summary>
        /// <returns>
        /// true if at least one object is pasted
        /// </returns>
        public void PasteSelection()
        {
            int n = _inMemoryList.Count;

            UnselectAll();

            if (n > 0)
            {
                var tempList = new ArrayList();

                int i;
                for (i = n - 1; i >= 0; i--)
                {
                    tempList.Add(((DrawObject)_inMemoryList[i]).Clone());
                }

                if (_inMemoryList.Count > 0)
                {
                    var cmd = new PasteCommand(_graphicsList, tempList);
                    cmd.Execute();
                    _undoRedo.AddCommand(cmd);

                    //If the items are cut, we will not delete it
                    if (_isCut)
                    {
                        _inMemoryList.Clear();
                    }
                }
            }
        }
コード例 #2
0
 private void DelayedPasteCommand(object sender, DelayerActionEventArgs <object> e)
 {
     if (PasteCommand.CanExecute(null))
     {
         PasteCommand.Execute(null);
     }
 }
コード例 #3
0
 private void AttemptExecute()
 {
     if (this.IsChecked && _pasteCommand.CanExecute(null))
     {
         _pasteCommand.Execute(null);
     }
 }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 private void OnExecutePaste(object sender, ExecutedRoutedEventArgs e)
 {
     PasteCommand?.Execute(e.Parameter);
 }
コード例 #6
0
 private void _pasteButton_Click(object sender, EventArgs e)
 {
     _pasteCommand.Execute();
 }
コード例 #7
0
        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();
        }
コード例 #8
0
        public void ReadAndShiftElementsAndConnections(XmlReader reader, Vector elementsShiftVector)
        {
            List <Element>         ReadElements         = new List <Element>();
            List <ConnectionModel> ReadConnectionModels = new List <ConnectionModel>();

            try
            {
                reader.MoveToContent();
                reader.Read();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "SimulationProperties")
                    {
                        if (reader.Read() && reader.Name == "ReferenceImpedance")
                        {
                            ReferenceImpedance = double.Parse(reader.ReadString());
                            OnPropertyChanged(nameof(ReferenceImpedance));
                        }
                        else
                        {
                            throw new Exception("ReferenceImpedance is missing or it is in the wrong place");
                        }
                        if (reader.Read() && reader.Name == "FromFreq")
                        {
                            FromFreq = double.Parse(reader.ReadString());
                            OnPropertyChanged(nameof(FromFreq));
                        }
                        else
                        {
                            throw new Exception("FromFreq is missing or it is in the wrong place");
                        }
                        if (reader.Read() && reader.Name == "ToFreq")
                        {
                            ToFreq = double.Parse(reader.ReadString());
                            OnPropertyChanged(nameof(ToFreq));
                        }
                        else
                        {
                            throw new Exception("ToFreq is missing or it is in the wrong place");
                        }
                        if (reader.Read() && reader.Name == "Step")
                        {
                            Step = double.Parse(reader.ReadString());
                            OnPropertyChanged(nameof(Step));
                        }
                        else
                        {
                            throw new Exception("Step is missing or it is in the wrong place");
                        }
                    }
                }

                do
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                        case "Element":
                            Element readElement = ReadElement(reader);
                            readElement.Position = Point.Add(readElement.Position, elementsShiftVector);
                            ReadElements.Add(readElement);
                            break;

                        case "Connection":
                            ReadConnectionModels.Add(ReadConnectionModel(reader, ReadElements));
                            break;
                        }
                    }
                } while (reader.Read());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return;
            }

            //changing ID's that every Element, connector and connection have unique
            foreach (Element readElement in ReadElements)
            {
                readElement.ID = Guid.NewGuid();
                foreach (ConnectorModel connectorModel in readElement.Connectors)
                {
                    connectorModel.ID = Guid.NewGuid();
                }
            }
            foreach (ConnectionModel readConnectionModel in ReadConnectionModels)
            {
                readConnectionModel.ID = Guid.NewGuid();
            }

            PasteCommand newPasteCommand = new PasteCommand(ReadElements, ReadConnectionModels, this);

            MyCommandManager.AddToList(newPasteCommand);
            newPasteCommand.Execute();
            RenumberPorts(Elements);
        }
コード例 #9
0
        private void PasteItem(object sender, ExecutedRoutedEventArgs e)
        {
            var cmd = new PasteCommand();

            cmd.Execute(null);
        }