Skip to content

Commit

Permalink
Add reload action
Browse files Browse the repository at this point in the history
  • Loading branch information
dubreuia committed Jan 17, 2019
1 parent e1fa97a commit faaa55a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -96,6 +96,10 @@ public boolean isJavaAvailable() {
return javaAvailable;
}

public Storage getStorage(Project project) {
return storageFactory.getStorage(project);
}

@Override
public void beforeAllDocumentsSaving() {
if (isRunning) {
Expand Down Expand Up @@ -136,8 +140,7 @@ public void processPsiFilesIfNecessary(Project project,
Set<PsiFile> psiFiles,
Action activation,
ExecutionMode mode) {
Storage storage = storageFactory.getStorage(project);
Engine engine = new Engine(storage, processors, project, psiFiles, activation, mode);
Engine engine = new Engine(getStorage(project), processors, project, psiFiles, activation, mode);
engine.processPsiFilesIfNecessary();
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/dubreuia/model/Action.java
Expand Up @@ -23,7 +23,7 @@ public enum Action {
activateOnBatch("Activate save actions on batch (\"Code > Save Actions > Execute on multiple files\")",
activation, false),

noActionIfCompileErrors("No action if compile errors",
noActionIfCompileErrors("No action if compile errors (applied per file)",
activation, false),

// Global
Expand All @@ -45,6 +45,9 @@ public enum Action {
compile("Compile files (using \"Build > Build Project\")",
build, false),

reload("Reload files in running debugger (using \"Run > Reload Changed Classes\")",
build, false),

// Java fixes

fieldCanBeFinal("Add final modifier to field",
Expand Down Expand Up @@ -136,4 +139,4 @@ public static Stream<Action> stream(ActionType type) {
return Arrays.stream(values()).filter(action -> action.type.equals(type));
}

}
}
19 changes: 19 additions & 0 deletions src/main/java/com/dubreuia/processors/BuildProcessor.java
Expand Up @@ -3,6 +3,10 @@
import com.dubreuia.core.ExecutionMode;
import com.dubreuia.core.component.SaveActionManager;
import com.dubreuia.model.Action;
import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.debugger.ui.HotSwapUI;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
Expand All @@ -28,6 +32,21 @@ public enum BuildProcessor implements Processor {
}
}),

reload(Action.reload,
(project, psiFiles) -> () -> {
if (SaveActionManager.getInstance().isCompilingAvailable()) {
DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
DebuggerSession session = debuggerManager.getContext().getDebuggerSession();
if (session != null && session.isAttached()) {
boolean compileEnabled = SaveActionManager.getInstance()
.getStorage(project).isEnabled(Action.compile);
boolean compileHotswapSetting = DebuggerSettings.getInstance().COMPILE_BEFORE_HOTSWAP;
boolean compileBeforeHotswap = compileEnabled ? false : compileHotswapSetting;
HotSwapUI.getInstance(project).reloadChangedClasses(session, compileBeforeHotswap);
}
}
}),

;

private final Action action;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/dubreuia/ui/BuildPanel.java
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;

import static com.dubreuia.model.Action.compile;
import static com.dubreuia.model.Action.reload;

class BuildPanel {

Expand All @@ -28,6 +29,7 @@ JPanel getPanel() {
panel.setBorder(IdeBorderFactory.createTitledBorder(TEXT_TITLE_ACTIONS));
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(checkboxes.get(compile));
panel.add(checkboxes.get(reload));
panel.add(Box.createHorizontalGlue());
panel.setMinimumSize(new Dimension(Short.MAX_VALUE, 0));
return panel;
Expand Down

0 comments on commit faaa55a

Please sign in to comment.