Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed May 31, 2024
1 parent b2fe8d3 commit ed9bc03
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
Expand Down Expand Up @@ -71,12 +73,13 @@ const fileBrowserFactory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
});

// check the url in iframe and open
app.restored.then(() => {
app.restored.then(async () => {
const windowPathname = window.location.pathname;
const treeIndex = windowPathname.indexOf('/tree/');
let path = windowPathname.substring(treeIndex + '/tree/'.length);
path = decodeURIComponent(path);
if (path) {
const content = await app.serviceManager.contents.get(path);
if (content.type !== 'directory') {
docManager.open(path);
}
});
Expand All @@ -87,6 +90,7 @@ const fileBrowserFactory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
return widget;
};

// @ts-ignore: DirListing._onPathChanged is private upstream, need to change this so we can remove the ignore
return { createFileBrowser, tracker };
}
};
Expand Down
32 changes: 23 additions & 9 deletions src/unfold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class FileTreeRenderer extends DirListing.Renderer {
/**
* A widget which hosts a filetree.
*/
// @ts-ignore: _onPathChanged is private upstream, need to change this
export class DirTreeListing extends DirListing {
constructor(options: DirTreeListing.IOptions) {
super({ ...options, renderer: new FileTreeRenderer(options.model) });
Expand Down Expand Up @@ -229,6 +230,10 @@ export class DirTreeListing extends DirListing {
}
}

_onPathChanged(): void {
// It's a no-op to overwrite the base class behavior
}

private _eventDragEnter(event: IDragEvent): void {
if (event.mimeData.hasData(CONTENTS_MIME)) {
// @ts-ignore
Expand Down Expand Up @@ -428,19 +433,26 @@ export class FilterFileTreeBrowserModel extends FilterFileBrowserModel {
}

set path(value: string) {
this._path = value;
let needsToEmit = false;

if (this._path === value) {
return;
if (this._path !== value) {
needsToEmit = true;
}

const pathChanged = this.pathChanged as Signal<this, IChangedArgs<string>>;
this._path = value;

pathChanged.emit({
name: 'path',
oldValue: this._path,
newValue: value
});
if (needsToEmit) {
const pathChanged = this.pathChanged as Signal<
this,
IChangedArgs<string>
>;

pathChanged.emit({
name: 'path',
oldValue: this._path,
newValue: PathExt.dirname(this._path)
});
}
}

/**
Expand Down Expand Up @@ -668,6 +680,7 @@ export class FileTreeBrowser extends FileBrowser {
}

protected createDirListing(options: DirListing.IOptions): DirListing {
// @ts-ignore: _onPathChanged is private upstream, need to change this
return new DirTreeListing({
model: this.model,
translator: this.translator
Expand All @@ -680,5 +693,6 @@ export class FileTreeBrowser extends FileBrowser {

model: FilterFileTreeBrowserModel;

// @ts-ignore: _onPathChanged is private upstream, need to change this
listing: DirTreeListing;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ed9bc03

Please sign in to comment.