diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 193488bc3..08d8d25ff 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -77,12 +77,14 @@ - - + + + - diff --git a/src/com/reason/build/bs/Bucklescript.java b/src/com/reason/build/bs/Bucklescript.java index a547169f4..3a4cd0bae 100644 --- a/src/com/reason/build/bs/Bucklescript.java +++ b/src/com/reason/build/bs/Bucklescript.java @@ -1,5 +1,6 @@ package com.reason.build.bs; +import com.intellij.execution.ui.ConsoleView; import com.intellij.openapi.editor.Document; import com.intellij.openapi.vfs.VirtualFile; import com.reason.build.Compiler; @@ -18,4 +19,6 @@ public interface Bucklescript extends Compiler { void refmt(@NotNull VirtualFile sourceFile, @NotNull String format, @NotNull Document document); boolean isRefmtOnSaveEnabled(); + + ConsoleView getBsbConsole(); } diff --git a/src/com/reason/build/bs/BucklescriptManager.java b/src/com/reason/build/bs/BucklescriptManager.java index bedd98ee7..9182e09b0 100644 --- a/src/com/reason/build/bs/BucklescriptManager.java +++ b/src/com/reason/build/bs/BucklescriptManager.java @@ -161,7 +161,7 @@ public boolean isRefmtOnSaveEnabled() { return RefmtProcess.getInstance(m_project).isOnSaveEnabled(); } - private ConsoleView getBsbConsole() { + public ConsoleView getBsbConsole() { ConsoleView console = null; ToolWindow window = ToolWindowManager.getInstance(m_project).getToolWindow("Bucklescript"); diff --git a/src/com/reason/build/console/BsToolWindowFactory.java b/src/com/reason/build/console/BsToolWindowFactory.java index 455a2df40..c4e668f33 100644 --- a/src/com/reason/build/console/BsToolWindowFactory.java +++ b/src/com/reason/build/console/BsToolWindowFactory.java @@ -24,7 +24,7 @@ public void createToolWindowContent(@NotNull final Project project, @NotNull Too BsConsole console = new BsConsole(project); panel.setContent(console.getComponent()); - ActionToolbar toolbar = createToolbar(project, console); + ActionToolbar toolbar = createToolbar(console); panel.setToolbar(toolbar.getComponent()); Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", true); @@ -35,12 +35,12 @@ public void createToolWindowContent(@NotNull final Project project, @NotNull Too Disposer.register(project, console); } - private ActionToolbar createToolbar(@NotNull Project project, @NotNull BsConsole console) { + private ActionToolbar createToolbar(@NotNull BsConsole console) { DefaultActionGroup group = new DefaultActionGroup(); group.add(new ScrollToTheEndToolbarAction(console.getEditor())); group.add(new ClearLogAction(console)); - group.add(new MakeAction(console, project)); - group.add(new MakeWorldAction(console, project)); + group.add(new MakeAction()); + group.add(new MakeWorldAction()); ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("left", group, false); toolbar.setTargetComponent(console.getComponent()); diff --git a/src/com/reason/build/console/CompilerAction.java b/src/com/reason/build/console/CompilerAction.java index 3730e6a27..ad307b66f 100644 --- a/src/com/reason/build/console/CompilerAction.java +++ b/src/com/reason/build/console/CompilerAction.java @@ -13,33 +13,30 @@ import com.reason.Platform; import com.reason.build.Compiler; import com.reason.build.CompilerManager; +import com.reason.build.bs.BucklescriptManager; import org.jetbrains.annotations.NotNull; import javax.swing.*; -public abstract class CompilerAction extends DumbAwareAction { +abstract class CompilerAction extends DumbAwareAction { - private final ConsoleView m_console; - private final Project m_project; - - CompilerAction(@NotNull String text, @NotNull String description, @NotNull Icon icon,@NotNull ConsoleView console, @NotNull Project project) { + CompilerAction(@NotNull String text, @NotNull String description, @NotNull Icon icon) { super(text, description, icon); - m_console = console; - m_project = project; } - void doAction(CliType cliType) { - Compiler compiler = CompilerManager.getInstance().getCompiler(m_project); + void doAction(@NotNull Project project, @NotNull CliType cliType) { + Compiler compiler = CompilerManager.getInstance().getCompiler(project); // Try to detect the current active editor - Editor editor = FileEditorManager.getInstance(m_project).getSelectedTextEditor(); + Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor == null) { - VirtualFile baseDir = Platform.findBaseRoot(m_project); - m_console.print("No active text editor found, using root directory " + baseDir.getPath() + "\n", ConsoleViewContentType.NORMAL_OUTPUT); + VirtualFile baseDir = Platform.findBaseRoot(project); + ConsoleView console = BucklescriptManager.getInstance(project).getBsbConsole(); + console.print("No active text editor found, using root directory " + baseDir.getPath() + "\n", ConsoleViewContentType.NORMAL_OUTPUT); compiler.run(baseDir, cliType); } else { Document document = editor.getDocument(); - PsiFile psiFile = PsiDocumentManager.getInstance(m_project).getPsiFile(document); + PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); if (psiFile != null) { compiler.run(psiFile.getVirtualFile(), cliType); } diff --git a/src/com/reason/build/console/MakeAction.java b/src/com/reason/build/console/MakeAction.java index ee659fcbc..7fc917ea2 100644 --- a/src/com/reason/build/console/MakeAction.java +++ b/src/com/reason/build/console/MakeAction.java @@ -1,19 +1,20 @@ package com.reason.build.console; -import com.intellij.execution.ui.ConsoleView; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; public class MakeAction extends CompilerAction { - MakeAction(@NotNull ConsoleView console, @NotNull Project project) { - super("Make", "Make", AllIcons.Actions.Compile, console, project); + public MakeAction() { + super("Make", "Make", AllIcons.Actions.Compile); } @Override public void actionPerformed(AnActionEvent e) { - doAction(CliType.make); + Project project = e.getProject(); + if (project != null) { + doAction(project, CliType.make); + } } } diff --git a/src/com/reason/build/console/MakeWorldAction.java b/src/com/reason/build/console/MakeWorldAction.java index 259c6d509..6f440eaea 100644 --- a/src/com/reason/build/console/MakeWorldAction.java +++ b/src/com/reason/build/console/MakeWorldAction.java @@ -1,18 +1,20 @@ package com.reason.build.console; -import com.intellij.execution.ui.ConsoleView; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.Project; public class MakeWorldAction extends CompilerAction { - MakeWorldAction(ConsoleView console, Project project) { - super("Clean and make world", "Clean and make world", AllIcons.General.Web, console, project); + MakeWorldAction() { + super("Clean and make world", "Clean and make world", AllIcons.General.Web); } @Override public void actionPerformed(AnActionEvent e) { - doAction(CliType.cleanMake); + Project project = e.getProject(); + if (project != null) { + doAction(project, CliType.cleanMake); + } } }