• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

TextMate is a graphical text editor for OS X 10.7+


Commit MetaInfo

Revision4e9d9414f15650d88cdb75886b09604aaca583de (tree)
Zeit2012-08-22 06:45:45
AutorAllan Odgaard <git@abet...>
CommiterAllan Odgaard

Log Message

Add encoding options to save dialogs

A minor caveat is that if there are encoding or newline (folder specific) settings in effect for the chosen path, these trump what’s selected in the save dialog.

If we wish to solve this, the best would be to update the options (shown in the save panel) based on selected folder/filename (and the settings in effect for that).

This closes issue #163.

Ändern Zusammenfassung

Diff

--- a/Frameworks/DocumentWindow/src/DocumentController.mm
+++ b/Frameworks/DocumentWindow/src/DocumentController.mm
@@ -837,7 +837,7 @@ NSString* const kUserDefaultsFileBrowserPlacementKey = @"fileBrowserPlacement";
837837 // = Document Action Methods =
838838 // ===========================
839839
840-- (void)savePanelDidEnd:(OakSavePanel*)sheet path:(NSString*)aPath contextInfo:(void*)info
840+- (void)savePanelDidEnd:(OakSavePanel*)sheet path:(NSString*)aPath encoding:(std::string const&)encoding newlines:(std::string const&)newlines useBOM:(BOOL)useBOM
841841 {
842842 if(!aPath)
843843 return;
@@ -849,6 +849,10 @@ NSString* const kUserDefaultsFileBrowserPlacementKey = @"fileBrowserPlacement";
849849 ASSERT_LT(0, paths.size());
850850
851851 [self selectedDocument]->set_path(paths[0]); // FIXME check if document already exists (overwrite)
852+ [self selectedDocument]->set_disk_encoding(encoding);
853+ [self selectedDocument]->set_disk_newlines(newlines);
854+ [self selectedDocument]->set_disk_bom(useBOM);
855+
852856 [DocumentSaveHelper trySaveDocument:self.selectedDocument forWindow:self.window defaultDirectory:nil andCallback:NULL];
853857
854858 if(paths.size() > 1)
@@ -858,6 +862,9 @@ NSString* const kUserDefaultsFileBrowserPlacementKey = @"fileBrowserPlacement";
858862 {
859863 documents.push_back(document::create(paths[i]));
860864 documents.back()->open(); // so that we find this when going to counterpart
865+ documents.back()->set_disk_encoding(encoding);
866+ documents.back()->set_disk_newlines(newlines);
867+ documents.back()->set_disk_bom(useBOM);
861868 }
862869
863870 [self addDocuments:documents andSelect:kSelectDocumentNone closeOther:NO pruneTabBar:NO];
@@ -870,18 +877,20 @@ NSString* const kUserDefaultsFileBrowserPlacementKey = @"fileBrowserPlacement";
870877 - (IBAction)saveDocument:(id)sender
871878 {
872879 D(DBF_DocumentController, bug("%s\n", [self selectedDocument]->path().c_str()););
873- if([self selectedDocument]->path() != NULL_STR)
874- [DocumentSaveHelper trySaveDocument:self.selectedDocument forWindow:self.window defaultDirectory:nil andCallback:NULL];
875- else [OakSavePanel showWithPath:DefaultSaveNameForDocument([self selectedDocument]) directory:self.untitledSavePath fowWindow:self.window delegate:self contextInfo:NULL];
880+ document::document_ptr doc = [self selectedDocument];
881+ if(doc->path() != NULL_STR)
882+ [DocumentSaveHelper trySaveDocument:doc forWindow:self.window defaultDirectory:nil andCallback:NULL];
883+ else [OakSavePanel showWithPath:DefaultSaveNameForDocument(doc) directory:self.untitledSavePath fowWindow:self.window delegate:self encoding:doc->disk_encoding() newlines:doc->disk_newlines() useBOM:doc->disk_bom()];
876884 }
877885
878886 - (IBAction)saveDocumentAs:(id)sender
879887 {
880888 D(DBF_DocumentController, bug("%s\n", [self selectedDocument]->path().c_str()););
881- std::string const documentPath = [self selectedDocument]->path();
889+ document::document_ptr doc = [self selectedDocument];
890+ std::string const documentPath = doc->path();
882891 NSString* documentFolder = [NSString stringWithCxxString:path::parent(documentPath)];
883892 NSString* documentName = [NSString stringWithCxxString:path::name(documentPath)];
884- [OakSavePanel showWithPath:(documentName ?: DefaultSaveNameForDocument([self selectedDocument])) directory:(documentFolder ?: self.untitledSavePath) fowWindow:self.window delegate:self contextInfo:NULL];
893+ [OakSavePanel showWithPath:(documentName ?: DefaultSaveNameForDocument(doc)) directory:(documentFolder ?: self.untitledSavePath) fowWindow:self.window delegate:self encoding:doc->disk_encoding() newlines:doc->disk_newlines() useBOM:doc->disk_bom()];
885894 }
886895
887896 - (IBAction)saveAllDocuments:(id)sender
--- a/Frameworks/DocumentWindow/src/DocumentSaveHelper.mm
+++ b/Frameworks/DocumentWindow/src/DocumentSaveHelper.mm
@@ -44,7 +44,7 @@ namespace
4444 D(DBF_DocumentController_SaveHelper, bug("\n"););
4545 init(context);
4646
47- [OakSavePanel showWithPath:DefaultSaveNameForDocument(_document) directory:_self.saveFolder fowWindow:_window delegate:_self contextInfo:NULL];
47+ [OakSavePanel showWithPath:DefaultSaveNameForDocument(_document) directory:_self.saveFolder fowWindow:_window delegate:_self encoding:_document->disk_encoding() newlines:_document->disk_newlines() useBOM:_document->disk_bom()];
4848 }
4949
5050 void select_make_writable (std::string const& path, io::bytes_ptr content, file::save_context_ptr context)
@@ -197,12 +197,15 @@ namespace
197197 // = Sheet Callbacks =
198198 // ===================
199199
200-- (void)savePanelDidEnd:(OakSavePanel*)sheet path:(NSString*)aPath contextInfo:(void*)info
200+- (void)savePanelDidEnd:(OakSavePanel*)sheet path:(NSString*)aPath encoding:(std::string const&)encoding newlines:(std::string const&)newlines useBOM:(BOOL)useBOM
201201 {
202202 D(DBF_DocumentController_SaveHelper, bug("%s\n", to_s(aPath).c_str()););
203203 if(aPath)
204204 {
205205 documents.back()->set_path(to_s(aPath));
206+ documents.back()->set_disk_encoding(encoding);
207+ documents.back()->set_disk_newlines(newlines);
208+ documents.back()->set_disk_bom(useBOM);
206209 context->set_path(to_s(aPath));
207210 }
208211 else
--- /dev/null
+++ b/Frameworks/OakAppKit/resources/English.lproj/EncodingSaveOptions.xib
@@ -0,0 +1,583 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
3+ <data>
4+ <int key="IBDocument.SystemTarget">1070</int>
5+ <string key="IBDocument.SystemVersion">12A269</string>
6+ <string key="IBDocument.InterfaceBuilderVersion">2549</string>
7+ <string key="IBDocument.AppKitVersion">1187</string>
8+ <string key="IBDocument.HIToolboxVersion">624.00</string>
9+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
10+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
11+ <string key="NS.object.0">2549</string>
12+ </object>
13+ <array key="IBDocument.IntegratedClassDependencies">
14+ <string>NSButton</string>
15+ <string>NSButtonCell</string>
16+ <string>NSCustomObject</string>
17+ <string>NSCustomView</string>
18+ <string>NSMenu</string>
19+ <string>NSMenuItem</string>
20+ <string>NSPopUpButton</string>
21+ <string>NSPopUpButtonCell</string>
22+ <string>NSTextField</string>
23+ <string>NSTextFieldCell</string>
24+ <string>NSUserDefaultsController</string>
25+ </array>
26+ <array key="IBDocument.PluginDependencies">
27+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28+ </array>
29+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
30+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
31+ <integer value="1" key="NS.object.0"/>
32+ </object>
33+ <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
34+ <object class="NSCustomObject" id="1001">
35+ <string key="NSClassName">OakEncodingSaveOptionsViewController</string>
36+ </object>
37+ <object class="NSCustomObject" id="1003">
38+ <string key="NSClassName">FirstResponder</string>
39+ </object>
40+ <object class="NSCustomObject" id="1004">
41+ <string key="NSClassName">NSApplication</string>
42+ </object>
43+ <object class="NSCustomView" id="1005">
44+ <reference key="NSNextResponder"/>
45+ <int key="NSvFlags">301</int>
46+ <array class="NSMutableArray" key="NSSubviews">
47+ <object class="NSTextField" id="594003581">
48+ <reference key="NSNextResponder" ref="1005"/>
49+ <int key="NSvFlags">268</int>
50+ <string key="NSFrame">{{17, 77}, {89, 17}}</string>
51+ <reference key="NSSuperview" ref="1005"/>
52+ <reference key="NSWindow"/>
53+ <reference key="NSNextKeyView" ref="346951456"/>
54+ <string key="NSReuseIdentifierKey">_NS:1535</string>
55+ <bool key="NSEnabled">YES</bool>
56+ <object class="NSTextFieldCell" key="NSCell" id="738497566">
57+ <int key="NSCellFlags">68157504</int>
58+ <int key="NSCellFlags2">272630784</int>
59+ <string key="NSContents">Line endings:</string>
60+ <object class="NSFont" key="NSSupport" id="687793405">
61+ <string key="NSName">LucidaGrande</string>
62+ <double key="NSSize">13</double>
63+ <int key="NSfFlags">1044</int>
64+ </object>
65+ <string key="NSCellIdentifier">_NS:1535</string>
66+ <reference key="NSControlView" ref="594003581"/>
67+ <object class="NSColor" key="NSBackgroundColor" id="152636918">
68+ <int key="NSColorSpace">6</int>
69+ <string key="NSCatalogName">System</string>
70+ <string key="NSColorName">controlColor</string>
71+ <object class="NSColor" key="NSColor">
72+ <int key="NSColorSpace">3</int>
73+ <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
74+ </object>
75+ </object>
76+ <object class="NSColor" key="NSTextColor" id="1070395174">
77+ <int key="NSColorSpace">6</int>
78+ <string key="NSCatalogName">System</string>
79+ <string key="NSColorName">controlTextColor</string>
80+ <object class="NSColor" key="NSColor">
81+ <int key="NSColorSpace">3</int>
82+ <bytes key="NSWhite">MAA</bytes>
83+ </object>
84+ </object>
85+ </object>
86+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
87+ </object>
88+ <object class="NSTextField" id="698805249">
89+ <reference key="NSNextResponder" ref="1005"/>
90+ <int key="NSvFlags">268</int>
91+ <string key="NSFrame">{{40, 46}, {66, 17}}</string>
92+ <reference key="NSSuperview" ref="1005"/>
93+ <reference key="NSWindow"/>
94+ <reference key="NSNextKeyView" ref="840486169"/>
95+ <string key="NSReuseIdentifierKey">_NS:1535</string>
96+ <bool key="NSEnabled">YES</bool>
97+ <object class="NSTextFieldCell" key="NSCell" id="889911502">
98+ <int key="NSCellFlags">68157504</int>
99+ <int key="NSCellFlags2">272630784</int>
100+ <string key="NSContents">Encoding:</string>
101+ <reference key="NSSupport" ref="687793405"/>
102+ <string key="NSCellIdentifier">_NS:1535</string>
103+ <reference key="NSControlView" ref="698805249"/>
104+ <reference key="NSBackgroundColor" ref="152636918"/>
105+ <reference key="NSTextColor" ref="1070395174"/>
106+ </object>
107+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
108+ </object>
109+ <object class="NSButton" id="380935517">
110+ <reference key="NSNextResponder" ref="1005"/>
111+ <int key="NSvFlags">268</int>
112+ <string key="NSFrame">{{109, 18}, {153, 18}}</string>
113+ <reference key="NSSuperview" ref="1005"/>
114+ <reference key="NSWindow"/>
115+ <reference key="NSNextKeyView"/>
116+ <string key="NSReuseIdentifierKey">_NS:9</string>
117+ <bool key="NSEnabled">YES</bool>
118+ <object class="NSButtonCell" key="NSCell" id="624531239">
119+ <int key="NSCellFlags">-2080374784</int>
120+ <int key="NSCellFlags2">268435456</int>
121+ <string key="NSContents">Add byte order mark</string>
122+ <reference key="NSSupport" ref="687793405"/>
123+ <string key="NSCellIdentifier">_NS:9</string>
124+ <reference key="NSControlView" ref="380935517"/>
125+ <int key="NSButtonFlags">1211912448</int>
126+ <int key="NSButtonFlags2">2</int>
127+ <object class="NSCustomResource" key="NSNormalImage">
128+ <string key="NSClassName">NSImage</string>
129+ <string key="NSResourceName">NSSwitch</string>
130+ </object>
131+ <object class="NSButtonImageSource" key="NSAlternateImage">
132+ <string key="NSImageName">NSSwitch</string>
133+ </object>
134+ <string key="NSAlternateContents"/>
135+ <string key="NSKeyEquivalent"/>
136+ <int key="NSPeriodicDelay">200</int>
137+ <int key="NSPeriodicInterval">25</int>
138+ </object>
139+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
140+ </object>
141+ <object class="NSPopUpButton" id="346951456">
142+ <reference key="NSNextResponder" ref="1005"/>
143+ <int key="NSvFlags">268</int>
144+ <string key="NSFrame">{{108, 72}, {174, 26}}</string>
145+ <reference key="NSSuperview" ref="1005"/>
146+ <reference key="NSWindow"/>
147+ <reference key="NSNextKeyView" ref="698805249"/>
148+ <string key="NSReuseIdentifierKey">_NS:9</string>
149+ <bool key="NSEnabled">YES</bool>
150+ <object class="NSPopUpButtonCell" key="NSCell" id="25918949">
151+ <int key="NSCellFlags">-2076180416</int>
152+ <int key="NSCellFlags2">2048</int>
153+ <reference key="NSSupport" ref="687793405"/>
154+ <string key="NSCellIdentifier">_NS:9</string>
155+ <reference key="NSControlView" ref="346951456"/>
156+ <int key="NSButtonFlags">109199360</int>
157+ <int key="NSButtonFlags2">129</int>
158+ <string key="NSAlternateContents"/>
159+ <string key="NSKeyEquivalent"/>
160+ <int key="NSPeriodicDelay">400</int>
161+ <int key="NSPeriodicInterval">75</int>
162+ <object class="NSMenuItem" key="NSMenuItem" id="512764947">
163+ <reference key="NSMenu" ref="297271712"/>
164+ <string key="NSTitle">LF (recommended)</string>
165+ <string key="NSKeyEquiv"/>
166+ <int key="NSKeyEquivModMask">1048576</int>
167+ <int key="NSMnemonicLoc">2147483647</int>
168+ <int key="NSState">1</int>
169+ <object class="NSCustomResource" key="NSOnImage" id="702917240">
170+ <string key="NSClassName">NSImage</string>
171+ <string key="NSResourceName">NSMenuCheckmark</string>
172+ </object>
173+ <object class="NSCustomResource" key="NSMixedImage" id="780782335">
174+ <string key="NSClassName">NSImage</string>
175+ <string key="NSResourceName">NSMenuMixedState</string>
176+ </object>
177+ <string key="NSAction">_popUpItemAction:</string>
178+ <reference key="NSTarget" ref="25918949"/>
179+ </object>
180+ <bool key="NSMenuItemRespectAlignment">YES</bool>
181+ <object class="NSMenu" key="NSMenu" id="297271712">
182+ <string key="NSTitle">OtherViews</string>
183+ <array class="NSMutableArray" key="NSMenuItems">
184+ <reference ref="512764947"/>
185+ <object class="NSMenuItem" id="675579889">
186+ <reference key="NSMenu" ref="297271712"/>
187+ <string key="NSTitle">CR (Classic Mac)</string>
188+ <string key="NSKeyEquiv"/>
189+ <int key="NSKeyEquivModMask">1048576</int>
190+ <int key="NSMnemonicLoc">2147483647</int>
191+ <reference key="NSOnImage" ref="702917240"/>
192+ <reference key="NSMixedImage" ref="780782335"/>
193+ <string key="NSAction">_popUpItemAction:</string>
194+ <int key="NSTag">1</int>
195+ <reference key="NSTarget" ref="25918949"/>
196+ </object>
197+ <object class="NSMenuItem" id="153269775">
198+ <reference key="NSMenu" ref="297271712"/>
199+ <string key="NSTitle">CRLF (MS-DOS)</string>
200+ <string key="NSKeyEquiv"/>
201+ <int key="NSKeyEquivModMask">1048576</int>
202+ <int key="NSMnemonicLoc">2147483647</int>
203+ <reference key="NSOnImage" ref="702917240"/>
204+ <reference key="NSMixedImage" ref="780782335"/>
205+ <string key="NSAction">_popUpItemAction:</string>
206+ <int key="NSTag">2</int>
207+ <reference key="NSTarget" ref="25918949"/>
208+ </object>
209+ </array>
210+ <reference key="NSMenuFont" ref="687793405"/>
211+ </object>
212+ <int key="NSPreferredEdge">1</int>
213+ <bool key="NSUsesItemFromMenu">YES</bool>
214+ <bool key="NSAltersState">YES</bool>
215+ <int key="NSArrowPosition">2</int>
216+ </object>
217+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
218+ </object>
219+ <object class="NSPopUpButton" id="840486169">
220+ <reference key="NSNextResponder" ref="1005"/>
221+ <int key="NSvFlags">268</int>
222+ <string key="NSFrame">{{108, 41}, {174, 26}}</string>
223+ <reference key="NSSuperview" ref="1005"/>
224+ <reference key="NSWindow"/>
225+ <reference key="NSNextKeyView" ref="380935517"/>
226+ <string key="NSReuseIdentifierKey">_NS:9</string>
227+ <bool key="NSEnabled">YES</bool>
228+ <object class="NSPopUpButtonCell" key="NSCell" id="664080352">
229+ <int key="NSCellFlags">-2076180416</int>
230+ <int key="NSCellFlags2">2048</int>
231+ <reference key="NSSupport" ref="687793405"/>
232+ <string key="NSCellIdentifier">_NS:9</string>
233+ <reference key="NSControlView" ref="840486169"/>
234+ <int key="NSButtonFlags">109199360</int>
235+ <int key="NSButtonFlags2">129</int>
236+ <string key="NSAlternateContents"/>
237+ <string key="NSKeyEquivalent"/>
238+ <int key="NSPeriodicDelay">400</int>
239+ <int key="NSPeriodicInterval">75</int>
240+ <object class="NSMenuItem" key="NSMenuItem" id="797115691">
241+ <reference key="NSMenu" ref="476751877"/>
242+ <string key="NSTitle">encoding</string>
243+ <string key="NSKeyEquiv"/>
244+ <int key="NSKeyEquivModMask">1048576</int>
245+ <int key="NSMnemonicLoc">2147483647</int>
246+ <int key="NSState">1</int>
247+ <reference key="NSOnImage" ref="702917240"/>
248+ <reference key="NSMixedImage" ref="780782335"/>
249+ <string key="NSAction">_popUpItemAction:</string>
250+ <reference key="NSTarget" ref="664080352"/>
251+ </object>
252+ <bool key="NSMenuItemRespectAlignment">YES</bool>
253+ <object class="NSMenu" key="NSMenu" id="476751877">
254+ <string key="NSTitle">OtherViews</string>
255+ <array class="NSMutableArray" key="NSMenuItems">
256+ <reference ref="797115691"/>
257+ </array>
258+ <reference key="NSMenuFont" ref="687793405"/>
259+ </object>
260+ <int key="NSPreferredEdge">1</int>
261+ <bool key="NSUsesItemFromMenu">YES</bool>
262+ <bool key="NSAltersState">YES</bool>
263+ <int key="NSArrowPosition">2</int>
264+ </object>
265+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
266+ </object>
267+ </array>
268+ <string key="NSFrameSize">{299, 116}</string>
269+ <reference key="NSSuperview"/>
270+ <reference key="NSWindow"/>
271+ <reference key="NSNextKeyView" ref="594003581"/>
272+ <string key="NSClassName">NSView</string>
273+ </object>
274+ <object class="NSUserDefaultsController" id="591468021">
275+ <bool key="NSSharedInstance">YES</bool>
276+ </object>
277+ </array>
278+ <object class="IBObjectContainer" key="IBDocument.Objects">
279+ <array class="NSMutableArray" key="connectionRecords">
280+ <object class="IBConnectionRecord">
281+ <object class="IBOutletConnection" key="connection">
282+ <string key="label">view</string>
283+ <reference key="source" ref="1001"/>
284+ <reference key="destination" ref="1005"/>
285+ </object>
286+ <int key="connectionID">228</int>
287+ </object>
288+ <object class="IBConnectionRecord">
289+ <object class="IBOutletConnection" key="connection">
290+ <string key="label">encodingPopUpButton</string>
291+ <reference key="source" ref="1001"/>
292+ <reference key="destination" ref="840486169"/>
293+ </object>
294+ <int key="connectionID">238</int>
295+ </object>
296+ <object class="IBConnectionRecord">
297+ <object class="IBBindingConnection" key="connection">
298+ <string key="label">selectedTag: lineEndings</string>
299+ <reference key="source" ref="346951456"/>
300+ <reference key="destination" ref="1001"/>
301+ <object class="NSNibBindingConnector" key="connector">
302+ <reference key="NSSource" ref="346951456"/>
303+ <reference key="NSDestination" ref="1001"/>
304+ <string key="NSLabel">selectedTag: lineEndings</string>
305+ <string key="NSBinding">selectedTag</string>
306+ <string key="NSKeyPath">lineEndings</string>
307+ <object class="NSDictionary" key="NSOptions">
308+ <string key="NS.key.0">NSValueTransformerName</string>
309+ <string key="NS.object.0">OakLineEndingsTransformer</string>
310+ </object>
311+ <int key="NSNibBindingConnectorVersion">2</int>
312+ </object>
313+ </object>
314+ <int key="connectionID">247</int>
315+ </object>
316+ <object class="IBConnectionRecord">
317+ <object class="IBBindingConnection" key="connection">
318+ <string key="label">value: useByteOrderMark</string>
319+ <reference key="source" ref="380935517"/>
320+ <reference key="destination" ref="1001"/>
321+ <object class="NSNibBindingConnector" key="connector">
322+ <reference key="NSSource" ref="380935517"/>
323+ <reference key="NSDestination" ref="1001"/>
324+ <string key="NSLabel">value: useByteOrderMark</string>
325+ <string key="NSBinding">value</string>
326+ <string key="NSKeyPath">useByteOrderMark</string>
327+ <int key="NSNibBindingConnectorVersion">2</int>
328+ </object>
329+ </object>
330+ <int key="connectionID">240</int>
331+ </object>
332+ <object class="IBConnectionRecord">
333+ <object class="IBBindingConnection" key="connection">
334+ <string key="label">enabled: canUseByteOrderMark</string>
335+ <reference key="source" ref="380935517"/>
336+ <reference key="destination" ref="1001"/>
337+ <object class="NSNibBindingConnector" key="connector">
338+ <reference key="NSSource" ref="380935517"/>
339+ <reference key="NSDestination" ref="1001"/>
340+ <string key="NSLabel">enabled: canUseByteOrderMark</string>
341+ <string key="NSBinding">enabled</string>
342+ <string key="NSKeyPath">canUseByteOrderMark</string>
343+ <int key="NSNibBindingConnectorVersion">2</int>
344+ </object>
345+ </object>
346+ <int key="connectionID">242</int>
347+ </object>
348+ </array>
349+ <object class="IBMutableOrderedSet" key="objectRecords">
350+ <array key="orderedObjects">
351+ <object class="IBObjectRecord">
352+ <int key="objectID">0</int>
353+ <array key="object" id="0"/>
354+ <reference key="children" ref="1000"/>
355+ <nil key="parent"/>
356+ </object>
357+ <object class="IBObjectRecord">
358+ <int key="objectID">-2</int>
359+ <reference key="object" ref="1001"/>
360+ <reference key="parent" ref="0"/>
361+ <string key="objectName">File's Owner</string>
362+ </object>
363+ <object class="IBObjectRecord">
364+ <int key="objectID">-1</int>
365+ <reference key="object" ref="1003"/>
366+ <reference key="parent" ref="0"/>
367+ <string key="objectName">First Responder</string>
368+ </object>
369+ <object class="IBObjectRecord">
370+ <int key="objectID">-3</int>
371+ <reference key="object" ref="1004"/>
372+ <reference key="parent" ref="0"/>
373+ <string key="objectName">Application</string>
374+ </object>
375+ <object class="IBObjectRecord">
376+ <int key="objectID">1</int>
377+ <reference key="object" ref="1005"/>
378+ <array class="NSMutableArray" key="children">
379+ <reference ref="346951456"/>
380+ <reference ref="594003581"/>
381+ <reference ref="840486169"/>
382+ <reference ref="698805249"/>
383+ <reference ref="380935517"/>
384+ </array>
385+ <reference key="parent" ref="0"/>
386+ </object>
387+ <object class="IBObjectRecord">
388+ <int key="objectID">33</int>
389+ <reference key="object" ref="594003581"/>
390+ <array class="NSMutableArray" key="children">
391+ <reference ref="738497566"/>
392+ </array>
393+ <reference key="parent" ref="1005"/>
394+ </object>
395+ <object class="IBObjectRecord">
396+ <int key="objectID">34</int>
397+ <reference key="object" ref="738497566"/>
398+ <reference key="parent" ref="594003581"/>
399+ </object>
400+ <object class="IBObjectRecord">
401+ <int key="objectID">2</int>
402+ <reference key="object" ref="840486169"/>
403+ <array class="NSMutableArray" key="children">
404+ <reference ref="664080352"/>
405+ </array>
406+ <reference key="parent" ref="1005"/>
407+ </object>
408+ <object class="IBObjectRecord">
409+ <int key="objectID">3</int>
410+ <reference key="object" ref="664080352"/>
411+ <array class="NSMutableArray" key="children">
412+ <reference ref="476751877"/>
413+ </array>
414+ <reference key="parent" ref="840486169"/>
415+ </object>
416+ <object class="IBObjectRecord">
417+ <int key="objectID">4</int>
418+ <reference key="object" ref="476751877"/>
419+ <array class="NSMutableArray" key="children">
420+ <reference ref="797115691"/>
421+ </array>
422+ <reference key="parent" ref="664080352"/>
423+ </object>
424+ <object class="IBObjectRecord">
425+ <int key="objectID">5</int>
426+ <reference key="object" ref="797115691"/>
427+ <reference key="parent" ref="476751877"/>
428+ </object>
429+ <object class="IBObjectRecord">
430+ <int key="objectID">11</int>
431+ <reference key="object" ref="346951456"/>
432+ <array class="NSMutableArray" key="children">
433+ <reference ref="25918949"/>
434+ </array>
435+ <reference key="parent" ref="1005"/>
436+ </object>
437+ <object class="IBObjectRecord">
438+ <int key="objectID">13</int>
439+ <reference key="object" ref="25918949"/>
440+ <array class="NSMutableArray" key="children">
441+ <reference ref="297271712"/>
442+ </array>
443+ <reference key="parent" ref="346951456"/>
444+ </object>
445+ <object class="IBObjectRecord">
446+ <int key="objectID">14</int>
447+ <reference key="object" ref="297271712"/>
448+ <array class="NSMutableArray" key="children">
449+ <reference ref="153269775"/>
450+ <reference ref="675579889"/>
451+ <reference ref="512764947"/>
452+ </array>
453+ <reference key="parent" ref="25918949"/>
454+ </object>
455+ <object class="IBObjectRecord">
456+ <int key="objectID">17</int>
457+ <reference key="object" ref="512764947"/>
458+ <reference key="parent" ref="297271712"/>
459+ </object>
460+ <object class="IBObjectRecord">
461+ <int key="objectID">16</int>
462+ <reference key="object" ref="675579889"/>
463+ <reference key="parent" ref="297271712"/>
464+ </object>
465+ <object class="IBObjectRecord">
466+ <int key="objectID">15</int>
467+ <reference key="object" ref="153269775"/>
468+ <reference key="parent" ref="297271712"/>
469+ </object>
470+ <object class="IBObjectRecord">
471+ <int key="objectID">25</int>
472+ <reference key="object" ref="380935517"/>
473+ <array class="NSMutableArray" key="children">
474+ <reference ref="624531239"/>
475+ </array>
476+ <reference key="parent" ref="1005"/>
477+ </object>
478+ <object class="IBObjectRecord">
479+ <int key="objectID">26</int>
480+ <reference key="object" ref="624531239"/>
481+ <reference key="parent" ref="380935517"/>
482+ </object>
483+ <object class="IBObjectRecord">
484+ <int key="objectID">29</int>
485+ <reference key="object" ref="698805249"/>
486+ <array class="NSMutableArray" key="children">
487+ <reference ref="889911502"/>
488+ </array>
489+ <reference key="parent" ref="1005"/>
490+ </object>
491+ <object class="IBObjectRecord">
492+ <int key="objectID">30</int>
493+ <reference key="object" ref="889911502"/>
494+ <reference key="parent" ref="698805249"/>
495+ </object>
496+ <object class="IBObjectRecord">
497+ <int key="objectID">243</int>
498+ <reference key="object" ref="591468021"/>
499+ <reference key="parent" ref="0"/>
500+ </object>
501+ </array>
502+ </object>
503+ <dictionary class="NSMutableDictionary" key="flattenedProperties">
504+ <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
505+ <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
506+ <string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
507+ <string key="1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
508+ <string key="11.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
509+ <string key="11.userInterfaceItemIdentifier">Line Endings Pop Up Button</string>
510+ <string key="13.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
511+ <string key="14.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
512+ <string key="15.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
513+ <string key="16.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
514+ <string key="17.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
515+ <string key="2.CustomClassName">OakEncodingPopUpButton</string>
516+ <string key="2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
517+ <string key="243.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
518+ <string key="25.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
519+ <string key="26.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
520+ <string key="29.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
521+ <string key="3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
522+ <string key="30.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
523+ <string key="33.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
524+ <string key="34.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
525+ <string key="4.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
526+ <string key="5.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
527+ </dictionary>
528+ <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
529+ <nil key="activeLocalization"/>
530+ <dictionary class="NSMutableDictionary" key="localizations"/>
531+ <nil key="sourceID"/>
532+ <int key="maxID">247</int>
533+ </object>
534+ <object class="IBClassDescriber" key="IBDocument.Classes">
535+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
536+ <object class="IBPartialClassDescription">
537+ <string key="className">OakEncodingPopUpButton</string>
538+ <string key="superclassName">NSPopUpButton</string>
539+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
540+ <string key="majorKey">IBProjectSource</string>
541+ <string key="minorKey">./Classes/OakEncodingPopUpButton.h</string>
542+ </object>
543+ </object>
544+ <object class="IBPartialClassDescription">
545+ <string key="className">OakEncodingSaveOptionsViewController</string>
546+ <string key="superclassName">NSViewController</string>
547+ <object class="NSMutableDictionary" key="outlets">
548+ <string key="NS.key.0">encodingPopUpButton</string>
549+ <string key="NS.object.0">OakEncodingPopUpButton</string>
550+ </object>
551+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
552+ <string key="NS.key.0">encodingPopUpButton</string>
553+ <object class="IBToOneOutletInfo" key="NS.object.0">
554+ <string key="name">encodingPopUpButton</string>
555+ <string key="candidateClassName">OakEncodingPopUpButton</string>
556+ </object>
557+ </object>
558+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
559+ <string key="majorKey">IBProjectSource</string>
560+ <string key="minorKey">./Classes/OakEncodingSaveOptionsViewController.h</string>
561+ </object>
562+ </object>
563+ </array>
564+ </object>
565+ <int key="IBDocument.localizationMode">0</int>
566+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
567+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
568+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
569+ <real value="1070" key="NS.object.0"/>
570+ </object>
571+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
572+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
573+ <real value="4400" key="NS.object.0"/>
574+ </object>
575+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
576+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
577+ <dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
578+ <string key="NSMenuCheckmark">{11, 11}</string>
579+ <string key="NSMenuMixedState">{10, 3}</string>
580+ <string key="NSSwitch">{15, 15}</string>
581+ </dictionary>
582+ </data>
583+</archive>
--- a/Frameworks/OakAppKit/src/OakSavePanel.h
+++ b/Frameworks/OakAppKit/src/OakSavePanel.h
@@ -1,11 +1,12 @@
1+@class OakEncodingSaveOptionsViewController;
2+
13 @interface OakSavePanel : NSObject
24 {
3- id delegate;
4- void* contextInfo;
5+ OakEncodingSaveOptionsViewController* optionsViewController;
56 }
6-+ (void)showWithPath:(NSString*)aPathSuggestion directory:(NSString*)aDirectorySuggestion fowWindow:(NSWindow*)aWindow delegate:(id)aDelegate contextInfo:(void*)info;
7++ (void)showWithPath:(NSString*)aPathSuggestion directory:(NSString*)aDirectorySuggestion fowWindow:(NSWindow*)aWindow delegate:(id)aDelegate encoding:(std::string const&)encoding newlines:(std::string const&)newlines useBOM:(BOOL)useBOM;
78 @end
89
910 @interface NSObject (OakSavePanelDelegate)
10-- (void)savePanelDidEnd:(OakSavePanel*)sheet path:(NSString*)aPath contextInfo:(void*)info;
11+- (void)savePanelDidEnd:(OakSavePanel*)sheet path:(NSString*)aPath encoding:(std::string const&)encoding newlines:(std::string const&)newlines useBOM:(BOOL)useBOM;
1112 @end
--- a/Frameworks/OakAppKit/src/OakSavePanel.mm
+++ b/Frameworks/OakAppKit/src/OakSavePanel.mm
@@ -1,13 +1,90 @@
1-#import "NSSavePanel Additions.h"
21 #import "OakSavePanel.h"
2+#import "OakEncodingPopUpButton.h"
3+#import "NSSavePanel Additions.h"
4+#import <OakFoundation/OakStringListTransformer.h>
5+#import <oak/oak.h>
6+#import <ns/ns.h>
7+
8+@interface OakEncodingSaveOptionsViewController : NSViewController
9+{
10+ IBOutlet OakEncodingPopUpButton* encodingPopUpButton;
11+
12+ NSString* encoding;
13+ NSString* lineEndings;
14+ BOOL useByteOrderMark;
15+}
16+@property (nonatomic, retain) NSString* lineEndings;
17+@property (nonatomic, retain) NSString* encoding;
18+@property (nonatomic, assign) BOOL useByteOrderMark;
19+@property (nonatomic, readonly) BOOL canUseByteOrderMark;
20+@end
21+
22+@implementation OakEncodingSaveOptionsViewController
23+@synthesize encoding, lineEndings, useByteOrderMark;
24+
25++ (NSSet*)keyPathsForValuesAffectingCanUseByteOrderMark { return [NSSet setWithObject:@"encoding"]; }
26+
27++ (void)initialize
28+{
29+ [OakStringListTransformer createTransformerWithName:@"OakLineEndingsTransformer" andObjectsArray:@[ @"\n", @"\r", @"\r\n" ]];
30+ [OakStringListTransformer createTransformerWithName:@"OakLineEndingsListTransformer" andObjectsArray:@[ @"\n", @"\r", @"\r\n" ]];
31+}
32+
33+- (id)init
34+{
35+ if(self = [super initWithNibName:@"EncodingSaveOptions" bundle:[NSBundle bundleForClass:[self class]]])
36+ {
37+ self.encoding = @"UTF-8";
38+ self.lineEndings = @"\n";
39+ }
40+ return self;
41+}
42+
43+- (void)dealloc
44+{
45+ [self unbind:@"encoding"];
46+ [super dealloc];
47+}
48+
49+- (void)loadView
50+{
51+ [super loadView];
52+ encodingPopUpButton.encoding = encoding;
53+ [self bind:@"encoding" toObject:encodingPopUpButton withKeyPath:@"encoding" options:nil];
54+}
55+
56+- (BOOL)canUseByteOrderMark
57+{
58+ return [self.encoding hasPrefix:@"UTF-"];
59+}
60+
61+- (void)setEncoding:(NSString*)newEncoding
62+{
63+ if(encoding != newEncoding && ![encoding isEqualToString:newEncoding])
64+ {
65+ [encoding autorelease];
66+ encoding = [newEncoding retain];
67+
68+ self.useByteOrderMark = [self canUseByteOrderMark] && ![encoding isEqualToString:@"UTF-8"];
69+ }
70+}
71+@end
372
473 @implementation OakSavePanel
5-- (id)initWithPath:(NSString*)aPathSuggestion directory:(NSString*)aDirectorySuggestion fowWindow:(NSWindow*)aWindow delegate:(id)aDelegate contextInfo:(void*)info
74+- (id)initWithPath:(NSString*)aPathSuggestion directory:(NSString*)aDirectorySuggestion fowWindow:(NSWindow*)aWindow delegate:(id)aDelegate encoding:(std::string const&)encoding newlines:(std::string const&)newlines useBOM:(BOOL)useBOM
675 {
776 if((self = [super init]))
877 {
9- delegate = aDelegate;
10- contextInfo = info;
78+ optionsViewController = [OakEncodingSaveOptionsViewController new];
79+ if(!optionsViewController)
80+ {
81+ [self release];
82+ return nil;
83+ }
84+
85+ optionsViewController.encoding = [NSString stringWithCxxString:encoding] ?: @"UTF-8";
86+ optionsViewController.lineEndings = [NSString stringWithCxxString:newlines] ?: @"\n";
87+ optionsViewController.useByteOrderMark = useBOM;
1188
1289 [[aWindow attachedSheet] orderOut:self]; // incase there already is a sheet showing (like “Do you want to save?”)
1390
@@ -16,9 +93,10 @@
1693 if(aDirectorySuggestion)
1794 [savePanel setDirectoryURL:[NSURL fileURLWithPath:aDirectorySuggestion]];
1895 [savePanel setNameFieldStringValue:[aPathSuggestion lastPathComponent]];
96+ [savePanel setAccessoryView:optionsViewController.view];
1997 [savePanel beginSheetModalForWindow:aWindow completionHandler:^(NSInteger result) {
2098 NSString* path = result == NSOKButton ? [[savePanel.URL filePathURL] path] : nil;
21- [delegate savePanelDidEnd:self path:path contextInfo:contextInfo];
99+ [aDelegate savePanelDidEnd:self path:path encoding:to_s(optionsViewController.encoding) newlines:to_s(optionsViewController.lineEndings) useBOM:optionsViewController.useByteOrderMark];
22100 [self release];
23101 }];
24102 [savePanel deselectExtension];
@@ -26,9 +104,14 @@
26104 return self;
27105 }
28106
29-+ (void)showWithPath:(NSString*)aPathSuggestion directory:(NSString*)aDirectorySuggestion fowWindow:(NSWindow*)aWindow delegate:(id)aDelegate contextInfo:(void*)info
107+- (void)dealloc
30108 {
31- [[OakSavePanel alloc] initWithPath:aPathSuggestion directory:aDirectorySuggestion fowWindow:aWindow delegate:aDelegate contextInfo:info];
109+ [optionsViewController release];
110+ [super dealloc];
32111 }
33112
113++ (void)showWithPath:(NSString*)aPathSuggestion directory:(NSString*)aDirectorySuggestion fowWindow:(NSWindow*)aWindow delegate:(id)aDelegate encoding:(std::string const&)encoding newlines:(std::string const&)newlines useBOM:(BOOL)useBOM
114+{
115+ [[OakSavePanel alloc] initWithPath:aPathSuggestion directory:aDirectorySuggestion fowWindow:aWindow delegate:aDelegate encoding:encoding newlines:newlines useBOM:useBOM];
116+}
34117 @end