public override int OnBeforeDropNotify(IOleDataObject o, uint dwEffect, out int fCancelDrop)
{
// If there is nothing to be dropped just return that drop should be cancelled.
if (ItemsDraggedOrCutOrCopied == null)
{
fCancelDrop = 1;
return VSConstants.S_OK;
}
fCancelDrop = 0;
var dirty = false;
foreach (var node in ItemsDraggedOrCutOrCopied)
{
bool isDirty, isOpen, isOpenedByUs;
uint docCookie;
IVsPersistDocData ppIVsPersistDocData;
var manager = node.GetDocumentManager();
if (manager != null)
{
manager.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out ppIVsPersistDocData);
if (isDirty && isOpenedByUs)
{
dirty = true;
break;
}
}
}
// if there are no dirty docs we are ok to proceed
if (!dirty)
{
return VSConstants.S_OK;
}
// Prompt to save if there are dirty docs
var message = SR.GetString(SR.SaveModifiedDocuments, CultureInfo.CurrentUICulture);
var title = string.Empty;
var icon = OLEMSGICON.OLEMSGICON_WARNING;
var buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL;
var defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
var result = VsShellUtilities.ShowMessageBox(Site, title, message, icon, buttons, defaultButton);
switch (result)
{
case NativeMethods.IDYES:
break;
case NativeMethods.IDNO:
return VSConstants.S_OK;
case NativeMethods.IDCANCEL:
goto default;
default:
fCancelDrop = 1;
return VSConstants.S_OK;
}
// Save all dirty documents
foreach (var node in ItemsDraggedOrCutOrCopied)
{
var manager = node.GetDocumentManager();
if (manager != null)
{
manager.Save(true);
}
}
return VSConstants.S_OK;
}