public virtual int TransferItem(string oldMkDoc, string newMkDoc, IVsWindowFrame frame)
{
// Fail if hierarchy already closed
if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
{
return VSConstants.E_FAIL;
}
//Fail if the document names passed are null.
if (oldMkDoc == null || newMkDoc == null)
return VSConstants.E_INVALIDARG;
int hr = VSConstants.S_OK;
VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1];
uint itemid = VSConstants.VSITEMID_NIL;
uint cookie = 0;
uint grfFlags = 0;
IVsRunningDocumentTable pRdt = GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
if (pRdt == null)
return VSConstants.E_ABORT;
string doc;
int found;
IVsHierarchy pHier;
uint id, readLocks, editLocks;
IntPtr docdataForCookiePtr = IntPtr.Zero;
IntPtr docDataPtr = IntPtr.Zero;
IntPtr hierPtr = IntPtr.Zero;
// We get the document from the running doc table so that we can see if it is transient
try
{
ErrorHandler.ThrowOnFailure(pRdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldMkDoc, out pHier, out id, out docdataForCookiePtr, out cookie));
}
finally
{
if (docdataForCookiePtr != IntPtr.Zero)
Marshal.Release(docdataForCookiePtr);
}
//Get the document info
try
{
ErrorHandler.ThrowOnFailure(pRdt.GetDocumentInfo(cookie, out grfFlags, out readLocks, out editLocks, out doc, out pHier, out id, out docDataPtr));
}
finally
{
if (docDataPtr != IntPtr.Zero)
Marshal.Release(docDataPtr);
}
// Now see if the document is in the project. If not, we fail
try
{
ErrorHandler.ThrowOnFailure(IsDocumentInProject(newMkDoc, out found, priority, out itemid));
Debug.Assert(itemid != VSConstants.VSITEMID_NIL && itemid != VSConstants.VSITEMID_ROOT);
hierPtr = Marshal.GetComInterfaceForObject(this, typeof(IVsUIHierarchy));
// Now rename the document
ErrorHandler.ThrowOnFailure(pRdt.RenameDocument(oldMkDoc, newMkDoc, hierPtr, itemid));
}
finally
{
if (hierPtr != IntPtr.Zero)
Marshal.Release(hierPtr);
}
//Change the caption if we are passed a window frame
if (frame != null)
{
string caption = "%2";
hr = frame.SetProperty((int)(__VSFPROPID.VSFPROPID_OwnerCaption), caption);
}
return hr;
}