Skip to content

Commit

Permalink
Set focus to right field in preference page
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Feb 19, 2022
1 parent 9f1e8ce commit 3fdda7a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2021 Pierre-Yves B. and others.
* Copyright (c) 2019-2022 Pierre-Yves B. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.lsp4e.debug.launcher.DSPLaunchDelegate;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.dialogs.PreferencesUtil;
Expand Down Expand Up @@ -68,16 +69,19 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
private void displayNotFoundWarning() {
Display display = Display.getDefault();
display.asyncExec(() -> {
MessageDialog dialog = new MessageDialog(display.getActiveShell(), "Readapt was not found", null,
MessageDialog notFoundDialog = new MessageDialog(display.getActiveShell(), "Readapt was not found", null,
"Readapt is required for debugging. Let Eclipse install the gem locally or specify its path "
+ "after running \"gem install readapt\" in a terminal." + System.lineSeparator()
+ System.lineSeparator() + "Please restart the debug session once installation is complete.",
MessageDialog.WARNING, 0, "Install gem", "Specify path");
if (dialog.open() == 0) { // First button index, install.
if (notFoundDialog.open() == 0) { // First button index, install.
GemHelper.install("Readapt", READAPT_PATH);
HAS_UPDATED_READAPT.set(true);
} else {
PreferencesUtil.createPreferenceDialogOn(null, PreferencePage.PAGE_ID, null, null).open();
PreferenceDialog preferenceDialog = PreferencesUtil.createPreferenceDialogOn(null, PreferencePage.PAGE_ID,
null, null);
((PreferencePage) preferenceDialog.getSelectedPage()).getReadaptPath().setFocus();
preferenceDialog.open();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020-2021 Pierre-Yves B. and others.
* Copyright (c) 2020-2022 Pierre-Yves B. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -50,15 +50,19 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe

public static final String PAGE_ID = "io.github.pyvesb.eclipse_solargraph";

private FileFieldEditor gemPath;
private FileFieldEditor readaptPath;
private BooleanFieldEditor systemRubyFieldEditor;
private DirectoryFieldEditor rubyDirFieldEditor;
private Composite rubyDirFieldEditorParent;
private Image gitHubImage;

@Override
public void createFieldEditors() {
addField(new FileFieldEditor(GEM_PATH.getKey(), GEM_PATH.getDesc(), true, getFieldEditorParent()));
addField(new FileFieldEditor(READAPT_PATH.getKey(), READAPT_PATH.getDesc(), true, getFieldEditorParent()));
gemPath = new FileFieldEditor(GEM_PATH.getKey(), GEM_PATH.getDesc(), true, getFieldEditorParent());
addField(gemPath);
readaptPath = new FileFieldEditor(READAPT_PATH.getKey(), READAPT_PATH.getDesc(), true, getFieldEditorParent());
addField(readaptPath);
addField(new BooleanFieldEditor(UPDATE_GEM.getKey(), UPDATE_GEM.getDesc(), getFieldEditorParent()));
systemRubyFieldEditor = new BooleanFieldEditor(SYSTEM_RUBY.getKey(), SYSTEM_RUBY.getDesc(), getFieldEditorParent());
addField(systemRubyFieldEditor);
Expand Down Expand Up @@ -105,4 +109,12 @@ public void dispose() {
}
}

public FileFieldEditor getGemPath() {
return gemPath;
}

public FileFieldEditor getReadaptPath() {
return readaptPath;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2020 Pierre-Yves B. and others.
* Copyright (c) 2019-2022 Pierre-Yves B. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.dialogs.PreferencesUtil;
Expand Down Expand Up @@ -65,15 +66,18 @@ private static List<String> getSolargraphCommand() {
private void displayNotFoundWarning() {
Display display = Display.getDefault();
display.asyncExec(() -> {
MessageDialog dialog = new MessageDialog(display.getActiveShell(), "Solargraph was not found", null,
MessageDialog notFoundDialog = new MessageDialog(display.getActiveShell(), "Solargraph was not found", null,
"Key features will not be available. Let Eclipse install the gem locally or specify its path "
+ "after running \"gem install solargraph\" in a terminal.",
MessageDialog.WARNING, 0, "Install gem", "Specify path");
if (dialog.open() == 0) { // First button index, install.
if (notFoundDialog.open() == 0) { // First button index, install.
GemHelper.install("Solargraph", GEM_PATH);
HAS_UPDATED_SOLARGRAPH.set(true);
} else {
PreferencesUtil.createPreferenceDialogOn(null, PreferencePage.PAGE_ID, null, null).open();
PreferenceDialog preferenceDialog = PreferencesUtil.createPreferenceDialogOn(null, PreferencePage.PAGE_ID,
null, null);
((PreferencePage) preferenceDialog.getSelectedPage()).getGemPath().setFocus();
preferenceDialog.open();
}
});
}
Expand Down

0 comments on commit 3fdda7a

Please sign in to comment.