int IPersistFileFormat.Load([CanBeNull] string pszFilename, uint grfMode, int fReadOnly) { // A valid file name is required. if ((pszFilename == null) && ((fileName == null) || (fileName.Length == 0))) { throw new ArgumentNullException(@"pszFilename"); } loading = true; var hr = VSConstants.S_OK; try { // If the new file name is null, then this operation is a reload var isReload = false; if (pszFilename == null) { isReload = true; } // Show the wait cursor while loading the file VsUIShell.SetWaitCursor(); // Set the new file name if (!isReload) { // Unsubscribe from the notification of the changes in the previous file. fileName = pszFilename; } // Load the file LoadFile(fileName); isDirty = false; // Notify the load or reload NotifyDocChanged(); } finally { loading = false; } return(hr); }
int IVsPersistDocData.SaveDocData(VSSAVEFLAGS dwSave, [CanBeNull] out string pbstrMkDocumentNew, out int pfSaveCanceled) { pbstrMkDocumentNew = null; pfSaveCanceled = 0; int hr; switch (dwSave) { case VSSAVEFLAGS.VSSAVE_Save: case VSSAVEFLAGS.VSSAVE_SilentSave: { var queryEditQuerySave = (IVsQueryEditQuerySave2)GetService(typeof(SVsQueryEditQuerySave)); // Call QueryEditQuerySave uint result; hr = queryEditQuerySave.QuerySaveFile(fileName, // filename 0, // flags null, // file attributes out result); // result if (ErrorHandler.Failed(hr)) { return(hr); } // Process according to result from QuerySave switch ((tagVSQuerySaveResult)result) { case tagVSQuerySaveResult.QSR_NoSave_Cancel: // Note that this is also case tagVSQuerySaveResult.QSR_NoSave_UserCanceled because these // two tags have the same value. pfSaveCanceled = ~0; break; case tagVSQuerySaveResult.QSR_SaveOK: // Call the shell to do the save for us hr = VsUIShell.SaveDocDataToFile(dwSave, this, fileName, out pbstrMkDocumentNew, out pfSaveCanceled); if (ErrorHandler.Failed(hr)) { return(hr); } break; case tagVSQuerySaveResult.QSR_ForceSaveAs: // Call the shell to do the SaveAS for us hr = VsUIShell.SaveDocDataToFile(VSSAVEFLAGS.VSSAVE_SaveAs, this, fileName, out pbstrMkDocumentNew, out pfSaveCanceled); if (ErrorHandler.Failed(hr)) { return(hr); } break; case tagVSQuerySaveResult.QSR_NoSave_Continue: // In this case there is nothing to do. break; default: throw new COMException(); } break; } case VSSAVEFLAGS.VSSAVE_SaveAs: case VSSAVEFLAGS.VSSAVE_SaveCopyAs: { // Make sure the file name as the right extension if (string.Compare(FileExtensionUsed, Path.GetExtension(fileName), true, CultureInfo.CurrentCulture) != 0) { fileName += FileExtensionUsed; } // Call the shell to do the save for us hr = VsUIShell.SaveDocDataToFile(dwSave, this, fileName, out pbstrMkDocumentNew, out pfSaveCanceled); if (ErrorHandler.Failed(hr)) { return(hr); } break; } default: throw new ArgumentException(); } return(VSConstants.S_OK); }