From b7f8eb4da006364a7f6e3820aa1b953473ce8f8d Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Mon, 17 Dec 2018 18:11:21 -0800 Subject: [PATCH] macOS: Use non-deprecated functions in GVExportViewController --- macosx/GVDocument.m | 4 +-- macosx/GVExportViewController.h | 4 +-- macosx/GVExportViewController.m | 54 ++++++++++++++------------------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/macosx/GVDocument.m b/macosx/GVDocument.m index c8d8e5a24..a27bf2c17 100644 --- a/macosx/GVDocument.m +++ b/macosx/GVDocument.m @@ -74,14 +74,14 @@ { if (!_exporter) { _exporter = [[GVExportViewController alloc] init]; - [_exporter setFilename:[[[self fileURL] path] stringByDeletingPathExtension]]; + [_exporter setURL:[[self fileURL] URLByDeletingPathExtension]]; } [_exporter beginSheetModalForWindow:[self windowForSheet] modalDelegate:self didEndSelector:@selector(exporterDidEnd:)]; } - (void)exporterDidEnd:(GVExportViewController *)exporter { - [_graph renderWithFormat:[exporter device] toURL:[NSURL fileURLWithPath:[exporter filename]]]; + [_graph renderWithFormat:[exporter device] toURL:[exporter URL]]; } - (void)fileDidChange:(NSString *)path diff --git a/macosx/GVExportViewController.h b/macosx/GVExportViewController.h index b168fcb70..340023bd5 100644 --- a/macosx/GVExportViewController.h +++ b/macosx/GVExportViewController.h @@ -16,14 +16,14 @@ @interface GVExportViewController : NSViewController { NSSavePanel *_panel; - NSString *_filename; + NSURL *_url; NSDictionary *_formatRender; NSString *_render; } @property(readonly) NSArray *formatRenders; @property(readonly) NSString *device; -@property(retain) NSString *filename; +@property(retain) NSURL *URL; @property(retain) NSDictionary *formatRender; @property(retain) NSString *render; diff --git a/macosx/GVExportViewController.m b/macosx/GVExportViewController.m index bf65cff1f..2c4820e2b 100644 --- a/macosx/GVExportViewController.m +++ b/macosx/GVExportViewController.m @@ -14,11 +14,11 @@ #import "GVExportViewController.h" #import "GVGraph.h" -NSMutableArray *_formatRenders = nil; +static NSMutableArray *_formatRenders = nil; @implementation GVExportViewController -@synthesize filename = _filename; +@synthesize URL = _url; @synthesize render = _render; + (void)initialize @@ -51,7 +51,7 @@ NSMutableArray *_formatRenders = nil; { if (self = [super initWithNibName:@"Export" bundle:nil]) { _panel = nil; - _filename = nil; + _url = nil; _formatRender = nil; _render = nil; @@ -89,7 +89,7 @@ NSMutableArray *_formatRenders = nil; _formatRender = [formatRender retain]; /* force save panel to use this file type */ - [_panel setRequiredFileType:[_formatRender objectForKey:@"format"]]; + [_panel setAllowedFileTypes:[NSArray arrayWithObject:[_formatRender objectForKey:@"format"]]]; /* remove existing render if it's not compatible with format */ if (![[_formatRender objectForKey:@"renders"] containsObject:_render]) @@ -105,42 +105,34 @@ NSMutableArray *_formatRenders = nil; [endInvocation setSelector:selector]; [endInvocation setArgument:&self atIndex:2]; [endInvocation retain]; - + _panel = [NSSavePanel savePanel]; [_panel setAccessoryView:[self view]]; - [_panel setRequiredFileType:[_formatRender objectForKey:@"format"]]; - [_panel - beginSheetForDirectory:[_filename stringByDeletingLastPathComponent] - file:[_filename lastPathComponent] - modalForWindow:window - modalDelegate:self - didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) - contextInfo:endInvocation]; -} + [_panel setAllowedFileTypes:[NSArray arrayWithObject:[_formatRender objectForKey:@"format"]]]; + [_panel setDirectoryURL:[_url URLByDeletingLastPathComponent]]; + [_panel setNameFieldStringValue:[_url lastPathComponent]]; + [_panel beginSheetModalForWindow:window completionHandler:^(NSInteger result) { + if (result == NSOKButton) { + NSURL *url = [_panel URL]; + if (_url != url) { + [_url release]; + _url = [url retain]; + } -- (void)savePanelDidEnd:(NSSavePanel *)savePanel returnCode:(int)returnCode contextInfo:(void *)contextInfo -{ - NSInvocation *endInvocation = (NSInvocation *)contextInfo; - if (returnCode == NSOKButton) { - NSString *filename = [savePanel filename]; - if (_filename != filename) { - [_filename release]; - _filename = [filename retain]; + /* invoke the end selector on the modal delegate */ + [endInvocation invoke]; } - - /* invoke the end selector on the modal delegate */ - [endInvocation invoke]; - } - - [endInvocation release]; - [_panel setAccessoryView:nil]; - _panel = nil; + + [endInvocation release]; + [_panel setAccessoryView:nil]; + _panel = nil; + }]; } - (void)dealloc { [_panel release]; - [_filename release]; + [_url release]; [_formatRender release]; [_render release]; [super dealloc]; -- 2.40.0