/// <summary>
/// After a drop or paste, will use the dwEffects
/// to determine whether we need to clean up the source nodes or not. If
/// justCleanup is set, it only does the cleanup work.
/// </summary>
internal void CleanupSelectionDataObject(bool dropped, bool cut, bool moved, bool justCleanup)
{
if (this.ItemsDraggedOrCutOrCopied == null || this.ItemsDraggedOrCutOrCopied.Count == 0)
{
return;
}
try
{
IVsUIHierarchyWindow w = UIHierarchyUtilities.GetUIHierarchyWindow(this.site, HierarchyNode.SolutionExplorer);
foreach (HierarchyNode node in this.ItemsDraggedOrCutOrCopied)
{
if ((moved && (cut || dropped) && !justCleanup))
{
// do not close it if the doc is dirty or we do not own it
bool isDirty, isOpen, isOpenedByUs;
uint docCookie;
IVsPersistDocData ppIVsPersistDocData;
DocumentManager manager = node.GetDocumentManager();
if (manager != null)
{
manager.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out ppIVsPersistDocData);
if (isDirty || (isOpen && !isOpenedByUs))
{
continue;
}
// close it if opened
if (isOpen)
{
manager.Close(__FRAMECLOSE.FRAMECLOSE_NoSave);
}
}
node.Remove(true);
}
else if (w != null)
{
ErrorHandler.ThrowOnFailure(w.ExpandItem((IVsUIHierarchy)this, node.ID, EXPANDFLAGS.EXPF_UnCutHighlightItem));
}
}
}
finally
{
try
{
// Now delete the memory allocated by the packaging of datasources.
// If we just did a cut, or we are told to cleanup, then we need to free the data object. Otherwise, we leave it
// alone so that you can continue to paste the data in new locations.
if (moved || cut || justCleanup)
{
this.ItemsDraggedOrCutOrCopied.Clear();
this.CleanAndFlushClipboard();
}
}
finally
{
this.dropDataType = DropDataType.None;
}
}
}