Skip to content

Commit

Permalink
Use a toggle action instead of two states for offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jul 18, 2024
1 parent fecc6d5 commit 69e6a79
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/main/java/icons/BldIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ private static javax.swing.Icon load(String path) {
}

public static final Icon Bld = load("/icons/bldIcon.svg");
public static final Icon Online = load("/icons/online.svg");
public static final Icon Offline = load("/icons/offline.svg");
}
30 changes: 17 additions & 13 deletions src/main/java/rife/bld/idea/project/BldProjectOfflineAction.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
package rife.bld.idea.project;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import icons.BldIcons;
import org.jetbrains.annotations.NotNull;
import rife.bld.idea.execution.BldExecution;
import rife.bld.idea.utils.BldBundle;

final class BldProjectOfflineAction extends AnAction implements DumbAware {
final class BldProjectOfflineAction extends ToggleAction implements DumbAware {
private final Project project_;

public BldProjectOfflineAction(Project project) {
super(BldBundle.messagePointer("offline.bld.command.action.name"),
BldBundle.messagePointer("offline.bld.command.action.description"), BldIcons.Online);
BldBundle.messagePointer("offline.bld.command.action.description"), AllIcons.Actions.OfflineMode);
project_ = project;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
var execution = BldExecution.getInstance(project_);
execution.setOffline(!execution.isOffline());
boolean state = !isSelected(e);
setSelected(e, state);
Presentation presentation = e.getPresentation();
Toggleable.setSelected(presentation, state);
}

@Override
public boolean isSelected(@NotNull AnActionEvent e) {
return BldExecution.getInstance(project_).isOffline();
}

@Override
public void setSelected(@NotNull AnActionEvent e, boolean state) {
BldExecution.getInstance(project_).setOffline(state);
}

@Override
public void update(@NotNull AnActionEvent event) {
final var presentation = event.getPresentation();
presentation.setText(BldBundle.messagePointer("offline.bld.command.action.name"));
if (BldExecution.getInstance(project_).isOffline()) {
presentation.setIcon(BldIcons.Offline);
}
else {
presentation.setIcon(BldIcons.Online);
}
}

@Override
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/icons/offline.svg

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/resources/icons/offline_dark.svg

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/resources/icons/online.svg

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/resources/icons/online_dark.svg

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/messages/BldBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ run.bld.command.action.name=Run
run.bld.command.action.description=Run the selected command(s) with bld
edit.bld.command.action.name=Edit Main
edit.bld.command.action.description=Edit the bld main class
offline.bld.command.action.name=Toggle Offline
offline.bld.command.action.name=Toggle Offline Mode
offline.bld.command.action.description=Work with or without internet
properties.bld.command.action.name=Edit Properties
properties.bld.command.action.description=Edit the bld wrapper properties
Expand Down

0 comments on commit 69e6a79

Please sign in to comment.