Browse Source

Remove wayward isPalette to unbreak Launcher

eels 4 years ago
parent
commit
9b07e1929d

+ 21 - 25
packages/fileeditor-extension/src/commands.ts

@@ -51,7 +51,7 @@ import {
 
 import { CommandRegistry } from '@lumino/commands';
 
-import { JSONObject, ReadonlyPartialJSONObject } from '@lumino/coreutils';
+import { JSONObject, ReadonlyJSONObject, ReadonlyPartialJSONObject } from '@lumino/coreutils';
 
 import { Menu } from '@lumino/widgets';
 import { TranslationBundle } from '@jupyterlab/translation';
@@ -99,10 +99,10 @@ export namespace CommandIDs {
   export const selectAll = 'fileeditor:select-all';
 }
 
-export interface IExtensionData {
-  iconName?: string;
+export interface IExtensionData extends ReadonlyJSONObject {
   fileExt: string;
   fileTypeName: string;
+  iconName: string;
 }
 
 /**
@@ -870,6 +870,8 @@ export namespace Commands {
 
   /**
    * Add the New File command
+   *
+   * Defaults to Text/.txt if file type data is not specified
    */
   export function addCreateNewCommand(
     commands: CommandRegistry,
@@ -879,12 +881,12 @@ export namespace Commands {
     commands.addCommand(CommandIDs.createNew, {
       label: args => {
         if (args.isPalette) {
-          return trans.__('New %1 File', args.fileType ?? 'Text');
+          return trans.__('New %1 File', args.fileTypeName ?? 'Text');
         }
-        return trans.__('%1 File', args.fileType ?? 'Text');
+        return trans.__('%1 File', args.fileTypeName ?? 'Text');
       },
-      caption: args => trans.__('Create a new %1 file', args.fileType ?? 'text'),
-      icon: args => (args.isPalette ? undefined : (LabIcon.resolve({ icon: args.iconName as string }) ?? textEditorIcon)),
+      caption: args => trans.__('Create a new %1 file', args.fileTypeName ?? 'text'),
+      icon: args => (args.isPalette ? undefined : LabIcon.resolve({ icon: (args.iconName as string ?? textEditorIcon) })),
       execute: args => {
         const cwd = args.cwd || browserFactory.defaultBrowser.model.path;
         return createNew(commands, cwd as string, args.fileExt as string ?? 'txt');
@@ -955,21 +957,19 @@ export namespace Commands {
   }
 
   /**
-   * Add Create New File items for available languages to the launcher
+   * Add ___ File items to the Launcher for common file types associated with available kernels
    */
   export function addKernelLanguageLauncherItems(
     launcher: ILauncher,
     trans: TranslationBundle,
-    availableLanguageExtensions: Set<IExtensionData>
+    availableKernelFileTypes: Set<IExtensionData>
   ): void {
-    for (let ext of availableLanguageExtensions) {
-      const { iconName, ...otherExtData } = ext;
-      const readOnlyExtData = iconName ? ext : otherExtData;
+    for (let ext of availableKernelFileTypes) {
       launcher.add({
         command: CommandIDs.createNew,
         category: trans.__('Other'),
         rank: 3,
-        args: { ...readOnlyExtData, isPalette: true }
+        args: ext
       });
     }
   }
@@ -1064,20 +1064,18 @@ export namespace Commands {
   }
 
   /**
-   * Add available language items to the File Editor palette
+   * Add New ___ File commands to the File Editor palette for common file types associated with available kernels
    */
   export function addKernelLanguagePaletteItems(
     palette: ICommandPalette,
     trans: TranslationBundle,
-    availableLanguageExtensions: Set<IExtensionData>
+    availableKernelFileTypes: Set<IExtensionData>
   ): void {
     const paletteCategory = trans.__('Text Editor');
-    for (let ext of availableLanguageExtensions) {
-      const { iconName, ...otherExtData } = ext;
-      const readOnlyExtData = iconName ? ext : otherExtData;
+    for (let ext of availableKernelFileTypes) {
       palette.addItem({
         command: CommandIDs.createNew,
-        args: { ...readOnlyExtData, isPalette: true },
+        args: { ...ext, isPalette: true },
         category: paletteCategory
       });
     }
@@ -1188,17 +1186,15 @@ export namespace Commands {
   }
 
   /**
-   * Add available language items to the File menu
+   * Add Create New ___ File commands to the File menu for common file types associated with available kernels
    */
   export function addKernelLanguageMenuItems(
     menu: IMainMenu,
-    availableLanguageExtensions: Set<IExtensionData>
+    availableKernelFileTypes: Set<IExtensionData>
   ): void {
-    for (let ext of availableLanguageExtensions) {
-      const { iconName, ...otherExtData } = ext;
-      const readOnlyExtData = iconName ? ext : otherExtData;
+    for (let ext of availableKernelFileTypes) {
       menu.fileMenu.newMenu.addGroup(
-        [{ command: CommandIDs.createNew, args: { ...readOnlyExtData } }],
+        [{ command: CommandIDs.createNew, args: ext }],
         30
       )
     }

+ 3 - 2
packages/fileeditor-extension/src/index.ts

@@ -192,11 +192,12 @@ function activate(
 
   const commonLanguageFileTypeData = new Map<string, IExtensionData[]>([
     ['python', [{ fileExt: 'py', fileTypeName: 'Python', iconName: 'ui-components:python' }]],
-    ['julia', [{ fileExt: 'jl', fileTypeName: 'Julia' }]],
+    ['julia', [{ fileExt: 'jl', fileTypeName: 'Julia', iconName: 'ui-components:text-editor' }]],
     ['R', [{ fileExt: 'r', fileTypeName: 'R', iconName: 'ui-components:r-kernel' }]]
   ]);
 
-  const getAvailableKernelFileTypes = async () => {
+  // Use available kernels to determine which common file types should have 'Create New' options in the Launcher, File Editor palette, and File menu
+  const getAvailableKernelFileTypes = async (): Promise<Set<IExtensionData>> => {
     const specsManager = app.serviceManager.kernelspecs;
     await specsManager.ready;
     let fileTypes = new Set<IExtensionData>();

+ 1 - 1
packages/launcher/src/index.tsx

@@ -331,7 +331,7 @@ export namespace ILauncher {
     /**
      * The category for the launcher item.
      *
-     * The default value is the an empty string.
+     * The default value is an empty string.
      */
     category?: string;