Skip to content

Commit 545bac0

Browse files
committed
feat: add SettingAction
1 parent d886341 commit 545bac0

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.huayi.intellijplatform.gitstats.components
2+
3+
import java.awt.event.ActionEvent
4+
import java.awt.event.ActionListener
5+
import javax.swing.JButton
6+
import javax.swing.SwingWorker
7+
8+
9+
class RefreshButton(text: String?) : JButton(text), ActionListener {
10+
private var isLoading = false
11+
12+
init {
13+
addActionListener(this)
14+
}
15+
16+
override fun actionPerformed(e: ActionEvent) {
17+
isLoading = true
18+
isEnabled = false
19+
text = "Loading..."
20+
BackgroundTask().execute()
21+
}
22+
23+
private inner class BackgroundTask : SwingWorker<String, String>() {
24+
override fun doInBackground(): String {
25+
return "null"
26+
}
27+
28+
override fun done() {
29+
isLoading = false
30+
isEnabled = true
31+
text = "Click me"
32+
}
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.huayi.intellijplatform.gitstats.components
2+
3+
import com.intellij.icons.AllIcons
4+
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.project.DumbAwareAction
6+
import org.jetbrains.annotations.Nls
7+
import java.util.function.Supplier
8+
9+
class SettingAction(text: @Nls String, defaultMode: String, private val onSelectedModeChanged: (String) -> Unit) :
10+
DumbAwareAction(Supplier { text }, AllIcons.General.Settings) {
11+
private var selectedMode: String = defaultMode
12+
set(value) {
13+
field = value
14+
onSelectedModeChanged.invoke(value)
15+
}
16+
17+
override fun actionPerformed(e: AnActionEvent) {
18+
val dialogWrapper = SettingDialogWrapper(selectedMode)
19+
dialogWrapper.showAndGet()
20+
if (dialogWrapper.isOK) {
21+
selectedMode = dialogWrapper.selectedMode
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)