diff --git a/src/main/java/com/devoxx/genie/action/AddDirectoryAction.java b/src/main/java/com/devoxx/genie/action/AddDirectoryAction.java index 9c75cb3a..43e2e522 100644 --- a/src/main/java/com/devoxx/genie/action/AddDirectoryAction.java +++ b/src/main/java/com/devoxx/genie/action/AddDirectoryAction.java @@ -2,9 +2,10 @@ import com.devoxx.genie.service.FileListManager; import com.devoxx.genie.ui.util.NotificationUtil; -import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,7 @@ import static com.devoxx.genie.ui.util.WindowPluginUtil.ensureToolWindowVisible; -public class AddDirectoryAction extends AnAction { +public class AddDirectoryAction extends DumbAwareAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { @@ -57,4 +58,14 @@ public void update(@NotNull AnActionEvent e) { VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); e.getPresentation().setEnabledAndVisible(file != null && file.isDirectory()); } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } + + @Override + public boolean isDumbAware() { + return true; + } } diff --git a/src/main/java/com/devoxx/genie/action/AddDirectoryToClipBoardAction.java b/src/main/java/com/devoxx/genie/action/AddDirectoryToClipBoardAction.java index 8414ecf8..da7ae734 100644 --- a/src/main/java/com/devoxx/genie/action/AddDirectoryToClipBoardAction.java +++ b/src/main/java/com/devoxx/genie/action/AddDirectoryToClipBoardAction.java @@ -1,6 +1,5 @@ package com.devoxx.genie.action; -import com.devoxx.genie.service.LLMProviderService; import com.devoxx.genie.service.ProjectContentService; import com.devoxx.genie.ui.util.NotificationUtil; import com.intellij.openapi.actionSystem.ActionUpdateThread; diff --git a/src/main/java/com/devoxx/genie/action/AddFileAction.java b/src/main/java/com/devoxx/genie/action/AddFileAction.java index c32ca6ab..83b818c2 100644 --- a/src/main/java/com/devoxx/genie/action/AddFileAction.java +++ b/src/main/java/com/devoxx/genie/action/AddFileAction.java @@ -2,22 +2,18 @@ import com.devoxx.genie.service.FileListManager; import com.devoxx.genie.ui.util.NotificationUtil; -import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import static com.devoxx.genie.ui.util.WindowPluginUtil.ensureToolWindowVisible; -public class AddFileAction extends AnAction { +public class AddFileAction extends DumbAwareAction { - /** - * Add file to the window context. - * - * @param e the action event - */ @Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getProject(); @@ -29,10 +25,28 @@ public void actionPerformed(@NotNull AnActionEvent e) { FileListManager fileListManager = FileListManager.getInstance(); VirtualFile selectedFile = e.getData(CommonDataKeys.VIRTUAL_FILE); - if (selectedFile != null && !fileListManager.contains(selectedFile)) { + if (selectedFile != null && !selectedFile.isDirectory() && !fileListManager.contains(selectedFile)) { fileListManager.addFile(selectedFile); + } else if (selectedFile != null && selectedFile.isDirectory()) { + NotificationUtil.sendNotification(project, "Cannot add directories. Please select a file."); } else { - NotificationUtil.sendNotification(project, "File already added"); + NotificationUtil.sendNotification(project, "File already added or no file selected"); } } + + @Override + public void update(@NotNull AnActionEvent e) { + VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); + e.getPresentation().setEnabledAndVisible(file != null && !file.isDirectory()); + } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } + + @Override + public boolean isDumbAware() { + return true; + } } diff --git a/src/main/java/com/devoxx/genie/action/AddSnippetAction.java b/src/main/java/com/devoxx/genie/action/AddSnippetAction.java index 1981d23a..cc2c219e 100644 --- a/src/main/java/com/devoxx/genie/action/AddSnippetAction.java +++ b/src/main/java/com/devoxx/genie/action/AddSnippetAction.java @@ -1,13 +1,14 @@ package com.devoxx.genie.action; import com.devoxx.genie.service.FileListManager; -import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.LightVirtualFile; @@ -15,7 +16,7 @@ import static com.devoxx.genie.ui.util.WindowPluginUtil.ensureToolWindowVisible; -public class AddSnippetAction extends AnAction { +public class AddSnippetAction extends DumbAwareAction { public static final String CODE_SNIPPET = "codeSnippet"; public static final Key ORIGINAL_FILE_KEY = Key.create("ORIGINAL_FILE"); @@ -72,8 +73,8 @@ private static void addSelectedFile(VirtualFile selectedFile) { * @param selectionModel the selection model * @param selectedText the selected text */ - private void createAndAddVirtualFile(VirtualFile originalFile, - SelectionModel selectionModel, + private void createAndAddVirtualFile(@NotNull VirtualFile originalFile, + @NotNull SelectionModel selectionModel, String selectedText) { LightVirtualFile virtualFile = new LightVirtualFile(originalFile.getName(), selectedText); virtualFile.setFileType(fileType); @@ -83,4 +84,15 @@ private void createAndAddVirtualFile(VirtualFile originalFile, virtualFile.putUserData(SELECTION_END_KEY, selectionModel.getSelectionEnd()); FileListManager.getInstance().addFile(virtualFile); } + + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; + } + + @Override + public boolean isDumbAware() { + return true; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bbd92856..5a25a572 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ -#Mon Jul 01 20:49:31 CEST 2024 +#Mon Jul 01 21:30:51 CEST 2024 version=0.2.0