Skip to content

Commit

Permalink
add filename searcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Oct 20, 2023
1 parent 4eb0d36 commit 7ea2001
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"jupyter.lab.toolbars": {
"FileSystemAccess": [
{ "name": "open-folder", "rank": 0 },
{ "name": "uploader", "rank": 10 }
{ "name": "uploader", "rank": 10 },
{ "name": "filename-searcher", "rank": 20 }
]
},
"jupyter.lab.transform": true,
Expand Down
34 changes: 33 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { ITranslator, nullTranslator } from '@jupyterlab/translation';

import { listIcon, folderIcon } from '@jupyterlab/ui-components';
import {
listIcon,
folderIcon,
IScore,
FilenameSearcher
} from '@jupyterlab/ui-components';

import { FileSystemDrive } from './drive';

Expand All @@ -29,6 +34,11 @@ import { FileSystemDrive } from './drive';
*/
const FILE_SYSTEM_ACCESS_FACTORY = 'FileSystemAccess';

/**
* The class name added to the filebrowser filterbox node.
*/
const FILTERBOX_CLASS = 'jp-FileBrowser-filterBox';

/**
* Initialization data for the jupyterlab-filesystem-access extension.
*/
Expand Down Expand Up @@ -120,6 +130,28 @@ const plugin: JupyterFrontEndPlugin<void> = {
translator
})
);

toolbarRegistry.addFactory(
FILE_SYSTEM_ACCESS_FACTORY,
'filename-searcher',
(browser: FileBrowser) => {
const searcher = FilenameSearcher({
updateFilter: (
filterFn: (item: string) => Partial<IScore> | null,
query?: string
) => {
widget.model.setFilter(value => {
return filterFn(value.name.toLowerCase());
});
},
useFuzzyFilter: true,
placeholder: trans.__('Filter files by name'),
forceRefresh: true
});
searcher.addClass(FILTERBOX_CLASS);
return searcher;
}
);
}

app.shell.add(widget, 'left', { type: 'FileSystemAccess' });
Expand Down

0 comments on commit 7ea2001

Please sign in to comment.