From fce91c7ad3c534d6eb26ce298722730819b90d36 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Sat, 17 Oct 2009 10:00:50 -0700 Subject: [PATCH] Cleanuped up open/save panel. Reviewed by me. --- AppKit/CPDocument.j | 2 +- AppKit/CPDocumentController.j | 12 +++--- AppKit/CPOpenPanel.j | 79 ++++++++--------------------------- AppKit/CPSavePanel.j | 26 +++--------- 4 files changed, 31 insertions(+), 88 deletions(-) diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 31ce78b0f..abf06fb9c 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -791,7 +791,7 @@ var CPDocumentUntitledCount = 0; if (!response) return; - var saveURL = [savePanel filename]; + var saveURL = [savePanel URL]; [[CPNotificationCenter defaultCenter] postNotificationName:CPDocumentWillSaveNotification diff --git a/AppKit/CPDocumentController.j b/AppKit/CPDocumentController.j index d336617e7..7011c7902 100644 --- a/AppKit/CPDocumentController.j +++ b/AppKit/CPDocumentController.j @@ -223,15 +223,15 @@ var CPSharedDocumentController = nil; -(void)openDocument:(id)aSender { var openPanel = [CPOpenPanel openPanel]; - - [openPanel runModalForTypes:nil];//[@"nib", @"xib", @"cib"]]; - - var filenames = [openPanel filenames], + + [openPanel runModal]; + + var URLs = [openPanel URLs], index = 0, - count = [filenames count]; + count = [URLs count]; for (; index < count; ++index) - [self openDocumentWithContentsOfURL:[CPURL URLWithString:filenames[index]] display:YES error:nil]; + [self openDocumentWithContentsOfURL:[CPURL URLWithString:URLs[index]] display:YES error:nil]; } // Managing Documents diff --git a/AppKit/CPOpenPanel.j b/AppKit/CPOpenPanel.j index eca9f3f1e..8cff33aed 100644 --- a/AppKit/CPOpenPanel.j +++ b/AppKit/CPOpenPanel.j @@ -5,7 +5,11 @@ @implementation CPOpenPanel : CPPanel { - JSObject _openPanel; + BOOL _canChooseFiles @accessors(property=canChooseFiles); + BOOL _canChooseDirectories @accessors(property=canChooseDirectories); + BOOL _allowsMultipleSelection @accessors(property=allowsMultipleSelection); + CPURL _directoryURL @accessors(property=directoryURL); + CPArray _URLs; } + (id)openPanel @@ -13,73 +17,26 @@ return [[CPOpenPanel alloc] init]; } -- (id)init -{ - if (self = [super init]) - _openPanel = window.application.createOpenPanel(); - - return self; -} - -- (BOOL)canChooseFiles -{ - return _openPanel.canChooseFiles; -} - -- (void)setCanChooseFiles:(BOOL)shouldChooseFiles -{ - _openPanel.canChooseFiles = shouldChooseFiles; -} - -- (BOOL)canChooseDirectories -{ - return _openPanel.canChooseDirectories; -} - -- (void)setCanChooseDirectories:(BOOL)shouldChooseDirectories -{ - _openPanel.canChooseDirectories = shouldChooseDirectories; -} - -- (BOOL)resolvesAliases -{ - return _openPanel.resolvesAliases; -} - -- (BOOL)setResolvesAliases:(BOOL)shouldResolveAliases -{ - return _openPanel.resolvesAliases = shouldResolveAliases; -} - -- (BOOL)allowsMultipleSelections -{ - return _openPanel.resolvesAliases; -} - -- (BOOL)setAllowsMultipleSelections:(BOOL)shouldAllowMultipleSelection -{ - return _openPanel.allowsMultipleSelection = shouldAllowMultipleSelection; -} - -- (void)filenames -{ - return _openPanel.filenames; -} - -- (CPInteger)runModalForDirectory:(CPString)anAbsoluteDirectoryPath file:(CPString)aFilename types:(CPArray)fileTypes +- (CPInteger)runModal { // FIXME: Is this correct??? [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; - return _openPanel.runModal(anAbsoluteDirectoryPath, aFilename, fileTypes); + var options = { directoryURL: [self directoryURL], + canChooseFiles: [self canChooseFiles], + canChooseDirectories: [self canChooseDirectories], + allowsMultipleSelection: [self allowsMultipleSelection] }; + + var result = window.cpOpenPanel(options); + + _URLs = result.URLs; + + return result.button; } -- (CPInteger)runModalForTypes:(CPArray)fileTypes +- (CPArray)URLs { - // FIXME: Is this correct??? - [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; - - return _openPanel.runModal(fileTypes); + return _URLs; } @end diff --git a/AppKit/CPSavePanel.j b/AppKit/CPSavePanel.j index 7813cbe40..bc99c3699 100644 --- a/AppKit/CPSavePanel.j +++ b/AppKit/CPSavePanel.j @@ -4,7 +4,7 @@ @implementation CPSavePanel : CPPanel { - JSObject _savePanel; + Object result; } + (id)savePanel @@ -12,33 +12,19 @@ return [[CPSavePanel alloc] init]; } -- (id)init -{ - if (self = [super init]) - _savePanel = window.application.createSavePanel(); - - return self; -} - - (CPInteger)runModal { // FIXME: Is this correct??? [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; - return _savePanel.runModal(); + result = window.cpSavePanel(); + + return result.button; } -- (CPInteger)runModalForDirectory:(CPString)anAbsoluteDirectoryPath +- (CPURL)URL { - // FIXME: Is this correct??? - [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; - - return _savePanel.runModal(anAbsoluteDirectoryPath); -} - -- (CPString)filename -{ - return _savePanel.filename; + return [CPURL URLWithString:result.URL]; } @end