11package com.huayi.intellijplatform.gitstats.toolWindow
22
33import com.huayi.intellijplatform.gitstats.MyBundle
4- import com.huayi.intellijplatform.gitstats.components.SettingDialogWrapper
4+ import com.huayi.intellijplatform.gitstats.components.SettingAction
55import com.huayi.intellijplatform.gitstats.services.GitStatsService
66import com.huayi.intellijplatform.gitstats.utils.Utils
77import com.intellij.icons.AllIcons
8+ import com.intellij.openapi.actionSystem.AnAction
89import com.intellij.openapi.components.service
910import com.intellij.openapi.diagnostic.thisLogger
1011import com.intellij.openapi.project.Project
11- import com.intellij.openapi.ui.popup.IconButton
1212import com.intellij.openapi.wm.ToolWindow
1313import com.intellij.openapi.wm.ToolWindowFactory
1414import com.intellij.ui.components.*
@@ -26,9 +26,9 @@ import kotlin.concurrent.thread
2626
2727class GitStatsWindowFactory : ToolWindowFactory {
2828
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+ // }
3232
3333 private val contentFactory = ContentFactory .SERVICE .getInstance()
3434
@@ -46,6 +46,7 @@ class GitStatsWindowFactory : ToolWindowFactory {
4646
4747 fun getContent (toolWindow : ToolWindow ) = JBPanel <JBPanel <* >>(BorderLayout ()).apply {
4848 var (startTime, endTime) = Utils .getThisWeekDateTimeRange()
49+ var defaultMode = " Top-speed"
4950 val table = JBTable ().apply {
5051 font = Font (" Arial" , Font .PLAIN , 14 )
5152 tableHeader.font = Font (" Arial" , Font .BOLD , 14 )
@@ -55,6 +56,7 @@ class GitStatsWindowFactory : ToolWindowFactory {
5556 rowHeight = 30
5657 setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
5758 }
59+ var refreshButton: JButton
5860 border = BorderFactory .createEmptyBorder(0 , 0 , 0 , 0 )
5961
6062 val contentPanel = JBPanel <JBPanel <* >>().apply {
@@ -125,21 +127,29 @@ class GitStatsWindowFactory : ToolWindowFactory {
125127 }
126128 }
127129 })
128- add(JButton (MyBundle .message(" refreshButtonLabel" )).apply {
130+ // add(LoadingButton(MyBundle.message("refreshButtonLabel")))
131+ refreshButton = JButton (MyBundle .message(" refreshButtonLabel" ), AllIcons .Actions .Refresh ).apply {
129132 addActionListener {
130133 (contentPanel.layout as CardLayout ).show(contentPanel, " content_loading" )
134+ isEnabled = false
135+ text = MyBundle .message(" refreshButtonLoadingLabel" )
131136 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+ }
134142 SwingUtilities .invokeLater {
135143 (contentPanel.layout as CardLayout ).show(contentPanel, " content_table" )
144+ isEnabled = true
145+ text = MyBundle .message(" refreshButtonLabel" )
136146 }
137147 }
138148 }
139149 doClick()
140- })
150+ }
151+ add(refreshButton)
141152 add(Box .createHorizontalGlue())
142- // add(IconButton(MyBundle.message("settingButtonTooltipText"), AllIcons.General.Settings))
143153// add(IconLabelButton(AllIcons.General.Settings) {
144154// SettingDialogWrapper().showAndGet()
145155// }.apply {
@@ -150,6 +160,15 @@ class GitStatsWindowFactory : ToolWindowFactory {
150160 add(headerPanel, BorderLayout .NORTH )
151161
152162 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)
153172 }
154173 }
155174}
0 commit comments