소스 검색

removed DocumentRegistry.FileType and reverts all usages to IFileType

- automagic upconversion of file type icons will now only occur for
the rendermime-interfaces version of IFileType.icon from
rendermime-interfaces. Conversely, all icons specified in the docregistry
version of IFileType.icon will need to be full JLIcon instances in the first
place
telamonian 5 년 전
부모
커밋
126a78e833

+ 2 - 5
packages/docregistry/src/mimedocument.ts

@@ -264,10 +264,7 @@ export class MimeDocumentFactory extends ABCWidgetFactory<MimeDocument> {
     this._rendermime = options.rendermime;
     this._renderTimeout = options.renderTimeout || 1000;
     this._dataType = options.dataType || 'string';
-
-    // resolve the passed in IFileType to a FileType
-    const ft = options.primaryFileType;
-    this._fileType = ft ? DocumentRegistry.FileType.resolve(ft) : ft;
+    this._fileType = options.primaryFileType;
   }
 
   /**
@@ -302,7 +299,7 @@ export class MimeDocumentFactory extends ABCWidgetFactory<MimeDocument> {
   private _rendermime: IRenderMimeRegistry;
   private _renderTimeout: number;
   private _dataType: 'string' | 'json';
-  private _fileType: DocumentRegistry.FileType | undefined;
+  private _fileType: DocumentRegistry.IFileType | undefined;
 }
 
 /**

+ 118 - 150
packages/docregistry/src/registry.ts

@@ -64,11 +64,14 @@ export class DocumentRegistry implements IDisposable {
     }
     this._modelFactories['text'] = factory || new TextModelFactory();
 
-    let fts =
-      options.initialFileTypes?.map(ft =>
-        DocumentRegistry.FileType.resolve(ft)
-      ) || DocumentRegistry.defaultFileTypes;
-    fts.forEach(ft => this._fileTypes.push(ft));
+    let fts = options.initialFileTypes || DocumentRegistry.defaultFileTypes;
+    fts.forEach(ft => {
+      let value: DocumentRegistry.IFileType = {
+        ...DocumentRegistry.fileTypeDefaults,
+        ...ft
+      };
+      this._fileTypes.push(value);
+    });
   }
 
   /**
@@ -287,7 +290,7 @@ export class DocumentRegistry implements IDisposable {
       ...DocumentRegistry.fileTypeDefaults,
       ...fileType
     };
-    this._fileTypes.push(DocumentRegistry.FileType.resolve(value));
+    this._fileTypes.push(value);
 
     this._changed.emit({
       type: 'fileType',
@@ -554,7 +557,7 @@ export class DocumentRegistry implements IDisposable {
   /**
    * Get a file type by name.
    */
-  getFileType(name: string): DocumentRegistry.FileType | undefined {
+  getFileType(name: string): DocumentRegistry.IFileType | undefined {
     name = name.toLowerCase();
     return find(this._fileTypes, fileType => {
       return fileType.name.toLowerCase() === name;
@@ -608,7 +611,7 @@ export class DocumentRegistry implements IDisposable {
    */
   getFileTypeForModel(
     model: Partial<Contents.IModel>
-  ): DocumentRegistry.FileType {
+  ): DocumentRegistry.IFileType {
     switch (model.type) {
       case 'directory':
         return (
@@ -640,8 +643,8 @@ export class DocumentRegistry implements IDisposable {
    *
    * @returns An ordered list of matching file types.
    */
-  getFileTypesForPath(path: string): DocumentRegistry.FileType[] {
-    let fts: DocumentRegistry.FileType[] = [];
+  getFileTypesForPath(path: string): DocumentRegistry.IFileType[] {
+    let fts: DocumentRegistry.IFileType[] = [];
     let name = PathExt.basename(path);
 
     // Look for a pattern match first.
@@ -688,7 +691,7 @@ export class DocumentRegistry implements IDisposable {
   private _widgetFactoriesForFileType: {
     [key: string]: string[];
   } = Object.create(null);
-  private _fileTypes: DocumentRegistry.FileType[] = [];
+  private _fileTypes: DocumentRegistry.IFileType[] = [];
   private _extenders: {
     [key: string]: DocumentRegistry.WidgetExtension[];
   } = Object.create(null);
@@ -1211,39 +1214,6 @@ export namespace DocumentRegistry {
     fileFormat: 'text'
   };
 
-  /**
-   * A wrapper for IFileTypes
-   */
-  export class FileType implements IFileType {
-    static resolve(ft: Partial<IFileType>): FileType {
-      if (ft instanceof FileType) {
-        return ft;
-      }
-
-      return new FileType(ft);
-    }
-
-    constructor(options: Partial<IFileType>) {
-      Object.assign(this, fileTypeDefaults, options);
-
-      if (this.icon) {
-        // ensure that the icon is resolved to a JLIcon
-        this.icon = JLIcon.resolve(this.icon);
-      }
-    }
-
-    readonly name: string;
-    readonly mimeTypes: ReadonlyArray<string>;
-    readonly extensions: ReadonlyArray<string>;
-    readonly displayName: string;
-    readonly pattern: string;
-    readonly icon?: JLIcon;
-    readonly iconClass: string;
-    readonly iconLabel: string;
-    readonly contentType: Contents.ContentType;
-    readonly fileFormat: Contents.FileFormat;
-  }
-
   /**
    * An arguments object for the `changed` signal.
    */
@@ -1271,18 +1241,18 @@ export namespace DocumentRegistry {
   /**
    * The default text file type used by the document registry.
    */
-  export const defaultTextFileType = new FileType({
+  export const defaultTextFileType: IFileType = {
     ...fileTypeDefaults,
     name: 'text',
     mimeTypes: ['text/plain'],
     extensions: ['.txt'],
     icon: fileIcon
-  });
+  };
 
   /**
    * The default notebook file type used by the document registry.
    */
-  export const defaultNotebookFileType = new FileType({
+  export const defaultNotebookFileType: IFileType = {
     ...fileTypeDefaults,
     name: 'notebook',
     displayName: 'Notebook',
@@ -1291,126 +1261,124 @@ export namespace DocumentRegistry {
     contentType: 'notebook',
     fileFormat: 'json',
     icon: notebookIcon
-  });
+  };
 
   /**
    * The default directory file type used by the document registry.
    */
-  export const defaultDirectoryFileType = new FileType({
+  export const defaultDirectoryFileType: IFileType = {
     ...fileTypeDefaults,
     name: 'directory',
     extensions: [],
     mimeTypes: ['text/directory'],
     contentType: 'directory',
     icon: folderIcon
-  });
+  };
 
   /**
    * The default file types used by the document registry.
    */
-  export const defaultFileTypes: ReadonlyArray<FileType> = [
+  export const defaultFileTypes: ReadonlyArray<Partial<IFileType>> = [
     defaultTextFileType,
     defaultNotebookFileType,
     defaultDirectoryFileType,
-    ...[
-      {
-        name: 'markdown',
-        displayName: 'Markdown File',
-        extensions: ['.md'],
-        mimeTypes: ['text/markdown'],
-        icon: markdownIcon
-      },
-      {
-        name: 'python',
-        displayName: 'Python File',
-        extensions: ['.py'],
-        mimeTypes: ['text/x-python'],
-        icon: pythonIcon
-      },
-      {
-        name: 'json',
-        displayName: 'JSON File',
-        extensions: ['.json'],
-        mimeTypes: ['application/json'],
-        icon: jsonIcon
-      },
-      {
-        name: 'csv',
-        displayName: 'CSV File',
-        extensions: ['.csv'],
-        mimeTypes: ['text/csv'],
-        icon: spreadsheetIcon
-      },
-      {
-        name: 'tsv',
-        displayName: 'TSV File',
-        extensions: ['.tsv'],
-        mimeTypes: ['text/csv'],
-        icon: spreadsheetIcon
-      },
-      {
-        name: 'r',
-        displayName: 'R File',
-        mimeTypes: ['text/x-rsrc'],
-        extensions: ['.r'],
-        icon: rKernelIcon
-      },
-      {
-        name: 'yaml',
-        displayName: 'YAML File',
-        mimeTypes: ['text/x-yaml', 'text/yaml'],
-        extensions: ['.yaml', '.yml'],
-        icon: yamlIcon
-      },
-      {
-        name: 'svg',
-        displayName: 'Image',
-        mimeTypes: ['image/svg+xml'],
-        extensions: ['.svg'],
-        icon: imageIcon,
-        fileFormat: 'base64'
-      },
-      {
-        name: 'tiff',
-        displayName: 'Image',
-        mimeTypes: ['image/tiff'],
-        extensions: ['.tif', '.tiff'],
-        icon: imageIcon,
-        fileFormat: 'base64'
-      },
-      {
-        name: 'jpeg',
-        displayName: 'Image',
-        mimeTypes: ['image/jpeg'],
-        extensions: ['.jpg', '.jpeg'],
-        icon: imageIcon,
-        fileFormat: 'base64'
-      },
-      {
-        name: 'gif',
-        displayName: 'Image',
-        mimeTypes: ['image/gif'],
-        extensions: ['.gif'],
-        icon: imageIcon,
-        fileFormat: 'base64'
-      },
-      {
-        name: 'png',
-        displayName: 'Image',
-        mimeTypes: ['image/png'],
-        extensions: ['.png'],
-        icon: imageIcon,
-        fileFormat: 'base64'
-      },
-      {
-        name: 'bmp',
-        displayName: 'Image',
-        mimeTypes: ['image/bmp'],
-        extensions: ['.bmp'],
-        icon: imageIcon,
-        fileFormat: 'base64'
-      }
-    ].map(ft => new FileType(ft as Partial<IFileType>))
+    {
+      name: 'markdown',
+      displayName: 'Markdown File',
+      extensions: ['.md'],
+      mimeTypes: ['text/markdown'],
+      icon: markdownIcon
+    },
+    {
+      name: 'python',
+      displayName: 'Python File',
+      extensions: ['.py'],
+      mimeTypes: ['text/x-python'],
+      icon: pythonIcon
+    },
+    {
+      name: 'json',
+      displayName: 'JSON File',
+      extensions: ['.json'],
+      mimeTypes: ['application/json'],
+      icon: jsonIcon
+    },
+    {
+      name: 'csv',
+      displayName: 'CSV File',
+      extensions: ['.csv'],
+      mimeTypes: ['text/csv'],
+      icon: spreadsheetIcon
+    },
+    {
+      name: 'tsv',
+      displayName: 'TSV File',
+      extensions: ['.tsv'],
+      mimeTypes: ['text/csv'],
+      icon: spreadsheetIcon
+    },
+    {
+      name: 'r',
+      displayName: 'R File',
+      mimeTypes: ['text/x-rsrc'],
+      extensions: ['.r'],
+      icon: rKernelIcon
+    },
+    {
+      name: 'yaml',
+      displayName: 'YAML File',
+      mimeTypes: ['text/x-yaml', 'text/yaml'],
+      extensions: ['.yaml', '.yml'],
+      icon: yamlIcon
+    },
+    {
+      name: 'svg',
+      displayName: 'Image',
+      mimeTypes: ['image/svg+xml'],
+      extensions: ['.svg'],
+      icon: imageIcon,
+      fileFormat: 'base64'
+    },
+    {
+      name: 'tiff',
+      displayName: 'Image',
+      mimeTypes: ['image/tiff'],
+      extensions: ['.tif', '.tiff'],
+      icon: imageIcon,
+      fileFormat: 'base64'
+    },
+    {
+      name: 'jpeg',
+      displayName: 'Image',
+      mimeTypes: ['image/jpeg'],
+      extensions: ['.jpg', '.jpeg'],
+      icon: imageIcon,
+      fileFormat: 'base64'
+    },
+    {
+      name: 'gif',
+      displayName: 'Image',
+      mimeTypes: ['image/gif'],
+      extensions: ['.gif'],
+      icon: imageIcon,
+      fileFormat: 'base64'
+    },
+    {
+      name: 'png',
+      displayName: 'Image',
+      mimeTypes: ['image/png'],
+      extensions: ['.png'],
+      icon: imageIcon,
+      fileFormat: 'base64'
+    },
+    {
+      name: 'bmp',
+      displayName: 'Image',
+      mimeTypes: ['image/bmp'],
+      extensions: ['.bmp'],
+      icon: imageIcon,
+      fileFormat: 'base64'
+    }
   ];
 }
 

+ 4 - 4
packages/filebrowser/src/listing.ts

@@ -1657,7 +1657,7 @@ export namespace DirListing {
     updateItemNode(
       node: HTMLElement,
       model: Contents.IModel,
-      fileType?: DocumentRegistry.FileType
+      fileType?: DocumentRegistry.IFileType
     ): void;
 
     /**
@@ -1683,7 +1683,7 @@ export namespace DirListing {
     createDragImage(
       node: HTMLElement,
       count: number,
-      fileType?: DocumentRegistry.FileType
+      fileType?: DocumentRegistry.IFileType
     ): HTMLElement;
   }
 
@@ -1830,7 +1830,7 @@ export namespace DirListing {
     updateItemNode(
       node: HTMLElement,
       model: Contents.IModel,
-      fileType?: DocumentRegistry.FileType
+      fileType?: DocumentRegistry.IFileType
     ): void {
       const iconContainer = DOMUtils.findElement(node, ITEM_ICON_CLASS);
       const text = DOMUtils.findElement(node, ITEM_TEXT_CLASS);
@@ -1932,7 +1932,7 @@ export namespace DirListing {
     createDragImage(
       node: HTMLElement,
       count: number,
-      fileType?: DocumentRegistry.FileType
+      fileType?: DocumentRegistry.IFileType
     ): HTMLElement {
       let dragImage = node.cloneNode(true) as HTMLElement;
       let modified = DOMUtils.findElement(dragImage, ITEM_MODIFIED_CLASS);

+ 2 - 2
packages/htmlviewer-extension/src/index.tsx

@@ -48,7 +48,7 @@ function activateHTMLViewer(
   restorer: ILayoutRestorer | null
 ): IHTMLViewerTracker {
   // Add an HTML file type to the docregistry.
-  const ft = new DocumentRegistry.FileType({
+  const ft: DocumentRegistry.IFileType = {
     name: 'html',
     contentType: 'file',
     fileFormat: 'text',
@@ -56,7 +56,7 @@ function activateHTMLViewer(
     extensions: ['.html'],
     mimeTypes: ['text/html'],
     icon: html5Icon
-  });
+  };
   app.docRegistry.addFileType(ft);
 
   // Create a new viewer factory.

+ 2 - 5
packages/markdownviewer/src/widget.ts

@@ -294,11 +294,8 @@ export class MarkdownViewerFactory extends ABCWidgetFactory<MarkdownDocument> {
    */
   constructor(options: MarkdownViewerFactory.IOptions) {
     super(Private.createRegistryOptions(options));
+    this._fileType = options.primaryFileType;
     this._rendermime = options.rendermime;
-
-    // resolve the passed in IFileType to a FileType
-    const ft = options.primaryFileType;
-    this._fileType = ft ? DocumentRegistry.FileType.resolve(ft) : ft;
   }
 
   /**
@@ -320,7 +317,7 @@ export class MarkdownViewerFactory extends ABCWidgetFactory<MarkdownDocument> {
     return widget;
   }
 
-  private _fileType: DocumentRegistry.FileType | undefined;
+  private _fileType: DocumentRegistry.IFileType | undefined;
   private _rendermime: IRenderMimeRegistry;
 }