|
3 | 3 | const MainViewFactory = brackets.getModule("view/MainViewFactory") |
4 | 4 | ``` |
5 | 5 |
|
6 | | -<a name="_"></a> |
| 6 | +<a name="module_view/MainViewFactory"></a> |
7 | 7 |
|
8 | | -## \_ |
9 | | -MainViewFactory is a singleton for managing view factories.Registering a view factory:```js registerViewFactory({ canOpenFile: function (fullPath) { return (fullPath.slice(-4) === ".ico"); }, openFile: function(file, pane) { return createIconView(file, pane); } });``` The openFile method is used to open the file and construct a view of it. Implementation should add the view to the pane```js function createIconView(file, pane) { // IconView will construct its DOM and append // it to pane.$el var view = new IconView(file, pane.$el); // Then tell the pane to add it to // its view map and show it pane.addView(view, true); return new $.Deferred().resolve().promise(); }``` Factories should only create 1 view of a file per pane. Brackets currently only supports 1 view of a file open at a given time but that may change to allow the same file open in more than 1 pane. Therefore Factories can do a simple check to see if a view already exists and show it before creating a new one:```js var view = pane.getViewForPath(file.fullPath); if (view) { pane.showView(view); } else { return createIconView(file, pane); }``` |
| 8 | +## view/MainViewFactory |
| 9 | +MainViewFactory is a singleton for managing view factories. |
10 | 10 |
|
11 | | -**Kind**: global variable |
12 | | -<a name="registerViewFactory"></a> |
| 11 | +Registering a view factory: |
| 12 | +```js |
| 13 | + registerViewFactory({ |
| 14 | + canOpenFile: function (fullPath) { |
| 15 | + return (fullPath.slice(-4) === ".ico"); |
| 16 | + }, |
| 17 | + openFile: function(file, pane) { |
| 18 | + return createIconView(file, pane); |
| 19 | + } |
| 20 | + }); |
| 21 | +``` |
| 22 | + The openFile method is used to open the file and construct |
| 23 | + a view of it. Implementation should add the view to the pane |
| 24 | +```js |
| 25 | + function createIconView(file, pane) { |
| 26 | + // IconView will construct its DOM and append |
| 27 | + // it to pane.$el |
| 28 | + var view = new IconView(file, pane.$el); |
| 29 | + // Then tell the pane to add it to |
| 30 | + // its view map and show it |
| 31 | + pane.addView(view, true); |
| 32 | + return new $.Deferred().resolve().promise(); |
| 33 | + } |
| 34 | +``` |
| 35 | + Factories should only create 1 view of a file per pane. Brackets currently only supports 1 view of |
| 36 | + a file open at a given time but that may change to allow the same file open in more than 1 pane. Therefore |
| 37 | + Factories can do a simple check to see if a view already exists and show it before creating a new one: |
| 38 | +```js |
| 39 | + var view = pane.getViewForPath(file.fullPath); |
| 40 | + if (view) { |
| 41 | + pane.showView(view); |
| 42 | + } else { |
| 43 | + return createIconView(file, pane); |
| 44 | + } |
| 45 | +``` |
| 46 | + |
| 47 | + |
| 48 | +* [view/MainViewFactory](#module_view/MainViewFactory) |
| 49 | + * [.registerViewFactory(factory)](#module_view/MainViewFactory..registerViewFactory) |
| 50 | + * [.findSuitableFactoryForPath(fullPath)](#module_view/MainViewFactory..findSuitableFactoryForPath) ⇒ <code>Factory</code> |
| 51 | + * [.Factory](#module_view/MainViewFactory..Factory) : <code>Object</code> |
| 52 | + |
| 53 | +<a name="module_view/MainViewFactory..registerViewFactory"></a> |
13 | 54 |
|
14 | | -## registerViewFactory(factory) |
| 55 | +### view/MainViewFactory.registerViewFactory(factory) |
15 | 56 | Registers a view factory |
16 | 57 |
|
17 | | -**Kind**: global function |
| 58 | +**Kind**: inner method of [<code>view/MainViewFactory</code>](#module_view/MainViewFactory) |
18 | 59 |
|
19 | 60 | | Param | Type | Description | |
20 | 61 | | --- | --- | --- | |
21 | | -| factory | [<code>Factory</code>](#Factory) | The view factory to register. | |
| 62 | +| factory | <code>Factory</code> | The view factory to register. | |
22 | 63 |
|
23 | | -<a name="findSuitableFactoryForPath"></a> |
| 64 | +<a name="module_view/MainViewFactory..findSuitableFactoryForPath"></a> |
24 | 65 |
|
25 | | -## findSuitableFactoryForPath(fullPath) ⇒ [<code>Factory</code>](#Factory) |
| 66 | +### view/MainViewFactory.findSuitableFactoryForPath(fullPath) ⇒ <code>Factory</code> |
26 | 67 | Finds a factory that can open the specified file |
27 | 68 |
|
28 | | -**Kind**: global function |
29 | | -**Returns**: [<code>Factory</code>](#Factory) - A factory that can create a view for the path or undefined if there isn't one. |
| 69 | +**Kind**: inner method of [<code>view/MainViewFactory</code>](#module_view/MainViewFactory) |
| 70 | +**Returns**: <code>Factory</code> - A factory that can create a view for the path or undefined if there isn't one. |
30 | 71 |
|
31 | 72 | | Param | Type | Description | |
32 | 73 | | --- | --- | --- | |
33 | 74 | | fullPath | <code>string</code> | The file to open. | |
34 | 75 |
|
35 | | -<a name="Factory"></a> |
| 76 | +<a name="module_view/MainViewFactory..Factory"></a> |
36 | 77 |
|
37 | | -## Factory : <code>Object</code> |
38 | | -**Kind**: global typedef |
| 78 | +### view/MainViewFactory.Factory : <code>Object</code> |
| 79 | +**Kind**: inner typedef of [<code>view/MainViewFactory</code>](#module_view/MainViewFactory) |
39 | 80 | **Properties** |
40 | 81 |
|
41 | 82 | | Name | Type | Description | |
|
0 commit comments