-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from devoxx/issue-157
Feat #157 Calc tokens for dir
- Loading branch information
Showing
5 changed files
with
122 additions
and
10 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/com/devoxx/genie/action/CalcTokensForDirectoryAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.devoxx.genie.action; | ||
|
||
import com.devoxx.genie.service.ProjectContentService; | ||
import com.devoxx.genie.ui.util.NotificationUtil; | ||
import com.devoxx.genie.ui.util.WindowContextFormatterUtil; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.progress.ProgressManager; | ||
import com.intellij.openapi.progress.Task; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class CalcTokensForDirectoryAction extends AnAction { | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
Project project = e.getProject(); | ||
VirtualFile selectedDir = e.getData(CommonDataKeys.VIRTUAL_FILE); | ||
|
||
if (project == null || selectedDir == null || !selectedDir.isDirectory()) { | ||
return; | ||
} | ||
|
||
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Calculating Tokens", false) { | ||
@Override | ||
public void run(@NotNull ProgressIndicator indicator) { | ||
ProjectContentService.getInstance() | ||
.getDirectoryContentAndTokens(project, selectedDir, Integer.MAX_VALUE, true) | ||
.thenAccept(result -> { | ||
String message = String.format("Directory '%s' contains approximately %s tokens", | ||
selectedDir.getName(), | ||
WindowContextFormatterUtil.format(result.getTokenCount())); | ||
NotificationUtil.sendNotification(project, message); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void update(@NotNull AnActionEvent e) { | ||
VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); | ||
e.getPresentation().setEnabledAndVisible(file != null && file.isDirectory()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#Thu Jul 04 22:09:48 CEST 2024 | ||
#Fri Jul 05 08:27:25 CEST 2024 | ||
version=0.2.3 |