public static int Run(NSSavePanel panel, Control parent) { int ret; if (parent != null) { var window = parent.ControlObject as NSWindow; if (window == null && parent.ControlObject is NSView) { window = ((NSView)parent.ControlObject).Window; } if (window == null || !panel.RespondsToSelector(new Selector("beginSheetModalForWindow:completionHandler:"))) { ret = (int)panel.RunModal(); } else { panel.BeginSheet(window, result => NSApplication.SharedApplication.StopModalWithCode(result)); ret = (int)NSApplication.SharedApplication.RunModalForWindow(window); } } else { ret = (int)panel.RunModal(); } return(ret); }
/// <summary> /// Saves the document being edited in the current window. If the document hasn't been saved /// before, it presents a Save File Dialog and allows to specify the name and location of /// the file. /// </summary> public void SaveDocument() { // Already saved? if (Window.RepresentedUrl != null) { var path = Window.RepresentedUrl.Path; // Save changes to file File.WriteAllText(path, ContentController.Text); Window.DocumentEdited = false; } else { var dlg = new NSSavePanel(); dlg.Title = "Save Document"; dlg.BeginSheet(Window, (rslt) => { // File selected? if (rslt == 1) { var path = dlg.Url.Path; File.WriteAllText(path, ContentController.Text); Window.DocumentEdited = false; ContentController.View.Window.SetTitleWithRepresentedFilename(Path.GetFileName(path)); ContentController.View.Window.RepresentedUrl = dlg.Url; ContentController.FilePath = path; // Add document to the Open Recent menu NSDocumentController.SharedDocumentController.NoteNewRecentDocumentURL(dlg.Url); } }); } }
partial void CreateFile(NSObject sender) { var xls = new XlsFile(1, true); xls.SetCellValue(1, 1, "Hello OSX Unified!"); xls.SetCellValue(2, 1, new TFormula("=\"Make sure to \" & \"look at the Windows examples\"")); xls.SetCellValue(3, 1, "for information on how to use FlexCel"); xls.SetCellValue(5, 1, "Concepts are similar, so it doesn't make sense to repeat them all here."); xls.AutofitCol(1, false, 1.2); NSSavePanel SaveDialog = new NSSavePanel(); { SaveDialog.Title = "Save file as..."; SaveDialog.AllowedFileTypes = new string[] { "xlsx", "xls" }; SaveDialog.BeginSheet(Window, (x) => { if (SaveDialog.Url != null) { xls.Save(SaveDialog.Url.Path); } }); } }
void ShowSaveAs(NSObject sender) { var dlg = new NSSavePanel(); dlg.Title = "Save Text File"; if (ShowSaveAsSheet) { dlg.BeginSheet(mainWindowController.Window, (result) => { var alert = new NSAlert() { AlertStyle = NSAlertStyle.Critical, InformativeText = "We need to save the document here...", MessageText = "Save Document", }; alert.RunModal(); }); } else { if (dlg.RunModal() == 1) { var alert = new NSAlert() { AlertStyle = NSAlertStyle.Critical, InformativeText = "We need to save the document here...", MessageText = "Save Document", }; alert.RunModal(); } } }
partial void SaveClicked(Foundation.NSObject sender) { reflectState(State.SAVING); var window = this.View.Window; var dlg = new NSSavePanel(); dlg.Title = "Save Result"; dlg.BeginSheet(window, (rslt) => { // File selected? if (rslt == 1) { var path = dlg.Url.Path; // store to file using (System.IO.StreamWriter file = new System.IO.StreamWriter(@path)) { // var range = new NSRange(0, Results.TextStorage.Length); file.Write(Results.Value); } reflectState(State.SAVED); } }); }
/// <summary> /// Saves the document being edited in the current window. If the document hasn't been saved /// before, it presents a Save File Dialog and allows to specify the name and location of /// the file. /// </summary> public void SaveDocument() { // Get path var path = (Window.RepresentedUrl == null) ? "" : Window.RepresentedUrl.Path; // Already saved? if (!string.IsNullOrEmpty(path)) { // Save changes to file File.WriteAllText(path, Portfolio.SaveToTextBase()); Window.DocumentEdited = false; } else { var dlg = new NSSavePanel(); dlg.Title = "Save Portfolio"; dlg.AllowedFileTypes = new string[] { "ksp" }; dlg.BeginSheet(Window, (rslt) => { // File selected? if (rslt == 1) { path = dlg.Url.Path; File.WriteAllText(path, Portfolio.SaveToTextBase()); Window.DocumentEdited = false; MainController.View.Window.SetTitleWithRepresentedFilename(Path.GetFileName(path)); MainController.View.Window.RepresentedUrl = dlg.Url; MainController.FilePath = path; // Add document to the Open Recent menu NSDocumentController.SharedDocumentController.NoteNewRecentDocumentURL(dlg.Url); } }); } }
async public Task SavehtmlToPDF() { var savePaenl = new NSSavePanel(); savePaenl.CanCreateDirectories = true; savePaenl.CanSelectHiddenExtension = false; savePaenl.Message = "Choose the path to save the document"; savePaenl.Prompt = "Save"; savePaenl.NameFieldStringValue = "LexisNexis-Document"; string title = PublicationsDataManager.SharedInstance.CurrentPublication.Name; savePaenl.BeginSheet(NSApplication.SharedApplication.KeyWindow, (nint result) => { if (result == 1) { PdfDocument pdfDocument = new PdfDocument(); CGRect documentRect = ContentWebView.MainFrame.FrameView.DocumentView.Frame; CGRect frameRect = ContentWebView.MainFrame.FrameView.Frame; CGRect pageRect = new CGRect(0, 0, frameRect.Width, frameRect.Height); CGRect pRect = ContentWebView.MainFrame.FrameView.DocumentView.RectForPage(1); int index = 0; while (pageRect.Y < documentRect.Height) { var pdfData = ContentWebView.MainFrame.FrameView.DocumentView.DataWithPdfInsideRect(pageRect); var image = new NSImage(pdfData); string footer = "Currency date: " + PublicationsDataManager.SharedInstance.CurrentPublication.CurrencyDate.Value.ToString("dd MMM yyyy") + " " + "© 2015 LexisNexis" + " " + "Printed page " + string.Format("{0}", index + 1); var footerPage = new FooterPdfPage(image); footerPage.PageHeader = title; footerPage.PageFooter = footer; pdfDocument.InsertPage(footerPage, index); index++; pageRect.Offset(0, frameRect.Height); } string fileName = savePaenl.Filename; int length = fileName.Length; if (length > 4 && fileName.Substring(length - 3).ToLower() == "pdf") { } else { fileName += ".pdf"; } string filePath = Path.Combine(Utility.GetAppCacheAbsolutePath(), fileName); pdfDocument.Write(filePath); } }); }
public bool Run(Optional <NSWindow> window = default(Optional <NSWindow>)) { if (window.HasValue) { _panel.BeginSheet(window.Value, result => NSApplication.SharedApplication.StopModalWithCode(result)); return(NSApplication.SharedApplication.RunModalForWindow(window.Value) == 1); } else { return(_panel.RunModal() == 1); } }
partial void saveProjectAs(NSObject sender) { NSSavePanel panel = NSSavePanel.SavePanel; panel.AllowedFileTypes = new string[] { @"header_hero" }; panel.BeginSheet(mainWindowController.Window, (result) => { if (result == (int)NSPanelButtonType.Ok) { Save(panel.Url.Path); } }); }
public static int Run (NSSavePanel panel, Control parent) { int ret; if (parent != null) { var window = parent.ControlObject as NSWindow; if (window == null && parent.ControlObject is NSView) window = ((NSView)parent.ControlObject).Window; if (window == null || !panel.RespondsToSelector (new Selector ("beginSheetModalForWindow:completionHandler:"))) ret = panel.RunModal (); else { panel.BeginSheet (window, delegate(int result) { NSApplication.SharedApplication.StopModalWithCode (result); }); ret = NSApplication.SharedApplication.RunModalForWindow (window); } } else ret = panel.RunModal (); return ret; }
public void SavePDF(Foundation.NSObject sender) { NSSavePanel panel = NSSavePanel.SavePanel; panel.AllowedFileTypes = new string[] { "pdf" }; panel.BeginSheet(this.Window, (result) => { if (result == 1) { CGRect r = this.Bounds; NSData data = this.DataWithPdfInsideRect(r); NSError error = null; bool successful = data.Save(panel.Url, false, out error); if (!successful) { NSAlert a = NSAlert.WithError(error); a.RunModal(); } } panel = null; }); }
public static Boolean SaveDocument(NSWindow Window) { var EditorViewController = AppDelegate.FindViewController(Window.ContentViewController) as ViewController; NSAttributedStringDocumentAttributes attributes = new NSAttributedStringDocumentAttributes(); attributes.DocumentType = NSDocumentType.RTF; NSError errors = new NSError(); NSRange range = new NSRange(0, EditorViewController.Text.Length); NSUrl currentUrl = Window.RepresentedUrl; if (Window.RepresentedUrl != null) { var textSave = EditorViewController.TextStorage.GetFileWrapper(range, attributes, out errors); textSave.Write(currentUrl, NSFileWrapperWritingOptions.Atomic, currentUrl, out errors); return(true); } else { var dlg = new NSSavePanel() { Title = "Save Document" }; dlg.BeginSheet(Window, (rslt) => { if (rslt == 1) { var path = dlg.Url.Path; NSUrl newUrl = dlg.Url; var textSave = EditorViewController.TextStorage.GetFileWrapper(range, attributes, out errors); textSave.Write(newUrl, NSFileWrapperWritingOptions.Atomic, newUrl, out errors); Window.DocumentEdited = false; EditorViewController.View.Window.SetTitleWithRepresentedFilename(Path.GetFileName(path)); EditorViewController.View.Window.RepresentedUrl = dlg.Url; EditorViewController.FilePath = path; NSDocumentController.SharedDocumentController.NoteNewRecentDocumentURL(dlg.Url); } }); return(false); } }
Task <string[]> RunPanel(NSSavePanel panel, IWindowImpl parent) { var keyWindow = MonoMacPlatform.App.KeyWindow; var tcs = new TaskCompletionSource <string[]>(); void OnComplete(int result) { if (result == 0) { tcs.SetResult(null); } else { if (panel is NSOpenPanel openPanel) { tcs.SetResult(openPanel.Urls.Select(url => url.AbsoluteString).ToArray()); } else { tcs.SetResult(new[] { panel.Url.AbsoluteString }); } } panel.OrderOut(panel); keyWindow?.MakeKeyAndOrderFront(keyWindow); MonoMacPlatform.App.ActivateIgnoringOtherApps(true); panel.Dispose(); } if (parent != null) { var window = (WindowImpl)parent; panel.BeginSheet(window.Window, OnComplete); } else { panel.Begin(OnComplete); } return(tcs.Task); }
public void SavehtmlToPDF() { var savePaenl = new NSSavePanel(); savePaenl.CanCreateDirectories = true; savePaenl.CanSelectHiddenExtension = false; savePaenl.Message = "Choose the path to save the document"; savePaenl.Prompt = "Save"; savePaenl.NameFieldStringValue = "LexisNexis-Document"; savePaenl.BeginSheet(NSApplication.SharedApplication.KeyWindow, (nint result) => { if (result == 1) { var pdfData = (NSData)ContentWebView.MainFrame.FrameView.DocumentView.DataWithPdfInsideRect( ContentWebView.MainFrame.FrameView.DocumentView.Frame); //PdfDocument pdfDocument = new PdfDocument(pdfData); string fileName = savePaenl.Filename; int length = fileName.Length; if (length > 4 && fileName.Substring(length - 3).ToLower() == "pdf") { } else { fileName += ".pdf"; } // for(int i=0; i<pdfDocument.PageCount; i++) { // var page = pdfDocument.GetPage(i); // } string filePath = Path.Combine(Utility.GetAppCacheAbsolutePath(), fileName); pdfData.Save(filePath, true); //pdfDocument.Write (filePath); } }); }
async Task SaveExportedData() { if (syncController?.SyncState != SyncState.Finished) { return; } var dialog = new NSSavePanel { Title = "Save Exported Rdio Data", NameFieldStringValue = syncController.FileName }; var window = Window; if (window == null) { await SaveExportedData(window, dialog.RunModal(), dialog.Url); } else { dialog.BeginSheet(window, async result => await SaveExportedData(window, result, dialog.Url)); } }
nint SavePanel(out string target) { nint res = 1; var savePanel = new NSSavePanel { }; NSWindow window = new NSWindow { }; savePanel.BeginSheet(window, (result) => { window.EndSheet(window); res = result; }); if (res == 1) { target = savePanel.Url.Path; } else { target = ""; } return(res); }
async Task SaveExportedData () { if (syncController?.SyncState != SyncState.Finished) return; var dialog = new NSSavePanel { Title = "Save Exported Rdio Data", NameFieldStringValue = syncController.FileName }; var window = Window; if (window == null) await SaveExportedData (window, dialog.RunModal (), dialog.Url); else dialog.BeginSheet (window, async result => await SaveExportedData (window, result, dialog.Url)); }
void ShowSaveAs (NSObject sender) { var dlg = new NSSavePanel (); dlg.Title = "Save Text File"; if (ShowSaveAsSheet) { dlg.BeginSheet(mainWindowController.Window,(result) => { var alert = new NSAlert () { AlertStyle = NSAlertStyle.Critical, InformativeText = "We need to save the document here...", MessageText = "Save Document", }; alert.RunModal (); }); } else { if (dlg.RunModal () == 1) { var alert = new NSAlert () { AlertStyle = NSAlertStyle.Critical, InformativeText = "We need to save the document here...", MessageText = "Save Document", }; alert.RunModal (); } } }
/// <summary> /// Saves the document being edited in the current window. If the document hasn't been saved /// before, it presents a Save File Dialog and allows to specify the name and location of /// the file. /// </summary> public void SaveDocument() { // Already saved? if (Window.RepresentedUrl != null) { var path = Window.RepresentedUrl.Path; // Save changes to file File.WriteAllText (path, ContentController.Text); Window.DocumentEdited = false; } else { var dlg = new NSSavePanel (); dlg.Title = "Save Document"; dlg.BeginSheet (Window, (rslt) => { // File selected? if (rslt == 1) { var path = dlg.Url.Path; File.WriteAllText (path, ContentController.Text); Window.DocumentEdited = false; ContentController.View.Window.SetTitleWithRepresentedFilename (Path.GetFileName(path)); ContentController.View.Window.RepresentedUrl = dlg.Url; ContentController.FilePath = path; // Add document to the Open Recent menu NSDocumentController.SharedDocumentController.NoteNewRecentDocumentURL(dlg.Url); } }); } }
/// <summary> /// Called before an <c>NSWindow</c> is closed. If the contents of the window has changed and /// not been saved, display a dialog allowing the user to: a) Cancel the closing, b) Close /// without saving, c) Save the changes to the document. /// </summary> /// <returns><c>true</c>, if the window can be closed, else <c>false</c> if it cannot.</returns> /// <param name="sender">The <c>NSWindowController</c> calling this method.</param> public override bool WindowShouldClose (Foundation.NSObject sender) { // is the window dirty? if (Window.DocumentEdited) { var alert = new NSAlert () { AlertStyle = NSAlertStyle.Critical, InformativeText = "Save changes to document before closing window?", MessageText = "Save Document", }; alert.AddButton ("Save"); alert.AddButton ("Lose Changes"); alert.AddButton ("Cancel"); var result = alert.RunSheetModal (Window); // Take action based on resu;t switch (result) { case 1000: // Grab controller var viewController = Window.ContentViewController as ViewController; // Already saved? if (Window.RepresentedUrl != null) { var path = Window.RepresentedUrl.Path; // Save changes to file File.WriteAllText (path, viewController.Text); return true; } else { var dlg = new NSSavePanel (); dlg.Title = "Save Document"; dlg.BeginSheet (Window, (rslt) => { // File selected? if (rslt == 1) { var path = dlg.Url.Path; File.WriteAllText (path, viewController.Text); Window.DocumentEdited = false; viewController.View.Window.SetTitleWithRepresentedFilename (Path.GetFileName(path)); viewController.View.Window.RepresentedUrl = dlg.Url; Window.Close(); } }); return true; } return false; case 1001: // Lose Changes return true; case 1002: // Cancel return false; } } return true; }
/// <summary> /// Called before an <c>NSWindow</c> is closed. If the contents of the window has changed and /// not been saved, display a dialog allowing the user to: a) Cancel the closing, b) Close /// without saving, c) Save the changes to the document. /// </summary> /// <returns><c>true</c>, if the window can be closed, else <c>false</c> if it cannot.</returns> /// <param name="sender">The <c>NSWindowController</c> calling this method.</param> public override bool WindowShouldClose(Foundation.NSObject sender) { // is the window dirty? if (Window.DocumentEdited) { var alert = new NSAlert() { AlertStyle = NSAlertStyle.Critical, InformativeText = "Save changes to document before closing window?", MessageText = "Save Document", }; alert.AddButton("Save"); alert.AddButton("Lose Changes"); alert.AddButton("Cancel"); var result = alert.RunSheetModal(Window); // Take action based on resu;t switch (result) { case 1000: // Grab controller var viewController = Window.ContentViewController as ViewController; // Already saved? if (Window.RepresentedUrl != null) { var path = Window.RepresentedUrl.Path; // Save changes to file File.WriteAllText(path, viewController.Text); return(true); } else { var dlg = new NSSavePanel(); dlg.Title = "Save Document"; dlg.BeginSheet(Window, (rslt) => { // File selected? if (rslt == 1) { var path = dlg.Url.Path; File.WriteAllText(path, viewController.Text); Window.DocumentEdited = false; viewController.View.Window.SetTitleWithRepresentedFilename(Path.GetFileName(path)); viewController.View.Window.RepresentedUrl = dlg.Url; Window.Close(); } }); return(true); } case 1001: // Lose Changes return(true); case 1002: // Cancel return(false); } } return(true); }
public void Export(NSMenuItem menuItem) { NSSavePanel savePanel = NSSavePanel.SavePanel; savePanel.AllowedFileTypes = new string[] { "txt" }; savePanel.Title = "Export Titles"; Process.log?.WriteLine("\nExport Titles"); savePanel.BeginSheet(Window, (nint result) => { if (result == (int)NSModalResponse.OK) { using (var writer = new StreamWriter(savePanel.Url.Path)) { Window.BeginSheet(sheet, ProgressComplete); userCancelled = false; writer.WriteLine("{0} {1}", NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleName").ToString(), NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString()); writer.WriteLine("--------------------------------------------------------------\n"); writer.WriteLine("Export titles starts at {0}\n", String.Format("{0:F}", DateTime.Now)); uint index = 0, count = (uint)titles.Count; foreach (var title in titles) { if (userCancelled) { userCancelled = false; break; } message.StringValue = title.titleName ?? ""; progress.DoubleValue = 100f * index++ / count; writer.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}", title.titleID, title.titleName, title.displayVersion, title.versionString, title.latestVersionString, title.firmware, title.masterkeyString, title.filename, NSByteCountFormatter.Format(title.filesize, NSByteCountFormatterCountStyle.File), title.typeString, title.distribution, title.structureString, title.signatureString, title.permissionString, title.error); } writer.WriteLine("\n{0} of {1} titles exported", index, titles.Count); Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count); Window.EndSheet(sheet); } } }); }