Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
Expand Down Expand Up @@ -269,18 +268,7 @@ private void createProjectInstructionsField(Composite parent, GridLayout gl) {
// Set the file location column to take remaining width (table width - project name column width)
fileLocationColumn.setWidth(tableGridData.widthHint > 0 ? tableGridData.widthHint - 150 : 400);

// Add resize listener to make the file location column take remaining width
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(org.eclipse.swt.events.ControlEvent e) {
int tableWidth = table.getClientArea().width;
int projectNameWidth = projectNameColumn.getWidth();
int remainingWidth = tableWidth - projectNameWidth;
if (remainingWidth > 100) { // Minimum width for file location column
fileLocationColumn.setWidth(remainingWidth);
}
}
});
SwtUtils.resizeColumnToFillTable(table, fileLocationColumn, 100, projectNameColumn);

// Populate table with actual workspace projects
populateProjectTable(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ private void createContents() {

private void createTable(Composite parent) {
tableViewer = new TableViewer(parent,
SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);
Table table = tableViewer.getTable();
GridData tableData = new GridData(SWT.FILL, SWT.FILL, true, false);
tableData.heightHint = TABLE_HEIGHT_HINT;
table.setLayoutData(tableData);
table.setHeaderVisible(true);
table.setLinesVisible(true);
SwtUtils.forwardVerticalMouseWheelToParentScrollerAtBoundary(table);

TableViewerColumn patternCol =
new TableViewerColumn(tableViewer, SWT.NONE);
Expand Down Expand Up @@ -177,6 +178,8 @@ public Color getForeground(Object element) {
? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
}
});
SwtUtils.resizeColumnToFillTable(table, statusCol.getColumn(), 100,
patternCol.getColumn(), descCol.getColumn());

tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.addSelectionChangedListener(e -> updateButtonState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ private void createContents() {

// Tree viewer for server/tool approval
treeViewer = new CheckboxTreeViewer(group,
SWT.BORDER | SWT.FULL_SELECTION);
SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL);
GridData treeData = new GridData(SWT.FILL, SWT.FILL, true, false);
treeData.heightHint = TREE_HEIGHT_HINT;
treeViewer.getTree().setLayoutData(treeData);
SwtUtils.forwardVerticalMouseWheelToParentScrollerAtBoundary(treeViewer.getTree());

treeViewer.setContentProvider(new McpTreeContentProvider());
treeViewer.setLabelProvider(new McpTreeLabelProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.microsoft.copilot.eclipse.core.CopilotCore;
import com.microsoft.copilot.eclipse.core.chat.TerminalAutoApproveRule;
import com.microsoft.copilot.eclipse.ui.chat.confirmation.TerminalConfirmationHandler;
import com.microsoft.copilot.eclipse.ui.utils.SwtUtils;

/**
* Terminal auto-approve section with a rule table, action buttons, and
Expand Down Expand Up @@ -90,13 +91,14 @@ private void createContents() {

private void createTable(Composite parent) {
tableViewer = new TableViewer(parent,
SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);
Table table = tableViewer.getTable();
GridData tableData = new GridData(SWT.FILL, SWT.FILL, true, false);
tableData.heightHint = TABLE_HEIGHT_HINT;
table.setLayoutData(tableData);
table.setHeaderVisible(true);
table.setLinesVisible(true);
SwtUtils.forwardVerticalMouseWheelToParentScrollerAtBoundary(table);

TableViewerColumn commandCol =
new TableViewerColumn(tableViewer, SWT.NONE);
Expand All @@ -123,6 +125,8 @@ public String getText(Object element) {
: Messages.preferences_page_auto_approve_deny;
}
});
SwtUtils.resizeColumnToFillTable(table, statusCol.getColumn(), 100,
commandCol.getColumn());

tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.addSelectionChangedListener(e -> updateButtonState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
Expand Down Expand Up @@ -272,6 +282,88 @@ public static Color getDefaultGhostTextColor(Display display) {
return new Color(display, new RGB(DEFAULT_GHOST_TEXT_SCALE, DEFAULT_GHOST_TEXT_SCALE, DEFAULT_GHOST_TEXT_SCALE));
}

/**
* Forwards vertical mouse wheel scrolling from a nested scrollable to its nearest parent scroller when the nested
* control is already at the scroll boundary.
*/
public static void forwardVerticalMouseWheelToParentScrollerAtBoundary(Scrollable scrollable) {
scrollable.addListener(SWT.MouseWheel, event -> {
if (event.count == 0 || scrollable.isDisposed()
|| canScrollVertically(scrollable.getVerticalBar(), event.count)) {
return;
}

ScrolledComposite parentScroller = findParentScroller(scrollable);
if (parentScroller != null
&& canScrollVertically(parentScroller.getVerticalBar(), event.count)) {
event.doit = false;
scrollParentVertically(parentScroller, event.count);
}
});
}

private static ScrolledComposite findParentScroller(Scrollable scrollable) {
Composite parent = scrollable.getParent();
while (parent != null) {
if (parent instanceof ScrolledComposite scrolledComposite) {
return scrolledComposite;
}
parent = parent.getParent();
}
return null;
}

private static void scrollParentVertically(ScrolledComposite scrolledComposite, int wheelCount) {
ScrollBar verticalBar = scrolledComposite.getVerticalBar();
if (verticalBar == null || verticalBar.isDisposed()) {
return;
}

Point origin = scrolledComposite.getOrigin();
int minimum = verticalBar.getMinimum();
int maximum = Math.max(minimum,
verticalBar.getMaximum() - verticalBar.getThumb());
int delta = -wheelCount * Math.max(1, verticalBar.getIncrement());
int nextY = Math.max(minimum, Math.min(maximum, origin.y + delta));
scrolledComposite.setOrigin(origin.x, nextY);
}

private static boolean canScrollVertically(ScrollBar verticalBar, int wheelCount) {
if (verticalBar == null || verticalBar.isDisposed()
|| !verticalBar.getEnabled()) {
return false;
}

int minimum = verticalBar.getMinimum();
int maximum = Math.max(minimum,
verticalBar.getMaximum() - verticalBar.getThumb());
int selection = Math.max(minimum,
Math.min(maximum, verticalBar.getSelection()));
if (wheelCount > 0) {
return selection > minimum;
}
return selection < maximum;
}

/**
* Resizes a table column to fill the table client area not occupied by the fixed-width columns.
*/
public static void resizeColumnToFillTable(Table table, TableColumn fillColumn,
int minWidth, TableColumn... fixedColumns) {
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
int remainingWidth = table.getClientArea().width;
for (TableColumn fixedColumn : fixedColumns) {
remainingWidth -= fixedColumn.getWidth();
}
if (remainingWidth > minWidth) {
fillColumn.setWidth(remainingWidth);
}
}
});
}

/**
* Copy the given text to the clipboard.
*/
Expand Down
Loading