소스 검색

Update setting editor extension.

Afshin Darian 8 년 전
부모
커밋
90aaacce03
3개의 변경된 파일37개의 추가작업 그리고 17개의 파일을 삭제
  1. 8 8
      packages/apputils-extension/src/index.ts
  2. 27 9
      packages/apputils-extension/src/settingeditor.ts
  3. 2 0
      packages/help-extension/src/index.ts

+ 8 - 8
packages/apputils-extension/src/index.ts

@@ -3,14 +3,6 @@
 | Distributed under the terms of the Modified BSD License.
 |----------------------------------------------------------------------------*/
 
-import {
-  JSONObject
-} from '@phosphor/coreutils';
-
-import {
-  Widget
-} from '@phosphor/widgets';
-
 import {
   JupyterLab, JupyterLabPlugin
 } from '@jupyterlab/application';
@@ -24,6 +16,14 @@ import {
   ISettingRegistry, IStateDB, SettingRegistry, StateDB
 } from '@jupyterlab/coreutils';
 
+import {
+  JSONObject
+} from '@phosphor/coreutils';
+
+import {
+  Widget
+} from '@phosphor/widgets';
+
 import {
   activatePalette
 } from './palette';

+ 27 - 9
packages/apputils-extension/src/settingeditor.ts

@@ -12,9 +12,12 @@ import {
 } from '@jupyterlab/apputils';
 
 import {
-  ISettingRegistry
+  InstanceTracker, ISettingRegistry
 } from '@jupyterlab/coreutils';
 
+import {
+  Message
+} from '@phosphor/messaging';
 
 import {
   Widget
@@ -24,6 +27,13 @@ import {
  * An interface for modifying and saving application settings.
  */
 class SettingEditor extends Widget {
+  /**
+   * Handle `'activate-request'` messages.
+   */
+  protected onActivateRequest(msg: Message): void {
+    this.node.tabIndex = -1;
+    this.node.focus();
+  }
 }
 
 
@@ -32,7 +42,7 @@ class SettingEditor extends Widget {
  */
 namespace CommandIDs {
   export
-  const activate = 'setting-editor:activate';
+  const open = 'setting-editor:open';
 };
 
 
@@ -42,22 +52,30 @@ namespace CommandIDs {
 export
 function activateSettingEditor(app: JupyterLab, restorer: ILayoutRestorer, settings: ISettingRegistry): void {
   const { commands, shell } = app;
+  const namespace = 'setting-editor';
   const editor = new SettingEditor();
+  const tracker = new InstanceTracker<SettingEditor>({ namespace });
 
-  // Let the application restorer track the setting editor for restoration of
-  // application state.
-  restorer.add(editor, 'setting-editor');
-
-  editor.id = 'setting-editor';
+  editor.id = namespace;
   editor.title.label = 'Settings';
+  editor.title.closable = true;
+
+  // Handle state restoration.
+  restorer.restore(tracker, {
+    command: CommandIDs.open,
+    args: widget => ({ }),
+    name: widget => namespace
+  });
+  tracker.add(editor);
 
-  commands.addCommand(CommandIDs.activate, {
+  commands.addCommand(CommandIDs.open, {
     execute: () => {
+      console.log('this command was called');
       if (editor.parent === null) {
         shell.addToMainArea(editor);
       }
       shell.activateById(editor.id);
     },
-    label: 'Activate Setting Editor'
+    label: 'Settings'
   });
 }

+ 2 - 0
packages/help-extension/src/index.ts

@@ -201,6 +201,7 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
     menu.addItem({ type: 'separator' });
     RESOURCES.forEach(args => { menu.addItem({ args, command }); });
     menu.addItem({ type: 'separator' });
+    menu.addItem({ command: 'setting-editor:open' });
     menu.addItem({ command: 'statedb:clear' });
 
     return menu;
@@ -231,6 +232,7 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
   });
 
   RESOURCES.forEach(args => { palette.addItem({ args, command, category }); });
+  palette.addItem({ command: 'setting-editor:open', category });
   palette.addItem({ command: 'statedb:clear', category });
   palette.addItem({ command: CommandIDs.launchClassic, category });