jupyter-js-filebrowser
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -8,3 +8,3 @@ import { IContentsModel, IContentsManager } from 'jupyter-js-services'; | ||
*/ | ||
export declare class FileHandler implements IMessageFilter { | ||
export declare abstract class AbstractFileHandler implements IMessageFilter { | ||
/** | ||
@@ -31,2 +31,6 @@ * Construct a new source file handler. | ||
/** | ||
* Get file contents given a path. | ||
*/ | ||
protected abstract getContents(manager: IContentsManager, path: string): Promise<IContentsModel>; | ||
/** | ||
* Create the widget from an `IContentsModel`. | ||
@@ -37,3 +41,3 @@ * | ||
*/ | ||
protected createWidget(contents: IContentsModel): Widget; | ||
protected abstract createWidget(contents: IContentsModel): Widget; | ||
/** | ||
@@ -54,4 +58,20 @@ * Get the path from the old path widget title text. | ||
/** | ||
* An implementation of a file handler. | ||
*/ | ||
export declare class FileHandler extends AbstractFileHandler { | ||
/** | ||
* Get file contents given a path. | ||
*/ | ||
protected getContents(manager: IContentsManager, path: string): Promise<IContentsModel>; | ||
/** | ||
* Create the widget from an `IContentsModel`. | ||
* | ||
* #### Notes | ||
* This is intended to be subclassed by other file handlers. | ||
*/ | ||
protected createWidget(contents: IContentsModel): Widget; | ||
} | ||
/** | ||
* An attached property with the widget path. | ||
*/ | ||
export declare const pathProperty: Property<Widget, string>; |
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
'use strict'; | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
var CodeMirror = require('codemirror'); | ||
@@ -20,11 +25,11 @@ var arrays = require('phosphor-arrays'); | ||
*/ | ||
var FileHandler = (function () { | ||
var AbstractFileHandler = (function () { | ||
/** | ||
* Construct a new source file handler. | ||
*/ | ||
function FileHandler(manager) { | ||
function AbstractFileHandler(manager) { | ||
this._openFiles = []; | ||
this._manager = manager; | ||
} | ||
Object.defineProperty(FileHandler.prototype, "fileExtensions", { | ||
Object.defineProperty(AbstractFileHandler.prototype, "fileExtensions", { | ||
/** | ||
@@ -42,3 +47,3 @@ * Get the list of file extensions supported by the handler. | ||
*/ | ||
FileHandler.prototype.open = function (path) { | ||
AbstractFileHandler.prototype.open = function (path) { | ||
var _this = this; | ||
@@ -49,3 +54,3 @@ var index = arrays.findIndex(this._openFiles, function (widget, ind) { return exports.pathProperty.get(widget) === path; }); | ||
} | ||
return this._manager.get(path).then(function (contents) { | ||
return this.getContents(this._manager, path).then(function (contents) { | ||
var widget = _this.createWidget(contents); | ||
@@ -63,3 +68,3 @@ widget.title.closable = true; | ||
*/ | ||
FileHandler.prototype.close = function (widget) { | ||
AbstractFileHandler.prototype.close = function (widget) { | ||
var index = this._openFiles.indexOf(widget); | ||
@@ -76,3 +81,3 @@ if (index === -1) { | ||
*/ | ||
FileHandler.prototype.filterMessage = function (handler, msg) { | ||
AbstractFileHandler.prototype.filterMessage = function (handler, msg) { | ||
if (msg.type == 'close-request') { | ||
@@ -84,15 +89,2 @@ return this.close(handler); | ||
/** | ||
* Create the widget from an `IContentsModel`. | ||
* | ||
* #### Notes | ||
* This is intended to be subclassed by other file handlers. | ||
*/ | ||
FileHandler.prototype.createWidget = function (contents) { | ||
var widget = new phosphor_codemirror_1.CodeMirrorWidget(); | ||
widget.editor.getDoc().setValue(contents.content); | ||
loadModeByFileName(widget.editor, contents.name); | ||
widget.title.text = contents.name; | ||
return widget; | ||
}; | ||
/** | ||
* Get the path from the old path widget title text. | ||
@@ -103,3 +95,3 @@ * | ||
*/ | ||
FileHandler.prototype.getNewPath = function (oldPath, title) { | ||
AbstractFileHandler.prototype.getNewPath = function (oldPath, title) { | ||
var dirname = oldPath.slice(0, oldPath.lastIndexOf('/') + 1); | ||
@@ -111,3 +103,3 @@ return dirname + title; | ||
*/ | ||
FileHandler.prototype.titleChanged = function (title, args) { | ||
AbstractFileHandler.prototype.titleChanged = function (title, args) { | ||
var widget = arrays.find(this._openFiles, function (w, index) { return w.title === title; }); | ||
@@ -125,4 +117,34 @@ if (widget === void 0) { | ||
}; | ||
return AbstractFileHandler; | ||
})(); | ||
exports.AbstractFileHandler = AbstractFileHandler; | ||
/** | ||
* An implementation of a file handler. | ||
*/ | ||
var FileHandler = (function (_super) { | ||
__extends(FileHandler, _super); | ||
function FileHandler() { | ||
_super.apply(this, arguments); | ||
} | ||
/** | ||
* Get file contents given a path. | ||
*/ | ||
FileHandler.prototype.getContents = function (manager, path) { | ||
return manager.get(path, { type: 'file' }); | ||
}; | ||
/** | ||
* Create the widget from an `IContentsModel`. | ||
* | ||
* #### Notes | ||
* This is intended to be subclassed by other file handlers. | ||
*/ | ||
FileHandler.prototype.createWidget = function (contents) { | ||
var widget = new phosphor_codemirror_1.CodeMirrorWidget(); | ||
widget.editor.getDoc().setValue(contents.content); | ||
loadModeByFileName(widget.editor, contents.name); | ||
widget.title.text = contents.name; | ||
return widget; | ||
}; | ||
return FileHandler; | ||
})(); | ||
})(AbstractFileHandler); | ||
exports.FileHandler = FileHandler; | ||
@@ -129,0 +151,0 @@ /** |
{ | ||
"name": "jupyter-js-filebrowser", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "File browser widget for Jupyter", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
107991
3063