Permalink
Browse files

Remember last entered data for "Connect to REPL" (Issue 498)

  • Loading branch information...
1 parent c5fa18e commit b0e2992b63cc34ad519e0a27ec66ec54aa72cb83 @laurentpetit laurentpetit committed Dec 30, 2012
Showing with 56 additions and 9 deletions.
  1. +1 −1 ccw.core/src/java/ccw/repl/Actions.java
  2. +55 −8 ccw.core/src/java/ccw/repl/ConnectDialog.java
@@ -24,7 +24,7 @@ private Actions () {}
public Object execute (ExecutionEvent event) throws ExecutionException {
try {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- ConnectDialog dlg = new ConnectDialog(window.getShell());
+ ConnectDialog dlg = new ConnectDialog(window.getShell(), CCWPlugin.getDefault().getDialogSettings());
REPLView repl = null;
if (dlg.open() == ConnectDialog.OK) {
@@ -1,27 +1,42 @@
package ccw.repl;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.DialogSettings;
+import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import ccw.util.StringUtils;
+
public class ConnectDialog extends Dialog {
- private Text hosts;
+ private static final String PORT_SETTING_DEFAULT = "";
+ private static final String HOST_SETTING_DEFAULT = "127.0.0.1";
+ private Text host;
private Text port;
- private int portNumber;
private String url;
- public ConnectDialog(Shell parentShell) {
+ private static final String CONNECT_DIALOG_SECTION = "ccw.repl.ConnectDialog";
+ private static final String PORT_SETTING = "port";
+ private static final String HOST_SETTING = "host";
+ private IDialogSettings dialogSettings;
+
+ public ConnectDialog(Shell parentShell, IDialogSettings dialogSettings) {
super(parentShell);
setBlockOnOpen(true);
+
+ if (dialogSettings != null) {
+ this.dialogSettings = DialogSettings.getOrCreateSection(dialogSettings, CONNECT_DIALOG_SECTION);
+ }
}
@Override
@@ -39,9 +54,7 @@ protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(2, false));
new Label(parent, 0).setText("Hostname");
- hosts = new Text(parent, SWT.BORDER);
- hosts.setText("127.0.0.1"); // don't know much about swt layouts yet :-(
- hosts.setSelection(new Point(0, hosts.getText().length()));
+ host = new Text(parent, SWT.BORDER);
new Label(parent, 0).setText("Port");
@@ -53,12 +66,46 @@ public void verifyText(VerifyEvent e) {
}
});
+ initValues();
+
+ composite.addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ saveValues();
+ }
+ });
+
port.setFocus();
+ port.setSelection(0, port.getText().length());
return composite;
}
+
+ private void initValues() {
+ if (dialogSettings == null) return;
+ setText(host, dialogSettings.get(HOST_SETTING), HOST_SETTING_DEFAULT);
+ setText(port, dialogSettings.get(PORT_SETTING), PORT_SETTING_DEFAULT);
+ }
+
+
+ private void setText(Text w, String value, String defaultValue) {
+ w.setText((value!=null) ? value : defaultValue);
+ }
+
+ private void saveValues() {
+ if (dialogSettings == null) return;
+ saveValue(host, HOST_SETTING, HOST_SETTING_DEFAULT);
+ saveValue(port, PORT_SETTING, PORT_SETTING_DEFAULT);
+ }
+
+ private void saveValue(Text w, String key, String defaultValue) {
+ String value = w.getText();
+ dialogSettings.put(
+ key,
+ StringUtils.isEmpty(value) ? defaultValue : value);
+ }
protected void okPressed () {
- url = String.format("nrepl://%s:%s", hosts.getText(), port.getText());
+ url = String.format("nrepl://%s:%s", host.getText(), port.getText());
super.okPressed();
}

0 comments on commit b0e2992

Please sign in to comment.