UNPKG

3.37 kBJavaScriptView Raw
1import { IMainMenu } from '@jupyterlab/mainmenu';
2import { ICommandPalette } from '@jupyterlab/apputils';
3import { INotebookTracker } from '@jupyterlab/notebook';
4import { ISettingRegistry } from '@jupyterlab/settingregistry';
5import { IFontManager, PACKAGE_NAME, CMD } from '.';
6import { ICONS } from './icons';
7import { FontManager } from './manager';
8import { NotebookFontsButton } from './button';
9import { FontEditor } from './editor';
10import { LicenseViewer } from './license';
11const PLUGIN_ID = `${PACKAGE_NAME}:fonts`;
12let licenseId = 0;
13const 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};
82export default plugin;
83//# sourceMappingURL=extension.js.map
\No newline at end of file