private void DropLayoutItems(object parameters) { DragDropHelper.DragDropData data = (DragDropHelper.DragDropData)parameters; IEnumerable <ContentItemBaseViewModel> items = (data.Data as IList).Cast <ContentItemBaseViewModel>().ToList(); using (new UndoManager.EventGroupScope()) { if (data.IsReorder) { // Find the destination bool IsAtEnd = false; ContentItemBase target = null; if (data.IndexInserted == _package.LayoutItems.Count) { IsAtEnd = true; } else { while (target == null && data.IndexInserted < _package.LayoutItems.Count) { ContentItemBase testTarget = _package.LayoutItems[data.IndexInserted]; if (items.Select(i => i.Item).Contains(testTarget)) { data.IndexInserted++; } else { target = testTarget; } } } // Remove the moved items items.ForEach(i => _package.LayoutItems.Remove(i.Item)); // Add them to the new location data.IndexInserted = IsAtEnd ? _package.LayoutItems.Count : 0; if (target != null) { data.IndexInserted = _package.LayoutItems.IndexOf(target); } } _package.LayoutItems.InsertRange(data.IndexInserted, items.Select(i => i.Item).ToList()); } }
private void InsertContentItems(object parameter) { ProjectViewModel project = ProjectViewModel.Current; DragDropHelper.DragDropData data = (DragDropHelper.DragDropData)parameter; IEnumerable <ContentItemViewModel> items = (data.Data as IList).Cast <ContentItemViewModel>(); // Check for duplicates var newItems = from civm in items where !project.ReferenceManager.HasExplicitReferencesToPackage(civm, this) select new PackageContentItem(civm.Id, civm.Language, civm.FileName); using (new UndoManager.EventGroupScope()) { _package.Items.AddRange(newItems); } }