Skip to content

Commit 744121f

Browse files
committed
feat: add advanced mode
1 parent 545bac0 commit 744121f

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.huayi.intellijplatform.gitstats
44
pluginName = GitStats
55
pluginRepositoryUrl = https://github.com/zhensherlock/intellij-platform-git-stats-plugin
66
# SemVer format -> https://semver.org
7-
pluginVersion = 0.0.1
7+
pluginVersion = 0.0.2
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 221

src/main/kotlin/com/huayi/intellijplatform/gitstats/components/SettingDialogWrapper.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import javax.swing.BoxLayout
1111
import javax.swing.JComponent
1212

1313

14-
class SettingDialogWrapper : DialogWrapper(true) {
14+
class SettingDialogWrapper(defaultMode: String) : DialogWrapper(true) {
15+
var selectedMode: String = defaultMode
16+
private lateinit var modeComboBox: ComboBox<String>
1517
init {
1618
title = "Git Stats Setting"
1719
init()
@@ -26,12 +28,19 @@ class SettingDialogWrapper : DialogWrapper(true) {
2628
add(JBLabel(MyBundle.message("settingDialogModeLabel", "")).apply {
2729
preferredSize = Dimension(50, 30)
2830
})
29-
add(ComboBox<String>().apply {
31+
modeComboBox = ComboBox<String>().apply {
3032
addItem("Top-speed")
3133
addItem("Advanced")
32-
})
34+
selectedItem = selectedMode
35+
}
36+
add(modeComboBox)
3337
}
3438
dialogPanel.add(modeFieldPanel)
3539
return dialogPanel
3640
}
41+
42+
override fun doOKAction() {
43+
selectedMode = modeComboBox.selectedItem as String
44+
super.doOKAction()
45+
}
3746
}

src/main/kotlin/com/huayi/intellijplatform/gitstats/toolWindow/GitStatsWindowFactory.kt

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.huayi.intellijplatform.gitstats.toolWindow
22

33
import com.huayi.intellijplatform.gitstats.MyBundle
4-
import com.huayi.intellijplatform.gitstats.components.SettingDialogWrapper
4+
import com.huayi.intellijplatform.gitstats.components.SettingAction
55
import com.huayi.intellijplatform.gitstats.services.GitStatsService
66
import com.huayi.intellijplatform.gitstats.utils.Utils
77
import com.intellij.icons.AllIcons
8+
import com.intellij.openapi.actionSystem.AnAction
89
import com.intellij.openapi.components.service
910
import com.intellij.openapi.diagnostic.thisLogger
1011
import com.intellij.openapi.project.Project
11-
import com.intellij.openapi.ui.popup.IconButton
1212
import com.intellij.openapi.wm.ToolWindow
1313
import com.intellij.openapi.wm.ToolWindowFactory
1414
import com.intellij.ui.components.*
@@ -26,9 +26,9 @@ import kotlin.concurrent.thread
2626

2727
class 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
}

src/main/resources/messages/MyBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ shuffle=Shuffle
55
filterStartTimeLabel=StartTime: {0}
66
filterEndTimeLabel=EndTime: {0}
77
refreshButtonLabel=Refresh
8+
refreshButtonLoadingLabel=Loading
89
settingButtonTooltipText=Show Setting
910
settingDialogModeLabel=Mode:

0 commit comments

Comments
 (0)