1
/*******************************************************************************
2
* Copyright (c) 2000, 2005 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.cdt.make.internal.ui;
14
import org.eclipse.jface.dialogs.IDialogSettings;
15
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.widgets.Shell;
19
* Helper class for dealing with setting and restoring dialog settings.
21
public class DialogSettingsHelper {
24
* Persists the location and dimensions of the shell in the
25
* Debug UI Plugin dialog settings under the provided dialog settings section name
27
* @param shell The shell whose geometry is to be stored
28
* @param dialogSettingsSectionName The name of the dialog settings section
30
public static void persistShellGeometry(Shell shell, String dialogSettingsSectionName) {
31
Point shellLocation = shell.getLocation();
32
Point shellSize = shell.getSize();
33
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
34
settings.put(IMakeUIPreferenceConstants.DIALOG_ORIGIN_X, shellLocation.x);
35
settings.put(IMakeUIPreferenceConstants.DIALOG_ORIGIN_Y, shellLocation.y);
36
settings.put(IMakeUIPreferenceConstants.DIALOG_WIDTH, shellSize.x);
37
settings.put(IMakeUIPreferenceConstants.DIALOG_HEIGHT, shellSize.y);
40
private static IDialogSettings getDialogSettings(String dialogSettingsSectionName) {
41
IDialogSettings settings = MakeUIPlugin.getDefault().getDialogSettings();
42
IDialogSettings section = settings.getSection(dialogSettingsSectionName);
43
if (section == null) {
44
section = settings.addNewSection(dialogSettingsSectionName);
50
* Returns the initial size which is the larger of the <code>initialSize</code> or
51
* the size persisted in the Debug UI Plugin dialog settings under the provided dialog setttings section name.
52
* If no size is persisted in the settings, the <code>initialSize</code> is returned.
54
* @param initialSize The initialSize to compare against
55
* @param dialogSettingsSectionName The name of the dialog settings section
56
* @return the initial size
58
public static Point getInitialSize(String dialogSettingsSectionName, Point initialSize) {
59
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
62
x = settings.getInt(IMakeUIPreferenceConstants.DIALOG_WIDTH);
63
y = settings.getInt(IMakeUIPreferenceConstants.DIALOG_HEIGHT);
64
return new Point(Math.max(x, initialSize.x), Math.max(y, initialSize.y));
65
} catch (NumberFormatException e) {
71
* Returns the initial location which is persisted in the Debug UI Plugin dialog settings
72
* under the provided dialog setttings section name.
73
* If location is not persisted in the settings, the <code>null</code> is returned.
75
* @param dialogSettingsSectionName The name of the dialog settings section
76
* @return The initial location or <code>null</code>
78
public static Point getInitialLocation(String dialogSettingsSectionName) {
79
IDialogSettings settings = getDialogSettings(dialogSettingsSectionName);
81
int x= settings.getInt(IMakeUIPreferenceConstants.DIALOG_ORIGIN_X);
82
int y= settings.getInt(IMakeUIPreferenceConstants.DIALOG_ORIGIN_Y);
83
return new Point(x,y);
84
} catch (NumberFormatException e) {