API  0.9.10
CPSavePanel.j
Go to the documentation of this file.
1 /*
2  * CPSavePanel.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2009, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 
25 @implementation CPSavePanel : CPPanel
26 {
27  CPURL _URL;
28 
29  BOOL _isExtensionHidden;
30  BOOL _canSelectHiddenExtension;
31  BOOL _allowsOtherFileTypes;
32  BOOL _canCreateDirectories;
33 
34  CPArray _allowedFileTypes;
35 }
36 
37 + (id)savePanel
38 {
39  return [[CPSavePanel alloc] init];
40 }
41 
42 - (id)init
43 {
44  if (self = [super init])
45  {
46  _canCreateDirectories = YES;
47  }
48 
49  return self;
50 }
51 
52 - (CPInteger)runModal
53 {
54  // FIXME: Is this correct???
55  [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
56 
57  if (typeof window["cpSavePanel"] === "function")
58  {
59  var resultObject = window.cpSavePanel({
60  isExtensionHidden: _isExtensionHidden,
61  canSelectHiddenExtension: _canSelectHiddenExtension,
62  allowsOtherFileTypes: _allowsOtherFileTypes,
63  canCreateDirectories: _canCreateDirectories,
64  allowedFileTypes: _allowedFileTypes
65  }),
66  result = resultObject.button;
67 
68  _URL = result ? [CPURL URLWithString:resultObject.URL] : nil;
69  }
70  else
71  {
72  // FIXME: This is not the best way to do this.
73  var documentName = window.prompt("Document Name:"),
74  result = documentName !== null;
75 
76  _URL = result ? [[self class] proposedFileURLWithDocumentName:documentName] : nil;
77  }
78 
79  return result;
80 }
81 
83 {
84  return _URL;
85 }
86 
87 @end
88 
90 
95 {
96  return _isExtensionHidden;
97 }
98 
102 - (void)setExtensionHidden:(BOOL)aValue
103 {
104  _isExtensionHidden = aValue;
105 }
106 
111 {
112  return _canSelectHiddenExtension;
113 }
114 
118 - (void)setCanSelectHiddenExtension:(BOOL)aValue
119 {
120  _canSelectHiddenExtension = aValue;
121 }
122 
127 {
128  return _allowsOtherFileTypes;
129 }
130 
134 - (void)setAllowsOtherFileTypes:(BOOL)aValue
135 {
136  _allowsOtherFileTypes = aValue;
137 }
138 
143 {
144  return _canCreateDirectories;
145 }
146 
150 - (void)setCanCreateDirectories:(BOOL)aValue
151 {
152  _canCreateDirectories = aValue;
153 }
154 
159 {
160  return _allowedFileTypes;
161 }
162 
166 - (void)setAllowedFileTypes:(CPArray)aValue
167 {
168  _allowedFileTypes = aValue;
169 }
170 
171 @end
CPInteger runModal()
Definition: CPSavePanel.j:52
The main run loop for the application.
Definition: CPRunLoop.h:2
CPRunLoop currentRunLoop()
Definition: CPRunLoop.j:232
CPDate limitDateForMode:(CPString aMode)
Definition: CPRunLoop.j:342
CPURL URL()
Definition: CPSavePanel.j:82
Class class()
Definition: CPObject.j:179
Definition: CPPanel.h:2
Definition: CPURL.h:2
id alloc()
Definition: CPObject.j:130