Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #325: Exclude specific files by name #326

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2.26"
version = "0.2.27"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public interface DevoxxGenieSettingsService {

Integer getDefaultWindowContext();

List<String> getExcludedFiles();

void setCustomPrompts(List<CustomPrompt> customPrompts);

void setLanguageModels(List<LanguageModel> languageModels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,15 @@ private boolean shouldExcludeDirectory(@NotNull VirtualFile file) {
* @return true if the file should be excluded, false otherwise
*/
private boolean shouldExcludeFile(@NotNull VirtualFile file) {
if (DevoxxGenieStateService.getInstance().getUseGitIgnore()) {
DevoxxGenieSettingsService settings = DevoxxGenieStateService.getInstance();

// Check if file is in excluded files list
if (settings.getExcludedFiles().contains(file.getName())) {
return true;
}

// Check gitignore if enabled
if (settings.getUseGitIgnore()) {
if (gitignoreParser != null) {
Path path = Paths.get(file.getPath());
return gitignoreParser.matches(path);
Expand All @@ -329,9 +337,15 @@ private boolean shouldExcludeFile(@NotNull VirtualFile file) {
*/
private boolean shouldIncludeFile(@NotNull VirtualFile file) {
DevoxxGenieSettingsService settings = DevoxxGenieStateService.getInstance();

// First check if file should be excluded
if (shouldExcludeFile(file)) {
return false;
}

// Then check if extension is included
String extension = file.getExtension();
boolean includedByExtension = extension != null && settings.getIncludedFileExtensions().contains(extension.toLowerCase());
return includedByExtension && !shouldExcludeFile(file);
return extension != null && settings.getIncludedFileExtensions().contains(extension.toLowerCase());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static DevoxxGenieStateService getInstance() {
return ApplicationManager.getApplication().getService(DevoxxGenieStateService.class);
}

private List<String> excludedFiles = new ArrayList<>(Arrays.asList(
"package-lock.json", "yarn.lock", "pom.xml", "build.gradle", "settings.gradle"
));

private List<CustomPrompt> customPrompts = new ArrayList<>();

private List<LanguageModel> languageModels = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devoxx.genie.ui.settings.copyproject;

import com.devoxx.genie.service.DevoxxGenieSettingsService;
import com.devoxx.genie.ui.settings.AbstractSettingsComponent;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.intellij.ui.AddEditRemovePanel;
Expand All @@ -19,6 +18,7 @@
public class CopyProjectSettingsComponent extends AbstractSettingsComponent {

private final ExcludedDirectoriesPanel excludedDirectoriesPanel;
private final ExcludedFilesPanel excludedFilesPanel; // New panel for excluded files
private final IncludedFileExtensionsPanel includedFileExtensionsPanel;
private final JCheckBox excludeJavadocCheckBox;
private final JCheckBox useGitIgnoreCheckBox;
Expand All @@ -27,6 +27,7 @@ public CopyProjectSettingsComponent() {
DevoxxGenieStateService settings = DevoxxGenieStateService.getInstance();
useGitIgnoreCheckBox = new JCheckBox("Use .gitignore", settings.getUseGitIgnore());
excludedDirectoriesPanel = new ExcludedDirectoriesPanel(settings.getExcludedDirectories());
excludedFilesPanel = new ExcludedFilesPanel(settings.getExcludedFiles()); // Initialize the new panel
includedFileExtensionsPanel = new IncludedFileExtensionsPanel(settings.getIncludedFileExtensions());
excludeJavadocCheckBox = new JCheckBox("Exclude Javadoc", settings.getExcludeJavaDoc());
}
Expand All @@ -46,6 +47,7 @@ public JPanel createPanel() {
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
contentPanel.add(excludedDirectoriesPanel);
contentPanel.add(excludedFilesPanel);

contentPanel.add(createUseGitIgnorePanel());

Expand Down Expand Up @@ -103,7 +105,7 @@ public List<String> getIncludedFileExtensions() {

private static class ExcludedDirectoriesPanel extends AddEditRemovePanel<String> {
public ExcludedDirectoriesPanel(List<String> initialData) {
super(new ExcludedDirectoriesModel(), initialData, "Excluded Directories");
super(new ExcludedDirectoriesModel(), initialData, "Excluded directories");
setPreferredSize(new Dimension(400, 200));
}

Expand Down Expand Up @@ -139,7 +141,7 @@ protected String editItem(String item) {

private static class IncludedFileExtensionsPanel extends AddEditRemovePanel<String> {
public IncludedFileExtensionsPanel(List<String> initialData) {
super(new IncludedFileExtensionsModel(), initialData, "Included File Extensions");
super(new IncludedFileExtensionsModel(), initialData, "Included file extensions");
setPreferredSize(new Dimension(400, 200));
}

Expand Down Expand Up @@ -177,6 +179,10 @@ public boolean getExcludeJavadoc() {
return excludeJavadocCheckBox.isSelected();
}

public List<String> getExcludedFiles() {
return excludedFilesPanel.getData();
}

public boolean getUseGitIgnore() {
return useGitIgnoreCheckBox.isSelected();
}
Expand Down Expand Up @@ -216,4 +222,58 @@ public Object getField(String o, int columnIndex) {
return o;
}
}

private static class ExcludedFilesPanel extends AddEditRemovePanel<String> {
public ExcludedFilesPanel(List<String> initialData) {
super(new ExcludedFilesModel(), initialData, "Excluded files");
setPreferredSize(new Dimension(400, 200));
}

@Override
protected String addItem() {
return showEditDialog("");
}

@Override
protected boolean removeItem(String item) {
return true;
}

@Override
protected String editItem(String item) {
return showEditDialog(item);
}

private @Nullable String showEditDialog(String initialValue) {
JBTextField field = new JBTextField(initialValue);
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("File name:"), BorderLayout.NORTH);
panel.add(field, BorderLayout.CENTER);
panel.setBorder(JBUI.Borders.empty(10));

int result = JOptionPane.showConfirmDialog(this, panel, "Enter File Name", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
return field.getText().trim();
}
return null;
}
}

private static class ExcludedFilesModel extends AddEditRemovePanel.TableModel<String> {
@Override
public int getColumnCount() {
return 1;
}

@Contract(pure = true)
@Override
public @NotNull String getColumnName(int columnIndex) {
return "File Name";
}

@Override
public Object getField(String o, int columnIndex) {
return o;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.devoxx.genie.ui.settings.copyproject;

import com.devoxx.genie.service.DevoxxGenieSettingsService;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.intellij.openapi.options.Configurable;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

public class CopyProjectSettingsConfigurable implements Configurable {

private CopyProjectSettingsComponent copyProjectSettingsComponent;
private final DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance();

@Nls(capitalization = Nls.Capitalization.Title)
@Override
Expand All @@ -27,20 +28,20 @@ public JComponent createComponent() {

@Override
public boolean isModified() {
DevoxxGenieStateService settings = DevoxxGenieStateService.getInstance();
return !copyProjectSettingsComponent.getExcludedDirectories().equals(settings.getExcludedDirectories()) ||
!copyProjectSettingsComponent.getIncludedFileExtensions().equals(settings.getIncludedFileExtensions()) ||
copyProjectSettingsComponent.getExcludeJavadoc() != settings.getExcludeJavaDoc() ||
copyProjectSettingsComponent.getUseGitIgnore() != settings.getUseGitIgnore();
return !copyProjectSettingsComponent.getExcludedDirectories().equals(stateService.getExcludedDirectories()) ||
!copyProjectSettingsComponent.getExcludedFiles().equals(stateService.getExcludedFiles()) || // Add check for excluded files
!copyProjectSettingsComponent.getIncludedFileExtensions().equals(stateService.getIncludedFileExtensions()) ||
copyProjectSettingsComponent.getExcludeJavadoc() != stateService.getExcludeJavaDoc() ||
copyProjectSettingsComponent.getUseGitIgnore() != stateService.getUseGitIgnore();
}

@Override
public void apply() {
DevoxxGenieStateService settings = DevoxxGenieStateService.getInstance();
settings.setExcludedDirectories(copyProjectSettingsComponent.getExcludedDirectories());
settings.setIncludedFileExtensions(copyProjectSettingsComponent.getIncludedFileExtensions());
settings.setExcludeJavaDoc(copyProjectSettingsComponent.getExcludeJavadoc());
settings.setUseGitIgnore(copyProjectSettingsComponent.getUseGitIgnore());
stateService.setExcludedDirectories(copyProjectSettingsComponent.getExcludedDirectories());
stateService.setExcludedFiles(copyProjectSettingsComponent.getExcludedFiles()); // Save excluded files
stateService.setIncludedFileExtensions(copyProjectSettingsComponent.getIncludedFileExtensions());
stateService.setExcludeJavaDoc(copyProjectSettingsComponent.getExcludeJavadoc());
stateService.setUseGitIgnore(copyProjectSettingsComponent.getUseGitIgnore());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<change-notes><![CDATA[
<h2>v0.2.26</h2>
<UL>
<LI></LI>
<LI>Feature #325: Exclude a single file for 'Scan & Copy Project'</LI>
</UL>
<h2>v0.2.25</h2>
<UL>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Wed Oct 23 11:16:36 EEST 2024
version=0.2.24
#Fri Nov 08 10:42:04 CET 2024
version=0.2.27