Skip to content

Commit

Permalink
fixed warnings in SuccessfulCheckin
Browse files Browse the repository at this point in the history
  • Loading branch information
dkandalov committed Oct 14, 2024
1 parent 52871f3 commit 5385b3b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/limitedwip/autorevert/components/AutorevertComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import limitedwip.common.settings.LimitedWipSettings
import limitedwip.common.vcs.SuccessfulCheckin
import limitedwip.common.vcs.defaultChangeList
import limitedwip.common.vcs.invokeLater
import limitedwip.common.vcs.registerSuccessfulCheckinListener

class AutoRevertComponentStartup: ProjectActivity {
override suspend fun execute(project: Project) = AutoRevertComponent(project).start()
Expand Down Expand Up @@ -53,7 +54,7 @@ class AutoRevertComponent(private val project: Project) {
}
})

SuccessfulCheckin.registerListener(project, object: SuccessfulCheckin.Listener {
registerSuccessfulCheckinListener(project, object: SuccessfulCheckin.Listener {
override fun onSuccessfulCheckin(allChangesAreCommitted: Boolean) {
if (allChangesAreCommitted) autoRevert.onAllChangesCommitted()
}
Expand Down
33 changes: 18 additions & 15 deletions src/limitedwip/common/vcs/SuccessfulCheckin.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package limitedwip.common.vcs

import com.intellij.openapi.Disposable
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.vcs.CheckinProjectPanel
import com.intellij.openapi.vcs.changes.CommitContext
import com.intellij.openapi.vcs.checkin.CheckinHandler
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory
import limitedwip.common.pluginId
import limitedwip.common.vcs.SuccessfulCheckin.Listener

class SuccessfulCheckin : CheckinHandlerFactory() {

override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext) =
object : CheckinHandler() {
override fun checkinSuccessful() {
Expand All @@ -19,23 +19,26 @@ class SuccessfulCheckin : CheckinHandlerFactory() {
}
}

private fun notifySettingsListeners(allChangesAreCommitted: Boolean) {
Extensions.getRootArea().getExtensionPoint<Listener>(extensionPointName).extensions.forEach { listener ->
listener.onSuccessfulCheckin(allChangesAreCommitted)
}
}

interface Listener {
fun onSuccessfulCheckin(allChangesAreCommitted: Boolean)
}
}

companion object {
private const val extensionPointName = "$pluginId.checkinListener"
private const val extensionPointName = "$pluginId.checkinListener"

fun registerListener(disposable: Disposable, listener: Listener) {
Extensions.getRootArea() // It has to be root area (not project area).
.getExtensionPoint<Listener>(extensionPointName)
.registerExtension(listener, disposable)
@Suppress("UnstableApiUsage")
private fun notifySettingsListeners(allChangesAreCommitted: Boolean) {
ApplicationManager.getApplication().extensionArea
.getExtensionPoint<Listener>(extensionPointName).extensions
.forEach { listener ->
listener.onSuccessfulCheckin(allChangesAreCommitted)
}
}
}

@Suppress("UnstableApiUsage")
fun registerSuccessfulCheckinListener(disposable: Disposable, listener: Listener) {
ApplicationManager.getApplication().extensionArea // It has to be root area (not project area).
.getExtensionPoint<Listener>(extensionPointName)
.registerExtension(listener, disposable)
}

3 changes: 2 additions & 1 deletion src/limitedwip/tcr/components/TcrComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import limitedwip.common.settings.LimitedWipSettings
import limitedwip.common.toPathMatchers
import limitedwip.common.vcs.AllowCommit
import limitedwip.common.vcs.SuccessfulCheckin
import limitedwip.common.vcs.registerSuccessfulCheckinListener
import limitedwip.tcr.Tcr
import limitedwip.tcr.Tcr.ChangeListModifications
import limitedwip.tcr.Tcr.Settings
Expand All @@ -33,7 +34,7 @@ private class TcrComponent(private val project: Project) {
override fun onUnitTestFailed(testName: String) = tcr.onUnitTestFailed(testName)
})

SuccessfulCheckin.registerListener(project, object: SuccessfulCheckin.Listener {
registerSuccessfulCheckinListener(project, object: SuccessfulCheckin.Listener {
override fun onSuccessfulCheckin(allChangesAreCommitted: Boolean) = tcr.onSuccessfulCommit()
})

Expand Down
3 changes: 2 additions & 1 deletion src/limitedwip/watchdog/components/WatchdogComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import limitedwip.common.toPathMatchers
import limitedwip.common.vcs.AllowCommit
import limitedwip.common.vcs.SuccessfulCheckin
import limitedwip.common.vcs.invokeLater
import limitedwip.common.vcs.registerSuccessfulCheckinListener
import limitedwip.watchdog.Watchdog
import limitedwip.watchdog.ui.WatchdogStatusBarWidget

Expand Down Expand Up @@ -58,7 +59,7 @@ class WatchdogComponent(private val project: Project) {
}
})

SuccessfulCheckin.registerListener(project, object : SuccessfulCheckin.Listener {
registerSuccessfulCheckinListener(project, object : SuccessfulCheckin.Listener {
override fun onSuccessfulCheckin(allChangesAreCommitted: Boolean) = watchdog.onSuccessfulCommit()
})
}
Expand Down

0 comments on commit 5385b3b

Please sign in to comment.