浏览代码

Backport PR #12532: Add "Open in Simple Mode" contextMenu option (#12577)

Co-authored-by: Divyansh Choudhary <divyanshchoudhary99@gmail.com>
Frédéric Collonval 2 年之前
父节点
当前提交
9cd6511758
共有 3 个文件被更改,包括 50 次插入5 次删除
  1. 1 0
      docs/source/index.rst
  2. 25 0
      docs/source/user/ui_customization.rst
  3. 24 5
      packages/filebrowser-extension/src/index.ts

+ 1 - 0
docs/source/index.rst

@@ -48,6 +48,7 @@ JupyterLab is the next-generation web-based user interface for Project Jupyter.
    user/export
    user/language
    user/rtc
+   user/ui_customization
    user/directories
 
 .. toctree::

+ 25 - 0
docs/source/user/ui_customization.rst

@@ -0,0 +1,25 @@
+.. _interface-customization:
+
+Interface Customization
+=======================
+
+You can customize some elements of the interface through settings.
+
+.. _context-menu-customization:
+
+Context Menu
+------------
+
+File Browser
+^^^^^^^^^^^^
+
+Users can add a "Open in Simple Mode" context menu option by adding the following to *Settings* -> *Application Context Menu* -> ``contextMenu``
+
+.. code:: json
+
+    {
+        "command": "filebrowser:open-browser-tab",
+        "args": { "mode": "single-document" },
+        "selector": ".jp-DirListing-item[data-isdir=\"false\"]",
+        "rank": 1.6
+    }

+ 24 - 5
packages/filebrowser-extension/src/index.ts

@@ -632,25 +632,44 @@ const openBrowserTabPlugin: JupyterFrontEndPlugin<void> = {
     const { tracker } = factory;
 
     commands.addCommand(CommandIDs.openBrowserTab, {
-      execute: () => {
+      execute: args => {
         const widget = tracker.currentWidget;
 
         if (!widget) {
           return;
         }
 
+        const mode = args['mode'] as string | undefined;
+
         return Promise.all(
           toArray(
             map(widget.selectedItems(), item => {
-              return commands.execute('docmanager:open-browser-tab', {
-                path: item.path
-              });
+              if (mode === 'single-document') {
+                const url = PageConfig.getUrl({
+                  mode: 'single-document',
+                  treePath: item.path
+                });
+                const opened = window.open();
+                if (opened) {
+                  opened.opener = null;
+                  opened.location.href = url;
+                } else {
+                  throw new Error('Failed to open new browser tab.');
+                }
+              } else {
+                return commands.execute('docmanager:open-browser-tab', {
+                  path: item.path
+                });
+              }
             })
           )
         );
       },
       icon: addIcon.bindprops({ stylesheet: 'menuItem' }),
-      label: trans.__('Open in New Browser Tab'),
+      label: args =>
+        args['mode'] === 'single-document'
+          ? trans.__('Open in Simple Mode')
+          : trans.__('Open in New Browser Tab'),
       mnemonic: 0
     });
   }