Aligned the electron app to the latest Theia APIs.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2020-09-18 12:23:52 +02:00
committed by Akos Kitta
parent def93ea32f
commit e755a1cd7e
11 changed files with 123 additions and 329 deletions

View File

@@ -1,7 +1,7 @@
import { inject, injectable, interfaces } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { ILogger } from '@theia/core/lib/common/logger';
import { FileSystem } from '@theia/filesystem/lib/common';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { MaybePromise } from '@theia/core/lib/common/types';
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
import { MessageService } from '@theia/core/lib/common/message-service';
@@ -59,8 +59,8 @@ export abstract class Contribution implements CommandContribution, MenuContribut
@injectable()
export abstract class SketchContribution extends Contribution {
@inject(FileSystem)
protected readonly fileSystem: FileSystem;
@inject(FileService)
protected readonly fileService: FileService;
@inject(FileSystemExt)
protected readonly fileSystemExt: FileSystemExt;

View File

@@ -1,5 +1,6 @@
import { injectable } from 'inversify';
import { remote } from 'electron';
import URI from '@theia/core/lib/common/uri';
import { ArduinoMenus } from '../menu/arduino-menus';
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
@@ -30,9 +31,9 @@ export class OpenSketchExternal extends SketchContribution {
protected async openExternal(): Promise<void> {
const uri = await this.sketchServiceClient.currentSketchFile();
if (uri) {
const exists = this.fileSystem.exists(uri);
const exists = this.fileService.exists(new URI(uri));
if (exists) {
const fsPath = await this.fileSystem.getFsPath(uri);
const fsPath = await this.fileService.fsPath(new URI(uri));
if (fsPath) {
remote.shell.showItemInFolder(fsPath);
}

View File

@@ -115,7 +115,7 @@ export class OpenSketch extends SketchContribution {
protected async selectSketch(): Promise<Sketch | undefined> {
const config = await this.configService.getConfiguration();
const defaultPath = await this.fileSystem.getFsPath(config.sketchDirUri);
const defaultPath = await this.fileService.fsPath(new URI(config.sketchDirUri));
const { filePaths } = await remote.dialog.showOpenDialog({
defaultPath,
properties: ['createDirectory', 'openFile'],
@@ -149,7 +149,7 @@ export class OpenSketch extends SketchContribution {
});
if (response === 1) { // OK
const newSketchUri = new URI(sketchFileUri).parent.resolve(name);
const exists = await this.fileSystem.exists(newSketchUri.toString());
const exists = await this.fileService.exists(newSketchUri);
if (exists) {
await remote.dialog.showMessageBox({
type: 'error',
@@ -158,8 +158,8 @@ export class OpenSketch extends SketchContribution {
});
return undefined;
}
await this.fileSystem.createFolder(newSketchUri.toString());
await this.fileSystem.move(sketchFileUri, newSketchUri.resolve(nameWithExt).toString());
await this.fileService.createFolder(newSketchUri);
await this.fileService.move(new URI(sketchFileUri), new URI(newSketchUri.resolve(nameWithExt).toString()));
return this.sketchService.getSketchFolder(newSketchUri.toString());
}
}

View File

@@ -45,11 +45,11 @@ export class SaveAsSketch extends SketchContribution {
// If target does not exist, propose a `directories.user`/${sketch.name} path
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
const sketchDirUri = new URI((await this.configService.getConfiguration()).sketchDirUri);
const exists = await this.fileSystem.exists(sketchDirUri.resolve(sketch.name).toString());
const exists = await this.fileService.exists(sketchDirUri.resolve(sketch.name));
const defaultUri = exists
? sketchDirUri.resolve(sketchDirUri.resolve(`${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`).toString())
: sketchDirUri.resolve(sketch.name);
const defaultPath = await this.fileSystem.getFsPath(defaultUri.toString())!;
const defaultPath = await this.fileService.fsPath(defaultUri);
const { filePath, canceled } = await remote.dialog.showSaveDialog({ title: 'Save sketch folder as...', defaultPath });
if (!filePath || canceled) {
return false;
@@ -61,7 +61,7 @@ export class SaveAsSketch extends SketchContribution {
const workspaceUri = await this.sketchService.copy(sketch, { destinationUri });
if (workspaceUri && openAfterMove) {
if (wipeOriginal) {
await this.fileSystem.delete(sketch.uri);
await this.fileService.delete(new URI(sketch.uri));
}
this.workspaceService.open(new URI(workspaceUri), { preserveWindow: true });
}