Skip to content

Commit e413b82

Browse files
authored
feat: Removed border for Add Context button and center layout in ActionBar (#1613)
1 parent d952984 commit e413b82

4 files changed

Lines changed: 23 additions & 51 deletions

File tree

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ActionBar.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public ActionBar(Composite parent, int style, ChatServiceManager chatServiceMana
178178
rowLayout.marginLeft = 0;
179179
rowLayout.marginTop = 0;
180180
rowLayout.marginBottom = 10;
181+
rowLayout.center = true;
181182
this.cmpFileRef = new Composite(actionBar, SWT.NONE);
182183
this.cmpFileRef.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
183184
this.cmpFileRef.setLayout(rowLayout);

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/AddContextButton.java

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
import org.eclipse.jdt.annotation.NonNull;
1616
import org.eclipse.jface.window.Window;
1717
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;
2220
import org.eclipse.swt.graphics.Image;
23-
import org.eclipse.swt.layout.GridData;
2421
import org.eclipse.swt.layout.GridLayout;
22+
import org.eclipse.swt.widgets.Button;
2523
import org.eclipse.swt.widgets.Composite;
26-
import org.eclipse.swt.widgets.Label;
2724
import org.eclipse.swt.widgets.Shell;
2825
import org.eclipse.ui.PlatformUI;
2926

@@ -37,71 +34,43 @@
3734
* A widget that displays a button to attach context.
3835
*/
3936
public class AddContextButton extends Composite {
40-
private Label lblAttachIcon;
41-
private Label lblButtonText;
37+
private Button btnAttachIcon;
4238

4339
/**
4440
* Creates a new AddContextButton.
4541
*/
4642
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;
5147
setLayout(layout);
5248

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);
5550
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() {
7456
@Override
75-
public void mouseDown(MouseEvent e) {
57+
public void widgetSelected(SelectionEvent e) {
7658
openFilePickerAndAddFiles();
7759
}
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();
9264
}
9365
});
94-
95-
AccessibilityUtils.addFocusBorderToComposite(this);
9666
}
9767

9868
/**
9969
* Opens the file picker dialog and adds the selected files to the referenced files.
10070
*/
10171
private void openFilePickerAndAddFiles() {
10272
List<IResource> files = selectFiles();
103-
ReferencedFileService fileService =
104-
CopilotUi.getPlugin().getChatServiceManager().getReferencedFileService();
73+
ReferencedFileService fileService = CopilotUi.getPlugin().getChatServiceManager().getReferencedFileService();
10574
fileService.addReferencedFiles(files);
10675
}
10776

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/i18n/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public final class Messages extends NLS {
120120
public static String chat_noAuthView_checkSubButton;
121121
public static String chat_noAuthView_checkSubButton_Tooltip;
122122
public static String chat_noAuthView_checkSubLink;
123+
public static String chat_addContext_tooltip;
123124
public static String chat_filePicker_title;
124125
public static String chat_filePicker_message;
125126
public static String chat_noQuotaView_fallbackModel;

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/i18n/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ chat_historyView_editIcon_tooltip=Edit conversation title
136136
chat_historyView_deleteIcon_tooltip=Delete conversation
137137
model_billing_multiplier_suffix=x
138138
model_billing_multiplier_variable=Variable
139+
chat_addContext_tooltip=Add Context...
139140
chat_filePicker_title=Search attachments
140141
chat_filePicker_message=Choose files from the list, or search for files:
141142
chat_currentReferencedFile_description=Current file

0 commit comments

Comments
 (0)