瀏覽代碼

move from notebook to apputils ext

Ahmed Fasih 4 年之前
父節點
當前提交
105f2cf0f3
共有 2 個文件被更改,包括 41 次插入39 次删除
  1. 40 1
      packages/apputils-extension/src/index.ts
  2. 1 38
      packages/notebook-extension/src/index.ts

+ 40 - 1
packages/apputils-extension/src/index.ts

@@ -24,7 +24,8 @@ import {
   Printing,
   sessionContextDialogs,
   ISanitizer,
-  defaultSanitizer
+  defaultSanitizer,
+  MainAreaWidget
 } from '@jupyterlab/apputils';
 
 import { URLExt, PageConfig } from '@jupyterlab/coreutils';
@@ -68,6 +69,8 @@ namespace CommandIDs {
   export const resetOnLoad = 'apputils:reset-on-load';
 
   export const runFirstEnabled = 'apputils:run-first-enabled';
+
+  export const toggleHeader = 'apputils:toggle-header';
 }
 
 /**
@@ -297,6 +300,41 @@ const print: JupyterFrontEndPlugin<void> = {
   }
 };
 
+export const toggleHeader: JupyterFrontEndPlugin<void> = {
+  id: '@jupyterlab/apputils-extension:toggle-header',
+  autoStart: true,
+  requires: [ITranslator],
+  optional: [ICommandPalette],
+  activate: (
+    app: JupyterFrontEnd,
+    translator: ITranslator,
+    palette: ICommandPalette | null
+  ) => {
+    const trans = translator.load('jupyterlab');
+
+    const category: string = trans.__('Main Area');
+    app.commands.addCommand(CommandIDs.toggleHeader, {
+      label: trans.__('Show Header'),
+      isEnabled: () => app.shell.currentWidget instanceof MainAreaWidget,
+      isToggled: () => {
+        const widget = app.shell.currentWidget;
+        return widget instanceof MainAreaWidget
+          ? !widget.customHeader.isHidden
+          : false;
+      },
+      execute: async () => {
+        const widget = app.shell.currentWidget;
+        if (widget instanceof MainAreaWidget) {
+          widget.customHeader.setHidden(!widget.customHeader.isHidden);
+        }
+      }
+    });
+    if (palette) {
+      palette.addItem({ command: CommandIDs.toggleHeader, category });
+    }
+  }
+};
+
 /**
  * The default state database for storing application state.
  *
@@ -540,6 +578,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
   sessionDialogs,
   themesPlugin,
   themesPaletteMenuPlugin,
+  toggleHeader,
   utilityCommands,
   workspacesPlugin
 ];

+ 1 - 38
packages/notebook-extension/src/index.ts

@@ -378,42 +378,6 @@ export const notebookTrustItem: JupyterFrontEndPlugin<void> = {
   }
 };
 
-export const toggleHeader: JupyterFrontEndPlugin<void> = {
-  id: '@jupyterlab/apputils-extension:toggle-header',
-  autoStart: true,
-  requires: [ITranslator],
-  optional: [ICommandPalette],
-  activate: (
-    app: JupyterFrontEnd,
-    translator: ITranslator,
-    palette: ICommandPalette | null
-  ) => {
-    const trans = translator.load('jupyterlab');
-
-    const command = 'apputils:toggle-header';
-    const category: string = trans.__('Main Area');
-    app.commands.addCommand(command, {
-      label: trans.__('Show Header'),
-      isEnabled: () => app.shell.currentWidget instanceof MainAreaWidget,
-      isToggled: () => {
-        const widget = app.shell.currentWidget;
-        return widget instanceof MainAreaWidget
-          ? !widget.customHeader.isHidden
-          : false;
-      },
-      execute: async () => {
-        const widget = app.shell.currentWidget;
-        if (widget instanceof MainAreaWidget) {
-          widget.customHeader.setHidden(!widget.customHeader.isHidden);
-        }
-      }
-    });
-    if (palette) {
-      palette.addItem({ command, category });
-    }
-  }
-};
-
 /**
  * The notebook widget factory provider.
  */
@@ -464,8 +428,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
   widgetFactoryPlugin,
   logNotebookOutput,
   clonedOutputsPlugin,
-  codeConsolePlugin,
-  toggleHeader
+  codeConsolePlugin
 ];
 export default plugins;