Skip to content

Commit

Permalink
Merge pull request #5698 from gnestor/navigate-to-cwd
Browse files Browse the repository at this point in the history
Follow file path between file browser and editor
  • Loading branch information
ian-r-rose committed Dec 19, 2018
2 parents bf808f8 + ca0f4aa commit 8b606ca
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/filebrowser-extension/schema/browser.json
@@ -1,6 +1,8 @@
{
"jupyter.lab.setting-icon-class": "jp-FileIcon",
"jupyter.lab.setting-icon-label": "File Browser",
"title": "File Browser",
"description": "File browser settings.",
"description": "File Browser settings.",
"jupyter.lab.shortcuts": [
{
"command": "filebrowser:create-main-launcher",
Expand All @@ -13,7 +15,14 @@
"selector": "body"
}
],
"properties": {},
"properties": {
"navigateToCurrentDirectory": {
"type": "boolean",
"title": "Navigate to document's current directory",
"description": "Whether to automatically navigate to a document's current directory",
"default": false
}
},
"additionalProperties": false,
"type": "object"
}
46 changes: 43 additions & 3 deletions packages/filebrowser-extension/src/index.ts
Expand Up @@ -15,7 +15,13 @@ import {
ToolbarButton
} from '@jupyterlab/apputils';

import { IStateDB, PageConfig, PathExt, URLExt } from '@jupyterlab/coreutils';
import {
IStateDB,
PageConfig,
PathExt,
URLExt,
ISettingRegistry
} from '@jupyterlab/coreutils';

import { IDocumentManager } from '@jupyterlab/docmanager';

Expand Down Expand Up @@ -94,7 +100,12 @@ namespace CommandIDs {
const browser: JupyterLabPlugin<void> = {
activate: activateBrowser,
id: '@jupyterlab/filebrowser-extension:browser',
requires: [IFileBrowserFactory, ILayoutRestorer],
requires: [
IFileBrowserFactory,
ILayoutRestorer,
IDocumentManager,
ISettingRegistry
],
autoStart: true
};

Expand Down Expand Up @@ -223,7 +234,9 @@ function activateFactory(
function activateBrowser(
app: JupyterLab,
factory: IFileBrowserFactory,
restorer: ILayoutRestorer
restorer: ILayoutRestorer,
docManager: IDocumentManager,
settingRegistry: ISettingRegistry
): void {
const browser = factory.defaultBrowser;
const { commands, shell } = app;
Expand Down Expand Up @@ -261,6 +274,33 @@ function activateBrowser(
shell.layoutModified.connect(() => {
maybeCreate();
});

let navigateToCurrentDirectory: boolean = false;

settingRegistry
.load('@jupyterlab/filebrowser-extension:browser')
.then(settings => {
settings.changed.connect(settings => {
navigateToCurrentDirectory = settings.get(
'navigateToCurrentDirectory'
).composite as boolean;
});
navigateToCurrentDirectory = settings.get('navigateToCurrentDirectory')
.composite as boolean;
});

// Whether to automatically navigate to a document's current directory
shell.currentChanged.connect((shell, change) => {
if (navigateToCurrentDirectory) {
const { newValue } = change;
const context = docManager.contextForWidget(newValue);
if (context) {
commands.execute('filebrowser:activate', { path: context.path });
commands.execute('filebrowser:navigate', { path: context.path });
}
}
});

maybeCreate();
});
}
Expand Down

0 comments on commit 8b606ca

Please sign in to comment.