Skip to content

Commit

Permalink
support for multiple selected folder copy
Browse files Browse the repository at this point in the history
bump version to "2.0.6"
  • Loading branch information
hemeda3 committed Sep 8, 2024
1 parent 4b10915 commit 1bb9f02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.mapledoum"
version = "2.0.5"
version = "2.0.6"

repositories {
mavenCentral()
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/mapledoum/cCopier/CopyFolderContentAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,28 @@ public void actionPerformed(@NotNull AnActionEvent e) {
PsiDirectory[] directories = view.getDirectories();
if (directories.length == 0) return;

PsiDirectory directory = directories[0];

Map<String, Object> config = loadConfiguration(project);

StringBuilder content = new StringBuilder();
List<String> copiedFiles = new ArrayList<>();

for (PsiDirectory directory : directories) {
copyFolderContent(project, directory, config, content, copiedFiles);
}

if (!copiedFiles.isEmpty()) {
StringSelection stringSelection = new StringSelection(content.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);

copyFolderContent(project, directory, config);
showCopiedFilesNotification(project, copiedFiles);
} else {
showNoFilesNotification(project);
}
}



private Map<String, Object> loadConfiguration(Project project) {
Map<String, Object> config = loadDefaultConfiguration();

Expand Down Expand Up @@ -107,10 +120,7 @@ private Map<String, Object> loadDefaultConfiguration() {
return new HashMap<>(); // Return empty map if default config can't be loaded
}
}
private void copyFolderContent(Project project, PsiDirectory directory, Map<String, Object> config) {
StringBuilder content = new StringBuilder();
List<String> copiedFiles = new ArrayList<>();

private void copyFolderContent(Project project, PsiDirectory directory, Map<String, Object> config, StringBuilder content, List<String> copiedFiles) {
String topInstruction = getConfigString(config, "top_instruction", "");
String commentPrefix = getConfigString(config, "comment_prefix", "//");
String fileInstructions = getConfigString(config, "to_file_instructions", "");
Expand All @@ -119,7 +129,7 @@ private void copyFolderContent(Project project, PsiDirectory directory, Map<Stri
boolean useRelativePaths = getConfigBoolean(config, "use_relative_paths", true);
boolean includeLastSeparator = getConfigBoolean(config, "include_last_separator", false);

if (!topInstruction.isEmpty()) {
if (content.length() == 0 && !topInstruction.isEmpty()) {
content.append(commentPrefix).append(" ").append(topInstruction).append("\n\n");
}

Expand All @@ -129,16 +139,6 @@ private void copyFolderContent(Project project, PsiDirectory directory, Map<Stri
if (!includeLastSeparator && content.length() >= fileSeparator.length()) {
content.setLength(content.length() - fileSeparator.length());
}

if (!copiedFiles.isEmpty()) {
StringSelection stringSelection = new StringSelection(content.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);

showCopiedFilesNotification(project, copiedFiles);
} else {
showNoFilesNotification(project);
}
}
private String getConfigString(Map<String, Object> config, String key, String defaultValue) {
Object value = config.get(key);
Expand Down

0 comments on commit 1bb9f02

Please sign in to comment.