|
@@ -1,7 +1,12 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import { showErrorMessage, Toolbar, ToolbarButton } from '@jupyterlab/apputils';
|
|
|
+import {
|
|
|
+ showErrorMessage,
|
|
|
+ Toolbar,
|
|
|
+ ToolbarButton,
|
|
|
+ ReactWidget
|
|
|
+} from '@jupyterlab/apputils';
|
|
|
|
|
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
|
|
|
@@ -17,10 +22,12 @@ import { BreadCrumbs } from './crumbs';
|
|
|
|
|
|
import { DirListing } from './listing';
|
|
|
|
|
|
-import { FileBrowserModel } from './model';
|
|
|
+import { FilterFileBrowserModel } from './model';
|
|
|
|
|
|
import { Uploader } from './upload';
|
|
|
|
|
|
+import { FilenameSearcher } from './search';
|
|
|
+
|
|
|
/**
|
|
|
* The class name added to file browsers.
|
|
|
*/
|
|
@@ -31,6 +38,11 @@ const FILE_BROWSER_CLASS = 'jp-FileBrowser';
|
|
|
*/
|
|
|
const CRUMBS_CLASS = 'jp-FileBrowser-crumbs';
|
|
|
|
|
|
+/**
|
|
|
+ * The class name added to the filebrowser filterbox node.
|
|
|
+ */
|
|
|
+const FILTERBOX_CLASS = 'jp-FileBrowser-filterBox';
|
|
|
+
|
|
|
/**
|
|
|
* The class name added to the filebrowser toolbar node.
|
|
|
*/
|
|
@@ -76,6 +88,7 @@ export class FileBrowser extends Widget {
|
|
|
tooltip: 'New Folder'
|
|
|
});
|
|
|
const uploader = new Uploader({ model });
|
|
|
+
|
|
|
const refresher = new ToolbarButton({
|
|
|
icon: refreshIcon,
|
|
|
onClick: () => {
|
|
@@ -90,16 +103,22 @@ export class FileBrowser extends Widget {
|
|
|
|
|
|
this._listing = new DirListing({ model, renderer });
|
|
|
|
|
|
+ this._filenameSearcher = FilenameSearcher({
|
|
|
+ listing: this._listing,
|
|
|
+ useFuzzyFilter: this._useFuzzyFilter,
|
|
|
+ placeholder: 'Filter files by name'
|
|
|
+ });
|
|
|
+
|
|
|
this._crumbs.addClass(CRUMBS_CLASS);
|
|
|
this.toolbar.addClass(TOOLBAR_CLASS);
|
|
|
+ this._filenameSearcher.addClass(FILTERBOX_CLASS);
|
|
|
this._listing.addClass(LISTING_CLASS);
|
|
|
|
|
|
- const layout = new PanelLayout();
|
|
|
-
|
|
|
- layout.addWidget(this.toolbar);
|
|
|
- layout.addWidget(this._crumbs);
|
|
|
- layout.addWidget(this._listing);
|
|
|
- this.layout = layout;
|
|
|
+ this.layout = new PanelLayout();
|
|
|
+ this.layout.addWidget(this.toolbar);
|
|
|
+ this.layout.addWidget(this._filenameSearcher);
|
|
|
+ this.layout.addWidget(this._crumbs);
|
|
|
+ this.layout.addWidget(this._listing);
|
|
|
|
|
|
if (options.restore !== false) {
|
|
|
void model.restore(this.id);
|
|
@@ -109,7 +128,7 @@ export class FileBrowser extends Widget {
|
|
|
/**
|
|
|
* The model used by the file browser.
|
|
|
*/
|
|
|
- readonly model: FileBrowserModel;
|
|
|
+ readonly model: FilterFileBrowserModel;
|
|
|
|
|
|
/**
|
|
|
* The toolbar used by the file browser.
|
|
@@ -259,7 +278,10 @@ export class FileBrowser extends Widget {
|
|
|
/**
|
|
|
* Handle a connection lost signal from the model.
|
|
|
*/
|
|
|
- private _onConnectionFailure(sender: FileBrowserModel, args: Error): void {
|
|
|
+ private _onConnectionFailure(
|
|
|
+ sender: FilterFileBrowserModel,
|
|
|
+ args: Error
|
|
|
+ ): void {
|
|
|
if (
|
|
|
args instanceof ServerConnection.ResponseError &&
|
|
|
args.response.status === 404
|
|
@@ -281,11 +303,39 @@ export class FileBrowser extends Widget {
|
|
|
this._navigateToCurrentDirectory = value;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Whether to use fuzzy filtering on file names.
|
|
|
+ */
|
|
|
+ set useFuzzyFilter(value: boolean) {
|
|
|
+ this._useFuzzyFilter = value;
|
|
|
+
|
|
|
+ this._filenameSearcher = FilenameSearcher({
|
|
|
+ listing: this._listing,
|
|
|
+ useFuzzyFilter: this._useFuzzyFilter,
|
|
|
+ placeholder: 'Filter files by name',
|
|
|
+ forceRefresh: true
|
|
|
+ });
|
|
|
+ this._filenameSearcher.addClass(FILTERBOX_CLASS);
|
|
|
+
|
|
|
+ this.layout.removeWidget(this._filenameSearcher);
|
|
|
+ this.layout.removeWidget(this._crumbs);
|
|
|
+ this.layout.removeWidget(this._listing);
|
|
|
+
|
|
|
+ this.layout.addWidget(this._filenameSearcher);
|
|
|
+ this.layout.addWidget(this._crumbs);
|
|
|
+ this.layout.addWidget(this._listing);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Override Widget.layout with a more specific PanelLayout type.
|
|
|
+ layout: PanelLayout;
|
|
|
+
|
|
|
private _crumbs: BreadCrumbs;
|
|
|
private _listing: DirListing;
|
|
|
+ private _filenameSearcher: ReactWidget;
|
|
|
private _manager: IDocumentManager;
|
|
|
private _directoryPending: boolean;
|
|
|
private _navigateToCurrentDirectory: boolean;
|
|
|
+ private _useFuzzyFilter: boolean = true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -304,7 +354,7 @@ export namespace FileBrowser {
|
|
|
/**
|
|
|
* A file browser model instance.
|
|
|
*/
|
|
|
- model: FileBrowserModel;
|
|
|
+ model: FilterFileBrowserModel;
|
|
|
|
|
|
/**
|
|
|
* An optional renderer for the directory listing area.
|