nsopenpanel

How to acquire a file path using objective c

风流意气都作罢 提交于 2019-12-07 18:19:24
问题 I want a function which just returns the full file path of a file selected in finder. I am currently have this function: + (NSString*)choosePathWindow:(NSString*)title buttonTitle:(NSString*)buttonTitle allowDir:(BOOL)dir allowFile:(BOOL)file{ [NSApp activateIgnoringOtherApps:YES]; NSOpenPanel *openPanel = [NSOpenPanel openPanel]; [openPanel setLevel:NSFloatingWindowLevel]; [openPanel setAllowsMultipleSelection:NO]; [openPanel setCanChooseDirectories:dir]; [openPanel setCanCreateDirectories

Restrict access to certain folders using NSOpenPanel

こ雲淡風輕ζ 提交于 2019-12-07 05:23:27
问题 I'm using NSOpenPanel to allow a user to select a folder to save documents into. I would like to restrict what folder (in terms of hierarchy) they can save into. Essentially, I want to prevent them from choosing any folder above: /Users/username/ So the folder /Users/username/cats/ would be acceptable but /Users/username/ /Applications/cats/ would not be allowed. I was wondering how to implement this restriction. Thanks. 回答1: Note that NSOpenPanel inherits from NSSavePanel, which in turn

NSOpenPanel crashes when debugging with Xcode 4.5.1

情到浓时终转凉″ 提交于 2019-12-06 09:23:03
I have a document-based application. Since upgrading to XCode 4.5.1 (from 4.4) NSOpenPanel crashes when I debug the application from Xcode. It does not crash when I start the program directly. I use NSOpenPanel on two occasions: When the user selects "Open" from the "File" menu (since it is a document-based application, none of my own code is involved) and for importing some data into my document (so it gets called by my own code). NSOpenPanel crashes on both occasions (the dialog opens, but before I can do anything, an exception is raised). I made clean, tried switching compiler from Apple

How to acquire a file path using objective c

放肆的年华 提交于 2019-12-05 20:28:13
I want a function which just returns the full file path of a file selected in finder. I am currently have this function: + (NSString*)choosePathWindow:(NSString*)title buttonTitle:(NSString*)buttonTitle allowDir:(BOOL)dir allowFile:(BOOL)file{ [NSApp activateIgnoringOtherApps:YES]; NSOpenPanel *openPanel = [NSOpenPanel openPanel]; [openPanel setLevel:NSFloatingWindowLevel]; [openPanel setAllowsMultipleSelection:NO]; [openPanel setCanChooseDirectories:dir]; [openPanel setCanCreateDirectories:dir]; [openPanel setCanChooseFiles:file]; [openPanel setMessage:title]; [openPanel setPrompt:buttonTitle

Restrict access to certain folders using NSOpenPanel

孤街醉人 提交于 2019-12-05 12:43:08
I'm using NSOpenPanel to allow a user to select a folder to save documents into. I would like to restrict what folder (in terms of hierarchy) they can save into. Essentially, I want to prevent them from choosing any folder above: /Users/username/ So the folder /Users/username/cats/ would be acceptable but /Users/username/ /Applications/cats/ would not be allowed. I was wondering how to implement this restriction. Thanks. Note that NSOpenPanel inherits from NSSavePanel , which in turn defines a delegate and a corresponding delegate protocol NSOpenSavePanelDelegate . You can use the delegate to

NSOpenPanel - Everything deprecated?

三世轮回 提交于 2019-12-04 10:27:27
问题 I've been trying to get a window to show up asking the person to choose a file, and I eventually did. The problem is, Xcode complains that the method I'm using is deprecated. I looked in the class reference, but everything under the "running panels" section has been deprecated as of Mac OS 10.6. Is there a different class I'm supposed to be using now? 回答1: As far as I know, you can use the runModal method like shown below: NSOpenPanel *openPanel = [[NSOpenPanel alloc] init]; if ([openPanel

NSOpenPanel takes longer time on Mac OSX 10.9

半城伤御伤魂 提交于 2019-12-04 05:27:02
问题 On Mac OSX 10.9,I am facing an issue with NSOpenPanel in My application. NSopenpanel takes longer time to launch it for the first time. I observed that [NSOpenPanel openPanel] takes longer time to execute for first time.Because of this it took some delay to launch for first time.Can any one suggest how to fix this issue 回答1: This is probably because of the special architecture of the NSOpenPanel. The open panel runs in it's own process called "Powerbox", especially if the app is sandboxed.

Resize and Save NSImage?

荒凉一梦 提交于 2019-12-03 07:57:48
I have an NSImageView which I get an image for from an NSOpenPanel. That works great. Now, how can I take that NSImage, half its size and save it as the same format in the same directory as the original as well? If you can help at all with anything I'd appreciate it, thanks. Check the ImageCrop sample project from Matt Gemmell: http://mattgemmell.com/source/ Nice example how to resize / crop images. Finally you can use something like this to save the result (dirty sample): // Write to TIF [[resultImg TIFFRepresentation] writeToFile:@"/Users/Anne/Desktop/Result.tif" atomically:YES]; // Write to

NSOpenPanel - Everything deprecated?

故事扮演 提交于 2019-12-03 06:48:55
I've been trying to get a window to show up asking the person to choose a file, and I eventually did. The problem is, Xcode complains that the method I'm using is deprecated. I looked in the class reference , but everything under the "running panels" section has been deprecated as of Mac OS 10.6. Is there a different class I'm supposed to be using now? As far as I know, you can use the runModal method like shown below: NSOpenPanel *openPanel = [[NSOpenPanel alloc] init]; if ([openPanel runModal] == NSOKButton) { NSString *selectedFileName = [openPanel filename]; } In 10.6, there was a few

NSOpenPanel in Swift . How to open?

不打扰是莪最后的温柔 提交于 2019-12-03 05:52:19
I have this Objective-C Code : - (IBAction)selectFileButtonAction:(id)sender { //create open panel... NSOpenPanel* openPanel = [NSOpenPanel openPanel]; // NSLog(@"Open Panel"); //set restrictions / allowances... [openPanel setAllowsMultipleSelection: NO]; [openPanel setCanChooseDirectories:NO]; [openPanel setCanCreateDirectories:NO]; [openPanel setCanChooseFiles:YES]; //only allow images... [openPanel setAllowedFileTypes:[NSImage imageFileTypes]]; //open panel as sheet on main window... [openPanel beginWithCompletionHandler:^(NSInteger result) { if (result == NSFileHandlingPanelOKButton) { /