Skip to content

Commit 8227c20

Browse files
committed
removed obsolete registerBeforeCommitListener()
1 parent a0866b4 commit 8227c20

File tree

1 file changed

+0
-68
lines changed

1 file changed

+0
-68
lines changed

src/limitedwip/common/vcs/allow-commit-listener.kt

-68
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,17 @@ import com.intellij.openapi.Disposable
44
import com.intellij.openapi.project.Project
55
import com.intellij.openapi.util.Disposer
66
import com.intellij.openapi.vcs.CheckinProjectPanel
7-
import com.intellij.openapi.vcs.VcsKey
87
import com.intellij.openapi.vcs.changes.Change
98
import com.intellij.openapi.vcs.changes.CommitContext
10-
import com.intellij.openapi.vcs.changes.CommitExecutor
11-
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesCommitExecutor
129
import com.intellij.openapi.vcs.checkin.*
1310
import com.intellij.openapi.vcs.checkin.CheckinHandler.ReturnResult.CANCEL
1411
import com.intellij.openapi.vcs.checkin.CheckinHandler.ReturnResult.COMMIT
15-
import com.intellij.openapi.vcs.impl.CheckinHandlersManager
16-
import com.intellij.util.containers.MultiMap
1712
import limitedwip.common.ifNotNull
1813
import java.util.concurrent.CopyOnWriteArraySet
1914

2015
object AllowCommit: CheckinHandlerFactory() {
2116
val listeners = CopyOnWriteArraySet<Listener>()
2217

23-
init {
24-
registerBeforeCommitListener(object: Listener {
25-
override fun allowCommit(project: Project, changes: List<Change>): Boolean {
26-
return listeners.all { it.allowCommit(project, changes) }
27-
}
28-
})
29-
}
30-
3118
override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler =
3219
object: CheckinHandler(), CheckinMetaHandler {
3320
private var result: ReturnResult? = null
@@ -62,58 +49,3 @@ object AllowCommit: CheckinHandlerFactory() {
6249
fun allowCommit(project: Project, changes: List<Change>): Boolean
6350
}
6451
}
65-
66-
/**
67-
* This function is obsolete because:
68-
* - the reflection trick doesn't work anymore since #IC-202.4357.23 or so
69-
* - the new commit dialog is not in a separate window,
70-
* and to cancel commits CheckinHandlerFactory must be used
71-
*
72-
* Not deleting this function for now to maintain compatibility with older IJ versions.
73-
*/
74-
private fun registerBeforeCommitListener(listener: AllowCommit.Listener): Boolean {
75-
// This is a hack caused by limitations of IntelliJ API.
76-
// - cannot use CheckinHandlerFactory because:
77-
// - CheckinHandler is used just before commit (and after displaying commit dialog)
78-
// - its CheckinHandlerFactory#createSystemReadyHandler() doesn't seem to be called
79-
// - cannot use VcsCheckinHandlerFactory through extension points because need to register
80-
// checkin handler for all VCSs available
81-
// - cannot use CheckinHandlersManager#registerCheckinHandlerFactory() because it doesn't properly
82-
// register VcsCheckinHandlerFactory
83-
//
84-
// Therefore, using reflection.
85-
86-
return accessField<MultiMap<VcsKey, VcsCheckinHandlerFactory>>(CheckinHandlersManager.getInstance(), listOf("a", "b", "myVcsMap", "vcsFactories")) { multiMap ->
87-
for (key in multiMap.keySet()) {
88-
multiMap.putValue(key, DelegatingCheckinHandlerFactory(key as VcsKey, listener))
89-
}
90-
}
91-
}
92-
93-
private inline fun <reified T> accessField(anObject: Any, possibleFieldNames: List<String>, f: (T) -> Unit): Boolean {
94-
for (field in anObject.javaClass.declaredFields) {
95-
if (possibleFieldNames.contains(field.name) && T::class.java.isAssignableFrom(field.type)) {
96-
field.isAccessible = true
97-
try {
98-
f.invoke(field.get(anObject) as T)
99-
return true
100-
} catch (ignored: Exception) {
101-
}
102-
}
103-
}
104-
return false
105-
}
106-
107-
private class DelegatingCheckinHandlerFactory(key: VcsKey, private val listener: AllowCommit.Listener): VcsCheckinHandlerFactory(key) {
108-
override fun createSystemReadyHandler(project: Project): BeforeCheckinDialogHandler {
109-
return object: BeforeCheckinDialogHandler() {
110-
override fun beforeCommitDialogShown(project: Project, changes: List<Change>, executors: Iterable<CommitExecutor>, showVcsCommit: Boolean): Boolean {
111-
return executors.all { it is ShelveChangesCommitExecutor } || listener.allowCommit(project, changes)
112-
}
113-
}
114-
}
115-
116-
override fun createVcsHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler {
117-
return object: CheckinHandler() {}
118-
}
119-
}

0 commit comments

Comments
 (0)