API  1.0.0
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 + (CPURL)proposedFileURLWithDocumentName:(CPString)aDocumentName
38 {
39  return [CPURL URLWithString:aDocumentName];
40 }
41 
42 + (id)savePanel
43 {
44  return [[CPSavePanel alloc] init];
45 }
46 
47 - (id)init
48 {
49  if (self = [super init])
50  {
51  _canCreateDirectories = YES;
52  }
53 
54  return self;
55 }
56 
57 - (CPInteger)runModal
58 {
59  // FIXME: Is this correct???
60  [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
61 
62  if (typeof window["cpSavePanel"] === "function")
63  {
64  var resultObject = window.cpSavePanel({
65  isExtensionHidden: _isExtensionHidden,
66  canSelectHiddenExtension: _canSelectHiddenExtension,
67  allowsOtherFileTypes: _allowsOtherFileTypes,
68  canCreateDirectories: _canCreateDirectories,
69  allowedFileTypes: _allowedFileTypes
70  }),
71  result = resultObject.button;
72 
73  _URL = result ? [CPURL URLWithString:resultObject.URL] : nil;
74  }
75  else
76  {
77  // FIXME: This is not the best way to do this.
78  var documentName = window.prompt("Document Name:"),
79  result = documentName !== null;
80 
81  _URL = result ? [[self class] proposedFileURLWithDocumentName:documentName] : nil;
82  }
83 
84  return result;
85 }
86 
87 - (CPURL)URL
88 {
89  return _URL;
90 }
91 
92 @end
93 
95 
99 - (BOOL)isExtensionHidden
100 {
101  return _isExtensionHidden;
102 }
103 
107 - (void)setExtensionHidden:(BOOL)aValue
108 {
109  _isExtensionHidden = aValue;
110 }
111 
115 - (BOOL)canSelectHiddenExtension
116 {
117  return _canSelectHiddenExtension;
118 }
119 
123 - (void)setCanSelectHiddenExtension:(BOOL)aValue
124 {
125  _canSelectHiddenExtension = aValue;
126 }
127 
131 - (BOOL)allowsOtherFileTypes
132 {
133  return _allowsOtherFileTypes;
134 }
135 
139 - (void)setAllowsOtherFileTypes:(BOOL)aValue
140 {
141  _allowsOtherFileTypes = aValue;
142 }
143 
147 - (BOOL)canCreateDirectories
148 {
149  return _canCreateDirectories;
150 }
151 
155 - (void)setCanCreateDirectories:(BOOL)aValue
156 {
157  _canCreateDirectories = aValue;
158 }
159 
163 - (CPArray)allowedFileTypes
164 {
165  return _allowedFileTypes;
166 }
167 
171 - (void)setAllowedFileTypes:(CPArray)aValue
172 {
173  _allowedFileTypes = aValue;
174 }
175 
176 @end
id init()
Definition: CALayer.j:126
The main run loop for the application.
Definition: CPRunLoop.h:2
CPRunLoop currentRunLoop()
Definition: CPRunLoop.j:232
An immutable string (collection of characters).
Definition: CPString.h:2
CPDate limitDateForMode:(CPString aMode)
Definition: CPRunLoop.j:342
Class class()
Definition: CPObject.j:179
Definition: CPPanel.h:2
id URLWithString:(CPString URLString)
Definition: CPURL.j:78
Definition: CPURL.h:2
id alloc()
Definition: CPObject.j:130