Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
M src/main/java/com/keenwrite/MainPane.java
1414
import com.keenwrite.events.spelling.LexiconLoadedEvent;
1515
import com.keenwrite.io.MediaType;
16
import com.keenwrite.io.MediaTypeExtension;
1617
import com.keenwrite.preferences.Workspace;
1718
import com.keenwrite.preview.HtmlPreview;
...
7374
import static com.keenwrite.events.StatusEvent.clue;
7475
import static com.keenwrite.io.MediaType.*;
76
import static com.keenwrite.io.MediaType.TypeName.TEXT;
7577
import static com.keenwrite.preferences.AppKeys.*;
7678
import static com.keenwrite.processors.IdentityProcessor.IDENTITY;
7779
import static com.keenwrite.processors.ProcessorContext.Mutator;
7880
import static com.keenwrite.processors.ProcessorContext.builder;
7981
import static com.keenwrite.processors.ProcessorFactory.createProcessors;
82
import static java.awt.Desktop.getDesktop;
8083
import static java.util.concurrent.Executors.newFixedThreadPool;
8184
import static java.util.concurrent.Executors.newScheduledThreadPool;
...
282285
    }
283286
284
    runLater( () -> open( eventFile ) );
287
    final var mediaType = MediaTypeExtension.fromFile( eventFile );
288
289
    runLater( () -> {
290
      // Open text files locally.
291
      if( mediaType.isType( TEXT ) ) {
292
        open( eventFile );
293
      }
294
      else {
295
        try {
296
          // Delegate opening all other file types to the operating system.
297
          getDesktop().open( eventFile );
298
        } catch( final Exception ex ) {
299
          clue( ex );
300
        }
301
      }
302
    } );
285303
  }
286304
M src/main/java/com/keenwrite/io/MediaTypeExtension.java
22
package com.keenwrite.io;
33
4
import org.apache.commons.io.FilenameUtils;
5
6
import java.io.File;
47
import java.util.List;
58
...
8689
8790
    return UNDEFINED;
91
  }
92
93
  /**
94
   * Returns the {@link MediaType} associated with the given file.
95
   *
96
   * @param file The file having an extension to map to a {@link MediaType}.
97
   * @return The associated {@link MediaType} as defined by IANA.
98
   */
99
  public static MediaType fromFile( final File file ) {
100
    return fromExtension( FilenameUtils.getExtension( file.getName() ) );
88101
  }
89102