Skip to content

Commit

Permalink
add button for new ui, implement force default while holding shift, v…
Browse files Browse the repository at this point in the history
…ersion 2.2
  • Loading branch information
LabyStudio committed Dec 15, 2022
1 parent d9a5c7a commit cff36dc
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 39 deletions.
31 changes: 31 additions & 0 deletions src/main/java/icons/ResourceIcon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package icons;

import com.intellij.ui.IconManager;

import javax.swing.Icon;
import java.awt.Component;
import java.awt.Graphics;

public class ResourceIcon implements Icon {

private final Icon baseIcon;

public ResourceIcon(String path) {
this.baseIcon = IconManager.getInstance().getIcon(path, ResourceIcon.class);
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
this.baseIcon.paintIcon(c, g, x, y);
}

@Override
public int getIconWidth() {
return this.baseIcon.getIconWidth();
}

@Override
public int getIconHeight() {
return this.baseIcon.getIconHeight();
}
}
36 changes: 4 additions & 32 deletions src/main/java/icons/SingleHotSwapIcons.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
package icons;

import com.intellij.icons.AllIcons;
import com.intellij.ui.IconManager;
import com.intellij.ui.JBColor;
import org.jetbrains.annotations.NotNull;

import javax.swing.Icon;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class SingleHotSwapIcons {

public static final @NotNull
Icon SINGLE_HOTSWAP = new Icon() {
private final Icon baseIcon = AllIcons.Actions.Compile;
@NotNull
public static final Icon SINGLE_HOTSWAP = new ResourceIcon("/icons/singlehotswap.svg");

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
IconManager.getInstance()
.colorize(
(Graphics2D) g,
this.baseIcon,
new JBColor(
new Color(0x3388FF),
new Color(0x3388FF)
)
).paintIcon(c, g, x, y);
}
@NotNull
public static final Icon SINGLE_HOTSWAP_REDESIGN = new ResourceIcon("/icons/singlehotswap_redesign.svg");

@Override
public int getIconWidth() {
return this.baseIcon.getIconWidth();
}

@Override
public int getIconHeight() {
return this.baseIcon.getIconHeight();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void actionPerformed(@NotNull AnActionEvent event) {
// Get debugger session
DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
DebuggerSession debugger = debuggerManager.getContext().getDebuggerSession();
assert debugger != null;

HotSwapProgressImpl progress = new HotSwapProgressImpl(project);
try {
Expand All @@ -126,7 +127,8 @@ public void actionPerformed(@NotNull AnActionEvent event) {
progress.setTitle("Initialize hotswap task...");

// Create compiler and progress
AbstractCompiler compiler = context.compiler(this.configuration);
boolean forceDefault = event.getInputEvent().isShiftDown();
AbstractCompiler compiler = context.compiler(this.configuration, forceDefault);
ClassFile outputFile = context.getClassFile(psiFile);
VirtualFile sourceFile = psiFile.getVirtualFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public interface Context {
* Returns the compiler for this context
*
* @param configuration The configuration to use to modify the compiler settings
* @param forceDefault Whether to force the default compiler
* @return The compiler for this context
*/
AbstractCompiler compiler(SingleHotswapConfiguration configuration);
AbstractCompiler compiler(SingleHotswapConfiguration configuration, boolean forceDefault);

/**
* Returns the class file for the given PSI file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public abstract class AbstractContext<T> implements Context {

@Override
public AbstractCompiler compiler(SingleHotswapConfiguration configuration) {
public AbstractCompiler compiler(SingleHotswapConfiguration configuration, boolean forceDefault) {
return new DefaultCompiler(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
public class JavaContext extends AbstractContext<PsiJavaFile> {

@Override
public AbstractCompiler compiler(SingleHotswapConfiguration configuration) {
public AbstractCompiler compiler(SingleHotswapConfiguration configuration, boolean forceDefault) {
// Choose between built-in Java compiler or default compiler
return configuration.isUseBuiltInCompiler()
return configuration.isUseBuiltInCompiler() && !forceDefault
? new BuiltInJavaCompiler(this)
: new DefaultCompiler(this);
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>net.labymod.intellij.singlehotswap</id>
<name>Single Hotswap</name>
<version>2.1</version>
<version>2.2</version>
<vendor email="[email protected]" url="https://www.labymod.net">LabyMedia</vendor>

<idea-version since-build="203.000"/>
Expand Down Expand Up @@ -35,17 +35,29 @@
</extensions>

<actions>
<action id="org.intellij.sdk.action.PopupDialogAction"
<action id="SingleHotswap"
class="net.labymod.intellij.singlehotswap.actions.SingleHotswapAction"
text="Single Hotswap" description="Hotswap just the opened file"
icon="SingleHotSwapIcons.SINGLE_HOTSWAP">
<add-to-group anchor="before" group-id="ToolbarRunGroup"
relative-to-action="RunConfiguration"/>
</action>
<action id="SingleHotswapRedesign"
class="net.labymod.intellij.singlehotswap.actions.SingleHotswapAction"
text="Single Hotswap" description="Hotswap just the opened file"
icon="SingleHotSwapIcons.SINGLE_HOTSWAP_REDESIGN">
<add-to-group anchor="before" group-id="RunToolbarMainActionGroup"
relative-to-action="MoreRunToolbarActions"/>
</action>
</actions>

<change-notes>
<![CDATA[
v2.2 (15.12.2022):
<ul>
<li>Added hotswap button to new UI</li>
<li>Added option to force the default compiler when holding shift while clicking on the hotswap button</li>
</ul>
v2.1 (17.07.2022):
<ul>
<li>Fixed support for kotlin & inner classes</li>
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/icons/singlehotswap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/resources/icons/singlehotswap_redesign.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cff36dc

Please sign in to comment.