@@ -4,6 +4,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
44import com.intellij.openapi.fileChooser.FileChooserDescriptor
55import com.intellij.openapi.fileChooser.ex.FileChooserDialogImpl
66import com.intellij.openapi.module.Module
7+ import com.intellij.openapi.progress.ProgressIndicator
78import com.intellij.openapi.progress.ProgressManager
89import com.intellij.openapi.project.DumbAwareAction
910import com.intellij.openapi.project.Project
@@ -22,7 +23,15 @@ import java.io.File
2223
2324const val CHUNK_SIZE = 1500
2425
25- fun Database.copyTo (destination : Database ) {
26+ fun Database.copyTo (destination : Database , moveProgressBar : Boolean ) {
27+ var progressIndicator: ProgressIndicator ? = null
28+ var count: Int? = null
29+
30+ if (moveProgressBar) {
31+ progressIndicator = ProgressManager .getInstance().progressIndicator
32+ count = transaction(this ) { CallInfoTable .selectAll().count() }
33+ }
34+
2635 var offset = 0
2736 while (true ) {
2837 val info: List <CallInfo > = transaction(this ) {
@@ -35,7 +44,12 @@ fun Database.copyTo(destination: Database) {
3544 transaction(destination) {
3645 info.forEach { CallInfoTable .insertInfoIfNotContains(it) }
3746 }
47+
3848 offset + = CHUNK_SIZE
49+
50+ if (moveProgressBar) {
51+ progressIndicator!! .fraction = offset.toDouble() / count!!
52+ }
3953 }
4054}
4155
@@ -45,11 +59,11 @@ class ExportContractsAction : ExportFileActionBase(
4559 extensions = arrayOf("mv.db")
4660) {
4761 override fun backgroundProcess (absoluteFilePath : String , module : Module ? , sdk : Sdk ? , project : Project ) {
48- exportContractsToFile(absoluteFilePath)
62+ exportContractsToFile(absoluteFilePath, moveProgressBar = true )
4963 }
5064
5165 companion object {
52- fun exportContractsToFile (pathToExport : String ) {
66+ fun exportContractsToFile (pathToExport : String , moveProgressBar : Boolean ) {
5367 check(pathToExport.endsWith(DatabaseProvider .H2_DB_FILE_EXTENSION )) {
5468 " Path to export must end with .mv.db"
5569 }
@@ -58,7 +72,7 @@ class ExportContractsAction : ExportFileActionBase(
5872 val databaseToExportTo = DatabaseProvider .connectToDB(pathToExport)
5973 DatabaseProvider .createAllDatabases(databaseToExportTo)
6074
61- DatabaseProvider .defaultDatabase!! .copyTo(databaseToExportTo)
75+ DatabaseProvider .defaultDatabase!! .copyTo(databaseToExportTo, moveProgressBar )
6276 }
6377 }
6478}
@@ -76,25 +90,24 @@ class ImportContractsAction : DumbAwareAction() {
7690
7791 try {
7892 ProgressManager .getInstance().runProcessWithProgressSynchronously(ThrowableComputable <Unit , Exception > {
79- files.forEach { importContractsFromFile(it.path) }
93+ files.forEach { importContractsFromFile(it.path, moveProgressBar = true ) }
8094 return @ThrowableComputable
8195 }, " Importing type contracts" , false , project)
8296 resetAllRubyTypeProviderAndIDEACaches(project)
83- Messages .showDialog(" Type contracts imported successfully" , " Info" , arrayOf(" OK" ), 0 , null )
8497 } catch (ex: Exception ) {
8598 Messages .showErrorDialog(ex.message, " Error while importing type contracts" )
8699 }
87100 }
88101
89102 companion object {
90- fun importContractsFromFile (pathToImportFrom : String ) {
103+ fun importContractsFromFile (pathToImportFrom : String , moveProgressBar : Boolean ) {
91104 check(pathToImportFrom.endsWith(DatabaseProvider .H2_DB_FILE_EXTENSION )) {
92105 " Path to import from must end with .mv.db"
93106 }
94107
95108 val dbToImportFrom = DatabaseProvider .connectToDB(pathToImportFrom)
96109
97- dbToImportFrom.copyTo(DatabaseProvider .defaultDatabase!! )
110+ dbToImportFrom.copyTo(DatabaseProvider .defaultDatabase!! , moveProgressBar )
98111 }
99112 }
100113}
0 commit comments