/// <summary> /// Paste questions in certain position /// </summary> /// <param name="position">Position to paste questions</param> private void OnPasteQuestions(Point position) { this.ClearSelection(); // for the case when mouse position was out of UI change start position if (position.X < 0 || position.Y < 0) { position.X = position.Y = 30; } // calculate delta between topmost item and paste position BaseQuestionViewModel topmostItem = this.copiedQuestionsBuffer.OrderByDescending(x => x.Top).Last(); double deltaTop = topmostItem.Top - position.Y; double deltaLeft = topmostItem.Left - position.X; // buffer for undo/redo BaseQuestionViewModel[] copiedElements = new BaseQuestionViewModel[this.copiedQuestionsBuffer.Count]; for (int i = 0; i < this.copiedQuestionsBuffer.Count; i++) { // create new copy and update name and position BaseQuestionViewModel copy = this.copiedQuestionsBuffer[i].CreateCopy(); copy.Name = NamingManager.GetNextAvailableElementName(this.PageQuestions); copy.Top -= deltaTop; copy.Left -= deltaLeft; this.OnAddQuestion(copy); copy.IsSelected = true; copiedElements[i] = copy; } ActionTracker.TrackAction(new AddElementsAction(copiedElements, this.PageQuestions)); }
/// <summary> /// Add new element via selection rectangle /// </summary> /// <param name="area">Element area</param> public void AddQuestion(Rect area) { string nextName = NamingManager.GetNextAvailableElementName(this.PageQuestions); BaseQuestionViewModel newQuestion; if (this.IsAddingChoiceBox) { newQuestion = new ChoiceBoxViewModel(nextName, area); this.IsAddingChoiceBox = false; } else { newQuestion = new GridViewModel(nextName, area); this.IsAddingGrid = false; } this.OnAddQuestion(newQuestion); newQuestion.IsSelected = true; ActionTracker.TrackAction(new AddElementsAction(new[] { newQuestion }, this.PageQuestions)); }