1
1
package com.huayi.intellijplatform.gitstats.toolWindow
2
2
3
3
import com.huayi.intellijplatform.gitstats.MyBundle
4
- import com.huayi.intellijplatform.gitstats.components.SettingDialogWrapper
4
+ import com.huayi.intellijplatform.gitstats.components.SettingAction
5
5
import com.huayi.intellijplatform.gitstats.services.GitStatsService
6
6
import com.huayi.intellijplatform.gitstats.utils.Utils
7
7
import com.intellij.icons.AllIcons
8
+ import com.intellij.openapi.actionSystem.AnAction
8
9
import com.intellij.openapi.components.service
9
10
import com.intellij.openapi.diagnostic.thisLogger
10
11
import com.intellij.openapi.project.Project
11
- import com.intellij.openapi.ui.popup.IconButton
12
12
import com.intellij.openapi.wm.ToolWindow
13
13
import com.intellij.openapi.wm.ToolWindowFactory
14
14
import com.intellij.ui.components.*
@@ -26,9 +26,9 @@ import kotlin.concurrent.thread
26
26
27
27
class GitStatsWindowFactory : ToolWindowFactory {
28
28
29
- init {
30
- thisLogger().warn(" Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`." )
31
- }
29
+ // init {
30
+ // thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
31
+ // }
32
32
33
33
private val contentFactory = ContentFactory .SERVICE .getInstance()
34
34
@@ -46,6 +46,7 @@ class GitStatsWindowFactory : ToolWindowFactory {
46
46
47
47
fun getContent (toolWindow : ToolWindow ) = JBPanel <JBPanel <* >>(BorderLayout ()).apply {
48
48
var (startTime, endTime) = Utils .getThisWeekDateTimeRange()
49
+ var defaultMode = " Top-speed"
49
50
val table = JBTable ().apply {
50
51
font = Font (" Arial" , Font .PLAIN , 14 )
51
52
tableHeader.font = Font (" Arial" , Font .BOLD , 14 )
@@ -55,6 +56,7 @@ class GitStatsWindowFactory : ToolWindowFactory {
55
56
rowHeight = 30
56
57
setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
57
58
}
59
+ var refreshButton: JButton
58
60
border = BorderFactory .createEmptyBorder(0 , 0 , 0 , 0 )
59
61
60
62
val contentPanel = JBPanel <JBPanel <* >>().apply {
@@ -125,21 +127,29 @@ class GitStatsWindowFactory : ToolWindowFactory {
125
127
}
126
128
}
127
129
})
128
- add(JButton (MyBundle .message(" refreshButtonLabel" )).apply {
130
+ // add(LoadingButton(MyBundle.message("refreshButtonLabel")))
131
+ refreshButton = JButton (MyBundle .message(" refreshButtonLabel" ), AllIcons .Actions .Refresh ).apply {
129
132
addActionListener {
130
133
(contentPanel.layout as CardLayout ).show(contentPanel, " content_loading" )
134
+ isEnabled = false
135
+ text = MyBundle .message(" refreshButtonLoadingLabel" )
131
136
thread {
132
- table.model = service.getTopSpeedUserStats(startTime, endTime)
133
- // table.model = service.getUserStats(startTime, endTime)
137
+ if (defaultMode == = " Top-speed" ) {
138
+ table.model = service.getTopSpeedUserStats(startTime, endTime)
139
+ } else {
140
+ table.model = service.getUserStats(startTime, endTime)
141
+ }
134
142
SwingUtilities .invokeLater {
135
143
(contentPanel.layout as CardLayout ).show(contentPanel, " content_table" )
144
+ isEnabled = true
145
+ text = MyBundle .message(" refreshButtonLabel" )
136
146
}
137
147
}
138
148
}
139
149
doClick()
140
- })
150
+ }
151
+ add(refreshButton)
141
152
add(Box .createHorizontalGlue())
142
- // add(IconButton(MyBundle.message("settingButtonTooltipText"), AllIcons.General.Settings))
143
153
// add(IconLabelButton(AllIcons.General.Settings) {
144
154
// SettingDialogWrapper().showAndGet()
145
155
// }.apply {
@@ -150,6 +160,15 @@ class GitStatsWindowFactory : ToolWindowFactory {
150
160
add(headerPanel, BorderLayout .NORTH )
151
161
152
162
add(contentPanel, BorderLayout .CENTER )
163
+
164
+ val actionList: MutableList <AnAction > = ArrayList ()
165
+ val settingAction =
166
+ SettingAction (MyBundle .message(" settingButtonTooltipText" ), defaultMode) { selectedMode ->
167
+ defaultMode = selectedMode
168
+ refreshButton.doClick()
169
+ }
170
+ actionList.add(settingAction)
171
+ toolWindow.setTitleActions(actionList)
153
172
}
154
173
}
155
174
}
0 commit comments