mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Tool setting tab resizing improvement
This commit is contained in:
parent
b172d1c096
commit
112824a214
2 changed files with 35 additions and 31 deletions
|
@ -44,22 +44,17 @@ import org.eclipse.jface.viewers.ViewerFilter;
|
|||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.SashForm;
|
||||
import org.eclipse.swt.custom.ScrolledComposite;
|
||||
import org.eclipse.swt.events.ControlAdapter;
|
||||
import org.eclipse.swt.events.ControlEvent;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.ScrollBar;
|
||||
|
||||
|
||||
public class ToolSettingsTab extends AbstractCBuildPropertyTab implements IPreferencePageContainer {
|
||||
/*
|
||||
* String constants
|
||||
*/
|
||||
private static final int[] DEFAULT_SASH_WEIGHTS = new int[] { 10, 20 };
|
||||
|
||||
/*
|
||||
* Dialog widgets
|
||||
*/
|
||||
|
@ -98,38 +93,40 @@ public class ToolSettingsTab extends AbstractCBuildPropertyTab implements IPrefe
|
|||
sashForm.setLayout(layout);
|
||||
createSelectionArea(sashForm);
|
||||
createEditArea(sashForm);
|
||||
sashForm.setWeights(DEFAULT_SASH_WEIGHTS);
|
||||
sashForm.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
if (event.detail == SWT.DRAG) return;
|
||||
int shift = event.x - sashForm.getBounds().x;
|
||||
GridData data = (GridData) containerSC.getLayoutData();
|
||||
if ((data.widthHint + shift) < 20) return;
|
||||
Point computedSize = usercomp.getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
Point currentSize = usercomp.getShell().getSize();
|
||||
boolean customSize = !computedSize.equals(currentSize);
|
||||
data.widthHint = data.widthHint;
|
||||
sashForm.layout(true);
|
||||
computedSize = usercomp.getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
if (customSize)
|
||||
computedSize.x = Math.max(computedSize.x, currentSize.x);
|
||||
computedSize.y = Math.max(computedSize.y, currentSize.y);
|
||||
if (computedSize.equals(currentSize)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
usercomp.addControlListener(new ControlAdapter() {
|
||||
public void controlResized(ControlEvent e) {
|
||||
specificResize();
|
||||
}});
|
||||
|
||||
propertyObject = page.getElement();
|
||||
setValues();
|
||||
}
|
||||
|
||||
private void specificResize() {
|
||||
Point p1 = optionList.getTree().computeSize(-1, -1);
|
||||
Point p2 = optionList.getTree().getSize();
|
||||
Point p3 = usercomp.getSize();
|
||||
p1.x += calcExtra();
|
||||
if (p1.x < p2.x || (p2.x * 2 < p3.x)) {
|
||||
optionList.getTree().setSize(p1.x , p2.y);
|
||||
sashForm.setWeights(new int[] {p1.x, (p3.x - p1.x)});
|
||||
}
|
||||
}
|
||||
|
||||
private int calcExtra() {
|
||||
int x = optionList.getTree().getBorderWidth() * 2;
|
||||
ScrollBar sb = optionList.getTree().getVerticalBar();
|
||||
if (sb != null) x += sb.getSize().x;
|
||||
return x;
|
||||
}
|
||||
|
||||
protected void createSelectionArea (Composite parent) {
|
||||
optionList = new TreeViewer(parent, SWT.SINGLE|SWT.H_SCROLL|SWT.V_SCROLL|SWT.BORDER);
|
||||
optionList.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
handleOptionSelection();
|
||||
}
|
||||
});
|
||||
}});
|
||||
optionList.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
optionList.setLabelProvider(new ToolListLabelProvider());
|
||||
optionList.addFilter(new ViewerFilter() {
|
||||
|
@ -328,6 +325,7 @@ public class ToolSettingsTab extends AbstractCBuildPropertyTab implements IPrefe
|
|||
optionList.setSelection(new StructuredSelection(selectedElement), true);
|
||||
}
|
||||
}
|
||||
specificResize();
|
||||
}
|
||||
|
||||
private ToolListElement matchSelectionElement(ToolListElement currentElement, ToolListElement[] elements) {
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.swt.SWT;
|
|||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -1012,7 +1013,12 @@ implements
|
|||
|
||||
public void resize() {
|
||||
Shell sh = parentComposite.getShell();
|
||||
sh.setSize(sh.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
|
||||
Point p0 = sh.getLocation();
|
||||
Point p1 = sh.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
|
||||
Rectangle r = sh.getDisplay().getClientArea();
|
||||
p1.x = Math.min(p1.x, (r.width - p0.x));
|
||||
p1.y = Math.min(p1.y, (r.height - p0.y));
|
||||
sh.setSize(p1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue