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

'Copy all' for context menu in output view #8057

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions packages/output/src/browser/output-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { injectable, inject } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { Widget } from '@theia/core/lib/browser/widgets/widget';
import { MaybePromise } from '@theia/core/lib/common/types';
Expand All @@ -24,6 +24,7 @@ import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-con
import { OutputWidget } from './output-widget';
import { OutputContextMenu } from './output-context-menu';
import { OutputUri } from '../common/output-uri';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';

export namespace OutputCommands {

Expand Down Expand Up @@ -100,11 +101,17 @@ export namespace OutputCommands {
category: OUTPUT_CATEGORY
};

export const COPY_ALL: Command = {
id: 'output:copy-all',
};
}

@injectable()
export class OutputContribution extends AbstractViewContribution<OutputWidget> implements OpenHandler {

@inject(ClipboardService)
protected readonly clipboardService: ClipboardService;

readonly id: string = `${OutputWidget.ID}-opener`;

constructor() {
Expand Down Expand Up @@ -136,13 +143,25 @@ export class OutputContribution extends AbstractViewContribution<OutputWidget> i
isVisible: widget => this.withWidget(widget, output => output.isLocked),
execute: () => this.widget.then(widget => widget.unlock())
});
registry.registerCommand(OutputCommands.COPY_ALL, {
kittaakos marked this conversation as resolved.
Show resolved Hide resolved
execute: () => {
const textToCopy = this.tryGetWidget()?.getText();
if (textToCopy) {
this.clipboardService.writeText(textToCopy);
}
}
});
}

registerMenus(registry: MenuModelRegistry): void {
super.registerMenus(registry);
registry.registerMenuAction(OutputContextMenu.TEXT_EDIT_GROUP, {
commandId: CommonCommands.COPY.id
});
registry.registerMenuAction(OutputContextMenu.TEXT_EDIT_GROUP, {
commandId: OutputCommands.COPY_ALL.id,
label: 'Copy All'
});
registry.registerMenuAction(OutputContextMenu.COMMAND_GROUP, {
commandId: quickCommand.id,
label: 'Find Command...'
Expand Down Expand Up @@ -173,5 +192,4 @@ export class OutputContribution extends AbstractViewContribution<OutputWidget> i

return widget instanceof OutputWidget ? predicate(widget) : false;
}

}
11 changes: 11 additions & 0 deletions packages/output/src/browser/output-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ export class OutputWidget extends BaseWidget implements StatefulWidget {
return undefined;
}

getText(): string | undefined {
const editor = this.editor;
if (editor) {
const model = editor.getControl().getModel();
if (model) {
return model.getValue();
}
}
return undefined;
}

}

export namespace OutputWidget {
Expand Down