internal virtual DataObject PackageSelectionDataObject(bool cutHighlightItems)
{
CleanupSelectionDataObject(false, false, false);
var sb = new StringBuilder();
DataObject dataObject = null;
try
{
var selectedNodes = GetSelectedNodes();
if (selectedNodes != null)
{
InstantiateItemsDraggedOrCutOrCopiedList();
StringBuilder selectionContent = null;
// If there is a selection package the data
if (selectedNodes.Count > 1)
{
foreach (var node in selectedNodes)
{
selectionContent = node.PrepareSelectedNodesForClipBoard();
if (selectionContent != null)
{
sb.Append(selectionContent);
}
}
}
else if (selectedNodes.Count == 1)
{
var selectedNode = selectedNodes[0];
selectionContent = selectedNode.PrepareSelectedNodesForClipBoard();
if (selectionContent != null)
{
sb.Append(selectionContent);
}
}
}
// Add the project items first.
var ptrToItems = PackageSelectionData(sb, false);
if (ptrToItems == IntPtr.Zero)
{
return null;
}
var fmt = DragDropHelper.CreateFormatEtc(DragDropHelper.CF_VSSTGPROJECTITEMS);
dataObject = new DataObject();
dataObject.SetData(fmt, ptrToItems);
// Now add the project path that sourced data. We just write the project file path.
var ptrToProjectPath = PackageSelectionData(new StringBuilder(GetMkDocument()), true);
if (ptrToProjectPath != IntPtr.Zero)
{
dataObject.SetData(DragDropHelper.CreateFormatEtc(DragDropHelper.CF_VSPROJECTCLIPDESCRIPTOR),
ptrToProjectPath);
}
if (cutHighlightItems)
{
var first = true;
var w = UIHierarchyUtilities.GetUIHierarchyWindow(site, SolutionExplorer);
// This happens in the context of cutting multiple items from the project.
// Since we are already in solution explorer, it is extremely unlikely that we get a null return.
// If we do, the icons for the cut items will not fade. The cut operation will still succeed.
if (w != null)
{
foreach (var node in ItemsDraggedOrCutOrCopied)
{
ErrorHandler.ThrowOnFailure(w.ExpandItem(InteropSafeIVsUIHierarchy, node.ID,
first ? EXPANDFLAGS.EXPF_CutHighlightItem : EXPANDFLAGS.EXPF_AddCutHighlightItem));
first = false;
}
}
}
}
catch (COMException e)
{
Trace.WriteLine("Exception : " + e.Message);
dataObject = null;
}
return dataObject;
}