public void SaveWorkbook(IWorkbookSaveOperation saveOperation) { AssertWorkbookSession(); Workbook.Save(saveOperation); UpdateTitle(); // Update working directory in agent. If not connected, this will happen when creating the // compilation workspace. if (Agent.IsConnected) { Agent.Api.AssociateClientSession( ClientSessionAssociationKind.Reassociating, Workbook.WorkingBasePath).Forget(); } }
public override bool WriteSafelyToUrl( NSUrl url, string typeName, NSSaveOperationType saveOperation, out NSError outError) { Log.Info(TAG, $"url: {url}, typeName: {typeName}, saveOperation: {saveOperation}"); outError = AppDelegate.SuppressionNSError; try { if (workbookSaveOperation == null) { workbookSaveOperation = Session.CreateWorkbookSaveOperation(); } switch (saveOperation) { case NSSaveOperationType.Save: case NSSaveOperationType.InPlace: case NSSaveOperationType.Autosave: break; default: workbookSaveOperation.Destination = url.Path; break; } Session.SaveWorkbook(workbookSaveOperation); } catch (Exception e) { e.ToUserPresentable(Catalog.Format(Catalog.GetString( "“{0}” could not be saved.", comment: "'{0}' is a URL"), url)).Present(); return(false); } finally { workbookSaveOperation = null; } outError = null; return(true); }
public void SaveWorkbook(IWorkbookSaveOperation saveOperation) { AssertWorkbookSession(); Workbook.Save(saveOperation); UpdateTitle(); }
public void Save(IWorkbookSaveOperation operation) { var saveOperation = operation as SaveOperation; if (saveOperation == null) { throw new ArgumentNullException(nameof(operation)); } LogicalPath = operation.Destination; SaveOptions = WorkbookSaveOptions.None; if (IndexPage != null && IndexPage.IsUntitled) { IndexPage.Title = LogicalPath.NameWithoutExtension; } if (saveOperation.OnlyPage != null && !saveOperation.OnlyPageHasDependencies && !openedFromDirectory) { // The workbook package has only a single page with no relative // dependencies. If the original path was a workbook directory, // keep that format. If we originally opened from a workbook // directory and our target save path is not a directory, keep // that format. Otherwise, save the page as a single file. var writePath = logicalPath.DirectoryExists ? logicalPath.Combine(saveOperation.OnlyPage.Path) : logicalPath; using (var writer = new StreamWriter(writePath)) saveOperation.OnlyPage.Write(writer, Packages); WorkingPath = logicalPath; return; } var sourceBasePath = WorkingBasePath; if (saveOperation.OnlyPage != null) { saveOperation.OnlyPage.Path = indexPageFileName; } if (logicalPath.FileExists) { File.Delete(logicalPath); } logicalPath.CreateDirectory(); if (WorkingPath.DirectoryExists && WorkingPath.Extension == dottedExtension) { CopyDirectoryContents(WorkingPath, logicalPath); } foreach (var page in saveOperation.AllDependencies) { using (var writer = new StreamWriter(logicalPath.Combine(page.Key.Path))) page.Key.Write(writer, Packages); foreach (var dep in page.Value) { var sourcePath = sourceBasePath.Combine(dep); if (!sourcePath.FileExists) { continue; } // FIXME: if the dep is not a child of the baseSourcePath this // copy will result in the file not being located in the actual // workbook package (e.g. the dep is something like '../foo.jpg'). // Adjust the dest path so that it will be copied into the package, // but the workbook content itself will be broken until we can // actually fix this up in the markdown. var destPath = logicalPath.Combine(dep); if (destPath.IsChildOfDirectory(logicalPath) && destPath != sourcePath) { destPath.ParentDirectory.CreateDirectory(); File.Copy(sourcePath, destPath, true); } } } if (saveOperation.Options.HasFlag(WorkbookSaveOptions.Archive)) { ArchiveDirectory(logicalPath); } // For overwrite saves of archives, WorkingPath should continue // to point to the extracted directory in temp if (!saveOperation.Options.HasFlag(WorkbookSaveOptions.Archive) || WorkingPath == null || !WorkingPath.Exists) { WorkingPath = logicalPath; } }
public override bool PrepareSavePanel(NSSavePanel savePanel) { workbookSaveOperation = Session.CreateWorkbookSaveOperation(); if (workbookSaveOperation.SupportedOptions == WorkbookSaveOptions.None) { return(true); } var stackView = new NSStackView { Orientation = NSUserInterfaceLayoutOrientation.Vertical, Spacing = 8, EdgeInsets = new NSEdgeInsets(12, 12, 12, 12) }; Action <NSView> addRow = row => { stackView.AddView(row, NSStackViewGravity.Top); stackView.AddConstraint(NSLayoutConstraint.Create( row, NSLayoutAttribute.Width, NSLayoutRelation.Equal, stackView, NSLayoutAttribute.Width, 1, 0)); }; if (workbookSaveOperation.SupportedOptions.HasFlag(WorkbookSaveOptions.Archive)) { addRow(CreateRow( Catalog.GetString("Workbook Format:"), new [] { Catalog.GetString("Package Directory"), Catalog.GetString("Archive") }, workbookSaveOperation.Options.HasFlag(WorkbookSaveOptions.Archive) ? 1 : 0, index => { switch (index) { case 0: workbookSaveOperation.Options &= ~WorkbookSaveOptions.Archive; break; case 1: workbookSaveOperation.Options |= WorkbookSaveOptions.Archive; break; default: throw new IndexOutOfRangeException(); } })); } #if false // stubbed UI for signing is unused for now if (workbookSaveOperation.SupportedOptions.HasFlag(WorkbookSaveOptions.Sign)) { addRow(CreateRow( Catalog.GetString("Signing Key:"), new [] { Catalog.GetString("None") }, 0, index => { })); } #endif savePanel.AccessoryView = stackView; return(true); }