internal static NSPopUpButton CreateFileFilterPopup (SelectFileDialogData data, NSSavePanel panel) { var filters = data.Filters; //no filtering if (filters == null || filters.Count == 0) { return null; } //filter, but no choice if (filters.Count == 1) { panel.ShouldEnableUrl = GetFileFilter (filters[0]); return null; } var popup = new NSPopUpButton (new RectangleF (0, 6, 200, 18), false); popup.SizeToFit (); var rect = popup.Frame; popup.Frame = new RectangleF (rect.X, rect.Y, 200, rect.Height); foreach (var filter in filters) popup.AddItem (filter.Name); var defaultIndex = data.DefaultFilter == null? 0 : Math.Max (0, filters.IndexOf (data.DefaultFilter)); if (defaultIndex > 0) { popup.SelectItem (defaultIndex); } panel.ShouldEnableUrl = GetFileFilter (filters[defaultIndex]); popup.Activated += delegate { panel.ShouldEnableUrl = GetFileFilter (filters[popup.IndexOfSelectedItem]); panel.Display (); }; return popup; }
public Task <bool> SaveFile(FileData fileToSave, FolderData folderPath, bool shouldOverWrite) { try { //Need to handle file collision var documents = folderPath; var savePanel = new NSSavePanel(); savePanel.Title = $"Save {fileToSave.FileName}"; savePanel.CanCreateDirectories = true; var result = savePanel.RunModal(documents.FolderPath, fileToSave.FileName); if (result == 1) { var path = savePanel.Url.Path; File.WriteAllBytes(path, fileToSave.DataArray); return(Task.FromResult(true)); } return(Task.FromResult(false)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(Task.FromResult(false)); } }
partial void SaveButton(NSObject sender) { if (SpectraListTable.IsRowSelected(SpectraListTable.SelectedRow)) { int k = (int)SpectraListTable.SelectedRow; var dlg = new NSSavePanel { Title = "Save Spectrum", AllowedFileTypes = new string[] { "dat", "txt" }, ShowsTagField = false, CanCreateDirectories = true, NameFieldStringValue = ListOfSpectra[k].Name + ".dat", AccessibilityExpanded = true }; if (dlg.RunModal() == 1) { string path = dlg.Url.Path; Console.WriteLine(path); double[][] tmpArray = new double[ListOfSpectra[k].XX.Length][]; for (int i = 0; i < tmpArray.GetLength(0); i++) { tmpArray[i] = new double[2]; tmpArray[i][0] = ListOfSpectra[k].XX[i]; tmpArray[i][1] = ListOfSpectra[k].YY[i]; } TableReader.SaveTable(path, tmpArray); } } }
public /* Interface KGuiControl */ void GuiChartSnapToSvg() { if (NSThread.IsMain) { string svg = Export.SnapToSVG(GuiChartSize()); var dlg = new NSSavePanel(); dlg.Title = "Save SVG File"; dlg.AllowedFileTypes = new string[] { "svg" }; dlg.Directory = MacControls.modelsDirectory; if (dlg.RunModal() == 1) { var path = ""; try { path = dlg.Url.Path; File.WriteAllText(path, svg, System.Text.Encoding.Unicode); } catch { var alert = new NSAlert() { AlertStyle = NSAlertStyle.Critical, MessageText = "Could not write this file:", InformativeText = path }; alert.RunModal(); } } } else { _ = BeginInvokeOnMainThreadAsync(() => { GuiChartSnapToSvg(); return(ack); }).Result; } }
MDAccessoryViewBox CreateAccessoryBox(TData data, NSSavePanel panel, out TState saveState) { saveState = default(TState); if (!ShouldCreateAccessoryBox(data)) { return(null); } var box = new MDAccessoryViewBox(); var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup(data, panel); if (filterPopup != null) { box.AddControl(filterPopup, GettextCatalog.GetString("Show Files:")); } foreach (var item in OnGetAccessoryBoxControls(data, panel, out saveState)) { box.AddControl(item.control, item.text); } box.Layout(); panel.AccessoryView = box.View; return(box); }
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); } }); }
static void SetCommonPanelProperties(TData data, NSSavePanel panel) { if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { IdeTheme.ApplyTheme(panel); } panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } if (!string.IsNullOrEmpty(data.InitialFileName)) { panel.NameFieldStringValue = data.InitialFileName; } if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.DirectoryUrl = new NSUrl(data.CurrentFolder, true); } panel.ParentWindow = NSApplication.SharedApplication.KeyWindow ?? NSApplication.SharedApplication.MainWindow; if (panel is NSOpenPanel openPanel) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }
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); } }); } }
/// <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); } }); } }
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); }
internal static void SetCommonPanelProperties(SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } //FIXME: 10.6 only //if (!string.IsNullOrEmpty (data.InitialFileName)) // panel.NameFieldStringValue = data.InitialFileName; if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.Directory = data.CurrentFolder; } //FIXME: 10.6 only // panel.DirectoryUrl = new NSUrl (data.CurrentFolder, true); var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; } }
public Task <bool> SaveFile(FileData fileToSave) { try { var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var savePanel = new NSSavePanel(); savePanel.Title = $"Save {fileToSave.FileName}"; savePanel.CanCreateDirectories = true; var result = savePanel.RunModal(documents, fileToSave.FileName); if (result == 1) { var path = savePanel.Url.Path; File.WriteAllBytes(path, fileToSave.DataArray); return(Task.FromResult(true)); } return(Task.FromResult(false)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(Task.FromResult(false)); } }
/// <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); } }); } }
internal static void SetCommonPanelProperties(SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } if (!string.IsNullOrEmpty(data.InitialFileName)) { panel.NameFieldStringValue = data.InitialFileName; } if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.DirectoryUrl = new NSUrl(data.CurrentFolder, true); } panel.ParentWindow = NSApplication.SharedApplication.KeyWindow ?? NSApplication.SharedApplication.MainWindow; var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }
public Task <FilePlaceholder> CreateOrOverwriteFile(string[] allowedTypes = null) { // for consistency with other platforms, only allow selecting of a single file. // would be nice if we passed a "file options" to override picking multiple files & directories var savePanel = new NSSavePanel(); savePanel.CanCreateDirectories = true; // macOS allows the file types to contain UTIs, filename extensions or a combination of the two. // If no types are specified, all files are selectable. if (allowedTypes != null) { savePanel.AllowedFileTypes = allowedTypes; } FilePlaceholder data = null; var result = savePanel.RunModal(); if (result == 1) { // Nab the first file var url = savePanel.Url; if (url != null) { var path = url.Path; var fileName = Path.GetFileName(path); data = new FilePlaceholder(path, fileName, saveAction); } } return(Task.FromResult(data)); }
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(); } } }
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 database. /// </summary> private void SaveDatabase() { if (!databaseCommands.IsOpen) { return; } Console.WriteLine("SaveDatabase"); try { // if the db is not yet saved then show the save dialog if (databaseCommands.IsNewAndNotSaved) { var savePanel = new NSSavePanel(); savePanel.ReleasedWhenClosed = true; savePanel.Prompt = "Save file"; savePanel.CanCreateDirectories = true; savePanel.AllowedFileTypes = new string[] { "kdbx" }; // suggest a name savePanel.NameFieldStringValue = "mydb"; var result = savePanel.RunModal(); string fileName; if (result != 1) { return; } fileName = savePanel.Url.AbsoluteString; StartProgress("Saving..."); databaseCommands.SaveDatabase(fileName); } else { StartProgress("Saving..."); databaseCommands.SaveDatabase(); } // reset the flag dbNeedsTobeSaved = false; } catch (Exception ex) { Console.WriteLine(ex.ToString()); NSAlert alert = new NSAlert(); alert.AlertStyle = NSAlertStyle.Critical; alert.MessageText = ex.Message; alert.RunModal(); return; } finally { EndProgress(); } }
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 string SaveMetadataFilename() { var panel = new NSSavePanel() { Title = "Save Metadata File", AllowedFileTypes = (from e in GuiController.MetaExtensions select e.Substring(1)).ToArray(), AllowsOtherFileTypes = true }; return((panel.RunModal() == 1) ? panel.Url?.Path ?? null : null); }
internal static FilePath[] GetSelectedFiles (NSSavePanel panel) { var openPanel = panel as NSOpenPanel; if (openPanel != null && openPanel.AllowsMultipleSelection) { return openPanel.Urls.Select (u => (FilePath) u.Path).ToArray (); } else { var url = panel.Url; return url != null ? new FilePath[] { panel.Url.Path } : new FilePath[0]; } }
public string ShowSaveDialog() { NSSavePanel savePanel = NSSavePanel.SavePanel; int result = savePanel.RunModal(); if (result > 0) { return(savePanel.Filename); } return(null); }
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); } }); }
static void SetAllowedFileTypes(NSSavePanel openPanel, string [] extensions) { if (extensions.Length == 0) { Messaging.void_objc_msgSendSuper_IntPtr(openPanel.SuperHandle, selSetAllowedFileTypes_Handle, IntPtr.Zero); } else { NSArray array = NSArray.FromStrings(extensions); Messaging.void_objc_msgSendSuper_IntPtr(openPanel.SuperHandle, selSetAllowedFileTypes_Handle, array.Handle); } }
public override bool ChooseFileForSave(string title, string initialFolder, string initialFile, out string file, params FileChooserFilter [] filters) { using (NSSavePanel savePanel = new NSSavePanel()) { savePanel.TreatsFilePackagesAsDirectories = true; savePanel.Title = title; if (Run(initialFolder, initialFile, out file, filters, savePanel)) { return(true); } } file = null; return(false); }
public override WindowResponse Show() { WindowResponse resp; List<string> filetypes = new List<string>(); NSUrl initDir = null; if (Directory.Exists(InitialDirectory)) initDir = new NSUrl(InitialDirectory); switch(DialogType) { case FileDialogType.OpenFile: ofdlg = new NSOpenPanel(); if (initDir != null) ofdlg.DirectoryUrl = initDir; ofdlg.Title = Title; ofdlg.CanChooseFiles = true; ofdlg.CanChooseDirectories = false; ofdlg.AllowsMultipleSelection = false; if(filetypes.Count > 0) { foreach(FileTypeFilter arr in FileTypeFilters) filetypes.AddRange(arr.Filter); ofdlg.AllowedFileTypes = filetypes.ToArray(); } resp = CocoaHelper.GetResponse(ofdlg.RunModal()); SelectedPath = ofdlg.Url.Path; return resp; case FileDialogType.SelectFolder: ofdlg = new NSOpenPanel(); if (initDir != null) ofdlg.DirectoryUrl = initDir; ofdlg.Title = Title; ofdlg.CanChooseFiles = false; ofdlg.CanChooseDirectories = true; ofdlg.AllowsMultipleSelection = false; resp = CocoaHelper.GetResponse(ofdlg.RunModal()); SelectedPath = ofdlg.Url.Path; return resp; case FileDialogType.SaveFile: sfdlg = new NSSavePanel(); if (initDir != null) sfdlg.DirectoryUrl = initDir; sfdlg.Title = Title; sfdlg.CanCreateDirectories = true; resp = CocoaHelper.GetResponse(sfdlg.RunModal()); SelectedPath = sfdlg.Url.Path; return resp; } return WindowResponse.None; }
public bool RunModal() { FileName = null; FileNames = null; if (Mode == FileDialogMode.Save) { using (var nsPanel = new NSSavePanel()) { if (InitialDirectory != null) { nsPanel.Directory = InitialDirectory; } if (AllowedFileTypes != null) { nsPanel.AllowedFileTypes = AllowedFileTypes; } nsPanel.CanCreateDirectories = CanCreateDirectories; nsPanel.NameFieldLabel = InitialFileName ?? System.String.Empty; if (nsPanel.RunModal() == (int)NSPanelButtonType.Ok) { FileName = nsPanel.Url.Path; FileNames = new[] { FileName }; return(true); } } } else { using (var nsPanel = new NSOpenPanel()) { if (InitialDirectory != null) { nsPanel.Directory = InitialDirectory; } if (AllowedFileTypes != null) { nsPanel.AllowedFileTypes = AllowedFileTypes; } nsPanel.AllowsMultipleSelection = AllowsMultipleSelection; nsPanel.CanChooseFiles = Mode == FileDialogMode.Open; nsPanel.CanChooseDirectories = !nsPanel.CanChooseFiles; nsPanel.CanCreateDirectories = CanCreateDirectories; nsPanel.NameFieldLabel = InitialFileName ?? System.String.Empty; if (nsPanel.RunModal() == (int)NSPanelButtonType.Ok) { FileName = nsPanel.Url.Path; FileNames = nsPanel.Urls.Select(i => i.Path).ToArray(); return(true); } } } return(false); }
public bool Run(SelectFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel(); } else { panel = new NSOpenPanel() { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } SetCommonPanelProperties(data, panel); if (!directoryMode) { var popup = CreateFileFilterPopup(data, panel); if (popup != null) { panel.AccessoryView = popup; } } var action = RunPanel(data, panel); if (action) { data.SelectedFiles = GetSelectedFiles(panel); GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); } else { GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); } return(action); } finally { if (panel != null) { panel.Dispose(); } } }
partial void SaveButtonClick(Foundation.NSObject sender) { var dlg = new NSSavePanel { Title = "Save Assembly", AllowedFileTypes = new[] { "tsv" } }; if (dlg.RunModal() == 1) { using var outputFile = new StreamWriter(dlg.Url.Path); outputFile.WriteLine("Section\tAddress\tData\tInstruction"); _disassemblyFile?.Write(outputFile); } }
internal static FilePath[] GetSelectedFiles(NSSavePanel panel) { var openPanel = panel as NSOpenPanel; if (openPanel != null && openPanel.AllowsMultipleSelection) { return(openPanel.Urls.Select(u => (FilePath)u.Path).ToArray()); } else { var url = panel.Url; return(url != null ? new FilePath[] { panel.Url.Path } : new FilePath[0]); } }
//save the existing speech script to a text file public void SaveFile(bool newFile) { NSUrl savePath = null; if (newFile || currentFile == null) //new file or save as { using (var saveDialog = new NSSavePanel()) { var result = saveDialog.RunModal(); if (result == 1) { if (!saveDialog.Url.RelativePath.EndsWith(".txt", StringComparison.CurrentCulture)) { savePath = saveDialog.Url.AppendPathExtension("txt"); } } } } else { savePath = currentFile; } //if a file path is specified, save the file if (savePath != null) { try { using (var fileStream = new FileStream(savePath.RelativePath, FileMode.Create)) { using (var streamWriter = new StreamWriter(fileStream)) { streamWriter.WriteLine(song.GetSpeechSynthesisScript()); } } currentFile = savePath; UnsavedChanges = false; UpdateTitle(); } catch (IOException ex) { Alert.CreateAlert($"An error occured while saving the file. ({ex.Message})", AlertType.Caution); } catch (UnauthorizedAccessException) { Alert.CreateAlert("File cannot be accessed.", AlertType.Caution); } } }
string IFileDialogs.SaveFileDialog(SaveFileDialogParams p) { var dlg = new NSSavePanel(); dlg.Title = p.Title ?? "Save"; if (p.SuggestedFileName != null) { dlg.NameFieldStringValue = p.SuggestedFileName; } if (dlg.RunModal() == 1) { return(dlg.Url.Path); } return(null); }
public override bool ShouldEnableUrl(NSSavePanel panel, NSUrl url) { if (Directory.Exists(url.Path)) { return(true); } var extension = Path.GetExtension(url.Path).ToLowerInvariant().TrimStart('.'); if (Handler.MacFilters == null || Handler.MacFilters.Contains(extension, StringComparer.InvariantCultureIgnoreCase)) { return(true); } return(false); }
internal static bool RunPanel(SelectFileDialogData data, NSSavePanel panel) { var dir = string.IsNullOrEmpty(data.CurrentFolder)? null : data.CurrentFolder; var file = string.IsNullOrEmpty(data.InitialFileName)? null : data.InitialFileName; if (panel is NSOpenPanel) { return(((NSOpenPanel)panel).RunModal(dir, file, null) != 0); } else { //FIXME: deprecated on 10.6, alternatives only on 10.6 return(panel.RunModal(dir, file) != 0); } }
public static void SaveCurrentSetFilePanel() { NSSavePanel savePanel = new NSSavePanel (); savePanel.Begin (((int result) => { try { if (savePanel.Url != null) { var urlString = savePanel.Url.Path; if (!string.IsNullOrEmpty (urlString)) { m_at.SaveCurrentSet (System.IO.Path.GetFileName (urlString), System.IO.Path.GetDirectoryName (urlString)); } // string not null } // url not null } finally { savePanel.Dispose (); } // finally })); }
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 bool Run (SelectFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel () { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } SetCommonPanelProperties (data, panel); if (!directoryMode) { var popup = CreateFileFilterPopup (data, panel); if (popup != null) { panel.AccessoryView = popup; } } var action = RunPanel (data, panel); if (action) { data.SelectedFiles = GetSelectedFiles (panel); GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } else { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } return action; } finally { if (panel != null) panel.Dispose (); } }
public bool Run (SelectFileDialogData data) { NSSavePanel panel = null; try { if (data.Action == FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel { CanChooseDirectories = (data.Action & FileChooserAction.FolderFlags) != 0, CanChooseFiles = (data.Action & FileChooserAction.FileFlags) != 0, CanCreateDirectories = (data.Action & FileChooserAction.CreateFolder) != 0, ResolvesAliases = false, }; } SetCommonPanelProperties (data, panel); if ((data.Action & FileChooserAction.FileFlags) != 0) { var popup = CreateFileFilterPopup (data, panel); if (popup != null) { panel.AccessoryView = popup; } } if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = GetSelectedFiles (panel); GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } finally { if (panel != null) panel.Dispose (); } }
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 LogsDoSave(bool selectedOnly) { string t = TableLogsController.GetBody (selectedOnly); if (t.Trim () != "") { //string filename = "AirVPN_" + DateTime.Now.ToString ("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture) + ".txt"; // TOCLEAN string filename = Engine.Logs.GetLogSuggestedFileName(); NSSavePanel panel = new NSSavePanel (); panel.NameFieldStringValue = filename; panel.CanCreateDirectories = true; int result = panel.RunModal (); if (result == 1) { Platform.Instance.FileContentsWriteText(panel.Url.Path, t); GuiUtils.MessageBox (Messages.LogsSaveToFileDone); } } }
public void SaveDocumentAs() { NSSavePanel saveDlg = new NSSavePanel(); saveDlg.CanCreateDirectories = true; saveDlg.AllowedFileTypes = new string[] { "xml", "PDF" }; saveDlg.AllowsOtherFileTypes = true; if (FileNameOK) { //openDlg.Sta = FileName; } int result = saveDlg.RunModal(); if (result == 1) { FileNameOK = true; FileName = saveDlg.Url.Path; SaveSettings(); } }
public bool Run (OpenFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open && data.Action != Gtk.FileChooserAction.Save; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel () { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); SelectEncodingPopUpButton encodingSelector = null; NSPopUpButton viewerSelector = null; NSButton closeSolutionButton = null; var box = new MDBox (LayoutDirection.Vertical, 2, 2); List<FileViewer> currentViewers = null; List<MDAlignment> labels = new List<MDAlignment> (); if (!directoryMode) { var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true); var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { filterLabel }, { new MDAlignment (filterPopup, true) { MinWidth = 200 } } }; labels.Add (filterLabel); box.Add (filterBox); if (data.ShowEncodingSelector) { encodingSelector = new SelectEncodingPopUpButton (data.Action != Gtk.FileChooserAction.Save); encodingSelector.SelectedEncodingId = data.Encoding; var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true); var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { encodingLabel }, { new MDAlignment (encodingSelector, true) { MinWidth = 200 } } }; labels.Add (encodingLabel); box.Add (encodingBox); } if (data.ShowViewerSelector && panel is NSOpenPanel) { currentViewers = new List<FileViewer> (); viewerSelector = new NSPopUpButton () { Enabled = false, }; if (encodingSelector != null) { viewerSelector.Activated += delegate { var idx = viewerSelector.IndexOfSelectedItem; encodingSelector.Enabled = ! (idx == 0 && currentViewers[0] == null); }; } var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:")); var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { viewSelLabel, true }, { new MDAlignment (viewerSelector, true) { MinWidth = 200 } } }; if (IdeApp.Workspace.IsOpen) { closeSolutionButton = new NSButton () { Title = GettextCatalog.GetString ("Close current workspace"), Hidden = true, State = NSCellStateValue.On, }; closeSolutionButton.SetButtonType (NSButtonType.Switch); closeSolutionButton.SizeToFit (); viewSelBox.Add (closeSolutionButton, true); } box.Add (viewSelBox); } } if (labels.Count > 0) { float w = labels.Max (l => l.MinWidth); foreach (var l in labels) { l.MinWidth = w; l.XAlign = LayoutAlign.Begin; } } if (box.Count > 0) { box.Layout (); panel.AccessoryView = box.View; box.Layout (box.View.Superview.Frame.Size); } panel.SelectionDidChange += delegate(object sender, EventArgs e) { var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); bool slnViewerSelected = false; if (viewerSelector != null) { FillViewers (currentViewers, viewerSelector, selection); if (currentViewers.Count == 0 || currentViewers[0] != null) { if (closeSolutionButton != null) closeSolutionButton.Hidden = true; slnViewerSelected = false; } else { if (closeSolutionButton != null) closeSolutionButton.Hidden = false; slnViewerSelected = true; } box.Layout (box.View.Superview.Frame.Size); } if (encodingSelector != null) encodingSelector.Enabled = !slnViewerSelected; }; try { var action = MacSelectFileDialogHandler.RunPanel (data, panel); if (!action) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } } catch (Exception ex) { System.Console.WriteLine (ex); throw; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); if (encodingSelector != null) data.Encoding = encodingSelector.SelectedEncodingId; if (viewerSelector != null ) { if (closeSolutionButton != null) data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; data.SelectedViewer = currentViewers[viewerSelector.IndexOfSelectedItem]; } GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } finally { if (panel != null) panel.Dispose (); } }
internal static void SetCommonPanelProperties (SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty (data.Title)) panel.Title = data.Title; //FIXME: 10.6 only //if (!string.IsNullOrEmpty (data.InitialFileName)) // panel.NameFieldStringValue = data.InitialFileName; if (!string.IsNullOrEmpty (data.CurrentFolder)) panel.Directory = data.CurrentFolder; //FIXME: 10.6 only // panel.DirectoryUrl = new NSUrl (data.CurrentFolder, true); var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; } }
internal static bool RunPanel (SelectFileDialogData data, NSSavePanel panel) { var dir = string.IsNullOrEmpty (data.CurrentFolder)? null : data.CurrentFolder; var file = string.IsNullOrEmpty (data.InitialFileName)? null : data.InitialFileName; if (panel is NSOpenPanel) { return ((NSOpenPanel)panel).RunModal (dir, file, null) != 0; } else { //FIXME: deprecated on 10.6, alternatives only on 10.6 return panel.RunModal (dir, file) != 0; } }
public bool SaveAsSubtitlePrompt() { if (Window.Subtitle.Paragraphs.Count == 0) { MessageBox.Show(_language.NoSubtitlesFound); return true; } var dlg = new NSSavePanel(); dlg.AllowedFileTypes = new string[] { GetCurrentSubtitleFormat().Extension.TrimStart('.') }; dlg.AllowsOtherFileTypes = false; if (_subtitleFileName != null) { dlg.NameFieldStringValue = Path.GetFileNameWithoutExtension(_subtitleFileName); } dlg.Title = _language.SaveSubtitleAs; ; if (dlg.RunModal() == Constants.NSOpenPanelOK) { SaveSubtitle(dlg.Filename); return true; } return false; }
public SparkleEventLog() : base() { using (var a = new NSAutoreleasePool ()) { Title = "Recent Changes"; Delegate = new SparkleEventsDelegate (); int min_width = 480; int min_height = 640; float x = (float) (NSScreen.MainScreen.Frame.Width * 0.61); float y = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5)); SetFrame ( new RectangleF ( new PointF (x, y), new SizeF (min_width, (int) (NSScreen.MainScreen.Frame.Height * 0.85))), true); StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled | NSWindowStyle.Resizable); MinSize = new SizeF (min_width, min_height); HasShadow = true; BackingType = NSBackingStore.Buffered; TitlebarHeight = Frame.Height - ContentView.Frame.Height; this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") { Frame = new RectangleF (new PointF (0, 0), new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39)) }; this.hidden_close_button = new NSButton () { KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask, KeyEquivalent = "w" }; this.hidden_close_button.Activated += delegate { Controller.WindowClosed (); }; this.size_label = new NSTextField () { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF ( new PointF (0, ContentView.Frame.Height - 30), new SizeF (60, 20)), StringValue = "Size:", Font = SparkleUI.BoldFont }; this.size_label_value = new NSTextField () { Alignment = NSTextAlignment.Left, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF ( new PointF (60, ContentView.Frame.Height - 30), new SizeF (60, 20)), StringValue = "…", Font = SparkleUI.Font }; this.history_label = new NSTextField () { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF ( new PointF (130, ContentView.Frame.Height - 30), new SizeF (60, 20)), StringValue = "History:", Font = SparkleUI.BoldFont }; this.history_label_value = new NSTextField () { Alignment = NSTextAlignment.Left, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF ( new PointF (190, ContentView.Frame.Height - 30), new SizeF (60, 20) ), StringValue = "…", Font = SparkleUI.Font }; this.popup_button = new NSPopUpButton () { Frame = new RectangleF ( new PointF (ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33), new SizeF (156, 26)), PullsDown = false }; this.background = new NSBox () { Frame = new RectangleF ( new PointF (-1, -1), new SizeF (Frame.Width + 2, this.web_view.Frame.Height + 2)), FillColor = NSColor.White, BorderColor = NSColor.LightGray, BoxType = NSBoxType.NSBoxCustom }; this.progress_indicator = new NSProgressIndicator () { Frame = new RectangleF ( new PointF (Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10), new SizeF (20, 20)), Style = NSProgressIndicatorStyle.Spinning }; this.progress_indicator.StartAnimation (this); ContentView.AddSubview (this.size_label); ContentView.AddSubview (this.size_label_value); ContentView.AddSubview (this.history_label); ContentView.AddSubview (this.history_label_value); ContentView.AddSubview (this.popup_button); ContentView.AddSubview (this.progress_indicator); ContentView.AddSubview (this.background); ContentView.AddSubview (this.hidden_close_button); (Delegate as SparkleEventsDelegate).WindowResized += Relayout; } // Hook up the controller events Controller.HideWindowEvent += delegate { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.progress_indicator.Hidden = true; PerformClose (this); }); } }; Controller.ShowWindowEvent += delegate { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { OrderFrontRegardless (); }); } }; Controller.UpdateChooserEvent += delegate (string [] folders) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { UpdateChooser (folders); }); } }; Controller.UpdateChooserEnablementEvent += delegate (bool enabled) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.popup_button.Enabled = enabled; }); } }; Controller.UpdateContentEvent += delegate (string html) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.progress_indicator.Hidden = true; UpdateContent (html); }); } }; Controller.ContentLoadingEvent += delegate { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.web_view.RemoveFromSuperview (); this.progress_indicator.Hidden = false; this.progress_indicator.StartAnimation (this); }); } }; Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (delegate { this.size_label_value.StringValue = size; this.history_label_value.StringValue = history_size; }); } }; Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { using (var a = new NSAutoreleasePool ()) { InvokeOnMainThread (() => { // TODO: Make this a sheet NSSavePanel panel = new NSSavePanel () { DirectoryUrl = new NSUrl (target_folder_path, true), NameFieldStringValue = file_name, ParentWindow = this, Title = "Restore from History", PreventsApplicationTerminationWhenModal = false }; if ((NSPanelButtonType) panel.RunModal ()== NSPanelButtonType.Ok) { string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath, panel.NameFieldStringValue); Controller.SaveDialogCompleted (target_file_path); } else { Controller.SaveDialogCancelled (); } }); } }; }
public bool Run (OpenFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open && data.Action != Gtk.FileChooserAction.Save; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel () { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); SelectEncodingPopUpButton encodingSelector = null; NSPopUpButton viewerSelector = null; NSButton closeSolutionButton = null; var box = new MDBox (LayoutDirection.Vertical, 2, 2); List<FileViewer> currentViewers = null; List<MDAlignment> labels = new List<MDAlignment> (); if (!directoryMode) { var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); if (filterPopup != null) { var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true); var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { filterLabel }, { new MDAlignment (filterPopup, true) { MinWidth = 200 } } }; labels.Add (filterLabel); box.Add (filterBox); } if (data.ShowEncodingSelector) { encodingSelector = new SelectEncodingPopUpButton (data.Action != Gtk.FileChooserAction.Save); encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0; var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true); var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { encodingLabel }, { new MDAlignment (encodingSelector, true) { MinWidth = 200 } } }; labels.Add (encodingLabel); box.Add (encodingBox); } if (data.ShowViewerSelector && panel is NSOpenPanel) { currentViewers = new List<FileViewer> (); viewerSelector = new NSPopUpButton () { Enabled = false, }; if (encodingSelector != null) { viewerSelector.Activated += delegate { var idx = viewerSelector.IndexOfSelectedItem; encodingSelector.Enabled = ! (idx == 0 && currentViewers [0] == null); }; } var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:")); var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { viewSelLabel, true }, { new MDAlignment (viewerSelector, true) { MinWidth = 200 } } }; if (IdeApp.Workspace.IsOpen) { closeSolutionButton = new NSButton () { Title = GettextCatalog.GetString ("Close current workspace"), Hidden = true, State = NSCellStateValue.On, }; closeSolutionButton.SetButtonType (NSButtonType.Switch); closeSolutionButton.SizeToFit (); viewSelBox.Add (closeSolutionButton, true); } box.Add (viewSelBox); } } if (labels.Count > 0) { float w = labels.Max (l => l.MinWidth); foreach (var l in labels) { l.MinWidth = w; l.XAlign = LayoutAlign.Begin; } } if (box.Count > 0) { box.Layout (); panel.AccessoryView = box.View; } panel.SelectionDidChange += delegate(object sender, EventArgs e) { var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); bool slnViewerSelected = false; if (viewerSelector != null) { FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection); if (currentViewers.Count == 0 || currentViewers [0] != null) { if (closeSolutionButton != null) closeSolutionButton.Hidden = true; slnViewerSelected = false; } else { if (closeSolutionButton != null) closeSolutionButton.Hidden = false; slnViewerSelected = true; } box.Layout (); //re-center the accessory view in its parent, Cocoa does this for us initially and after //resizing the window, but we need to do it again after altering its layout var superFrame = box.View.Superview.Frame; var frame = box.View.Frame; //not sure why it's ceiling, but this matches the Cocoa layout frame.X = (float)Math.Ceiling ((superFrame.Width - frame.Width) / 2); frame.Y = (float)Math.Ceiling ((superFrame.Height - frame.Height) / 2); box.View.Frame = frame; } if (encodingSelector != null) encodingSelector.Enabled = !slnViewerSelected; }; var action = MacSelectFileDialogHandler.RunPanel (data, panel); if (!action) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); if (encodingSelector != null) data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null; if (viewerSelector != null ) { if (closeSolutionButton != null) data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; data.SelectedViewer = currentViewers[viewerSelector.IndexOfSelectedItem]; } GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } catch (Exception ex) { LoggingService.LogError ("Error in Open File dialog", ex); MessageService.ShowException (ex); } finally { if (panel != null) panel.Dispose (); } return true; }
internal static void SetCommonPanelProperties (SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty (data.Title)) panel.Title = data.Title; if (!string.IsNullOrEmpty (data.InitialFileName)) panel.NameFieldStringValue = data.InitialFileName; if (!string.IsNullOrEmpty (data.CurrentFolder)) panel.DirectoryUrl = new NSUrl (data.CurrentFolder, true); panel.ParentWindow = NSApplication.SharedApplication.KeyWindow ?? NSApplication.SharedApplication.MainWindow; var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }
public bool Run (OpenFileDialogData data) { NSSavePanel panel = null; try { if (data.Action == FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel { CanChooseDirectories = (data.Action & FileChooserAction.FolderFlags) != 0, CanChooseFiles = (data.Action & FileChooserAction.FileFlags) != 0, }; } MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel); SelectEncodingPopUpButton encodingSelector = null; NSPopUpButton viewerSelector = null; NSButton closeSolutionButton = null; var box = new MDBox (LayoutDirection.Vertical, 2, 2); List<FileViewer> currentViewers = null; var labels = new List<MDAlignment> (); if ((data.Action & FileChooserAction.FileFlags) != 0) { var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel); if (filterPopup != null) { var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true); var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { filterLabel }, { new MDAlignment (filterPopup, true) { MinWidth = 200 } } }; labels.Add (filterLabel); box.Add (filterBox); } if (data.ShowEncodingSelector) { encodingSelector = new SelectEncodingPopUpButton (data.Action != FileChooserAction.Save); encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0; var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true); var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { encodingLabel }, { new MDAlignment (encodingSelector, true) { MinWidth = 200 } } }; labels.Add (encodingLabel); box.Add (encodingBox); } if (data.ShowViewerSelector && panel is NSOpenPanel) { currentViewers = new List<FileViewer> (); viewerSelector = new NSPopUpButton { Enabled = false, }; if (encodingSelector != null || IdeApp.Workspace.IsOpen) { viewerSelector.Activated += delegate { var idx = viewerSelector.IndexOfSelectedItem; bool workbenchViewerSelected = idx == 0 && currentViewers [0] == null; if (encodingSelector != null) encodingSelector.Enabled = !workbenchViewerSelected; if (closeSolutionButton != null) { if (closeSolutionButton.Hidden == workbenchViewerSelected) { closeSolutionButton.Hidden = !workbenchViewerSelected; CenterAccessoryView (box); } } }; } var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:")); var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) { { viewSelLabel, true }, { new MDAlignment (viewerSelector, true) { MinWidth = 200 } } }; if (IdeApp.Workspace.IsOpen) { closeSolutionButton = new NSButton { Title = GettextCatalog.GetString ("Close current workspace"), Hidden = true, State = NSCellStateValue.On, }; closeSolutionButton.SetButtonType (NSButtonType.Switch); closeSolutionButton.SizeToFit (); viewSelBox.Add (closeSolutionButton, true); } box.Add (viewSelBox); } } if (labels.Count > 0) { float w = labels.Max (l => l.MinWidth); foreach (var l in labels) { l.MinWidth = w; l.XAlign = LayoutAlign.Begin; } } if (box.Count > 0) { box.Layout (); panel.AccessoryView = box.View; } panel.SelectionDidChange += delegate { var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); bool slnViewerSelected = false; if (viewerSelector != null) { slnViewerSelected = FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection); if (closeSolutionButton != null) closeSolutionButton.Hidden = !slnViewerSelected; CenterAccessoryView (box); } if (encodingSelector != null) encodingSelector.Enabled = !slnViewerSelected; }; if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel); if (encodingSelector != null) data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null; if (viewerSelector != null ) { if (closeSolutionButton != null) data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off; data.SelectedViewer = viewerSelector.IndexOfSelectedItem >= 0 ? currentViewers[(int)viewerSelector.IndexOfSelectedItem] : null; } GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } catch (Exception ex) { LoggingService.LogInternalError ("Error in Open File dialog", ex); } finally { if (panel != null) panel.Dispose (); } return true; }
/// <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; }
partial void actionExportPreset(NSObject sender) { if(tablePresets.SelectedRow < 0) return; string filePath = string.Empty; using(NSSavePanel savePanel = new NSSavePanel()) { savePanel.AllowedFileTypes = new string[1] { "json" }; savePanel.ReleasedWhenClosed = true; savePanel.Title = "Please choose a file path"; savePanel.Prompt = "Export preset as JSON"; // Check for cancel if(savePanel.RunModal() == 0) return; filePath = savePanel.Url.Path; } var preset = _presets[tablePresets.SelectedRow]; OnExportPreset(preset.EQPresetId, filePath); }