API 0.9.5
AppKit/CPSavePanel.j
Go to the documentation of this file.
00001 /*
00002  * CPSavePanel.j
00003  * AppKit
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2009, 280 North, Inc.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 
00024 
00025 @implementation CPSavePanel : CPPanel
00026 {
00027     CPURL   _URL;
00028 
00029     BOOL    _isExtensionHidden;
00030     BOOL    _canSelectHiddenExtension;
00031     BOOL    _allowsOtherFileTypes;
00032     BOOL    _canCreateDirectories;
00033 
00034     CPArray _allowedFileTypes;
00035 }
00036 
00037 + (id)savePanel
00038 {
00039     return [[CPSavePanel alloc] init];
00040 }
00041 
00042 - (id)init
00043 {
00044     if (self = [super init])
00045     {
00046         _canCreateDirectories = YES;
00047     }
00048 
00049     return self;
00050 }
00051 
00052 - (CPInteger)runModal
00053 {
00054     // FIXME: Is this correct???
00055     [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
00056 
00057     if (typeof window["cpSavePanel"] === "function")
00058     {
00059         var resultObject = window.cpSavePanel({
00060                 isExtensionHidden: _isExtensionHidden,
00061                 canSelectHiddenExtension: _canSelectHiddenExtension,
00062                 allowsOtherFileTypes: _allowsOtherFileTypes,
00063                 canCreateDirectories: _canCreateDirectories,
00064                 allowedFileTypes: _allowedFileTypes
00065             }),
00066             result = resultObject.button;
00067 
00068         _URL = result ? [CPURL URLWithString:resultObject.URL] : nil;
00069     }
00070     else
00071     {
00072         // FIXME: This is not the best way to do this.
00073         var documentName = window.prompt("Document Name:"),
00074             result = documentName !== null;
00075 
00076         _URL = result ? [[self class] proposedFileURLWithDocumentName:documentName] : nil;
00077     }
00078 
00079     return result;
00080 }
00081 
00082 - (CPURL)URL
00083 {
00084     return _URL;
00085 }
00086 
00087 @end
00088 
00089 @implementation CPSavePanel (CPSynthesizedAccessors)
00090 
00094 - (BOOL)isExtensionHidden
00095 {
00096     return _isExtensionHidden;
00097 }
00098 
00102 - (void)setExtensionHidden:(BOOL)aValue
00103 {
00104     _isExtensionHidden = aValue;
00105 }
00106 
00110 - (BOOL)canSelectHiddenExtension
00111 {
00112     return _canSelectHiddenExtension;
00113 }
00114 
00118 - (void)setCanSelectHiddenExtension:(BOOL)aValue
00119 {
00120     _canSelectHiddenExtension = aValue;
00121 }
00122 
00126 - (BOOL)allowsOtherFileTypes
00127 {
00128     return _allowsOtherFileTypes;
00129 }
00130 
00134 - (void)setAllowsOtherFileTypes:(BOOL)aValue
00135 {
00136     _allowsOtherFileTypes = aValue;
00137 }
00138 
00142 - (BOOL)canCreateDirectories
00143 {
00144     return _canCreateDirectories;
00145 }
00146 
00150 - (void)setCanCreateDirectories:(BOOL)aValue
00151 {
00152     _canCreateDirectories = aValue;
00153 }
00154 
00158 - (CPArray)allowedFileTypes
00159 {
00160     return _allowedFileTypes;
00161 }
00162 
00166 - (void)setAllowedFileTypes:(CPArray)aValue
00167 {
00168     _allowedFileTypes = aValue;
00169 }
00170 
00171 @end
 All Classes Files Functions Variables Defines