• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]


  • Subject: Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]
  • From: Steve Christensen <email@hidden>
  • Date: Thu, 15 Oct 2009 12:40:27 -0700

I had written this NSOpenPanel category to work in a plugin environment, and I think it should do the right thing. Just set up the NSOpenPanel as you like then call - runModalForDirectory:file:types:relativeToWindow: and it will return when the user has selected (or not) a file.

steve


// category on NSOpenPanel that runs the open sheet modally and returns when done
@interface NSOpenPanel(ModalSheets)


- (NSInteger)runModalForDirectory:(NSString*)path file:(NSString*) name types:(NSArray*)fileTypes
relativeToWindow:(NSWindow*)window;


@end

@implementation NSOpenPanel(ModalSheets)

- (void)__modalOpenPanelDidEnd:(NSOpenPanel*)panel returnCode:(int) returnCode contextInfo:(void*)contextInfo
{
#pragma unused(panel, contextInfo)


	[NSApp stopModalWithCode:returnCode];
}

- (NSInteger)runModalForDirectory:(NSString*)path file:(NSString*) name types:(NSArray*)fileTypes
relativeToWindow:(NSWindow*)window
{
NSInteger result;


if (window != nil)
{
[self beginSheetForDirectory:path file:name modalForWindow:window modalDelegate:self
didEndSelector:@selector (__modalOpenPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];


		result = [NSApp runModalForWindow:self];

		[NSApp endSheet:self];
	}
	else
	{
		result = [self runModalForDirectory:path file:name types:fileTypes];
	}

	return result;
}

@end




On Oct 14, 2009, at 6:02 AM, Motti Shneor wrote:

I'm in a strange situation, where I am implementing a plugin component that runs within a host application which I don't have access to.

Within this context, The host sometimes calls my plug-in to open an NSSavePanel (or NSOpenPanel). The host expects that I'm synchronous --- i.e. I only return when the NSSavePanel is dismissed, and there's a result.

However, The host also provides me with its own Window, and I need to open my NSSavePanel as a Sheet-window over the host's window.

Now NSSavePanel (and NSOpenPanel) provide 2 different ways to run them

1. runModal (or a vaiant) that is synchronous --- but it does not create a sheet window
2 beginSheetFor... (or variants) that are asynchronous (I must supply with a callback selector to be called as the NSSavePanel is dismissed) --- these DO create a sheet over the parent window.


Is there a decent way to combine these two requirements?

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]
      • From: Motti Shneor <email@hidden>
References: 
 >Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal] (From: Motti Shneor <email@hidden>)

  • Prev by Date: Re: language based scaning,
  • Next by Date: Re: NSURLConnection timeout -- what happens?
  • Previous by thread: Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]
  • Next by thread: Re: Opening a NSSavePanel as a Sheet, and blocking like in [panel runModal]
  • Index(es):
    • Date
    • Thread