Skip to content

Commit

Permalink
Create a welcome IdeHook (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Jan 30, 2023
2 parents b47c159 + 80aebb6 commit 45356d3
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 7 deletions.
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.

## [Unreleased]
### Added
- `equoIde { welcome().openUrl('...` for opening a browser on startup. ([#65](https://github.com/equodev/equo-ide/pull/65))

## [0.12.1] - 2023-01-25
### Fixed
Expand Down
7 changes: 4 additions & 3 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ plugins {
id 'dev.equo.ide' version '{{ latest version at top of page }}'
}
equoIde { // launch with gradlew equoIde
branding.title('My IDE')
branding.icon(file('my_icon.png'))
branding.splash(file('my_splash.png'))
branding().title('My IDE')
branding().icon(file('my_icon.png'))
branding().splash(file('my_splash.png'))
welcome().openUrl('https://github.com/me/myproject/CONTRIBUTING.md')
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import dev.equo.ide.IdeHook;
import dev.equo.ide.IdeHookBranding;
import dev.equo.ide.IdeHookWelcome;
import dev.equo.solstice.p2.P2Client;
import dev.equo.solstice.p2.P2Model;
import dev.equo.solstice.p2.P2Query;
Expand All @@ -29,6 +30,20 @@ public class EquoIdeExtension extends P2ModelDsl {
ideHooks.add(branding);
}

public IdeHookBranding branding() {
return branding;
}

private IdeHookWelcome welcome = null;

public IdeHookWelcome welcome() {
if (welcome == null) {
welcome = new IdeHookWelcome();
ideHooks.add(welcome);
}
return welcome;
}

private static void setToDefault(P2Model model) {
model.addP2Repo("https://download.eclipse.org/eclipse/updates/4.26/");
model.getInstall().add("org.eclipse.releng.java.languages.categoryIU");
Expand Down
2 changes: 2 additions & 0 deletions plugin-maven/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.

## [Unreleased]
### Added
- `<welcome><openUrl>...` for opening a browser on startup. ([#65](https://github.com/equodev/equo-ide/pull/65))

## [0.12.1] - 2023-01-25
### Fixed
Expand Down
3 changes: 3 additions & 0 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Use it like this with `mvn equo-ide:launch`
<icon>${project.basedir}/my_icon.png</icon>
<splash>${project.basedir}/my_splash.png</splash>
</branding>
<welcome>
<openUrl>https://github.com/me/myproject/CONTRIBUTING.md</openUrl>
</welcome>
</configuration>
</plugin>

Expand Down
9 changes: 9 additions & 0 deletions plugin-maven/src/main/java/dev/equo/ide/maven/LaunchMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.equo.ide.BuildPluginIdeMain;
import dev.equo.ide.IdeHook;
import dev.equo.ide.IdeHookBranding;
import dev.equo.ide.IdeHookWelcome;
import dev.equo.ide.IdeLockFile;
import dev.equo.solstice.NestedJars;
import dev.equo.solstice.p2.P2Client;
Expand Down Expand Up @@ -48,6 +49,9 @@ public class LaunchMojo extends AbstractP2Mojo {
@Parameter(required = false)
private Branding branding = new Branding();

@Parameter(required = false)
private Welcome welcome = new Welcome();

/** Wipes all IDE settings and state before rebuilding and launching. */
@Parameter(property = "clean", defaultValue = "false")
private boolean clean;
Expand Down Expand Up @@ -135,6 +139,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
var ideHooks = new IdeHook.List();
ideHooks.add(
new IdeHookBranding().title(branding.title).icon(branding.icon).splash(branding.splash));
if (welcome != null) {
var welcomeHook = new IdeHookWelcome();
welcomeHook.openUrl(welcome.openUrl);
ideHooks.add(welcomeHook);
}

BuildPluginIdeMain.Caller caller = new BuildPluginIdeMain.Caller();
caller.lockFile = lockfile;
Expand Down
21 changes: 21 additions & 0 deletions plugin-maven/src/main/java/dev/equo/ide/maven/Welcome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2022 EquoTech, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EquoTech, Inc. - initial API and implementation
*******************************************************************************/
package dev.equo.ide.maven;

import org.apache.maven.plugins.annotations.Parameter;
import org.sonatype.inject.Nullable;

public class Welcome {
@Parameter @Nullable String openUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ equo-ide:launch
User property: useAtomos
Determines whether to use Solstice's built-in OSGi runtime or instead
Atomos+Equinox.

welcome
(no description available)
.
.
[INFO] ------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions solstice/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.

## [Unreleased]
### Added
- `IdeHookWelcome` for opening a browser on welcome, and `PartDescriptor` for creating IDE parts without any `plugin.xml` metadata ([#65](https://github.com/equodev/equo-ide/pull/65))

## [0.12.1] - 2023-01-25
### Fixed
Expand Down
22 changes: 18 additions & 4 deletions solstice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ apply from: 干.file('sonatype.gradle')

apply plugin: 'eclipse'

jar.manifest.attributes.put('Implementation-Version', spotlessChangelog.versionNext)
jar.manifest.attributes(
'Bundle-SymbolicName': 'dev.equo.ide; singleton:=true',
'Bundle-Version': '0.0.0',
'Implementation-Version': spotlessChangelog.versionNext
)

spotless {
java {
custom 'AtomosFrontend', { text ->
Expand Down Expand Up @@ -58,14 +63,19 @@ tasks.named('test') {
}
apply from: 干.file('snapshot-testing.gradle')

def PLUGIN_SHIMS = []
for (glue in PLUGIN_SHIMS) {
sourceSets.register(glue) {
def PLUGIN_SHIMS = ['welcome']
for (shim in PLUGIN_SHIMS) {
sourceSets.register(shim) {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
java {}
}
}
jar {
for (shim in PLUGIN_SHIMS) {
from sourceSets.getByName(shim).output.classesDirs
}
}

apply plugin: 'dev.equo.p2deps'
p2deps {
Expand All @@ -86,6 +96,10 @@ p2deps {
install 'org.eclipse.ui.ide.application'
install 'org.eclipse.equinox.event'
}
into 'welcomeCompileOnly', {
p2repo 'https://download.eclipse.org/eclipse/updates/4.26/'
install 'org.eclipse.platform.ide.categoryIU'
}
}

tasks.register('IdeMainTest', JavaExec) {
Expand Down
34 changes: 34 additions & 0 deletions solstice/src/main/java/dev/equo/ide/IdeHookWelcome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2022 EquoTech, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EquoTech, Inc. - initial API and implementation
*******************************************************************************/
package dev.equo.ide;

public class IdeHookWelcome implements IdeHook {
String openUrl;

public IdeHookWelcome openUrl(String openUrl) {
this.openUrl = openUrl;
return this;
}

@Override
public IdeHookInstantiated instantiate() {
try {
var clazz = Class.forName("dev.equo.ide.Welcome");
var constructor = clazz.getDeclaredConstructor(IdeHookWelcome.class);
return (IdeHookInstantiated) constructor.newInstance(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
100 changes: 100 additions & 0 deletions solstice/src/main/java/dev/equo/ide/ui/PartDescriptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (c) 2022 EquoTech, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EquoTech, Inc. - initial API and implementation
*******************************************************************************/
package dev.equo.ide.ui;

import java.util.function.Consumer;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

/** Creates Eclipse parts using only code, no metadata. */
public class PartDescriptor {
private Consumer<Composite> coat;
private ImageDescriptor tabIcon;
private String tabName;
private String toolTipText;

public static PartDescriptor create(String tabName, Consumer<Composite> coat) {
return new PartDescriptor(tabName, coat);
}

private PartDescriptor(String tabName, Consumer<Composite> coat) {
this.tabName = tabName;
this.coat = coat;
}

public PartDescriptor tabIcon(ImageDescriptor tabIcon) {
this.tabIcon = tabIcon;
return this;
}

public PartDescriptor toolTipText(String toolTipText) {
this.toolTipText = toolTipText;
return this;
}

public void openOn(IWorkbenchPage page) {
try {
page.openEditor(new Input(), PartDescriptorHelper.EDITOR_ID);
} catch (PartInitException e) {
throw new RuntimeException(e);
}
}

public void openOnActivePage() {
var workbench = PlatformUI.getWorkbench();
var window = workbench.getActiveWorkbenchWindow();
openOn(window.getActivePage());
}

class Input implements IEditorInput {
@Override
public boolean exists() {
return false;
}

@Override
public ImageDescriptor getImageDescriptor() {
return tabIcon;
}

@Override
public String getName() {
return tabName;
}

@Override
public String getToolTipText() {
return toolTipText;
}

@Override
public IPersistableElement getPersistable() {
return null;
}

@Override
public <T> T getAdapter(Class<T> adapter) {
return null;
}

void createPartControl(Composite parentCmp) {
coat.accept(parentCmp);
}
}
}
67 changes: 67 additions & 0 deletions solstice/src/main/java/dev/equo/ide/ui/PartDescriptorHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2022 EquoTech, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EquoTech, Inc. - initial API and implementation
*******************************************************************************/
package dev.equo.ide.ui;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.part.EditorPart;

/** NOT FOR END-USER USAGE, use {@link PartDescriptor}. */
public class PartDescriptorHelper extends EditorPart {
static final String EDITOR_ID = "dev.equo.ide.ui.PartDescriptorHelper";

@Override
public void createPartControl(Composite parentCmp) {
var input = (PartDescriptor.Input) getEditorInput();
input.createPartControl(parentCmp);
}

@SuppressWarnings("unchecked")
@Override
public void init(IEditorSite site, IEditorInput input) {
setSite(site);
setInput(input);

var inputCast = (PartDescriptor.Input) getEditorInput();
setPartName(inputCast.getName());
var image = inputCast.getImageDescriptor();
if (image == null) {
setTitleImage(null);
} else {
setTitleImage(image.createImage());
}
setTitleToolTip(inputCast.getToolTipText());
}

@Override
public final boolean isSaveAsAllowed() {
return false;
}

@Override
public boolean isDirty() {
return false;
}

@Override
public void doSave(IProgressMonitor monitor) {}

@Override
public void doSaveAs() {}

@Override
public void setFocus() {}
}
Loading

0 comments on commit 45356d3

Please sign in to comment.