From 5d5d455ca9861d72e8efacae1928574fcc32fb6e Mon Sep 17 00:00:00 2001 From: PyvesB Date: Sat, 10 Oct 2020 12:00:26 +0100 Subject: [PATCH] Add support page link in preferences page --- eclipse-solargraph-plugin/icon/github.png | Bin 0 -> 461 bytes .../preferences/PreferencePage.java | 35 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 eclipse-solargraph-plugin/icon/github.png diff --git a/eclipse-solargraph-plugin/icon/github.png b/eclipse-solargraph-plugin/icon/github.png new file mode 100644 index 0000000000000000000000000000000000000000..9b02913f908e39627e4f9a1e7c0372089ea09ab7 GIT binary patch literal 461 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbMf>Hwb*S0KIr|NqlwNF1_YHRJ5HTGcje0U+js9hc=YD;x9>mxO*dB72Wpw`>Eak7A<25MTZt)< zf%QP-)-Mj7LJI|KJ!S9y`9FOogTe~DWM4fOpKe@ literal 0 HcmV?d00001 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 012f78f..b885392 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) 2019 Pierre-Yves B. and others. + * Copyright (c) 2020 Pierre-Yves B. and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -18,14 +18,27 @@ import static io.github.pyvesb.eclipse_solargraph.preferences.StringPreferences.READAPT_PATH; import static io.github.pyvesb.eclipse_solargraph.preferences.StringPreferences.RUBY_DIR; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.DirectoryFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FileFieldEditor; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.preferences.ScopedPreferenceStore; @@ -39,6 +52,7 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe private BooleanFieldEditor systemRubyFieldEditor; private DirectoryFieldEditor rubyDirFieldEditor; private Composite rubyDirFieldEditorParent; + private Image gitHubImage; @Override public void createFieldEditors() { @@ -52,6 +66,17 @@ public void createFieldEditors() { rubyDirFieldEditor = new DirectoryFieldEditor(RUBY_DIR.getKey(), RUBY_DIR.getDesc(), rubyDirFieldEditorParent); rubyDirFieldEditor.setEnabled(!SYSTEM_RUBY.getValue(), rubyDirFieldEditorParent); addField(rubyDirFieldEditor); + + Composite composite = new Composite(rubyDirFieldEditorParent.getParent(), SWT.NONE); + composite.setLayout(new RowLayout(SWT.HORIZONTAL)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 7)); + URL url = FileLocator.find(FrameworkUtil.getBundle(getClass()), new Path("/icon/github.png")); + gitHubImage = ImageDescriptor.createFromURL(url).createImage(); + new Label(composite, SWT.NONE).setImage(gitHubImage); + Link supportLink = new Link(composite, SWT.NONE); + supportLink.setText("Head over to GitHub for support. " + + "Also feel free to star or fork the repository."); + supportLink.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> Program.launch(e.text))); } @Override @@ -70,4 +95,12 @@ public void propertyChange(PropertyChangeEvent event) { super.propertyChange(event); } + @Override + public void dispose() { + super.dispose(); + if (gitHubImage != null) { + gitHubImage.dispose(); + } + } + }