浏览代码

Initial version of previous active tab toggle. (#4296)

* Initial version of previous active tab toggle. Keyboard shortcut doesn't seem to work.

* check if the command has already been added.

* update keyboard shortcut to ctrl shift '

* remove trailing white spaces to stop failing travis-ci continuous integration.

* remove trailing white spaces to stop failing travis-ci continuous integration.

* change the name of the command to something more understandable.

* remove trailing whitespace to pass continuous integration tests.

* Change `Ctrl` to `Accel` for OS independence.

* grey out previously used tab command when unusable.

* add previously used tab command to the palette.

* remove trailing whitespaces.
Sergey Kojoian 7 年之前
父节点
当前提交
e377acd19b
共有 2 个文件被更改,包括 43 次插入2 次删除
  1. 34 2
      packages/mainmenu-extension/src/index.ts
  2. 9 0
      packages/shortcuts-extension/schema/plugin.json

+ 34 - 2
packages/mainmenu-extension/src/index.ts

@@ -28,6 +28,9 @@ import {
  */
 export
 namespace CommandIDs {
+  export
+  const activatePreviouslyUsedTab = 'tabmenu:activate-previously-used-tab';
+
   export
   const undo = 'editmenu:undo';
 
@@ -125,6 +128,11 @@ const menuPlugin: JupyterLabPlugin<IMainMenu> = {
       category: 'Kernel Operations'
     });
 
+    palette.addItem({
+      command: CommandIDs.activatePreviouslyUsedTab,
+      category: 'Main Area'
+    });
+
     app.shell.addToTopArea(logo);
     app.shell.addToTopArea(menu);
 
@@ -463,10 +471,10 @@ function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
   // Add commands for cycling the active tabs.
   menu.addGroup([
     { command: 'application:activate-next-tab' },
-    { command: 'application:activate-previous-tab' }
+    { command: 'application:activate-previous-tab' },
+    { command: CommandIDs.activatePreviouslyUsedTab }
   ], 0);
 
-
   let tabGroup: Menu.IItemOptions[] = [];
 
   // Utility function to create a command to activate
@@ -485,6 +493,16 @@ function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
     return { command: commandID };
   };
 
+  let previousId = '';
+
+  // Command to toggle between the current
+  // tab and the last modified tab.
+  commands.addCommand(CommandIDs.activatePreviouslyUsedTab, {
+    label: 'Activate Previously Used Tab',
+    isEnabled: () => !!previousId,
+    execute: () => previousId && app.commands.execute(`tabmenu:activate-${previousId}`)
+  });
+
   app.restored.then(() => {
     // Iterate over the current widgets in the
     // main area, and add them to the tab group
@@ -492,13 +510,27 @@ function createTabsMenu(app: JupyterLab, menu: TabsMenu): void {
     const populateTabs = () => {
       menu.removeGroup(tabGroup);
       tabGroup.length = 0;
+      let isPreviouslyUsedTabAttached = false;
       each(app.shell.widgets('main'), widget => {
+        if (widget.id === previousId) {
+          isPreviouslyUsedTabAttached = true;
+        }
         tabGroup.push(createMenuItem(widget));
       });
       menu.addGroup(tabGroup, 1);
+      previousId = isPreviouslyUsedTabAttached ? previousId : '';
     };
     populateTabs();
     app.shell.layoutModified.connect(() => { populateTabs(); });
+    // Update the id of the previous active tab if
+    // a new tab is selected.
+    app.shell.currentChanged.connect((sender, args) => {
+      let widget = args.oldValue;
+      if (!widget) {
+        return;
+      }
+      previousId = widget.id;
+    });
   });
 }
 

+ 9 - 0
packages/shortcuts-extension/schema/plugin.json

@@ -22,6 +22,15 @@
       },
       "type": "object"
     },
+    "tabmenu:activate-previously-used-tab": {
+      "default": { },
+      "properties": {
+        "command": { "default": "tabmenu:activate-previously-used-tab" },
+        "keys": { "default": ["Accel Shift '"] },
+        "selector": { "default": "body" }
+      },
+      "type": "object"
+    },
     "application:toggle-mode": {
       "default": { },
       "properties": {