Skip to content

Commit

Permalink
Bring jupyterlab-recents into the core
Browse files Browse the repository at this point in the history
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Shreyas Cholia <[email protected]>
Co-authored-by: Matt Henderson <[email protected]>
Co-authored-by: Trevor Slaton <[email protected]>
Co-authored-by: Adrien Delsalle <[email protected]>
  • Loading branch information
6 people committed Nov 30, 2023
1 parent 5d7c44b commit f5bca42
Show file tree
Hide file tree
Showing 22 changed files with 712 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/docmanager-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@jupyterlab/docregistry": "^4.1.0-alpha.3",
"@jupyterlab/services": "^7.1.0-alpha.3",
"@jupyterlab/settingregistry": "^4.1.0-alpha.3",
"@jupyterlab/statedb": "^4.1.0-alpha.3",
"@jupyterlab/statusbar": "^4.1.0-alpha.3",
"@jupyterlab/translation": "^4.1.0-alpha.3",
"@jupyterlab/ui-components": "^4.1.0-alpha.3",
Expand Down
7 changes: 7 additions & 0 deletions packages/docmanager-extension/schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@
"title": "Rename Untitled File On First Save",
"description": "Whether to prompt to rename untitled file on first manual save.",
"default": true
},
"maximalRecents": {
"type": "number",
"title": "Recent Items Number",
"description": "Number of recently opened/closed files and directories to remember.",
"default": 10,
"minimum": 0
}
},
"additionalProperties": false,
Expand Down
19 changes: 15 additions & 4 deletions packages/docmanager-extension/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
DocumentManager,
IDocumentManager,
IDocumentWidgetOpener,
IRecentsManager,
PathStatus,
renameDialog,
SavingStatus
Expand All @@ -52,6 +53,7 @@ import { IDisposable } from '@lumino/disposable';
import { ISignal, Signal } from '@lumino/signaling';
import { Widget } from '@lumino/widgets';
import * as React from 'react';
import { recentsManagerPlugin } from './recents';

/**
* The command IDs used by the document manager plugin.
Expand Down Expand Up @@ -168,14 +170,21 @@ const manager: JupyterFrontEndPlugin<IDocumentManager> = {
description: 'Provides the document manager.',
provides: IDocumentManager,
requires: [IDocumentWidgetOpener],
optional: [ITranslator, ILabStatus, ISessionContextDialogs, JupyterLab.IInfo],
optional: [
ITranslator,
ILabStatus,
ISessionContextDialogs,
JupyterLab.IInfo,
IRecentsManager
],
activate: (
app: JupyterFrontEnd,
widgetOpener: IDocumentWidgetOpener,
translator_: ITranslator | null,
status: ILabStatus | null,
sessionDialogs_: ISessionContextDialogs | null,
info: JupyterLab.IInfo | null
info: JupyterLab.IInfo | null,
recentsManager: IRecentsManager | null
) => {
const { serviceManager: manager, docRegistry: registry } = app;
const translator = translator_ ?? nullTranslator;
Expand All @@ -196,7 +205,8 @@ const manager: JupyterFrontEndPlugin<IDocumentManager> = {
return info.isConnected;
}
return true;
}
},
recentsManager: recentsManager ?? undefined
});

return docManager;
Expand Down Expand Up @@ -556,7 +566,8 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
savingStatusPlugin,
downloadPlugin,
openBrowserTabPlugin,
openerPlugin
openerPlugin,
recentsManagerPlugin
];
export default plugins;

Expand Down
73 changes: 73 additions & 0 deletions packages/docmanager-extension/src/recents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { IRecentsManager, RecentsManager } from '@jupyterlab/docmanager';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { IStateDB } from '@jupyterlab/statedb';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';

/**
* A namespace for command IDs.
*/
namespace CommandIDs {
export const clearRecents = 'docmanager:clear-recents';
}

namespace PluginIDs {
export const recentsManager = '@jupyterlab/docmanager-extension:recents';
export const mainPlugin = '@jupyterlab/docmanager-extension:plugin';
}

export const recentsManagerPlugin: JupyterFrontEndPlugin<IRecentsManager> = {
id: PluginIDs.recentsManager,
autoStart: true,
requires: [IStateDB],
optional: [ISettingRegistry, ITranslator],
provides: IRecentsManager,
activate: (
app: JupyterFrontEnd,
stateDB: IStateDB,
settingRegistry: ISettingRegistry | null,
translator: ITranslator | null
): IRecentsManager => {
const { serviceManager } = app;
const trans = (translator ?? nullTranslator).load('jupyterlab');

// Create the manager
const recentsManager = new RecentsManager({
stateDB: stateDB,
contents: serviceManager.contents
});

const updateSettings = (settings: ISettingRegistry.ISettings) => {
recentsManager.maximalRecentsLength = settings.get('maximalRecents')
.composite as number;
};

if (settingRegistry) {
Promise.all([

Check failure on line 54 in packages/docmanager-extension/src/recents.ts

View workflow job for this annotation

GitHub Actions / Linux (lint, 3.11)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
app.restored,
settingRegistry.load(PluginIDs.mainPlugin)
]).then(([_, settings]) => {
settings.changed.connect(updateSettings);
updateSettings(settings);
});
}

app.commands.addCommand(CommandIDs.clearRecents, {
execute: () => {
recentsManager.clearRecents();
},
label: trans.__('Clear Recently Opened'),
caption: trans.__('Clear the list of recently opened items.')
});

return recentsManager;
}
};
3 changes: 3 additions & 0 deletions packages/docmanager-extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
{
"path": "../settingregistry"
},
{
"path": "../statedb"
},
{
"path": "../statusbar"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/docmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
"@jupyterlab/coreutils": "^6.1.0-alpha.3",
"@jupyterlab/docregistry": "^4.1.0-alpha.3",
"@jupyterlab/services": "^7.1.0-alpha.3",
"@jupyterlab/statedb": "^4.1.0-alpha.3",
"@jupyterlab/statusbar": "^4.1.0-alpha.3",
"@jupyterlab/translation": "^4.1.0-alpha.3",
"@jupyterlab/ui-components": "^4.1.0-alpha.3",
"@lumino/algorithm": "^2.0.1",
"@lumino/coreutils": "^2.1.2",
"@lumino/disposable": "^2.1.2",
"@lumino/messaging": "^2.0.1",
"@lumino/polling": "^2.1.2",
"@lumino/properties": "^2.0.1",
"@lumino/signaling": "^2.1.2",
"@lumino/widgets": "^2.3.1",
Expand Down
1 change: 1 addition & 0 deletions packages/docmanager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './savehandler';
export * from './savingstatus';
export * from './tokens';
export * from './widgetmanager';
export * from './recents';
14 changes: 12 additions & 2 deletions packages/docmanager/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { AttachedProperty } from '@lumino/properties';
import { ISignal, Signal } from '@lumino/signaling';
import { Widget } from '@lumino/widgets';
import { SaveHandler } from './savehandler';
import { IDocumentManager, IDocumentWidgetOpener } from './tokens';
import {
IDocumentManager,
IDocumentWidgetOpener,
IRecentsManager
} from './tokens';
import { DocumentWidgetManager } from './widgetmanager';

/**
Expand Down Expand Up @@ -48,7 +52,8 @@ export class DocumentManager implements IDocumentManager {

const widgetManager = new DocumentWidgetManager({
registry: this.registry,
translator: this.translator
translator: this.translator,
recentsManager: options.recentsManager
});
widgetManager.activateRequested.connect(this._onActivateRequested, this);
widgetManager.stateChanged.connect(this._onWidgetStateChanged, this);
Expand Down Expand Up @@ -766,6 +771,11 @@ export namespace DocumentManager {
* By default, it always returns `true`.
*/
isConnectedCallback?: () => boolean;

/**
* The manager for recent documents.
*/
recentsManager?: IRecentsManager;
}
}

Expand Down
Loading

0 comments on commit f5bca42

Please sign in to comment.