nssavepanel

Document Type Icon not showing on custom file MacOS

自古美人都是妖i 提交于 2021-02-08 20:54:12
问题 My application needs to have custom document support, but I did not start out with a Document-template in xcode. I did manage to properly load and save the data by following among other things this tutorial: https://www.brandpending.com/2016/02/21/opening-and-saving-custom-document-types-from-a-swift-cocoa-application/. One problem though, is that my custom icon is not showing on my file! it is still a blank page-icon :(. What Am I doing wrong? Here is my setup: my HSDocument code: -(BOOL

macOS - How to have NSSavePanel to add a file extension in the file name?

萝らか妹 提交于 2020-06-26 04:25:27
问题 I'm using this code to give the user the choice to specify a name and a location where to save a plain text file on disk. All seems to work but the saved file hasn't any extension. Actually I have not specify an extension in any part of my code, I read NSSavePanel documentation without notice the part where explained this option. Here is the code I'm using: let textToExport = mainTextField.textStorage?.string if textToExport != "" { let mySave = NSSavePanel() mySave.begin { (result) -> Void

Replace a file using the NSSavePanel in a sandboxed application

我怕爱的太早我们不能终老 提交于 2020-01-04 06:11:42
问题 I create a NSSavePanel using this code: NSSavePanel *savePanel = [NSSavePanel savePanel]; savePanel.delegate = self; savePanel.directoryURL = ...; savePanel.nameFieldStringValue = ...; [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger returnCode) { if (returnCode == NSFileHandlingPanelOKButton) { // the completion handler } }]; If in the save panel the user select an already existing file, appears the alert box "“XXX” already exists. Do you want to replace it?". If

Replace a file using the NSSavePanel in a sandboxed application

眉间皱痕 提交于 2020-01-04 06:11:09
问题 I create a NSSavePanel using this code: NSSavePanel *savePanel = [NSSavePanel savePanel]; savePanel.delegate = self; savePanel.directoryURL = ...; savePanel.nameFieldStringValue = ...; [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger returnCode) { if (returnCode == NSFileHandlingPanelOKButton) { // the completion handler } }]; If in the save panel the user select an already existing file, appears the alert box "“XXX” already exists. Do you want to replace it?". If

Saving an NSView to a png file?

谁说我不能喝 提交于 2019-12-29 04:28:16
问题 I am making a simple program that creates game cards for a game I play. I have sent it out to some friends of mine for testing, but they really want it to save images, not just print them. I have tried to make it save as a .png file. I have to questions here. How can I make it save my view as a .png file, including all of the view's NSImageWells. How can I add an NSPopupButton to an NSSavePanel to allow users to select a format? Any help is greatly appreciated. 回答1: First create a TIFF

Cocoa/OSX - Strange behavior in NSSavePanel that not shows sub-itens

我们两清 提交于 2019-12-25 05:15:18
问题 I've a NSSavePanel instance with a strange behavior: whenever I open it and click on a directory's arrow (the little expand button) it shows an indeterminate loading icon on the left-bottom corner that never ends, and not shows the directory/file tree. An image can see as follow: In that example, I've clicked in "workspace" directory. And the panel not shows the sub-itens. Even strange is that after I click it again (redrawing the directory) and then click again (re-open the directory), it

Getting path to users Library folder in OS X

痴心易碎 提交于 2019-12-22 04:35:08
问题 I need to open a NSSavePanel with the users Library folder as destination folder. Normally I would do this by entering ~/Library/ in [NSSavePanel beginSheetForDirectory] . This works fine as long as the application is not sandboxed. For sandboxed applications this will result in the NSSavePanel trying to access a folder inside the applications document "box". I cannot refer to /Users/username/Library/ as I do not know the users username at runtime. So how do I link to this path in cocoa? 回答1:

How can i use NSSavePanel to select a directory?

会有一股神秘感。 提交于 2019-12-21 07:23:32
问题 I need the user select an existing or a new directory where my app can save a few files. Can i do this with NSSavePanel or is there another directory selector class? 回答1: NSSavePanel doesn't give the ability to choose folders but NSOpenPanel (a subclass of NSSavePanel) does. You set YES for -setCanChooseDirectories: and -setCanCreateDirectories:, set a prompt that makes sense with -setPrompt:. 来源: https://stackoverflow.com/questions/3396081/how-can-i-use-nssavepanel-to-select-a-directory

Using Cocoa NSSavePanel in Sandbox causes Assertion failure

橙三吉。 提交于 2019-12-20 17:18:54
问题 I'm trying to use the NSSavePanel and added this line to my code. let test = NSSavePanel() Everytime this code is called the this error appears. I'm not quite sure what is happening here because I'm only creating a new object. Any help appreciated. Thanks! *** Assertion failure in -[NSVBSavePanel viewWillInvalidate:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.20.106/Nav.subproj/OpenAndSavePanelRemote/NSVBOpenAndSavePanels.m:387 2017-12-23 18:11:33.110099+0100 test

NSSavePanel not working when sandboxed? - OSX • Objective C

大兔子大兔子 提交于 2019-12-13 19:05:33
问题 I have the following save panel in my app. I have recently tried to sandbox it but unfortunately when sandboxed saving doesn't seem to be working. I understand that beginSheetForDirectory is depreciated, so possibly that's why it's not working? How can I get this to work with sandboxing? - (IBAction)saveButtonPressed:(id)sender { NSSavePanel *sp = [NSSavePanel savePanel]; [sp setRequiredFileType:@"jpg"]; [sp beginSheetForDirectory:[NSString stringWithFormat:@"%@/Pictures", NSHomeDirectory()]