diff --git a/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/launch/debug/ReadaptDebugDelegate.java b/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/launch/debug/ReadaptDebugDelegate.java index 8644458..9684c74 100644 --- a/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/launch/debug/ReadaptDebugDelegate.java +++ b/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/launch/debug/ReadaptDebugDelegate.java @@ -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 @@ -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; @@ -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(); } }); } diff --git a/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/preferences/PreferencePage.java b/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/preferences/PreferencePage.java index 67c8277..eebc5e0 100644 --- a/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/preferences/PreferencePage.java +++ b/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/preferences/PreferencePage.java @@ -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 @@ -50,6 +50,8 @@ 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; @@ -57,8 +59,10 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe @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); @@ -105,4 +109,12 @@ public void dispose() { } } + public FileFieldEditor getGemPath() { + return gemPath; + } + + public FileFieldEditor getReadaptPath() { + return readaptPath; + } + } diff --git a/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/server/SolargraphStreamConnectionProvider.java b/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/server/SolargraphStreamConnectionProvider.java index cedf7c7..a49e237 100644 --- a/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/server/SolargraphStreamConnectionProvider.java +++ b/eclipse-solargraph-plugin/src/main/java/io/github/pyvesb/eclipse_solargraph/server/SolargraphStreamConnectionProvider.java @@ -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 @@ -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; @@ -65,15 +66,18 @@ private static List 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(); } }); }