Skip to content

Commit

Permalink
#112 - build hotkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Oct 27, 2018
1 parent 209ff02 commit bd6511c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
8 changes: 5 additions & 3 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@
</project-components>

<actions>
<!-- Add your actions here -->
<action id="reason.refmt" class="com.reason.ide.actions.ReformatAction" text="Reformat code (refmt)">
<action id="reason.actions.make" class="com.reason.build.console.MakeAction" text="Bsb -make"/>
<action id="reason.actions.makeWorld" class="com.reason.build.console.MakeWorldAction"
text="bsb -clean-world -make-world"/>
<action id="reason.actions.refmt" class="com.reason.ide.actions.ReformatAction" text="Reformat code (refmt)">
<add-to-group group-id="CodeFormatGroup" anchor="after" relative-to-action="ReformatCode"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt shift R"/>
</action>
<action id="com.reason.ide.actions.ConvertAction" class="com.reason.ide.actions.ConvertAction"
<action id="reason.actions.convert" class="com.reason.ide.actions.ConvertAction"
text="Convert Reason-OCaml" description="Convert between Reason and OCaml code">
<add-to-group group-id="EditMenu" anchor="last"/>
</action>
Expand Down
3 changes: 3 additions & 0 deletions src/com/reason/build/bs/Bucklescript.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,4 +19,6 @@ public interface Bucklescript extends Compiler {
void refmt(@NotNull VirtualFile sourceFile, @NotNull String format, @NotNull Document document);

boolean isRefmtOnSaveEnabled();

ConsoleView getBsbConsole();
}
2 changes: 1 addition & 1 deletion src/com/reason/build/bs/BucklescriptManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/com/reason/build/console/BsToolWindowFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
23 changes: 10 additions & 13 deletions src/com/reason/build/console/CompilerAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions src/com/reason/build/console/MakeAction.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
10 changes: 6 additions & 4 deletions src/com/reason/build/console/MakeWorldAction.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit bd6511c

Please sign in to comment.