/// <summary>
        /// Saves the hierarchy item to disk.
        /// </summary>
        /// <param name="dwSave">Flags whose values are taken from the VSSAVEFLAGS enumeration.</param>
        /// <param name="silentSaveAsName">File name to be applied when dwSave is set to VSSAVE_SilentSave. </param>
        /// <param name="itemid">Item identifier of the hierarchy item saved from VSITEMID. </param>
        /// <param name="punkDocData">Pointer to the IUnknown interface of the hierarchy item saved.</param>
        /// <param name="pfCancelled">TRUE if the save action was canceled. </param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int SaveItem(VSSAVEFLAGS dwSave, string silentSaveAsName, uint itemid, IntPtr punkDocData, out int pfCancelled)
        {
            // Don't ignore/unignore file changes
            // Use Advise/Unadvise to work around rename situations
            try
            {
                this.StopObservingNestedProjectFile();
                Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
                Debug.Assert(punkDocData != IntPtr.Zero, "docData intptr was zero");

                // Get an IPersistFileFormat object from docData object (we don't call release on punkDocData since did not increment its ref count)
                IPersistFileFormat persistFileFormat = Marshal.GetTypedObjectForIUnknown(punkDocData, typeof(IPersistFileFormat)) as IPersistFileFormat;
                Debug.Assert(persistFileFormat != null, "The docData object does not implement the IPersistFileFormat interface");

                IVsUIShell uiShell = this.GetService(typeof(SVsUIShell)) as IVsUIShell;
                string     newName;
                uiShell.SaveDocDataToFile(dwSave, persistFileFormat, silentSaveAsName, out newName, out pfCancelled);

                // When supported do a rename of the nested project here
            }
            finally
            {
                // Succeeded or not we must hook to the file change events
                // Don't ignore/unignore file changes
                // Use Advise/Unadvise to work around rename situations
                this.ObserveNestedProjectFile();
            }

            return(VSConstants.S_OK);
        }
Exemple #2
0
        int IVsPersistDocData.SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            pbstrMkDocumentNew = null;
            pfSaveCanceled     = 0;
            int hr = VSConstants.S_OK;

            switch (dwSave)
            {
            case VSSAVEFLAGS.VSSAVE_Save:
            case VSSAVEFLAGS.VSSAVE_SilentSave:
            {
                IVsQueryEditQuerySave2 queryEditQuerySave = (IVsQueryEditQuerySave2)GetService(typeof(SVsQueryEditQuerySave));

                // Call QueryEditQuerySave
                uint result = 0;
                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
                    IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                    hr = uiShell.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
                    IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                    hr = uiShell.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(Resources.ExceptionMessageQEQS);
                }
                break;
            }

            case VSSAVEFLAGS.VSSAVE_SaveAs:
            case VSSAVEFLAGS.VSSAVE_SaveCopyAs:
            {
                // Make sure the file name as the right extension
                if (string.Compare(Constants.fileExtension, System.IO.Path.GetExtension(fileName), true, CultureInfo.CurrentCulture) != 0)
                {
                    fileName += Constants.fileExtension;
                }
                // Call the shell to do the save for us
                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                hr = uiShell.SaveDocDataToFile(dwSave, this, fileName, out pbstrMkDocumentNew, out pfSaveCanceled);
                if (ErrorHandler.Failed(hr))
                {
                    return(hr);
                }
                break;
            }

            default:
                throw new ArgumentException(Resources.ExceptionMessageSaveFlag);
            }
            ;

            return(VSConstants.S_OK);
        }
Exemple #3
0
        /// <summary>
        /// Saves the document
        /// </summary>
        /// <param name="saveFlag">Save flags</param>
        /// <param name="newFilePath">File path</param>
        /// <param name="saveCanceled">True if save was not successuful</param>
        public int SaveDocData(VSSAVEFLAGS saveFlag, out string newFilePath, out int saveCanceled)
        {
            newFilePath  = null;
            saveCanceled = 0;
            int hr = VSConstants.S_OK;

            switch (saveFlag)
            {
            case VSSAVEFLAGS.VSSAVE_Save:
            case VSSAVEFLAGS.VSSAVE_SilentSave: {
                IVsQueryEditQuerySave2 queryEditQuerySave = (IVsQueryEditQuerySave2)Package.GetGlobalService(typeof(SVsQueryEditQuerySave));

                // Call QueryEditQuerySave
                uint result = 0;
                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.
                    saveCanceled = ~0;
                    break;

                case tagVSQuerySaveResult.QSR_SaveOK: {
                    // Call the shell to do the save for us
                    IVsUIShell uiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
                    hr = uiShell.SaveDocDataToFile(saveFlag, (IPersistFileFormat)this, FileName, out newFilePath, out saveCanceled);
                    if (ErrorHandler.Failed(hr))
                    {
                        return(hr);
                    }
                }
                break;

                case tagVSQuerySaveResult.QSR_ForceSaveAs: {
                    // Call the shell to do the SaveAS for us
                    IVsUIShell uiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
                    hr = uiShell.SaveDocDataToFile(VSSAVEFLAGS.VSSAVE_SaveAs, (IPersistFileFormat)this, FileName, out newFilePath, out saveCanceled);
                    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("Invalid QuerySave result.");
                }
                break;
            }

            case VSSAVEFLAGS.VSSAVE_SaveAs:
            case VSSAVEFLAGS.VSSAVE_SaveCopyAs: {
                // Call the shell to do the save for us
                IVsUIShell uiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
                hr = uiShell.SaveDocDataToFile(saveFlag, (IPersistFileFormat)this, FileName, out newFilePath, out saveCanceled);
                if (ErrorHandler.Failed(hr))
                {
                    return(hr);
                }
                break;
            }

            default:
                throw new ArgumentException("Invalid VSSAVEFLAGS.");
            }


            return(VSConstants.S_OK);
        }
Exemple #4
0
        int IVsPersistDocData.SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
        {
            pbstrMkDocumentNew = null;
            pfSaveCanceled     = 0;
            int hr;

            IVsUIShell uiShell = (IVsUIShell)serviceProvider.GetService(typeof(IVsUIShell));

            switch (dwSave)
            {
            case VSSAVEFLAGS.VSSAVE_Save:
            case VSSAVEFLAGS.VSSAVE_SilentSave:
            {
                tagVSQuerySaveResult qsResult;
                hr = QuerySave(out qsResult);
                if (ErrorHandler.Failed(hr))
                {
                    return(hr);
                }

                if (qsResult == tagVSQuerySaveResult.QSR_NoSave_Cancel)
                {
                    pfSaveCanceled = ~0;
                }
                else if (qsResult == tagVSQuerySaveResult.QSR_SaveOK)
                {
                    hr = uiShell.SaveDocDataToFile(dwSave, this, fileName,
                                                   out pbstrMkDocumentNew, out pfSaveCanceled);
                    if (ErrorHandler.Failed(hr))
                    {
                        return(hr);
                    }
                }
                else if (qsResult == tagVSQuerySaveResult.QSR_ForceSaveAs)
                {
                    hr = uiShell.SaveDocDataToFile(VSSAVEFLAGS.VSSAVE_SaveAs, this, fileName,
                                                   out pbstrMkDocumentNew, out pfSaveCanceled);
                    if (ErrorHandler.Failed(hr))
                    {
                        return(hr);
                    }
                }
                break;
            }

            case VSSAVEFLAGS.VSSAVE_SaveAs:
            case VSSAVEFLAGS.VSSAVE_SaveCopyAs:
            {
                // --- Make sure the file name as the right extension
                if (String.Compare(".mysql", Path.GetExtension(fileName), true,
                                   CultureInfo.CurrentCulture) != 0)
                {
                    fileName += ".mysql";
                }

                // --- Call the shell to do the save for us
                hr = uiShell.SaveDocDataToFile(dwSave, this, fileName,
                                               out pbstrMkDocumentNew, out pfSaveCanceled);
                if (ErrorHandler.Failed(hr))
                {
                    return(hr);
                }
                break;
            }

            default:
                throw new ArgumentException("Unable to save file");
            }
            return(VSConstants.S_OK);
        }