Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Make the widgetFactory a property #89

Merged
merged 3 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ function main(): void {
let sessionsManager = new NotebookSessionManager({ baseUrl: baseUrl });

let fbModel = new FileBrowserModel(contentsManager, sessionsManager);
let fbWidget = new FileBrowserWidget(fbModel, path => {
let fbWidget = new FileBrowserWidget(fbModel)
fbWidget.widgetFactory = path => {
return handler.open(path);
});
};
let handler = new FileHandler(contentsManager);

let panel = new SplitPanel();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyter-js-filebrowser",
"version": "0.4.6",
"version": "0.4.7",
"description": "File browser widget for Jupyter",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
18 changes: 16 additions & 2 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ class FileBrowserWidget extends Widget {
*
* @param model - The file browser view model.
*/
constructor(model: FileBrowserModel, widgetFactory?: (path: string) => Widget) {
constructor(model: FileBrowserModel) {
super();
this.addClass(FILE_BROWSER_CLASS);
this._model = model;
this._model.refreshed.connect(this._handleRefresh, this)
this._crumbs = new BreadCrumbs(model);
this._buttons = new FileButtons(model);
this._listing = new DirListing(model, widgetFactory);
this._listing = new DirListing(model);
this._listing.openRequested.connect((listing, path) => {
this.openRequested.emit(path);
});
Expand Down Expand Up @@ -134,6 +134,20 @@ class FileBrowserWidget extends Widget {
return Private.openRequestedSignal.bind(this);
}

/**
* Get the widget factory for the widget.
*/
get widgetFactory(): (path: string) => Widget {
return this._listing.widgetFactory;
}

/**
* Set the widget factory for the widget.
*/
set widgetFactory(factory: (path: string) => Widget) {
this._listing.widgetFactory = factory;
}

/**
* Change directory.
*/
Expand Down
17 changes: 15 additions & 2 deletions src/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,11 @@ class DirListing extends Widget {
*
* @param model - The file browser view model.
*/
constructor(model: FileBrowserModel, widgetFactory?: (path: string) => Widget) {
constructor(model: FileBrowserModel) {
super();
this.addClass(DIRLISTING_CLASS);
this._model = model;
this._model.refreshed.connect(this.update, this);
if (widgetFactory) this._widgetFactory = widgetFactory;
this._editNode = document.createElement('input');
this._editNode.className = ITEM_EDIT_CLASS;
}
Expand Down Expand Up @@ -258,6 +257,20 @@ class DirListing extends Widget {
return Private.openRequestedSignal.bind(this);
}

/**
* Get the widget factory for the widget.
*/
get widgetFactory(): (path: string) => Widget {
return this._widgetFactory;
}

/**
* Set the widget factory for the widget.
*/
set widgetFactory(factory: (path: string) => Widget) {
this._widgetFactory = factory;
}

/**
* Rename the first currently selected item.
*/
Expand Down