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

Conversation

salkin-naj
Copy link
Contributor

What it does

This adds another option to the context menu of the output view.
It copies everything in the selected channel into the clipboard.

How to test

  1. Open output view
  2. Select a channel with text in it
  3. Open context menu and select 'Copy All'

Review checklist

Reminder for reviewers

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salkin-naj we have a clipboard-service which should be used instead and has handling for specific cases:

export interface ClipboardService {
readText(): MaybePromise<string>;
writeText(value: string): MaybePromise<void>;
}

@vince-fugnitto vince-fugnitto added clipboard issues related to the clipboard output issues related to the output labels Jun 19, 2020
@salkin-naj
Copy link
Contributor Author

@vince-fugnitto: I tried using the clipboardService in the outputContribution, but I get circular dependencies that I cannot figure out. Is there something I need to do? In preferenceContribution it is used exactly like I want to use it and it works fine.

@vince-fugnitto
Copy link
Member

@vince-fugnitto: I tried using the clipboardService in the outputContribution, but I get circular dependencies that I cannot figure out. Is there something I need to do? In preferenceContribution it is used exactly like I want to use it and it works fine.

@salkin-naj you can push your changes so far and I can take a look at it with you to help you along the way if you'd like :)
There should not be any circular dependencies present since the service is from core, at a high-level it should look something along the lines of:

import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';

export class OutputContribution extends AbstractViewContribution<OutputWidget> implements OpenHandler {

@inject(ClipboardService)
protected readonly clipboardService: ClipboardService;

...

this.clipboardService.writeText('foo');
}

@salkin-naj salkin-naj force-pushed the output-context-menu branch from 98c5f20 to 6e7386d Compare June 23, 2020 16:45
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes work well with the service, I have some comments about some improvements.

@@ -100,11 +101,19 @@ export namespace OutputCommands {
category: OUTPUT_CATEGORY
};

export const COPY_ALL: Command = {
id: 'output:copy-all',
label: 'Copy all',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to Copy All

registerKeybindings(registry: KeybindingRegistry): void {
registry.registerKeybinding({
command: OutputCommands.COPY_ALL.id,
keybinding: 'ctrlcmd+shift+c'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salkin-naj we should only register the keybinding when the view has focus else it will override all other commands with ctrlc+shift+c which is not the behavior we would want or expect.

We can do so by implementing a when context similarly to how it is done in other views:

Please let me know if you require help, I could assist you :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everybody can do Ctrl/⌘+A then Ctrl/⌘+C. We do not need a keybinding for this. Please remove.

@akosyakov akosyakov requested a review from kittaakos June 24, 2020 07:32
@salkin-naj salkin-naj force-pushed the output-context-menu branch from 6e7386d to 3342e53 Compare June 24, 2020 14:57
Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great, @salkin-naj. Let's simplify a little bit and were are ready to go ;)

Thank you! 🙏

return model.getValue();
}
}
return '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return undefined when the model value cannot be retrieved.

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

Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, @salkin-naj 🥇

@kittaakos
Copy link
Contributor

Please make sure you have squashed and the commit is signed.

@salkin-naj salkin-naj force-pushed the output-context-menu branch from 8285f46 to dbf7cb4 Compare June 25, 2020 13:54
@salkin-naj
Copy link
Contributor Author

salkin-naj commented Jun 25, 2020

Please make sure you have squashed and the commit is signed.

@kittaakos Done :)

@salkin-naj salkin-naj force-pushed the output-context-menu branch from dbf7cb4 to e196e15 Compare June 25, 2020 14:01
@kittaakos
Copy link
Contributor

@salkin-naj, I found a bug. I cannot accept the PR as is 😕

I propose the following:

diff --git a/packages/output/src/browser/output-contribution.ts b/packages/output/src/browser/output-contribution.ts
index daf4a4903..b16646b75 100644
--- a/packages/output/src/browser/output-contribution.ts
+++ b/packages/output/src/browser/output-contribution.ts
@@ -102,9 +102,7 @@ export namespace OutputCommands {
     };
 
     export const COPY_ALL: Command = {
-        id: 'output:copy-all',
-        label: 'Copy All',
-        category: OUTPUT_CATEGORY,
+        id: 'output:copy-all'
     };
 }
 
@@ -161,7 +159,8 @@ export class OutputContribution extends AbstractViewContribution<OutputWidget> i
             commandId: CommonCommands.COPY.id
         });
         registry.registerMenuAction(OutputContextMenu.TEXT_EDIT_GROUP, {
-            commandId: OutputCommands.COPY_ALL.id
+            commandId: OutputCommands.COPY_ALL.id,
+            label: 'Copy All'
         });
         registry.registerMenuAction(OutputContextMenu.COMMAND_GROUP, {
             commandId: quickCommand.id,

If you add a label to the command, it will show up in the Command Palette (F1 or Ctrl/⌘+Shift+P) if it's enabled. Since the handler for the command does not define the isEnabled/isVisible function, the command will be always enabled and visible. So if I close the Output view and open the Command Palette and search for Output: Copy All, it is visible and I can execute it. Yes, it does not do anything but it should not be there.

👆Solution: move the label property from the command and move it to the menu.

This adds another option to the context menu of the output view,
which copies everything in the selected channel into the clipboard,
using the ClipboardService.

Closes eclipse-theia#7912

Signed-off-by: Jan-Niklas Spangenberg <jan-niklas.spangenberg@gmx.de>
@salkin-naj salkin-naj force-pushed the output-context-menu branch from e196e15 to 2cbc217 Compare June 26, 2020 08:28
@kittaakos kittaakos merged commit bb85452 into eclipse-theia:master Jun 26, 2020
@kittaakos
Copy link
Contributor

Thanks for your persistence on this PR, @salkin-naj

@salkin-naj salkin-naj deleted the output-context-menu branch June 26, 2020 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clipboard issues related to the clipboard output issues related to the output
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants