Exemple #1
0
 HResult INiPersistDocData.SaveDocData(NiSaveMode mode, out string document, out bool saved)
 {
     return(((INiShell)_serviceProvider.GetService(typeof(INiShell))).SaveDocDataToFile(
                mode,
                this,
                _fileName,
                out document,
                out saved
                ));
 }
 HResult INiPersistDocData.SaveDocData(NiSaveMode mode, out string document, out bool saved)
 {
     return ((INiShell)_serviceProvider.GetService(typeof(INiShell))).SaveDocDataToFile(
         mode,
         this,
         _fileName,
         out document,
         out saved
     );
 }
Exemple #3
0
        public HResult SaveDocDataToFile(NiSaveMode mode, INiPersistFile persistFile, string fileName, out string newFileName, out bool saved)
        {
            newFileName = null;
            saved = false;

            try
            {
                bool isDirty;
                ErrorUtil.ThrowOnFailure(persistFile.IsDirty(out isDirty));

                if (!isDirty)
                {
                    newFileName = fileName;
                    saved = true;

                    return HResult.OK;
                }

                switch (mode)
                {
                    case NiSaveMode.SaveAs:
                    case NiSaveMode.SaveCopyAs:
                        throw new NotImplementedException();

                    case NiSaveMode.Save:
                        INiHierarchy hier;
                        INiWindowFrame windowFrame;
                        ErrorUtil.ThrowOnFailure(((INiOpenDocumentManager)GetService(typeof(INiOpenDocumentManager))).IsDocumentOpen(
                            fileName,
                            out hier,
                            out windowFrame
                        ));

                        if (hier != null)
                        {
                            NiQuerySaveResult querySaveResult;
                            var hr = QuerySaveViaDialog(new[] { hier }, out querySaveResult);

                            if (ErrorUtil.Failure(hr))
                                return hr;

                            switch (querySaveResult)
                            {
                                case NiQuerySaveResult.Cancel:
                                    return HResult.OK;

                                case NiQuerySaveResult.DoNotSave:
                                    // We pretend the document was saved if the
                                    // user asked us not to save the document.

                                    saved = true;
                                    return HResult.OK;
                            }
                        }
                        break;
                }

                newFileName = fileName;
                saved = true;

                return persistFile.Save(newFileName, true);
            }
            catch (Exception ex)
            {
                return ErrorUtil.GetHResult(ex);
            }
        }