Skip to content

Commit

Permalink
Upload command always visible on browser (eclipse-theia#11756)
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Bozzini <federico.bozzini@gmail.com>

Signed-off-by: Federico Bozzini <federico.bozzini@gmail.com>
  • Loading branch information
federicobozzini authored Jan 22, 2023
1 parent bf600d7 commit ca59f1d
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,19 @@ export class FileSystemFrontendContribution implements FrontendApplicationContri
}

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(FileSystemCommands.UPLOAD, new FileSelection.CommandHandler(this.selectionService, {
multi: false,
isEnabled: selection => this.canUpload(selection),
isVisible: selection => this.canUpload(selection),
execute: selection => this.upload(selection)
}));
commands.registerCommand(FileSystemCommands.UPLOAD, {
isEnabled: (...args: unknown[]) => {
const selection = this.getSelection(...args);
return !!selection && this.canUpload(selection);
},
isVisible: () => !environment.electron.is(),
execute: (...args: unknown[]) => {
const selection = this.getSelection(...args);
if (selection) {
return this.upload(selection);
}
}
});
}

protected canUpload({ fileStat }: FileSelection): boolean {
Expand All @@ -148,6 +155,15 @@ export class FileSystemFrontendContribution implements FrontendApplicationContri
}
}

protected getSelection(...args: unknown[]): FileSelection | undefined {
const { selection } = this.selectionService;
return this.toSelection(args[0]) ?? (Array.isArray(selection) ? selection.find(FileSelection.is) : this.toSelection(selection));
};

protected toSelection(arg: unknown): FileSelection | undefined {
return FileSelection.is(arg) ? arg : undefined;
}

protected pendingOperation = Promise.resolve();
protected run(operation: () => MaybePromise<void>): Promise<void> {
return this.pendingOperation = this.pendingOperation.then(async () => {
Expand Down

0 comments on commit ca59f1d

Please sign in to comment.