Skip to content

Commit

Permalink
Merge pull request #492 from devoxx/feat-489
Browse files Browse the repository at this point in the history
Feat #489 Right click to exclude directories
  • Loading branch information
stephanj authored Feb 6, 2025
2 parents a342501 + b725188 commit 7a0ac66
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.devoxx.genie"
version = "0.4.14"
version = "0.4.15"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AddDirectoryAction extends DumbAwareAction {

private static final String ADD_TO_CONTEXT = "AddDirectoryToContextWindow";
private static final String COPY_TO_CLIPBOARD = "CopyDirectoryToClipboard";

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/com/devoxx/genie/action/ExcludeDirectoryAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.devoxx.genie.action;

import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.util.NotificationUtil;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class ExcludeDirectoryAction extends AnAction {

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
// Get the current project
Project project = e.getProject();
if (project == null) {
Messages.showErrorDialog("No project found.", "Error");
return;
}

VirtualFile selectedDir = e.getData(CommonDataKeys.VIRTUAL_FILE);
if (selectedDir == null || !selectedDir.isDirectory()) {
NotificationUtil.sendNotification(project, "Please select a directory to exclude");
return;
}

// Get the absolute path of the directory
String directoryPath = selectedDir.getPath();

// Access the state service
DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance();

// Get current excluded directories
List<String> excludedDirectories = stateService.getExcludedDirectories();

// Check if already excluded
if (excludedDirectories.contains(directoryPath)) {
Messages.showInfoMessage(project, "Directory is already excluded.", "Information");
return;
}

// Add to excluded directories
excludedDirectories.add(directoryPath);
stateService.setExcludedDirectories(excludedDirectories);

// Optionally, refresh the settings UI if it's open
// This can be achieved by notifying listeners or using a messaging system

// Provide feedback to the user
Messages.showInfoMessage(project, "Directory excluded successfully.", "Success");
}

@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ private String truncateToTokens(@NotNull String text,
private boolean shouldExcludeDirectory(@NotNull VirtualFile file) {
DevoxxGenieSettingsService settings = DevoxxGenieStateService.getInstance();
return file.isDirectory() &&
(settings.getExcludedDirectories().contains(file.getName()) || shouldExcludeFile(file));
(settings.getExcludedDirectories().contains(file.getName()) ||
settings.getExcludedDirectories().contains(file.getPath()) ||
shouldExcludeFile(file));
}

private boolean shouldExcludeFile(@NotNull VirtualFile file) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
]]></description>

<change-notes><![CDATA[
<h2>V0.4.15</h2>
<UL>
<LI>Feat #488 : Increase timeout maximum value enhancement</LI>
<LI>Feat #420 : Migrate to Langchain4J 1.0.0-alpha1 enhancement</LI>
<LI>Feat #442 : OpenAi O1 doesn't support temperature, waiting for LangChain4J upgrade enhancement</LI>
<LI>Feat #489 : Right click to exclude directories</LI>
</UL>
<h2>V0.4.14</h2>
<UL>
<LI>Fix #462 : Remove deprecated Anthropics models</LI>
Expand Down Expand Up @@ -588,7 +595,15 @@
text="Add Directory to Prompt Context"
icon="/icons/pluginIcon.svg"
description="Add the selected directory to the context window">
<add-to-group group-id="ProjectViewPopupMenu"/>
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</action>

<action id="ExcludeDirectory"
class="com.devoxx.genie.action.ExcludeDirectoryAction"
text="Exclude Directory from Add Project"
icon="/icons/pluginIcon.svg"
description="Exclude selected directory from Add Project">
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</action>

<action id="CopyDirectoryToClipboard"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.4.14
version=0.4.15

0 comments on commit 7a0ac66

Please sign in to comment.