Made the file dialogs modal.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2022-08-04 14:41:35 +02:00 committed by Akos Kitta
parent 42f6f43870
commit 6a35bbfa7e
6 changed files with 68 additions and 54 deletions

View File

@ -15,7 +15,7 @@ import { CurrentSketch } from '../../common/protocol/sketches-service-client-imp
@injectable() @injectable()
export class AddFile extends SketchContribution { export class AddFile extends SketchContribution {
@inject(FileDialogService) @inject(FileDialogService)
protected readonly fileDialogService: FileDialogService; private readonly fileDialogService: FileDialogService;
override registerCommands(registry: CommandRegistry): void { override registerCommands(registry: CommandRegistry): void {
registry.registerCommand(AddFile.Commands.ADD_FILE, { registry.registerCommand(AddFile.Commands.ADD_FILE, {
@ -31,7 +31,7 @@ export class AddFile extends SketchContribution {
}); });
} }
protected async addFile(): Promise<void> { private async addFile(): Promise<void> {
const sketch = await this.sketchServiceClient.currentSketch(); const sketch = await this.sketchServiceClient.currentSketch();
if (!CurrentSketch.isValid(sketch)) { if (!CurrentSketch.isValid(sketch)) {
return; return;
@ -41,6 +41,7 @@ export class AddFile extends SketchContribution {
canSelectFiles: true, canSelectFiles: true,
canSelectFolders: false, canSelectFolders: false,
canSelectMany: false, canSelectMany: false,
modal: true,
}); });
if (!toAddUri) { if (!toAddUri) {
return; return;

View File

@ -17,13 +17,13 @@ import { nls } from '@theia/core/lib/common';
@injectable() @injectable()
export class AddZipLibrary extends SketchContribution { export class AddZipLibrary extends SketchContribution {
@inject(EnvVariablesServer) @inject(EnvVariablesServer)
protected readonly envVariableServer: EnvVariablesServer; private readonly envVariableServer: EnvVariablesServer;
@inject(ResponseServiceClient) @inject(ResponseServiceClient)
protected readonly responseService: ResponseServiceClient; private readonly responseService: ResponseServiceClient;
@inject(LibraryService) @inject(LibraryService)
protected readonly libraryService: LibraryService; private readonly libraryService: LibraryService;
override registerCommands(registry: CommandRegistry): void { override registerCommands(registry: CommandRegistry): void {
registry.registerCommand(AddZipLibrary.Commands.ADD_ZIP_LIBRARY, { registry.registerCommand(AddZipLibrary.Commands.ADD_ZIP_LIBRARY, {
@ -43,23 +43,26 @@ export class AddZipLibrary extends SketchContribution {
}); });
} }
async addZipLibrary(): Promise<void> { private async addZipLibrary(): Promise<void> {
const homeUri = await this.envVariableServer.getHomeDirUri(); const homeUri = await this.envVariableServer.getHomeDirUri();
const defaultPath = await this.fileService.fsPath(new URI(homeUri)); const defaultPath = await this.fileService.fsPath(new URI(homeUri));
const { canceled, filePaths } = await remote.dialog.showOpenDialog({ const { canceled, filePaths } = await remote.dialog.showOpenDialog(
title: nls.localize( remote.getCurrentWindow(),
'arduino/selectZip', {
"Select a zip file containing the library you'd like to add" title: nls.localize(
), 'arduino/selectZip',
defaultPath, "Select a zip file containing the library you'd like to add"
properties: ['openFile'], ),
filters: [ defaultPath,
{ properties: ['openFile'],
name: nls.localize('arduino/library/zipLibrary', 'Library'), filters: [
extensions: ['zip'], {
}, name: nls.localize('arduino/library/zipLibrary', 'Library'),
], extensions: ['zip'],
}); },
],
}
);
if (!canceled && filePaths.length) { if (!canceled && filePaths.length) {
const zipUri = await this.fileSystemExt.getUri(filePaths[0]); const zipUri = await this.fileSystemExt.getUri(filePaths[0]);
try { try {

View File

@ -28,7 +28,7 @@ export class ArchiveSketch extends SketchContribution {
}); });
} }
protected async archiveSketch(): Promise<void> { private async archiveSketch(): Promise<void> {
const [sketch, config] = await Promise.all([ const [sketch, config] = await Promise.all([
this.sketchServiceClient.currentSketch(), this.sketchServiceClient.currentSketch(),
this.configService.getConfiguration(), this.configService.getConfiguration(),
@ -43,13 +43,16 @@ export class ArchiveSketch extends SketchContribution {
const defaultPath = await this.fileService.fsPath( const defaultPath = await this.fileService.fsPath(
new URI(config.sketchDirUri).resolve(archiveBasename) new URI(config.sketchDirUri).resolve(archiveBasename)
); );
const { filePath, canceled } = await remote.dialog.showSaveDialog({ const { filePath, canceled } = await remote.dialog.showSaveDialog(
title: nls.localize( remote.getCurrentWindow(),
'arduino/sketch/saveSketchAs', {
'Save sketch folder as...' title: nls.localize(
), 'arduino/sketch/saveSketchAs',
defaultPath, 'Save sketch folder as...'
}); ),
defaultPath,
}
);
if (!filePath || canceled) { if (!filePath || canceled) {
return; return;
} }

View File

@ -26,21 +26,21 @@ import { nls } from '@theia/core/lib/common';
@injectable() @injectable()
export class OpenSketch extends SketchContribution { export class OpenSketch extends SketchContribution {
@inject(MenuModelRegistry) @inject(MenuModelRegistry)
protected readonly menuRegistry: MenuModelRegistry; private readonly menuRegistry: MenuModelRegistry;
@inject(ContextMenuRenderer) @inject(ContextMenuRenderer)
protected readonly contextMenuRenderer: ContextMenuRenderer; private readonly contextMenuRenderer: ContextMenuRenderer;
@inject(BuiltInExamples) @inject(BuiltInExamples)
protected readonly builtInExamples: BuiltInExamples; private readonly builtInExamples: BuiltInExamples;
@inject(ExamplesService) @inject(ExamplesService)
protected readonly examplesService: ExamplesService; private readonly examplesService: ExamplesService;
@inject(Sketchbook) @inject(Sketchbook)
protected readonly sketchbook: Sketchbook; private readonly sketchbook: Sketchbook;
protected readonly toDispose = new DisposableCollection(); private readonly toDispose = new DisposableCollection();
override registerCommands(registry: CommandRegistry): void { override registerCommands(registry: CommandRegistry): void {
registry.registerCommand(OpenSketch.Commands.OPEN_SKETCH, { registry.registerCommand(OpenSketch.Commands.OPEN_SKETCH, {
@ -130,7 +130,7 @@ export class OpenSketch extends SketchContribution {
}); });
} }
async openSketch( private async openSketch(
toOpen: MaybePromise<Sketch | undefined> = this.selectSketch() toOpen: MaybePromise<Sketch | undefined> = this.selectSketch()
): Promise<void> { ): Promise<void> {
const sketch = await toOpen; const sketch = await toOpen;
@ -139,21 +139,24 @@ export class OpenSketch extends SketchContribution {
} }
} }
protected async selectSketch(): Promise<Sketch | undefined> { private async selectSketch(): Promise<Sketch | undefined> {
const config = await this.configService.getConfiguration(); const config = await this.configService.getConfiguration();
const defaultPath = await this.fileService.fsPath( const defaultPath = await this.fileService.fsPath(
new URI(config.sketchDirUri) new URI(config.sketchDirUri)
); );
const { filePaths } = await remote.dialog.showOpenDialog({ const { filePaths } = await remote.dialog.showOpenDialog(
defaultPath, remote.getCurrentWindow(),
properties: ['createDirectory', 'openFile'], {
filters: [ defaultPath,
{ properties: ['createDirectory', 'openFile'],
name: nls.localize('arduino/sketch/sketch', 'Sketch'), filters: [
extensions: ['ino', 'pde'], {
}, name: nls.localize('arduino/sketch/sketch', 'Sketch'),
], extensions: ['ino', 'pde'],
}); },
],
}
);
if (!filePaths.length) { if (!filePaths.length) {
return undefined; return undefined;
} }

View File

@ -50,7 +50,7 @@ export class SaveAsSketch extends SketchContribution {
/** /**
* Resolves `true` if the sketch was successfully saved as something. * Resolves `true` if the sketch was successfully saved as something.
*/ */
async saveAs( private async saveAs(
{ {
execOnlyIfTemp, execOnlyIfTemp,
openAfterMove, openAfterMove,
@ -82,13 +82,16 @@ export class SaveAsSketch extends SketchContribution {
: sketch.name : sketch.name
); );
const defaultPath = await this.fileService.fsPath(defaultUri); const defaultPath = await this.fileService.fsPath(defaultUri);
const { filePath, canceled } = await remote.dialog.showSaveDialog({ const { filePath, canceled } = await remote.dialog.showSaveDialog(
title: nls.localize( remote.getCurrentWindow(),
'arduino/sketch/saveFolderAs', {
'Save sketch folder as...' title: nls.localize(
), 'arduino/sketch/saveFolderAs',
defaultPath, 'Save sketch folder as...'
}); ),
defaultPath,
}
);
if (!filePath || canceled) { if (!filePath || canceled) {
return false; return false;
} }

View File

@ -502,6 +502,7 @@ export class SettingsComponent extends React.Component<
canSelectFiles: false, canSelectFiles: false,
canSelectMany: false, canSelectMany: false,
canSelectFolders: true, canSelectFolders: true,
modal: true,
}); });
if (uri) { if (uri) {
const sketchbookPath = await this.props.fileService.fsPath(uri); const sketchbookPath = await this.props.fileService.fsPath(uri);