-
Notifications
You must be signed in to change notification settings - Fork 24
[FIX] Copy action #293
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
base: master
Are you sure you want to change the base?
[FIX] Copy action #293
Conversation
shubhamWaghmare-sap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor refactoring changes.
| manager.add(AbapGitView.this.actionCopy); | ||
|
|
||
| // Create the sub-menu for Copy | ||
| MenuManager copySubMenu = new MenuManager("Copy"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Externalize the string.
| this.actionCopyCell = new Action("Copy Cell") { | ||
| @Override | ||
| public void run() { | ||
| copyCell(); | ||
| } | ||
| }; | ||
|
|
||
| this.actionCopyRow = new Action("Copy Row") { | ||
| @Override | ||
| public void run() { | ||
| copyRow(); | ||
| } | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Externalize both strings.
| final Clipboard clipboard = new Clipboard(this.viewer.getControl().getDisplay()); | ||
| String textToCopy = null; | ||
|
|
||
| TableItem[] selection = this.viewer.getTable().getSelection(); | ||
| if (selection.length > 0 && this.focusedColumnIndex != -1) { | ||
| textToCopy = selection[0].getText(this.focusedColumnIndex); | ||
| } | ||
|
|
||
| if (textToCopy != null && !textToCopy.isEmpty()) { | ||
| clipboard.setContents(new String[] { textToCopy }, new TextTransfer[] { TextTransfer.getInstance() }); | ||
| } | ||
| clipboard.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying to clipboard is common in both the copyCell & copyRow methods. Extract the logic as a separate method and use it in the copy methods.
private void copyToClipboard(String textToCopy) {
if (textToCopy == null || textToCopy.isEmpty()) return;
final Clipboard clipboard = new Clipboard(this.viewer.getControl().getDisplay());
clipboard.setContents(new String[] { textToCopy },
new TextTransfer[] { TextTransfer.getInstance() });
clipboard.dispose();
}
}
| return; // Found the column | ||
| } | ||
| } | ||
| AbapGitView.this.focusedColumnIndex = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low prio: Can extract -1 as a new constant. Say NO_COLUMN_SELECTED.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can extract the complete logic to find the selected column into a separate method. Easier to understand what's happening via the method name.
| table.addMouseListener(new MouseAdapter() { | ||
| @Override | ||
| public void mouseDown(MouseEvent e) { | ||
| Point pt = new Point(e.x, e.y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use full variable name wherever possible. i.e. use point instead of pt.
Changes Made
Previous flow:
when clicked on copyAction whole row was copied and copied text have to be truncatedNew flow: