Skip to content

Commit

Permalink
Fix recents menu not getting updated after loading history (#16149)
Browse files Browse the repository at this point in the history
* Fix recents menu not getting updated after loading history

* Update items even before first change from manager, add isEnabled

on the clear recent documents command.
  • Loading branch information
krassowski committed Apr 16, 2024
1 parent 5b23d24 commit 73a947d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/docmanager-extension/src/recents.ts
Expand Up @@ -67,6 +67,9 @@ export const recentsManagerPlugin: JupyterFrontEndPlugin<IRecentsManager> = {
execute: () => {
recentsManager.clearRecents();
},
isEnabled: () =>
recentsManager.recentlyOpened.length != 0 ||
recentsManager.recentlyClosed.length != 0,
label: trans.__('Clear Recent Documents'),
caption: trans.__('Clear the list of recently opened items.')
});
Expand Down
1 change: 1 addition & 0 deletions packages/docmanager/src/recents.ts
Expand Up @@ -218,6 +218,7 @@ export class RecentsManager implements IRecentsManager {
type as 'opened' | 'closed'
);
}
this._recentsChanged.emit(undefined);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/docmanager/test/recents.spec.ts
Expand Up @@ -46,6 +46,19 @@ describe('@jupyterlab/docmanager', () => {
it('should create a new recents manager', () => {
expect(manager).toBeInstanceOf(RecentsManager);
});

it('should emit `changed` signal after loading', async () => {
const stateDB = new StateDB();
const done = new PromiseDelegate<boolean>();
manager = new TestRecentsManager({
stateDB,
contents: services.contents
});
manager.changed.connect(() => {
done.resolve(true);
});
expect(await done.promise).toBe(true);
});
});

describe('#isDisposed', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/mainmenu-extension/src/recents.ts
Expand Up @@ -52,6 +52,7 @@ class RecentsMenu extends Menu {
super(options);
this._manager = options.manager;
this._showDirectories = options.showDirectories;
this.updateItems();
this._manager.changed.connect(this.updateItems, this);
}

Expand Down Expand Up @@ -230,7 +231,7 @@ export const recentsMenuPlugin: JupyterFrontEndPlugin<void> = {
});
submenu.title.label = trans.__('Open Recent');
mainMenu.fileMenu.addItem({
type: 'submenu' as Menu.ItemType,
type: 'submenu',
submenu,
rank: 1
});
Expand Down

0 comments on commit 73a947d

Please sign in to comment.