ProxyAI/src/main/java/ee/carlrobert/codegpt/actions/DisableCompletionsAction.java
Carl-Robert 657868453f
feat: migrate to a new inline completion api (#425)
* fix: plugin since/until build versions

* add necessary kotlin deps

* migrate to new inline completions api

* remove previous implementation

* replace build and platform versions

* bump gradle-intellij-plugin version
2024-03-27 14:34:09 +02:00

41 lines
1.6 KiB
Java

package ee.carlrobert.codegpt.actions;
import static ee.carlrobert.codegpt.settings.service.ServiceType.LLAMA_CPP;
import static ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import ee.carlrobert.codegpt.settings.GeneralSettings;
import ee.carlrobert.codegpt.settings.configuration.ConfigurationSettings;
import java.util.List;
import org.jetbrains.annotations.NotNull;
/**
* Disables code-completion.<br/> Publishes message to {@link CodeCompletionEnabledListener#TOPIC}
*/
public class DisableCompletionsAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
ConfigurationSettings.getCurrentState().setCodeCompletionsEnabled(false);
ApplicationManager.getApplication()
.getMessageBus().syncPublisher(CodeCompletionEnabledListener.TOPIC)
.onCodeCompletionsEnabledChange(false);
}
@Override
public void update(@NotNull AnActionEvent e) {
var selectedService = GeneralSettings.getCurrentState().getSelectedService();
var codeCompletionEnabled = ConfigurationSettings.getCurrentState().isCodeCompletionsEnabled();
e.getPresentation().setEnabled(codeCompletionEnabled);
e.getPresentation()
.setVisible(codeCompletionEnabled && List.of(OPENAI, LLAMA_CPP).contains(selectedService));
}
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}