Progress Bar Update Issues in My Plugin
I am trying to integrate a progress bar into my code. The intention is for it to display the current status, making it easier to debug in the event of an issue or any future bugs.
When I initiate my plugin and the action begins, the progress bar displays with the initial status "Starting translation...".
However, after that, the process continues without updating the progress bar, and it only displays the final result as a notification, as I intended.
I want the progress bar to reflect each status change according to my code.
Could you please assist me with this issue?
private val totalWeight = 100.0
private val weightLoadFiles = 10.0
private val weightIdentifyKeys = 30.0
private val weightTranslateKeys = 50.0
private val weightSaveKeys = 10.0private fun performTranslation(event: AnActionEvent, indicator: ProgressIndicator) {
LOG.info("TranslationAction triggered!")indicator.isIndeterminate = false
indicator.fraction = 0.1
indicator.text = "Starting translation..."
Thread.sleep(500)
indicator.checkCanceled()val selectedFiles = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY) ?: return
ApplicationManager.getApplication().invokeAndWait {
// ... Code for selecting translator and files// Load Files
indicator.text = "Loading English properties..."
Thread.sleep(500)
indicator.checkCanceled()...
indicator.fraction += weightLoadFiles / totalWeight
// ... Code for identifying keys// Identify Missing Keys
indicator.text = "Identifying missing keys in ${InputType.file.name}..."
Thread.sleep(500)
indicator.checkCanceled() ...indicator.fraction += weightIdentifyKeys / totalWeight
// ... Code for translating keys
// Translate Missing Keys
indicator.text = "Translating missing keys..."
Thread.sleep(1000) ...indicator.fraction += weightTranslateKeys / totalWeight
// Save Translated Keys
indicator.text = "Saving translated keys..."
indicator.fraction += weightSaveKeys / totalWeight
Thread.sleep(500)
indicator.checkCanceled()
// ... Code for saving keys ...indicator.text = "Translation action completed!"
indicator.fraction = 1.0
}
}override fun actionPerformed(event: AnActionEvent) {
val project = event.project ?: return
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Translating Properties", true) {
override fun run(indicator: ProgressIndicator) {
performTranslation(event, indicator)
}
})
}
Please sign in to leave a comment.
Hi Saeed,
Why do you wrap it in
ApplicationManager.getApplication().invokeAndWait{ … }
?I removed this code part and
val selectedFiles = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY) ?: return
and everything works fine.Hi Karol,
Thank you for your comment.
regarding this report , the code is attempting to access UI-related components or perform UI-related operations from a non-EDT thread.
This is a part of the code i am trying to implement