1 | import { IMainMenu } from '@jupyterlab/mainmenu';
|
2 | import { ICommandPalette } from '@jupyterlab/apputils';
|
3 | import { INotebookTracker } from '@jupyterlab/notebook';
|
4 | import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
5 | import { IFontManager, PACKAGE_NAME, CMD } from '.';
|
6 | import { ICONS } from './icons';
|
7 | import { FontManager } from './manager';
|
8 | import { NotebookFontsButton } from './button';
|
9 | import { FontEditor } from './editor';
|
10 | import { LicenseViewer } from './license';
|
11 | const PLUGIN_ID = `${PACKAGE_NAME}:fonts`;
|
12 | let licenseId = 0;
|
13 | const plugin = {
|
14 | id: PLUGIN_ID,
|
15 | autoStart: true,
|
16 | requires: [IMainMenu, ISettingRegistry, ICommandPalette, INotebookTracker],
|
17 | provides: IFontManager,
|
18 | activate: function (app, menu, settingRegistry, palette, notebooks) {
|
19 | const manager = new FontManager(app.commands, palette, notebooks);
|
20 | manager.licensePaneRequested.connect((it, font) => {
|
21 | let license = new LicenseViewer({ font });
|
22 | license.id = `jp-fonts-license-${licenseId++}`;
|
23 | license.title.label = font.name;
|
24 | license.title.closable = true;
|
25 | license.title.icon = ICONS.license;
|
26 | app.shell.add(license, 'main');
|
27 | app.shell.activateById(license.id);
|
28 | });
|
29 | menu.settingsMenu.addGroup([{ type: 'submenu', submenu: manager.menu }]);
|
30 | app.commands.addCommand(CMD.editFonts, {
|
31 | label: 'Global Fonts...',
|
32 | execute: args => {
|
33 | const editor = new FontEditor();
|
34 | const { model } = editor;
|
35 | model.fonts = manager;
|
36 | editor.title.icon = ICONS.fonts;
|
37 | editor.title.closable = true;
|
38 | if ((args || {})['global']) {
|
39 | editor.title.label = 'Global';
|
40 | editor.id = 'font-editor-global';
|
41 | }
|
42 | else {
|
43 | const { currentWidget } = notebooks;
|
44 | if (currentWidget == null) {
|
45 | return;
|
46 | }
|
47 | model.notebook = currentWidget;
|
48 | editor.id = `font-editor-${model.notebook.id}`;
|
49 | model.notebook.disposed.connect(() => editor.dispose());
|
50 | }
|
51 | app.shell.add(editor, 'main', { mode: 'split-right' });
|
52 | }
|
53 | });
|
54 | const fontsButton = new NotebookFontsButton();
|
55 | fontsButton.widgetRequested.connect(async () => {
|
56 | try {
|
57 | await app.commands.execute(CMD.editFonts);
|
58 | }
|
59 | catch (err) {
|
60 | console.warn(err);
|
61 | }
|
62 | });
|
63 | app.docRegistry.addWidgetExtension('Notebook', fontsButton);
|
64 | Promise.all([settingRegistry.load(PLUGIN_ID), app.restored])
|
65 | .then(async ([settings]) => {
|
66 | manager.settings = settings;
|
67 | settingRegistry
|
68 | .load('@jupyterlab/apputils-extension:themes')
|
69 | .then(settings => {
|
70 | settings.changed.connect(() => {
|
71 | setTimeout(() => manager.hack(), 100);
|
72 | });
|
73 | })
|
74 | .catch(console.warn);
|
75 | })
|
76 | .catch((reason) => {
|
77 | console.error(reason);
|
78 | });
|
79 | return manager;
|
80 | }
|
81 | };
|
82 | export default plugin;
|
83 |
|
\ | No newline at end of file |