|
15 | 15 | import org.eclipse.jdt.annotation.NonNull; |
16 | 16 | import org.eclipse.jface.window.Window; |
17 | 17 | import org.eclipse.swt.SWT; |
18 | | -import org.eclipse.swt.events.KeyAdapter; |
19 | | -import org.eclipse.swt.events.KeyEvent; |
20 | | -import org.eclipse.swt.events.MouseAdapter; |
21 | | -import org.eclipse.swt.events.MouseEvent; |
| 18 | +import org.eclipse.swt.events.SelectionAdapter; |
| 19 | +import org.eclipse.swt.events.SelectionEvent; |
22 | 20 | import org.eclipse.swt.graphics.Image; |
23 | | -import org.eclipse.swt.layout.GridData; |
24 | 21 | import org.eclipse.swt.layout.GridLayout; |
| 22 | +import org.eclipse.swt.widgets.Button; |
25 | 23 | import org.eclipse.swt.widgets.Composite; |
26 | | -import org.eclipse.swt.widgets.Label; |
27 | 24 | import org.eclipse.swt.widgets.Shell; |
28 | 25 | import org.eclipse.ui.PlatformUI; |
29 | 26 |
|
|
37 | 34 | * A widget that displays a button to attach context. |
38 | 35 | */ |
39 | 36 | public class AddContextButton extends Composite { |
40 | | - private Label lblAttachIcon; |
41 | | - private Label lblButtonText; |
| 37 | + private Button btnAttachIcon; |
42 | 38 |
|
43 | 39 | /** |
44 | 40 | * Creates a new AddContextButton. |
45 | 41 | */ |
46 | 42 | public AddContextButton(Composite parent) { |
47 | | - super(parent, SWT.BORDER); |
48 | | - GridLayout layout = new GridLayout(2, false); |
49 | | - layout.marginWidth = 4; |
50 | | - layout.marginHeight = 2; |
| 43 | + super(parent, SWT.NONE); |
| 44 | + GridLayout layout = new GridLayout(1, false); |
| 45 | + layout.marginWidth = 0; |
| 46 | + layout.marginHeight = 0; |
51 | 47 | setLayout(layout); |
52 | 48 |
|
53 | | - lblAttachIcon = new Label(this, SWT.NONE); |
54 | | - lblAttachIcon.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 49 | + btnAttachIcon = UiUtils.createIconButton(this, SWT.PUSH | SWT.FLAT); |
55 | 50 | Image attachImage = UiUtils.buildImageFromPngPath("/icons/chat/attach_context.png"); |
56 | | - lblAttachIcon.setImage(attachImage); |
57 | | - lblAttachIcon.addDisposeListener(e -> { |
58 | | - if (attachImage != null && !attachImage.isDisposed()) { |
59 | | - attachImage.dispose(); |
60 | | - } |
61 | | - }); |
62 | | - |
63 | | - lblButtonText = new Label(this, SWT.NONE); |
64 | | - lblButtonText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); |
65 | | - lblButtonText.setText("Add Context..."); |
66 | | - |
67 | | - // Register for chat font updates via centralized service |
68 | | - var chatServiceManager = CopilotUi.getPlugin().getChatServiceManager(); |
69 | | - if (chatServiceManager != null) { |
70 | | - chatServiceManager.getChatFontService().registerControl(lblButtonText); |
71 | | - } |
72 | | - |
73 | | - MouseAdapter clickListener = new MouseAdapter() { |
| 51 | + btnAttachIcon.setImage(attachImage); |
| 52 | + String attachTooltip = Messages.chat_addContext_tooltip; |
| 53 | + btnAttachIcon.setToolTipText(attachTooltip); |
| 54 | + AccessibilityUtils.addAccessibilityNameForUiComponent(btnAttachIcon, attachTooltip); |
| 55 | + btnAttachIcon.addSelectionListener(new SelectionAdapter() { |
74 | 56 | @Override |
75 | | - public void mouseDown(MouseEvent e) { |
| 57 | + public void widgetSelected(SelectionEvent e) { |
76 | 58 | openFilePickerAndAddFiles(); |
77 | 59 | } |
78 | | - }; |
79 | | - // Add mouse listener to 'this' so that clicking margin spaces will also trigger the action |
80 | | - this.addMouseListener(clickListener); |
81 | | - lblAttachIcon.addMouseListener(clickListener); |
82 | | - lblButtonText.addMouseListener(clickListener); |
83 | | - this.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND)); |
84 | | - |
85 | | - // Add keyboard support for Enter activation |
86 | | - this.addKeyListener(new KeyAdapter() { |
87 | | - @Override |
88 | | - public void keyPressed(KeyEvent e) { |
89 | | - if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { |
90 | | - openFilePickerAndAddFiles(); |
91 | | - } |
| 60 | + }); |
| 61 | + btnAttachIcon.addDisposeListener(e -> { |
| 62 | + if (attachImage != null && !attachImage.isDisposed()) { |
| 63 | + attachImage.dispose(); |
92 | 64 | } |
93 | 65 | }); |
94 | | - |
95 | | - AccessibilityUtils.addFocusBorderToComposite(this); |
96 | 66 | } |
97 | 67 |
|
98 | 68 | /** |
99 | 69 | * Opens the file picker dialog and adds the selected files to the referenced files. |
100 | 70 | */ |
101 | 71 | private void openFilePickerAndAddFiles() { |
102 | 72 | List<IResource> files = selectFiles(); |
103 | | - ReferencedFileService fileService = |
104 | | - CopilotUi.getPlugin().getChatServiceManager().getReferencedFileService(); |
| 73 | + ReferencedFileService fileService = CopilotUi.getPlugin().getChatServiceManager().getReferencedFileService(); |
105 | 74 | fileService.addReferencedFiles(files); |
106 | 75 | } |
107 | 76 |
|
|
0 commit comments