@@ -4,30 +4,17 @@ import com.intellij.openapi.Disposable
4
4
import com.intellij.openapi.project.Project
5
5
import com.intellij.openapi.util.Disposer
6
6
import com.intellij.openapi.vcs.CheckinProjectPanel
7
- import com.intellij.openapi.vcs.VcsKey
8
7
import com.intellij.openapi.vcs.changes.Change
9
8
import com.intellij.openapi.vcs.changes.CommitContext
10
- import com.intellij.openapi.vcs.changes.CommitExecutor
11
- import com.intellij.openapi.vcs.changes.shelf.ShelveChangesCommitExecutor
12
9
import com.intellij.openapi.vcs.checkin.*
13
10
import com.intellij.openapi.vcs.checkin.CheckinHandler.ReturnResult.CANCEL
14
11
import com.intellij.openapi.vcs.checkin.CheckinHandler.ReturnResult.COMMIT
15
- import com.intellij.openapi.vcs.impl.CheckinHandlersManager
16
- import com.intellij.util.containers.MultiMap
17
12
import limitedwip.common.ifNotNull
18
13
import java.util.concurrent.CopyOnWriteArraySet
19
14
20
15
object AllowCommit: CheckinHandlerFactory() {
21
16
val listeners = CopyOnWriteArraySet <Listener >()
22
17
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
-
31
18
override fun createHandler (panel : CheckinProjectPanel , commitContext : CommitContext ): CheckinHandler =
32
19
object : CheckinHandler (), CheckinMetaHandler {
33
20
private var result: ReturnResult ? = null
@@ -62,58 +49,3 @@ object AllowCommit: CheckinHandlerFactory() {
62
49
fun allowCommit (project : Project , changes : List <Change >): Boolean
63
50
}
64
51
}
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