cappuccino/cappuccino — pull request #1555 by ggsato (2012-05-29 03:54:28+00:00)
Title: fix for opening document

A couple of fixes to make **opening document** work for Document-based application.

I am not sure how it has worked. So let me know if there is a Cappuccino way.

#### 1 - if opening untitled or the specified existing ones

URLs to open are given by the following dynamic functions.

```Javascript
URLStrings = window.cpOpeningURLStrings && window.cpOpeningURLStrings()
```

And they had been evaluated such as:

```Objective-J
var needsUntitled = !!_documentController;
needsUntitled = ![self _openURL:[CPURL URLWithString:URLStrings[index]]] || needsUntitled;
```

Every Document-based app has a valid *_documentController* instance, so which makes *needsUntitled* true. Thus, whatever opening URLs are given, *needsUntitled* stays true.

It was fixed as:

```Objective-J
needsUntitled = ![self _openURL:[CPURL URLWithString:URLStrings[index]]] && needsUntitled;
```

#### 2 - message flow through 5 and 7
*Please refer to [Document Opening Message Flow in Document-Based App Programming Guide](http://developer.apple.com/library/mac/#documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/AdvancedTopics/AdvancedTopics.html%23//apple_ref/doc/uid/TP40011179-CH7-SW15).*

5: addDocument
6: makeWindowControllers
7: showWindows

CPDocumentController was fixed so 5, 6, and 7 are properly called against the opening document in *openDocumentWithContentsOfURL*.

#### TestApp

It has two Document types. CappDoc(.cappdoc) and CappDoc2(.cappdoc2). The default type is CappDoc. The test app opens CappDoc2. So if it succeeds, a window from Document2.cib appears that says "This is Document2" as well as the window title "bar.cappdoc2".

By selecting "New" from File menu, you can open a CappDoc window.