diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 82159b55f..31ce78b0f 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -24,6 +24,7 @@ @import @import "CPResponder.j" +@import "CPSavePanel.j" @import "CPViewController.j" @import "CPWindowController.j" @@ -416,7 +417,7 @@ var CPDocumentUntitledCount = 0; // FIXME: Oh man is this every looking for trouble, we need to handle login at the Cappuccino level, with HTTP Errors. _readConnection = [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:anAbsoluteURL] delegate:self]; - + _readConnection.session = _CPReadSessionMake(aType, aDelegate, aDidReadSelector, aContextInfo); } @@ -459,17 +460,17 @@ var CPDocumentUntitledCount = 0; _writeRequest = [CPURLRequest requestWithURL:anAbsoluteURL]; - [_writeRequest setHTTPMethod:@"POST"]; + [_writeRequest setHTTPMethod:@"PUT"]; [_writeRequest setHTTPBody:[data string]]; - + [_writeRequest setValue:@"close" forHTTPHeaderField:@"Connection"]; if (aSaveOperation == CPSaveOperation) [_writeRequest setValue:@"true" forHTTPHeaderField:@"x-cappuccino-overwrite"]; - + if (aSaveOperation != CPSaveToOperation) [self updateChangeCount:CPChangeCleared]; - + // FIXME: Oh man is this every looking for trouble, we need to handle login at the Cappuccino level, with HTTP Errors. var connection = [CPURLConnection connectionWithRequest:_writeRequest delegate:self]; @@ -784,16 +785,19 @@ var CPDocumentUntitledCount = 0; */ - (void)saveDocumentAs:(id)aSender { - _documentName = window.prompt("Document Name:"); + var savePanel = [CPSavePanel savePanel], + response = [savePanel runModal]; - if (!_documentName) + if (!response) return; - + + var saveURL = [savePanel filename]; + [[CPNotificationCenter defaultCenter] postNotificationName:CPDocumentWillSaveNotification object:self]; - - [self saveToURL:[self proposedFileURL] ofType:[self fileType] forSaveOperation:CPSaveAsOperation delegate:self didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:NULL]; + + [self saveToURL:saveURL ofType:[self fileType] forSaveOperation:CPSaveAsOperation delegate:self didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:NULL]; } /* diff --git a/AppKit/CPDocumentController.j b/AppKit/CPDocumentController.j index 4a8f83724..d336617e7 100644 --- a/AppKit/CPDocumentController.j +++ b/AppKit/CPDocumentController.j @@ -24,6 +24,7 @@ @import @import "CPDocument.j" +@import "CPOpenPanel.j"; var CPSharedDocumentController = nil; @@ -138,11 +139,11 @@ var CPSharedDocumentController = nil; - (CPDocument)openDocumentWithContentsOfURL:(CPURL)anAbsoluteURL display:(BOOL)shouldDisplay error:(CPError)anError { var result = [self documentForURL:anAbsoluteURL]; - + if (!result) { var type = [self typeForContentsOfURL:anAbsoluteURL error:anError]; - + result = [self makeDocumentWithContentsOfURL:anAbsoluteURL ofType:type delegate:self didReadSelector:@selector(document:didRead:contextInfo:) contextInfo:[CPDictionary dictionaryWithObject:shouldDisplay forKey:@"shouldDisplay"]]; } else if (shouldDisplay) @@ -219,6 +220,20 @@ var CPSharedDocumentController = nil; [self openUntitledDocumentOfType:[[_documentTypes objectAtIndex:0] objectForKey:@"CPBundleTypeName"] display:YES]; } +-(void)openDocument:(id)aSender +{ + var openPanel = [CPOpenPanel openPanel]; + + [openPanel runModalForTypes:nil];//[@"nib", @"xib", @"cib"]]; + + var filenames = [openPanel filenames], + index = 0, + count = [filenames count]; + + for (; index < count; ++index) + [self openDocumentWithContentsOfURL:[CPURL URLWithString:filenames[index]] display:YES error:nil]; +} + // Managing Documents /*! diff --git a/AppKit/CPMenu.j b/AppKit/CPMenu.j index 2434040a7..c343273ab 100644 --- a/AppKit/CPMenu.j +++ b/AppKit/CPMenu.j @@ -1499,7 +1499,9 @@ var _CPMenuBarWindowBackgroundColor = nil, if (self) { // FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/39-dont-allow-windows-to-go-above-menubar - [self setLevel:-1];//CPTornOffMenuWindowLevel]; + if ([CPPlatform isBrowser]) + [self setLevel:-1];//CPTornOffMenuWindowLevel]; + [self setAutoresizingMask:CPWindowWidthSizable]; var contentView = [self contentView]; diff --git a/AppKit/CPOpenPanel.j b/AppKit/CPOpenPanel.j index 058853416..eca9f3f1e 100644 --- a/AppKit/CPOpenPanel.j +++ b/AppKit/CPOpenPanel.j @@ -2,60 +2,84 @@ @import #include "Platform/Platform.h" -var SharedOpenPanel = nil; @implementation CPOpenPanel : CPPanel { - CPArray _files; - BOOL _canChooseFiles @accessors(property=canChooseFiles); - BOOL _canChooseDirectories @accessors(property=canChooseDirectories); - BOOL _allowsMultipleSelection @accessors(property=allowsMultipleSelection); + JSObject _openPanel; } + (id)openPanel { - if (!SharedOpenPanel) - SharedOpenPanel = [[CPOpenPanel alloc] init]; - - return SharedOpenPanel; + return [[CPOpenPanel alloc] init]; } - (id)init { if (self = [super init]) - { - _files = []; - _canChooseFiles = YES; - } + _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 _files; + return _openPanel.filenames; } -- (unsigned)runModalForDirectory:(CPString)absoluteDirectoryPath file:(CPString)filename types:(CPArray)fileTypes +- (CPInteger)runModalForDirectory:(CPString)anAbsoluteDirectoryPath file:(CPString)aFilename types:(CPArray)fileTypes { -#if PLATFORM(DOM) - if (window.Titanium) - { - _files = Titanium.Desktop.openFiles({ - path:absoluteDirectoryPath, - types:fileTypes, - multiple:_allowsMultipleSelection, - filename:filename, - directories:_canChooseDirectories, - files:_canChooseFiles - }); - } -#endif + // FIXME: Is this correct??? + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + return _openPanel.runModal(anAbsoluteDirectoryPath, aFilename, fileTypes); } -- (unsigned)runModalForTypes:(CPArray)fileTypes -{alert("HERE"); - [self runModalForDirectory:"/" file:nil types:fileTypes]; +- (CPInteger)runModalForTypes:(CPArray)fileTypes +{ + // FIXME: Is this correct??? + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + return _openPanel.runModal(fileTypes); } @end