Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 140306
Collapse All | Expand All

(-)src/org/eclipse/jface/messages.properties (+1 lines)
Lines 118-123 Link Here
118
PopupDialog.move = &Move
118
PopupDialog.move = &Move
119
PopupDialog.persistBounds = R&emember Size and Location
119
PopupDialog.persistBounds = R&emember Size and Location
120
PopupDialog.menuTooltip = Menu
120
PopupDialog.menuTooltip = Menu
121
Dialog.restoreDialogSize = &Restore preferred dialog size
121
122
122
############################################################
123
############################################################
123
124
(-)src/org/eclipse/jface/dialogs/Dialog.java (-67 / +29 lines)
Lines 16-30 Link Here
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.jface.action.Action;
20
import org.eclipse.jface.action.MenuManager;
19
import org.eclipse.jface.resource.JFaceResources;
21
import org.eclipse.jface.resource.JFaceResources;
20
import org.eclipse.jface.util.Policy;
22
import org.eclipse.jface.util.Policy;
21
import org.eclipse.jface.window.IShellProvider;
23
import org.eclipse.jface.window.IShellProvider;
22
import org.eclipse.jface.window.SameShellProvider;
24
import org.eclipse.jface.window.SameShellProvider;
23
import org.eclipse.jface.window.Window;
25
import org.eclipse.jface.window.Window;
24
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.MouseAdapter;
26
import org.eclipse.swt.events.MouseEvent;
27
import org.eclipse.swt.events.MouseListener;
28
import org.eclipse.swt.events.SelectionAdapter;
27
import org.eclipse.swt.events.SelectionAdapter;
29
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.graphics.Font;
29
import org.eclipse.swt.graphics.Font;
Lines 41-46 Link Here
41
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.Control;
43
import org.eclipse.swt.widgets.Display;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Menu;
44
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.swt.widgets.Shell;
45
45
46
/**
46
/**
Lines 206-223 Link Here
206
	public Control buttonBar;
206
	public Control buttonBar;
207
	
207
	
208
	/**
208
	/**
209
	 * A mouse listener that can be used to restore the default size
210
	 * of a dialog.  
211
	 * 
212
	 * @since 3.2
213
	 */
214
	private MouseListener restoreSizeMouseListener = new MouseAdapter() {
215
		public void mouseDoubleClick(MouseEvent event) {
216
			restoreDialogToComputedSize();
217
		}
218
	};
219
220
	/**
221
	 * Collection of buttons created by the <code>createButton</code> method.
209
	 * Collection of buttons created by the <code>createButton</code> method.
222
	 */
210
	 */
223
	private HashMap buttons = new HashMap();
211
	private HashMap buttons = new HashMap();
Lines 996-1003 Link Here
996
			saveDialogBounds(getShell());
984
			saveDialogBounds(getShell());
997
		}
985
		}
998
		
986
		
999
		removeRestoreSizeMouseListeners();
1000
1001
		boolean returnValue = super.close();
987
		boolean returnValue = super.close();
1002
		if (returnValue) {
988
		if (returnValue) {
1003
			buttons = new HashMap();
989
			buttons = new HashMap();
Lines 1111-1120 Link Here
1111
		super.create();
1097
		super.create();
1112
		applyDialogFont(buttonBar);
1098
		applyDialogFont(buttonBar);
1113
		
1099
		
1114
		// Register a mouse listener so that the user can restore this 
1100
		// Register a context menu so that the user can restore the dialog size.
1115
		// size with a double-click.
1116
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=116906
1101
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=116906
1117
		addRestoreSizeMouseListeners();
1102
		addRestoreSizeMenus();
1118
	}
1103
	}
1119
1104
1120
	/**
1105
	/**
Lines 1306-1319 Link Here
1306
	}
1291
	}
1307
	
1292
	
1308
	/**
1293
	/**
1309
	 * Add mouse listeners as needed to provide dialog size restore 
1294
	 * Add context menus as needed to provide dialog size restore 
1310
	 * behavior.  Double-clicking in unused areas will restore
1295
	 * behavior.  The context menu in unused areas will allow to restore
1311
	 * the dialog size.
1296
	 * the dialog size.
1312
	 * 
1297
	 * 
1313
	 *  @since 3.2
1298
	 *  @since 3.3
1314
	 */
1299
	 */
1315
	private void addRestoreSizeMouseListeners() {
1300
	private void addRestoreSizeMenus() {
1316
		// Hook a double click event for restoring the dialog's computed
1301
		// Hook context menus for restoring the dialog's computed
1317
		// size.  We hook onto the button bar and the contents, and any
1302
		// size.  We hook onto the button bar and the contents, and any
1318
		// nested composites in between, in order to accomodate different
1303
		// nested composites in between, in order to accomodate different
1319
		// layout and construction styles.
1304
		// layout and construction styles.
Lines 1322-1399 Link Here
1322
			// Hook onto the button bar composite and
1307
			// Hook onto the button bar composite and
1323
			// any nested composites within the button bar.
1308
			// any nested composites within the button bar.
1324
			// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=137315
1309
			// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=137315
1325
			addRestoreSizeMouseListenerToComposites(buttonBar);	
1310
			addRestoreSizeMenuToComposites(buttonBar);	
1326
			// Hook onto any nested composites between the button bar
1311
			// Hook onto any nested composites between the button bar
1327
			// and the contents.
1312
			// and the contents.
1328
			Control control = buttonBar.getParent();
1313
			Control control = buttonBar.getParent();
1329
			while (control != dialogContents && control != null) {
1314
			while (control != dialogContents && control != null) {
1330
				if (control.getClass() == Composite.class) {
1315
				if (control.getClass() == Composite.class) {
1331
					control.addMouseListener(restoreSizeMouseListener);
1316
					hookRestoreSizeContextMenu(control);
1332
				}
1317
				}
1333
				control = control.getParent();
1318
				control = control.getParent();
1334
			}
1319
			}
1335
		}
1320
		}
1336
		if (dialogContents != null) {
1321
		if (dialogContents != null) {
1337
			dialogContents.addMouseListener(restoreSizeMouseListener);
1322
			hookRestoreSizeContextMenu(dialogContents);
1338
		}
1339
	}
1340
	
1341
	/**
1342
	 * Add mouse listeners to the specified control if it is a composite,
1343
	 * and any child composites.  Called recursively.
1344
	 * 
1345
	 *  @since 3.2
1346
	 */
1347
	private void addRestoreSizeMouseListenerToComposites(Control control) {
1348
		// Check explicitly for instances of Composite, not instances of
1349
		// subclasses of composite.
1350
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=140306
1351
		if (control.getClass() == Composite.class) {
1352
			control.addMouseListener(restoreSizeMouseListener);
1353
			Control [] children = ((Composite)control).getChildren();
1354
			for (int i=0; i<children.length; i++) {
1355
				addRestoreSizeMouseListenerToComposites(children[i]);
1356
			}
1357
		}
1323
		}
1358
	}
1324
	}
1359
	
1325
1360
	/**
1326
	/**
1361
	 * Remove any mouse listeners that were registered.
1327
	 * Add a context menu to the specified control.
1362
	 * 
1328
	 * 
1363
	 *  @since 3.2
1329
	 *  @since 3.3
1364
	 */
1330
	 */
1365
	private void removeRestoreSizeMouseListeners() {
1331
	private void hookRestoreSizeContextMenu(Control control) {
1366
		Control dialogContents = getContents();
1332
		if (control.getMenu() == null) {
1367
		if (buttonBar != null && !buttonBar.isDisposed()) {
1333
			MenuManager menuManager= new MenuManager();
1368
			removeRestoreSizeMouseListenerFromComposites(buttonBar);
1334
			menuManager.add(new Action(JFaceResources.getString("Dialog.restoreDialogSize")) { //$NON-NLS-1$
1369
			Control control = buttonBar.getParent();
1335
				public void run() {
1370
			while (control != dialogContents && control != null && !control.isDisposed()) {
1336
					restoreDialogToComputedSize();
1371
				if (control.getClass() == Composite.class) {
1372
					control.removeMouseListener(restoreSizeMouseListener);
1373
				}
1337
				}
1374
				control = control.getParent();
1338
			});
1375
			}
1339
			Menu menu= menuManager.createContextMenu(control);
1376
		}
1340
			control.setMenu(menu);
1377
		if (dialogContents != null && !dialogContents.isDisposed()) {
1378
			dialogContents.removeMouseListener(restoreSizeMouseListener);
1379
		}
1341
		}
1380
	}
1342
	}
1381
	
1343
	
1382
	/**
1344
	/**
1383
	 * Remove mouse listeners from the specified control if it is a composite,
1345
	 * Add context menus to the specified control if it is a composite,
1384
	 * and any child composites.  Called recursively.
1346
	 * and any child composites.  Called recursively.
1385
	 * 
1347
	 * 
1386
	 *  @since 3.3
1348
	 *  @since 3.3
1387
	 */
1349
	 */
1388
	private void removeRestoreSizeMouseListenerFromComposites(Control control) {
1350
	private void addRestoreSizeMenuToComposites(Control control) {
1389
		// Check explicitly for instances of Composite, not instances of
1351
		// Check explicitly for instances of Composite, not instances of
1390
		// subclasses of composite.
1352
		// subclasses of composite.
1391
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=140306
1353
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=140306
1392
		if (control.getClass() == Composite.class) {
1354
		if (control.getClass() == Composite.class) {
1393
			control.removeMouseListener(restoreSizeMouseListener);
1355
			hookRestoreSizeContextMenu(control);
1394
			Control [] children = ((Composite)control).getChildren();
1356
			Control [] children = ((Composite)control).getChildren();
1395
			for (int i=0; i<children.length; i++) {
1357
			for (int i=0; i<children.length; i++) {
1396
				removeRestoreSizeMouseListenerFromComposites(children[i]);
1358
				addRestoreSizeMenuToComposites(children[i]);
1397
			}
1359
			}
1398
		}
1360
		}
1399
	}
1361
	}

Return to bug 140306