Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jul 20, 2024
1 parent c80b29f commit 156026f
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 57 deletions.
31 changes: 31 additions & 0 deletions src/main/java/rife/bld/idea/console/BldConsoleClearAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.console;

import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull;

class BldConsoleClearAction extends DumbAwareAction {
public BldConsoleClearAction() {
super(IdeBundle.message("terminal.action.ClearBuffer.text"), null, AllIcons.Actions.GC);
}

@Override
public void actionPerformed(AnActionEvent e) {
var project = e.getProject();
if (project != null) {
BldConsoleManager.getConsole(project).clear();
}
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
46 changes: 46 additions & 0 deletions src/main/java/rife/bld/idea/console/BldConsoleStopAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.console;

import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull;
import rife.bld.idea.execution.BldExecution;
import rife.bld.idea.utils.BldBundle;

class BldConsoleStopAction extends DumbAwareAction {
public BldConsoleStopAction() {
super(IdeBundle.message("action.stop"), null, AllIcons.Actions.Suspend);
}

@Override
public void actionPerformed(AnActionEvent e) {
var project = e.getProject();
if (project != null) {
BldExecution.getInstance(project).terminateBldProcess();
BldConsoleManager.getConsole(project).print(BldBundle.message("bld.command.terminated"), ConsoleViewContentType.ERROR_OUTPUT);
}
}

@Override
public void update(AnActionEvent event) {
// Make the action only clickable when there is an active bld process
var presentation = event.getPresentation();
var project = event.getProject();
if (project == null) {
return;
}
presentation.setEnabled(BldExecution.getInstance(project).hasActiveBldProcess());
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
59 changes: 2 additions & 57 deletions src/main/java/rife/bld/idea/console/BldConsoleViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
package rife.bld.idea.console;

import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.errorTreeView.NewErrorTreeRenderer;
import com.intellij.ide.errorTreeView.impl.ErrorTreeViewConfiguration;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.ui.AutoScrollToSourceHandler;
import com.intellij.ui.IdeBorderFactory;
Expand All @@ -21,8 +18,6 @@
import com.intellij.util.EditSourceOnDoubleClickHandler;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.NotNull;
import rife.bld.idea.execution.BldExecution;
import rife.bld.idea.utils.BldBundle;
import rife.bld.idea.utils.BldConstants;

import javax.swing.*;
Expand Down Expand Up @@ -89,60 +84,10 @@ public void setRowHeight(int i) {
};
}

private static class StopAction extends DumbAwareAction {
public StopAction() {
super(IdeBundle.message("action.stop"), null, AllIcons.Actions.Suspend);
}

@Override
public void actionPerformed(AnActionEvent e) {
var project = e.getProject();
if (project != null) {
BldExecution.getInstance(project).terminateBldProcess();
BldConsoleManager.getConsole(project).print(BldBundle.message("bld.command.terminated"), ConsoleViewContentType.ERROR_OUTPUT);
}
}

@Override
public void update(AnActionEvent event) {
// Make the action only clickable when there is an active bld process
var presentation = event.getPresentation();
var project = event.getProject();
if (project == null) {
return;
}
presentation.setEnabled(BldExecution.getInstance(project).hasActiveBldProcess());
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}

private static class ClearAction extends DumbAwareAction {
public ClearAction() {
super(IdeBundle.message("terminal.action.ClearBuffer.text"), null, AllIcons.Actions.GC);
}

@Override
public void actionPerformed(AnActionEvent e) {
var project = e.getProject();
if (project != null) {
BldConsoleManager.getConsole(project).clear();
}
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}

private JPanel createToolbarPanel() {
var group = new DefaultActionGroup();
group.add(new StopAction());
group.add(new ClearAction());
group.add(new BldConsoleStopAction());
group.add(new BldConsoleClearAction());

var toolbar_panel = new JPanel(new BorderLayout());
var action_manager = ActionManager.getInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.project;

import com.intellij.icons.AllIcons;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.project;

import com.intellij.icons.AllIcons;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.project;

import com.intellij.icons.AllIcons;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.project;

import com.intellij.icons.AllIcons;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.project;

import com.intellij.execution.ui.ConsoleViewContentType;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/rife/bld/idea/project/BldProjectRunAction.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.idea.project;

import com.intellij.icons.AllIcons;
Expand Down

0 comments on commit 156026f

Please sign in to comment.