Skip to content

Commit 1934cad

Browse files
committed
update for migration to latest version of intellij platform. slight change to UI overview and daily target dial chart. Added update on every keystroke option, removed only counting work space option and added UI update when opening the tool window
1 parent 04feae7 commit 1934cad

17 files changed

+285
-260
lines changed

.run/Run IDE with Plugin.run.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run Plugin" type="GradleRunConfiguration" factoryName="Gradle">
3+
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log"/>
4+
<ExternalSystemSettings>
5+
<option name="executionName"/>
6+
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
7+
<option name="externalSystemIdString" value="GRADLE"/>
8+
<option name="scriptParameters" value=""/>
9+
<option name="taskDescriptions">
10+
<list/>
11+
</option>
12+
<option name="taskNames">
13+
<list>
14+
<option value="runIde"/>
15+
</list>
16+
</option>
17+
<option name="vmOptions" value=""/>
18+
</ExternalSystemSettings>
19+
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
20+
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
21+
<DebugAllEnabled>false</DebugAllEnabled>
22+
<method v="2"/>
23+
</configuration>
24+
</component>

build.gradle.kts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import org.jetbrains.changelog.markdownToHTML
22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33

44
plugins {
5-
id("org.jetbrains.kotlin.jvm") version "1.6.0"
6-
id("org.jetbrains.intellij") version "1.5.3"
5+
id("org.jetbrains.kotlin.jvm") version "1.9.25"
6+
id("org.jetbrains.intellij") version "1.17.4"
77
id("org.jetbrains.changelog") version "1.3.0"
88
}
99

@@ -25,11 +25,10 @@ version = pluginVersion
2525

2626
repositories {
2727
mavenCentral()
28-
jcenter()
2928
}
3029

3130
dependencies {
32-
implementation("org.knowm.xchart:xchart:3.6.5")
31+
implementation("org.knowm.xchart:xchart:3.8.8")
3332
}
3433

3534
intellij {
@@ -53,13 +52,11 @@ changelog {
5352
tasks {
5453
// Set the compatibility versions to 1.8
5554
withType<JavaCompile> {
56-
sourceCompatibility = "1.8"
57-
targetCompatibility = "1.8"
55+
sourceCompatibility = "17"
56+
targetCompatibility = "17"
5857
}
59-
listOf("compileKotlin", "compileTestKotlin").forEach {
60-
getByName<KotlinCompile>(it) {
61-
kotlinOptions.jvmTarget = "1.8"
62-
}
58+
withType<KotlinCompile> {
59+
kotlinOptions.jvmTarget = "17"
6360
}
6461

6562
patchPluginXml {

gradle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# -> https://www.jetbrains.org/intellij/sdk/docs/reference_guide/intellij_artifacts.html
33
pluginGroup = org.anilmisirlioglu.keystroke
44
pluginName_ = Keystroke Counter
5-
pluginVersion = 1.1.3
6-
pluginSinceBuild = 203
7-
pluginUntilBuild = 221.*
5+
pluginVersion = 2.0.0
6+
pluginSinceBuild = 241
7+
pluginUntilBuild = 243.*
88

99
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
1010
# See https://jb.gg/intellij-platform-builds-list for available build versions
11-
pluginVerifierIdeVersions = 2022.1.1
11+
pluginVerifierIdeVersions = 2024.1.7
1212

1313
platformType = IC
14-
platformVersion = LATEST-EAP-SNAPSHOT
14+
platformVersion = 2024.1.7
1515
platformDownloadSources = true
1616
# Plugin Dependencies -> https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html
1717
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,48 @@
11
package org.anilmisirlioglu.keystroke
22

3-
import com.intellij.openapi.Disposable
4-
import com.intellij.openapi.editor.impl.EditorComponentImpl
3+
import com.intellij.ide.IdeEventQueue
54
import org.anilmisirlioglu.keystroke.settings.SettingsService
65
import org.anilmisirlioglu.keystroke.statistics.StatisticsService
76
import java.awt.AWTEvent
8-
import java.awt.Toolkit
9-
import java.awt.event.AWTEventListener
107
import java.awt.event.KeyEvent
118

12-
class KeyboardListener : AWTEventListener, Disposable{
9+
class KeyboardListener : IdeEventQueue.EventDispatcher {
1310

14-
private val statistics = StatisticsService.instance
15-
private val settings = SettingsService.instance
11+
private val statistics = StatisticsService.getInstance()
12+
private val settings = SettingsService.getInstance()
1613

17-
init{
18-
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK)
19-
}
20-
21-
override fun eventDispatched(event: AWTEvent?){
22-
if(event is KeyEvent && event.id == KeyEvent.KEY_RELEASED){
23-
if(!settings.isCountOnlyWorkspace || event.component is EditorComponentImpl){
24-
when{
25-
event.isTypingKey -> statistics.inc()
26-
settings.isAllowedFunctionKeys && event.isFunctionKey -> statistics.inc()
27-
settings.isAllowedCursorControlKeys && event.isCursorControlKey -> statistics.inc()
28-
settings.isAllowedOtherKeys -> statistics.inc()
29-
}
14+
override fun dispatch(e: AWTEvent): Boolean {
15+
if (e is KeyEvent && e.id == KeyEvent.KEY_RELEASED) {
16+
when {
17+
e.isTypingKey -> statistics.inc()
18+
settings.isAllowedFunctionKeys && e.isFunctionKey -> statistics.inc()
19+
settings.isAllowedCursorControlKeys && e.isCursorControlKey -> statistics.inc()
20+
settings.isAllowedOtherKeys -> statistics.inc()
3021
}
3122
}
32-
}
33-
34-
override fun dispose(){
35-
Toolkit.getDefaultToolkit().removeAWTEventListener(this)
23+
return false
3624
}
3725

3826
private val KeyEvent.isTypingKey: Boolean
39-
get() = when(keyCode){
27+
get() = when (keyCode) {
4028
KeyEvent.VK_UNDEFINED,
41-
KeyEvent.VK_ESCAPE,
42-
KeyEvent.VK_TAB,
43-
KeyEvent.VK_SPACE,
44-
KeyEvent.VK_DELETE,
45-
KeyEvent.VK_BACK_SPACE,
46-
KeyEvent.VK_ENTER -> false
29+
KeyEvent.VK_TAB -> false
30+
4731
else -> keyChar != KeyEvent.CHAR_UNDEFINED
4832
}
4933

5034
private val KeyEvent.isCursorControlKey: Boolean
51-
get() = when(keyCode){
35+
get() = when (keyCode) {
5236
KeyEvent.VK_RIGHT,
5337
KeyEvent.VK_LEFT,
5438
KeyEvent.VK_UP,
5539
KeyEvent.VK_DOWN -> true
40+
5641
else -> false
5742
}
5843

5944
private val KeyEvent.isFunctionKey: Boolean
60-
get() = when(keyCode){
45+
get() = when (keyCode) {
6146
KeyEvent.VK_F1,
6247
KeyEvent.VK_F2,
6348
KeyEvent.VK_F3,
@@ -82,7 +67,7 @@ class KeyboardListener : AWTEventListener, Disposable{
8267
KeyEvent.VK_F22,
8368
KeyEvent.VK_F23,
8469
KeyEvent.VK_F24 -> true
70+
8571
else -> false
8672
}
87-
8873
}

src/main/kotlin/org/anilmisirlioglu/keystroke/converters/LocalDateTimeConverter.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import java.time.Instant
55
import java.time.LocalDateTime
66
import java.time.ZoneId
77

8-
class LocalDateTimeConverter : Converter<LocalDateTime?>(){
8+
class LocalDateTimeConverter : Converter<LocalDateTime?>() {
99

10-
override fun toString(value: LocalDateTime): String? = value
11-
.atZone(ZoneId.systemDefault())
12-
.toInstant()
13-
.toEpochMilli()
14-
.toString()
10+
override fun toString(value: LocalDateTime?): String? {
11+
if (value != null) {
12+
return value.atZone(ZoneId.systemDefault())
13+
.toInstant()
14+
.toEpochMilli()
15+
.toString()
16+
}
17+
return null
18+
}
1519

1620
override fun fromString(value: String): LocalDateTime? = Instant
1721
.ofEpochMilli(value.toLong())

src/main/kotlin/org/anilmisirlioglu/keystroke/rebuild/Int.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package org.anilmisirlioglu.keystroke.rebuild
33
import java.text.DecimalFormat
44
import java.text.DecimalFormatSymbols
55

6-
fun Int.toDecimal(): String{
7-
val decimalFormatSymbols = DecimalFormatSymbols().apply{
6+
fun Int.toDecimal(): String {
7+
val decimalFormatSymbols = DecimalFormatSymbols().apply {
88
decimalSeparator = '.'
99
}
1010

11-
return DecimalFormat("#,###.##", decimalFormatSymbols).run{
11+
return DecimalFormat("#,###.##", decimalFormatSymbols).run {
1212
format(this@toDecimal)
1313
}
1414
}

src/main/kotlin/org/anilmisirlioglu/keystroke/settings/Settings.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ data class Settings(
66
var countOnlyWorkspace: Boolean = true,
77
var dailyTarget: Int = 5000,
88
var keyboardFlags: Int = KeyboardFlags.TYPING_KEYS,
9-
){
9+
var updateOnEveryKeystroke: Boolean = false,
10+
) {
1011

11-
object KeyboardFlags{
12+
object KeyboardFlags {
1213
const val TYPING_KEYS = 1 shl 0 // Letters & numbers
1314
const val FUNCTION_KEYS = 1 shl 1 // F1-F12
1415
const val CURSOR_CONTROL_KEYS = 1 shl 2 // ->, <- etc.
@@ -24,5 +25,4 @@ data class Settings(
2425
)
2526
}
2627

27-
}
28-
28+
}

src/main/kotlin/org/anilmisirlioglu/keystroke/settings/SettingsComponent.kt

Lines changed: 42 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,36 @@ import java.awt.Dimension
88
import javax.swing.*
99

1010
// Simple settings form
11-
class SettingsComponent{
11+
class SettingsComponent {
1212

13-
private val settings = SettingsService.instance
13+
private val settings = SettingsService.getInstance()
1414

1515
/* Titles */
16-
private val generalTitledSeparator = TitledSeparator(
17-
MessageBundle.message("settings.separator.general")
18-
)
16+
private val generalTitledSeparator = TitledSeparator(MessageBundle.message("settings.separator.general"))
1917
private val settingsTitledSeparator = TitledSeparator("Settings")
20-
private val keyboardTitledSeparator = TitledSeparator(
21-
MessageBundle.message("settings.separator.keyboard")
22-
)
18+
private val keyboardTitledSeparator = TitledSeparator(MessageBundle.message("settings.separator.keyboard"))
2319

2420
/* Checkboxes */
25-
private val countOnlyWorkspaceCheckbox = JCheckBox(
26-
MessageBundle.message("settings.checkbox.workspace")
27-
)
28-
private val allowFunctionKeysCheckbox = JCheckBox(
29-
MessageBundle.message("settings.checkbox.keys.function")
30-
)
31-
private val allowCursorControlKeysCheckbox = JCheckBox(
32-
MessageBundle.message("settings.checkbox.keys.cursor")
33-
)
34-
private val allowOtherKeysCheckbox = JCheckBox(
35-
MessageBundle.message("settings.checkbox.keys.other")
36-
)
21+
private val updateOnEveryKeystrokeCheckbox =
22+
JCheckBox(MessageBundle.message("settings.checkbox.updateAfterEveryKey"))
23+
private val allowFunctionKeysCheckbox = JCheckBox(MessageBundle.message("settings.checkbox.keys.function"))
24+
private val allowCursorControlKeysCheckbox = JCheckBox(MessageBundle.message("settings.checkbox.keys.cursor"))
25+
private val allowOtherKeysCheckbox = JCheckBox(MessageBundle.message("settings.checkbox.keys.other"))
26+
3727
private val allowTypingKeysCheckbox = JCheckBox(
3828
MessageBundle.message("settings.checkbox.keys.typing"),
3929
true
40-
).apply{
30+
).apply {
4131
isEnabled = false
4232
}
4333

4434
/* Labels */
45-
private val dailyTargetLabel = JLabel(
46-
MessageBundle.message("settings.label.daily.target")
47-
)
35+
private val dailyTargetLabel = JLabel(MessageBundle.message("settings.label.daily.target"))
4836

4937
/* Inputs */
5038
private val dailyTargetSpinner = JSpinner(
5139
SpinnerNumberModel(settings.dailyTarget, 100, Int.MAX_VALUE, 50)
52-
).apply{
40+
).apply {
5341
val dimension = Dimension(96, 30)
5442

5543
maximumSize = dimension
@@ -58,55 +46,50 @@ class SettingsComponent{
5846
}
5947

6048
/* Panels */
61-
private val dailyTargetPanel = JPanel(HorizontalLayout(12)).apply{
62-
add(dailyTargetLabel)
63-
add(dailyTargetSpinner)
64-
}
65-
66-
val panel: JPanel
67-
68-
init{
69-
panel = FormBuilder.createFormBuilder()
70-
.addComponent(generalTitledSeparator)
71-
.addComponentToRightColumn(countOnlyWorkspaceCheckbox)
72-
.addVerticalGap(10)
73-
.addComponent(keyboardTitledSeparator)
74-
.addComponentToRightColumn(allowTypingKeysCheckbox)
75-
.addComponentToRightColumn(allowFunctionKeysCheckbox)
76-
.addComponentToRightColumn(allowCursorControlKeysCheckbox)
77-
.addComponentToRightColumn(allowOtherKeysCheckbox)
78-
.addVerticalGap(10)
79-
.addComponent(settingsTitledSeparator)
80-
.addComponentToRightColumn(dailyTargetPanel)
81-
.addComponentFillVertically(JPanel(), 0)
82-
.panel
83-
}
84-
85-
fun apply(){
86-
settings.isCountOnlyWorkspace = countOnlyWorkspaceCheckbox.isSelected
49+
private val dailyTargetPanel = JPanel(HorizontalLayout(12))
50+
.apply {
51+
add(dailyTargetLabel)
52+
add(dailyTargetSpinner)
53+
}
54+
55+
val panel: JPanel = FormBuilder.createFormBuilder()
56+
.addComponent(generalTitledSeparator)
57+
.addComponentToRightColumn(updateOnEveryKeystrokeCheckbox)
58+
.addVerticalGap(10)
59+
.addComponent(keyboardTitledSeparator)
60+
.addComponentToRightColumn(allowTypingKeysCheckbox)
61+
.addComponentToRightColumn(allowFunctionKeysCheckbox)
62+
.addComponentToRightColumn(allowCursorControlKeysCheckbox)
63+
.addComponentToRightColumn(allowOtherKeysCheckbox)
64+
.addVerticalGap(10)
65+
.addComponent(settingsTitledSeparator)
66+
.addComponentToRightColumn(dailyTargetPanel)
67+
.addComponentFillVertically(JPanel(), 0)
68+
.panel
69+
70+
fun apply() {
71+
settings.updateOnEveryKeystroke = updateOnEveryKeystrokeCheckbox.isSelected
8772
settings.dailyTarget = dailyTargetSpinner.value as Int
8873

8974
settings.isAllowedOtherKeys = allowOtherKeysCheckbox.isSelected
9075
settings.isAllowedCursorControlKeys = allowCursorControlKeysCheckbox.isSelected
9176
settings.isAllowedFunctionKeys = allowFunctionKeysCheckbox.isSelected
9277
}
9378

94-
fun reset(){
95-
countOnlyWorkspaceCheckbox.isSelected = settings.isCountOnlyWorkspace
79+
fun reset() {
80+
updateOnEveryKeystrokeCheckbox.isSelected = settings.updateOnEveryKeystroke
9681
dailyTargetSpinner.value = settings.dailyTarget
9782

9883
allowOtherKeysCheckbox.isSelected = settings.isAllowedOtherKeys
9984
allowFunctionKeysCheckbox.isSelected = settings.isAllowedFunctionKeys
10085
allowCursorControlKeysCheckbox.isSelected = settings.isAllowedCursorControlKeys
10186
}
10287

103-
fun isModified(): Boolean{
104-
return countOnlyWorkspaceCheckbox.isSelected != settings.isCountOnlyWorkspace ||
88+
fun isModified(): Boolean {
89+
return allowCursorControlKeysCheckbox.isSelected != settings.isAllowedCursorControlKeys ||
10590
allowOtherKeysCheckbox.isSelected != settings.isAllowedOtherKeys ||
10691
allowFunctionKeysCheckbox.isSelected != settings.isAllowedFunctionKeys ||
107-
allowCursorControlKeysCheckbox.isSelected != settings.isAllowedCursorControlKeys ||
108-
dailyTargetSpinner.value != settings.dailyTarget
109-
92+
dailyTargetSpinner.value != settings.dailyTarget ||
93+
updateOnEveryKeystrokeCheckbox.isSelected != settings.updateOnEveryKeystroke
11094
}
111-
11295
}

0 commit comments

Comments
 (0)