mirror of
https://github.com/Microsoft/vscode
synced 2024-08-26 20:39:37 +00:00
guess notebook file extension.
This commit is contained in:
parent
c7d204f416
commit
23c5190ea0
|
@ -23,6 +23,7 @@ import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
|
|||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
|
||||
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
|
||||
|
||||
export interface NotebookEditorInputOptions {
|
||||
startDirty?: boolean;
|
||||
|
@ -145,7 +146,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const pathCandidate = this.hasCapability(EditorInputCapabilities.Untitled) ? await this._suggestName(this.labelService.getUriBasenameLabel(this.resource)) : this._editorModelReference.object.resource;
|
||||
const pathCandidate = this.hasCapability(EditorInputCapabilities.Untitled) ? await this._suggestName(provider, this.labelService.getUriBasenameLabel(this.resource)) : this._editorModelReference.object.resource;
|
||||
let target: URI | undefined;
|
||||
if (this._editorModelReference.object.hasAssociatedFilePath()) {
|
||||
target = pathCandidate;
|
||||
|
@ -179,7 +180,27 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
|
|||
return await this._editorModelReference.object.saveAs(target);
|
||||
}
|
||||
|
||||
private async _suggestName(suggestedFilename: string) {
|
||||
private async _suggestName(provider: NotebookProviderInfo, suggestedFilename: string) {
|
||||
// guess file extensions
|
||||
const firstSelector = provider.selectors[0];
|
||||
let selectorStr = firstSelector && typeof firstSelector === 'string' ? firstSelector : undefined;
|
||||
if (!selectorStr && firstSelector) {
|
||||
const include = (firstSelector as { include?: string }).include;
|
||||
if (typeof include === 'string') {
|
||||
selectorStr = include;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectorStr) {
|
||||
const matches = /^\*\.([A-Za-z_-]*)$/.exec(selectorStr);
|
||||
if (matches && matches.length > 1) {
|
||||
const fileExt = matches[1];
|
||||
if (!suggestedFilename.endsWith(fileExt)) {
|
||||
return joinPath(await this._fileDialogService.defaultFilePath(), suggestedFilename + '.' + fileExt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return joinPath(await this._fileDialogService.defaultFilePath(), suggestedFilename);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue