/// <summary> /// Copy command can execute. /// </summary> private bool CopyAllTreeCommand_CanExecute() { Collection <ModelElement> modelElements = new Collection <ModelElement>(); if (this.SelectedItem is ModelTreeViewModel) { foreach (BaseModelElementViewModel vm in this.ModelTreeViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } if (!(vm.GetHostedElement() is DomainClass)) { continue; } modelElements.Add(vm.GetHostedElement()); } } if (modelElements.Count == 1) { if (CopyAndPasteOperations.CanExecuteCopy(modelElements)) { modelElements.Clear(); return(true); } } return(false); }
/// <summary> /// Paste command executed. /// </summary> public virtual void OnPasteCommandExecuted() { using (new WaitCursor()) { try { ValidationResult result = CopyAndPasteOperations.ExecutePaste(this.Element); if (result != null) { List <BaseErrorListItemViewModel> errors = new List <BaseErrorListItemViewModel>(); foreach (IValidationMessage msg in result) { errors.Add(new StringErrorListItemViewModel(this.ViewModelStore, msg.MessageId, ModelErrorListItemViewModel.ConvertCategory(msg.Type), msg.Description)); } if (errors.Count > 0) { // clear error list this.EventManager.GetEvent <ErrorListClearItems>().Publish(this); // notify of change this.EventManager.GetEvent <ErrorListAddItems>().Publish(errors); } } } catch (System.Exception ex) { this.GlobalServiceProvider.Resolve <IMessageBoxService>().ShowError("Pasting failed: " + ex.Message); } } }
/// <summary> /// PasteCommand executed. /// </summary> private void PasteCommand_Executed() { Collection <ModelElement> modelElements = new Collection <ModelElement>(); if (this.SelectedItem is ModelTreeViewModel) { foreach (BaseModelElementViewModel vm in this.ModelTreeViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } modelElements.Add(vm.GetHostedElement()); } } else if (this.SelectedItem is DiagramViewModel) { foreach (BaseModelElementViewModel vm in this.DiagramViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } modelElements.Add(vm.GetHostedElement()); } } if (modelElements.Count == 0) { modelElements.Add(this.ModelContext); } using (new WaitCursor()) { try { ValidationResult result = CopyAndPasteOperations.ExecutePaste(modelElements[0]); if (result != null) { string errors = string.Empty; foreach (IValidationMessage msg in result) { errors += msg.Type + " " + msg.MessageId + ": " + msg.Description; } if (!String.IsNullOrEmpty(errors)) { this.GlobalServiceProvider.Resolve <IMessageBoxService>().ShowError("Pasting failed: " + errors); } } } catch (System.Exception ex) { this.GlobalServiceProvider.Resolve <IMessageBoxService>().ShowError("Pasting failed: " + ex.Message); } } }
/// <summary> /// Copy command can execute. /// </summary> public virtual bool OnCopyCommandCanExecute() { if (!this.IsDomainModel) { Collection <ModelElement> modelElements = new Collection <ModelElement>(); modelElements.Add(this.Element); return(CopyAndPasteOperations.CanExecuteCopy(modelElements)); } return(false); }
/// <summary> /// PasteCommand can execute. /// </summary> private bool PasteCommand_CanExecute() { List <ModelElement> modelElements = new List <ModelElement>(); if (this.SelectedItem is ModelTreeViewModel) { foreach (BaseModelElementViewModel vm in this.ModelTreeViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } modelElements.Add(vm.GetHostedElement()); } } else if (this.SelectedItem is DiagramViewModel) { foreach (BaseModelElementViewModel vm in this.DiagramViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } modelElements.Add(vm.GetHostedElement()); } } if (modelElements.Count == 0) { modelElements.Add(this.ModelContext); } if (modelElements.Count == 1) { try { System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject(); if (idataObject != null) { CopyAndPasteOperations.ProcessMoveMode(idataObject); return(CopyAndPasteOperations.CanExecutePaste(modelElements[0], idataObject)); } } catch { } return(false); } return(false); }
/// <summary> /// Copy command executed. /// </summary> public virtual void OnCopyCommandExecuted() { if (!this.IsDomainModel) { using (new WaitCursor()) { try { Collection <ModelElement> modelElements = new Collection <ModelElement>(); modelElements.Add(this.Element); CopyAndPasteOperations.ExecuteCopy(modelElements); } catch (System.Exception ex) { this.GlobalServiceProvider.Resolve <IMessageBoxService>().ShowError("Copying to clipboard failed: " + ex.Message); } } } }
/// <summary> /// Copy command executed. /// </summary> private void CopyCommand_Executed() { Collection <ModelElement> modelElements = new Collection <ModelElement>(); if (this.SelectedItem is ModelTreeViewModel) { foreach (BaseModelElementViewModel vm in this.ModelTreeViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } modelElements.Add(vm.GetHostedElement()); } } else if (this.SelectedItem is DiagramViewModel) { foreach (BaseModelElementViewModel vm in this.DiagramViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } modelElements.Add(vm.GetHostedElement()); } } using (new WaitCursor()) { try { CopyAndPasteOperations.ExecuteCopy(modelElements); } catch (System.Exception ex) { this.GlobalServiceProvider.Resolve <IMessageBoxService>().ShowError("Copying to clipboard failed: " + ex.Message); } } }
/// <summary> /// Copy command executed. /// </summary> private void CopyReferenceTreeCommand_Executed() { Collection <ModelElement> modelElements = new Collection <ModelElement>(); if (this.SelectedItem is ModelTreeViewModel) { foreach (BaseModelElementViewModel vm in this.ModelTreeViewModel.SelectedItems) { if (vm.GetHostedElement() == null) { continue; } if (!(vm.GetHostedElement() is DomainClass)) { continue; } modelElements.Add(vm.GetHostedElement()); } } if (modelElements.Count != 1) { return; } using (new WaitCursor()) { try { CopyAndPasteOperations.Operation = CopyAndPasteOperation.CopyReferenceTree; CopyAndPasteOperations.ExecuteCopy(modelElements); CopyAndPasteOperations.Operation = CopyAndPasteOperation.Default; } catch (System.Exception ex) { this.GlobalServiceProvider.Resolve <IMessageBoxService>().ShowError("Copying to clipboard failed: " + ex.Message); } } }
/// <summary> /// Paste command can execute. /// </summary> public virtual bool OnPasteCommandCanExecute() { try { System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject(); if (this.ViewModelStore != null) { if (this.EventManager != null) { CopyAndPasteOperations.ProcessMoveMode(this.EventManager, idataObject); } } else { } if (idataObject != null) { return(CopyAndPasteOperations.CanExecutePaste(this.Element, idataObject)); } } catch { } return(false); }