浏览代码

Add documentation

Frederic Collonval 6 年之前
父节点
当前提交
59ef060152
共有 1 个文件被更改,包括 39 次插入0 次删除
  1. 39 0
      docs/source/developer/ui_helpers.rst

+ 39 - 0
docs/source/developer/ui_helpers.rst

@@ -65,3 +65,42 @@ a ``Promise`` resolving in a ``Dialog.IResult`` object.
     InputDialog.getText({ title: 'Provide a text' }).then(value => {
       console.log('text ' + value.value);
     });
+
+File Dialogs
+''''''''''''
+
+Two helper functions to ask a user to open a file or a directory are 
+available in the ``filebrowser`` package under the namespace ``FileDialog``.
+
+Here is an example to request a file.
+
+.. code:: typescript
+
+    const dialog = FileDialog.getExistingDirectory({
+      manager, // IDocumentManager
+      filter: model => model.type == 'notebook' // optional (model: Contents.IModel) => boolean
+    });
+
+    const result = await dialog;
+
+    if(result.button.accept){
+      let files = result.value;
+    }
+
+And for a folder.
+
+.. code:: typescript
+
+    const dialog = FileDialog.getExistingDirectory({
+      manager // IDocumentManager
+    });
+
+    const result = await dialog;
+
+    if(result.button.accept){
+      let folders = result.value;
+    }
+
+.. note:: The document manager can be obtained in a plugin by requesting 
+    ``IFileBrowserFactory`` service. The manager will be accessed through
+    ``factory.defaultBrowser.model.manager``.