Skip to content

Commit

Permalink
implement configuration to toggle force built-in compiler option
Browse files Browse the repository at this point in the history
  • Loading branch information
LabyStudio committed Jan 24, 2022
1 parent 0b64d12 commit 9550691
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 2 deletions.
Expand Up @@ -12,6 +12,7 @@
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.module.Module;
Expand All @@ -23,6 +24,7 @@
import com.intellij.task.impl.ModuleFilesBuildTaskImpl;
import net.labymod.intellij.singlehotswap.hotswap.EnumFileType;
import net.labymod.intellij.singlehotswap.hotswap.IHotswap;
import net.labymod.intellij.singlehotswap.storage.SingleHotswapConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -35,6 +37,8 @@
*/
public class SingleHotswapAction extends CompileAction {

private final SingleHotswapConfiguration configuration = ServiceManager.getService( SingleHotswapConfiguration.class );

/**
* Update the visibility of the single hotswap button
* The button is only visible if the debug session is running and a compilable file is available.
Expand Down Expand Up @@ -148,7 +152,7 @@ private void compileSingleFile( Project project, VirtualFile virtualFile, Consum
ExternalSystemModulePropertyManager propertyManager = ExternalSystemModulePropertyManager.getInstance( module );
String prevSystemIdName = propertyManager.getExternalSystemId();
@Nullable ProjectSystemId prevSystemId = prevSystemIdName == null ? null : ProjectSystemId.findById( prevSystemIdName );
if ( prevSystemId != null ) {
if ( prevSystemId != null && this.configuration.isForceBuiltInCompiler() ) {
propertyManager.setExternalId( ProjectSystemId.IDE );
}

Expand All @@ -159,7 +163,7 @@ private void compileSingleFile( Project project, VirtualFile virtualFile, Consum
settings.RUN_HOTSWAP_AFTER_COMPILE = prevRunHotswap;

// Switch back to previous compiler
if ( prevSystemId != null ) {
if ( prevSystemId != null && this.configuration.isForceBuiltInCompiler() ) {
ApplicationManager.getApplication().invokeLater( ( ) -> propertyManager.setExternalId( prevSystemId ) );
}

Expand Down
@@ -0,0 +1,47 @@
package net.labymod.intellij.singlehotswap.storage;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@State( name = "SingleHotswapConfiguration", storages = @Storage( "singlehotswap.xml" ) )
public class SingleHotswapConfiguration implements PersistentStateComponent<SingleHotswapConfiguration> {

private boolean forceBuiltInCompiler = false;

@Override
public @Nullable SingleHotswapConfiguration getState( ) {
return this;
}

@Override
public void loadState( @NotNull SingleHotswapConfiguration languageConfiguration ) {
XmlSerializerUtil.copyBean( languageConfiguration, this );
}

@Override
public boolean equals( Object o ) {
if ( this == o ) return true;
if ( o == null || this.getClass() != o.getClass() ) return false;
SingleHotswapConfiguration that = (SingleHotswapConfiguration) o;
return this.forceBuiltInCompiler == that.forceBuiltInCompiler;
}

@Override
public int hashCode( ) {
return Objects.hash( this.forceBuiltInCompiler );
}

public boolean isForceBuiltInCompiler( ) {
return this.forceBuiltInCompiler;
}

public void setForceBuiltInCompiler( boolean forceBuiltInCompiler ) {
this.forceBuiltInCompiler = forceBuiltInCompiler;
}
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.labymod.intellij.singlehotswap.storage.SingleHotswapConfigurationGui">
<grid id="5007" binding="panel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="3">
<constraints>
<xy x="0" y="0" width="712" height="79"/>
</constraints>
<properties>
<alignmentY value="0.0"/>
<minimumSize width="-1" height="-1"/>
<preferredSize width="-1" height="-1"/>
</properties>
<border type="none"/>
<children>
<component id="a729c" class="javax.swing.JCheckBox" binding="checkBoxForceBuiltInCompiler">
<constraints/>
<properties>
<selected value="false"/>
<text value="Force Built-In Compiler"/>
<toolTipText value="Increases the speed of a hotswap for Gradle projects by using Intellij's internal compiler for single hotswaps."/>
</properties>
</component>
</children>
</grid>
</form>
@@ -0,0 +1,52 @@
package net.labymod.intellij.singlehotswap.storage;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.SearchableConfigurable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class SingleHotswapConfigurationGui implements SearchableConfigurable, Configurable.NoScroll {

private final SingleHotswapConfiguration state;

private JPanel panel;

private JCheckBox checkBoxForceBuiltInCompiler;

public SingleHotswapConfigurationGui( ) {
this.state = ServiceManager.getService( SingleHotswapConfiguration.class );
}

@Override
public @NotNull String getId( ) {
return "SingleHotswapGui";
}

@Override
public String getDisplayName( ) {
return "Single Hotswap";
}

@Override
public @Nullable JComponent createComponent( ) {
return this.panel;
}

@Override
public boolean isModified( ) {
return this.state.isForceBuiltInCompiler() != this.checkBoxForceBuiltInCompiler.isSelected();
}

@Override
public void apply( ) {
this.state.setForceBuiltInCompiler( this.checkBoxForceBuiltInCompiler.isSelected() );
}

@Override
public void reset( ) {
this.checkBoxForceBuiltInCompiler.setSelected( this.state.isForceBuiltInCompiler() );
}
}
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Expand Up @@ -23,6 +23,12 @@

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="SingleHotswap" displayType="BALLOON"/>

<!-- Settings Configuration -->
<applicationService id="CDSLanguageConfiguration"
serviceImplementation="net.labymod.intellij.singlehotswap.storage.SingleHotswapConfiguration"/>
<applicationConfigurable instance="net.labymod.intellij.singlehotswap.storage.SingleHotswapConfigurationGui"
id="debugger.singlehotswap" parentId="project.propDebugger" displayName="Single Hotswap"/>
</extensions>

<actions>
Expand Down

0 comments on commit 9550691

Please sign in to comment.