Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7451 [showSaveDialog] incompatible with VSCode #7461

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/plugin-ext/src/main/browser/dialogs-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
import { interfaces } from 'inversify';
import { RPCProtocol } from '../../common/rpc-protocol';
import { OpenDialogOptionsMain, SaveDialogOptionsMain, DialogsMain, UploadDialogOptionsMain } from '../../common/plugin-api-rpc';
import { DirNode, OpenFileDialogProps, SaveFileDialogProps, OpenFileDialogFactory, SaveFileDialogFactory } from '@theia/filesystem/lib/browser';
import { DirNode, OpenFileDialogProps, SaveFileDialogProps, OpenFileDialogFactory, SaveFileDialogFactory, SaveFileDialog } from '@theia/filesystem/lib/browser';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
import { UriSelection } from '@theia/core/lib/common/selection';
import URI from '@theia/core/lib/common/uri';
import { FileUploadService } from '@theia/filesystem/lib/browser/file-upload-service';

export class DialogsMainImpl implements DialogsMain {
Expand Down Expand Up @@ -49,6 +50,11 @@ export class DialogsMainImpl implements DialogsMain {
rootStat = await this.fileSystem.getFileStat(defaultUri);
}

// Try to use as root the parent folder of existing file URI/non existing URI
if (rootStat && !rootStat.isDirectory || !rootStat) {
rootStat = await this.fileSystem.getFileStat(new URI(defaultUri).parent.toString());
}

// Try to use workspace service root if there is no preconfigured URI
if (!rootStat) {
rootStat = (await this.workspaceService.roots)[0];
Expand Down Expand Up @@ -120,24 +126,34 @@ export class DialogsMainImpl implements DialogsMain {
async $showSaveDialog(options: SaveDialogOptionsMain): Promise<string | undefined> {
const rootStat = await this.getRootUri(options.defaultUri ? options.defaultUri : undefined);

// Fail if root not fount
// Fail if root not found
if (!rootStat) {
throw new Error('Unable to find the rootStat');
}

// Take the info for root node
const rootNode = DirNode.createRoot(rootStat);

// File name field should be empty unless the URI is a file
let fileNameValue = '';
if (options.defaultUri) {
const defaultURIStat = await this.fileSystem.getFileStat(options.defaultUri);
if (defaultURIStat && !defaultURIStat.isDirectory || !defaultURIStat) {
fileNameValue = new URI(options.defaultUri).path.base;
}
}

try {
// Create save file dialog props
const dialogProps = {
title: 'Save',
saveLabel: options.saveLabel,
filters: options.filters
filters: options.filters,
inputValue: fileNameValue
} as SaveFileDialogProps;

// Show save file dialog
const dialog = this.saveFileDialogFactory(dialogProps);
const dialog: SaveFileDialog = this.saveFileDialogFactory(dialogProps);
dialog.model.navigateTo(rootNode);
const result = await dialog.open();

Expand Down