Skip to content

Commit

Permalink
feat(lab): add an entry for guide view in menu and add config
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk committed Dec 16, 2024
1 parent 087a7ff commit 020058e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions packages/libro-lab/src/command/lab-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export const LabCommands = {
id: 'libro-lab-header-menu-help-about',
label: '关于',
},
Guide: {
id: 'libro-lab-header-menu-help-guide',
label: '使用指南',
},
Save: {
id: 'libro-lab-save',
label: '保存',
Expand Down
17 changes: 15 additions & 2 deletions packages/libro-lab/src/command/lab-menu-contribution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
NotebookCommands,
} from '@difizen/libro-jupyter';
import { TerminalCommands, TerminalManager } from '@difizen/libro-terminal';
import type { MenuRegistry } from '@difizen/mana-app';
import type { KeybindingRegistry } from '@difizen/mana-app';
import type { KeybindingRegistry, MenuRegistry } from '@difizen/mana-app';
import { SlotViewManager } from '@difizen/mana-app';
import { KeybindingContribution } from '@difizen/mana-app';
import { Saveable } from '@difizen/mana-app';
import {
Expand All @@ -20,6 +20,7 @@ import {
} from '@difizen/mana-app';
import { l10n } from '@difizen/mana-l10n';

import { GuideView } from '../guide/index.js';
import { LibroLabLayoutSlots } from '../layout/index.js';
import { LayoutService } from '../layout/layout-service.js';

Expand All @@ -43,6 +44,7 @@ export class LabMenu
@inject(LayoutService) protected layoutService: LayoutService;
@inject(TerminalManager) terminalManager: TerminalManager;
@inject(ViewManager) viewManager: ViewManager;
@inject(SlotViewManager) slotManager: SlotViewManager;

registerKeybindings(keybindings: KeybindingRegistry) {
keybindings.registerKeybinding({
Expand Down Expand Up @@ -75,6 +77,11 @@ export class LabMenu
command: LabCommands.About.id,
label: () => <div>{l10n.t(LabCommands.About.label)}</div>,
});
menu.registerMenuAction(LabMenus.HELP, {
id: LabCommands.Guide.id,
command: LabCommands.Guide.id,
label: () => <div>{l10n.t(LabCommands.Guide.label)}</div>,
});
menu.registerMenuAction(LabMenus.FILE, {
id: LabCommands.Save.id,
command: LabCommands.Save.id,
Expand Down Expand Up @@ -261,6 +268,12 @@ export class LabMenu
//TODO: 关于
},
});
commands.registerCommand(LabCommands.Guide, {
execute: async () => {
const view = await this.viewManager.getOrCreateView(GuideView);
this.slotManager.addView(view, LibroLabLayoutSlots.content);
},
});
commands.registerCommand(LabCommands.Save);
commands.registerHandler(LabCommands.Save.id, {
execute: async () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/libro-lab/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ export const LibroLabTocPanelEnabled: ConfigurationNode<boolean> = {
},
};

export const LibroLabGuideViewEnabled: ConfigurationNode<boolean> = {
id: 'libro.lab.guide.view.enabled',
description: 'whether enable guide view ',
title: l10n.t('是否激活使用指南'),
type: 'checkbox',
defaultValue: false,
schema: {
type: 'boolean',
},
};

export const LibroLabConfiguration = {
LibroLabKernelAndTerminalPanelEnabled: LibroLabKernelAndTerminalPanelEnabled,
LibroLabTocPanelEnabled: LibroLabTocPanelEnabled,
LibroLabGuideViewEnabled: LibroLabGuideViewEnabled,
};
12 changes: 10 additions & 2 deletions packages/libro-lab/src/lab-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
singleton,
} from '@difizen/mana-app';

import { LibroLabConfiguration } from './config/index.js';
import { LibroLabConfiguration, LibroLabGuideViewEnabled } from './config/index.js';
import { GuideView } from './guide/index.js';
import { KernelAndTerminalPanelView } from './kernel-and-terminal-panel/index.js';
import { LibroLabLayoutSlots } from './layout/index.js';
import { LayoutService } from './layout/layout-service.js';
Expand Down Expand Up @@ -67,11 +68,18 @@ export class LibroLabApp implements ApplicationContribution {
}
}
this.serverManager.ready
.then(() => {
.then(async () => {
this.layoutService.setAreaVisible(LibroLabLayoutSlots.navigator, true);
this.layoutService.setAreaVisible(LibroLabLayoutSlots.alert, false);
this.layoutService.serverSatus = 'success';
this.initialWorkspace();
const isGuideEnabled = await this.configurationService.get(
LibroLabGuideViewEnabled,
);
if (isGuideEnabled) {
const view = await this.viewManager.getOrCreateView(GuideView);
this.slotViewManager.addView(view, LibroLabLayoutSlots.content);
}
return;
})
.catch(console.error);
Expand Down
9 changes: 0 additions & 9 deletions packages/libro-lab/src/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ export const LibroLabModule = ManaModule.create()
}),
LibroGuidebookContentContribution,
GuideView,
createViewPreference({
view: GuideView,
slot: LibroLabLayoutSlots.content,
autoCreate: true,
openOptions: {
reveal: true,
order: 'guide',
},
}),
EntryPointView,
)
.dependOn(
Expand Down

0 comments on commit 020058e

Please sign in to comment.