-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathToolWindowManager.kt
More file actions
222 lines (187 loc) · 8.67 KB
/
ToolWindowManager.kt
File metadata and controls
222 lines (187 loc) · 8.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.wm
import com.intellij.icons.AllIcons
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.MessageType
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.BalloonBuilder
import com.intellij.openapi.util.NlsContexts
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.ApiStatus.Internal
import org.jetbrains.annotations.NonNls
import java.util.function.Consumer
import java.util.function.Supplier
import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.event.HyperlinkListener
/**
* If you want to register a toolwindow, which will be enabled during the dumb mode, please use [ToolWindowManager]'s
* registration methods which have 'canWorkInDumbMode' parameter.
*
* @see com.intellij.openapi.wm.ex.ToolWindowManagerListener
*/
abstract class ToolWindowManager {
companion object {
@JvmStatic
fun getInstance(project: Project): ToolWindowManager = project.service<ToolWindowManager>()
}
abstract val focusManager: IdeFocusManager
abstract fun canShowNotification(toolWindowId: String): Boolean
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
fun registerToolWindow(id: String, component: JComponent, anchor: ToolWindowAnchor): ToolWindow {
return registerToolWindow(RegisterToolWindowTask(id = id, component = component, anchor = anchor, canCloseContent = false, canWorkInDumbMode = false))
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
fun registerToolWindow(id: String, canCloseContent: Boolean, anchor: ToolWindowAnchor): ToolWindow {
return registerToolWindow(RegisterToolWindowTask(id = id, anchor = anchor, canCloseContent = canCloseContent, canWorkInDumbMode = false))
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
fun registerToolWindow(id: String,
canCloseContent: Boolean,
anchor: ToolWindowAnchor,
secondary: Boolean): ToolWindow {
return registerToolWindow(RegisterToolWindowTask(id = id, anchor = anchor, sideTool = secondary, canCloseContent = canCloseContent, canWorkInDumbMode = false))
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
fun registerToolWindow(id: String,
canCloseContent: Boolean,
anchor: ToolWindowAnchor,
@Suppress("UNUSED_PARAMETER") parentDisposable: Disposable,
canWorkInDumbMode: Boolean): ToolWindow {
return registerToolWindow(RegisterToolWindowTask(id = id, anchor = anchor, canCloseContent = canCloseContent, canWorkInDumbMode = canWorkInDumbMode))
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
fun registerToolWindow(id: String,
canCloseContent: Boolean,
anchor: ToolWindowAnchor,
@Suppress("UNUSED_PARAMETER") parentDisposable: Disposable,
canWorkInDumbMode: Boolean,
secondary: Boolean): ToolWindow {
return registerToolWindow(RegisterToolWindowTask(id = id, anchor = anchor, sideTool = secondary, canCloseContent = canCloseContent, canWorkInDumbMode = canWorkInDumbMode))
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
@ApiStatus.ScheduledForRemoval
fun registerToolWindow(id: String,
canCloseContent: Boolean,
anchor: ToolWindowAnchor,
@Suppress("UNUSED_PARAMETER") parentDisposable: Disposable): ToolWindow {
return registerToolWindow(RegisterToolWindowTask(id = id, anchor = anchor, canCloseContent = canCloseContent, canWorkInDumbMode = false))
}
@ApiStatus.OverrideOnly
abstract fun registerToolWindow(task: RegisterToolWindowTask): ToolWindow
/**
* Use only for dynamically registered toolwindows required for a certain operation.
*
* [ToolWindow.getAnchor] is set to [ToolWindowAnchor.BOTTOM] by default.
* [ToolWindow.setToHideOnEmptyContent] is set to `true` by default.
*/
inline fun registerToolWindow(id: String, builder: RegisterToolWindowTaskBuilder.() -> Unit): ToolWindow {
val b = RegisterToolWindowTaskBuilder(id)
b.builder()
return registerToolWindow(b.build())
}
/**
* Does nothing if a tool window with specified id isn't registered.
*/
@Deprecated("Use ToolWindowFactory and com.intellij.toolWindow extension point")
abstract fun unregisterToolWindow(id: String)
abstract fun activateEditorComponent()
/**
* @return `true` if and only if an editor component is active.
*/
abstract val isEditorComponentActive: Boolean
/**
* @return array of `id`s of all registered tool windows.
*/
abstract val toolWindowIds: Array<String>
abstract val toolWindowIdSet: Set<String>
/**
* @return `ID` of currently active tool window or `null` if there is no active tool window.
*/
abstract val activeToolWindowId: String?
/**
* @return `ID` of tool window activated last time.
*/
abstract val lastActiveToolWindowId: String?
/**
* @return registered tool window with specified `id`. If there is no registered
* tool window with specified `id` then the method returns `null`.
* @see ToolWindowId
*/
abstract fun getToolWindow(@NonNls id: String?): ToolWindow?
/**
* Puts specified runnable to the tail of the current command queue.
*/
abstract fun invokeLater(runnable: Runnable)
fun notifyByBalloon(toolWindowId: String, type: MessageType, @NlsContexts.NotificationContent htmlBody: String) {
notifyByBalloon(ToolWindowBalloonShowOptions(toolWindowId, type, htmlBody))
}
fun notifyByBalloon(toolWindowId: String,
type: MessageType,
@NlsContexts.PopupContent htmlBody: String,
icon: Icon?,
listener: HyperlinkListener?) {
notifyByBalloon(ToolWindowBalloonShowOptions(toolWindowId, type, htmlBody, icon, listener))
}
abstract fun notifyByBalloon(options: ToolWindowBalloonShowOptions)
abstract fun getToolWindowBalloon(id: String): Balloon?
@Internal
open fun closeBalloons() {
}
abstract fun isMaximized(window: ToolWindow): Boolean
abstract fun setMaximized(window: ToolWindow, maximized: Boolean)
/*
* Returns visual representation of tool window location
* @see AllIcons.Actions#MoveToBottomLeft ... com.intellij.icons.AllIcons.Actions#MoveToWindow icon set
*/
open fun getLocationIcon(id: String, fallbackIcon: Icon): Icon = fallbackIcon
open fun getShowInFindToolWindowIcon(): Icon = AllIcons.General.OpenInToolWindow
open fun isStripeButtonShow(toolWindow: ToolWindow): Boolean = false
}
class RegisterToolWindowTaskBuilder @PublishedApi internal constructor(private val id: String) {
@JvmField
var anchor: ToolWindowAnchor = ToolWindowAnchor.BOTTOM
@JvmField
var stripeTitle: Supplier<@NlsContexts.TabTitle String>? = null
@JvmField
var icon: Icon? = null
@JvmField
var shouldBeAvailable: Boolean = true
@JvmField
var canCloseContent: Boolean = true
@JvmField
var hideOnEmptyContent: Boolean = true
@JvmField
var sideTool: Boolean = false
@JvmField
var contentFactory: ToolWindowFactory? = null
@PublishedApi
internal fun build(): RegisterToolWindowTask {
return RegisterToolWindowTask(RegisterToolWindowTaskData(
id = id,
anchor = anchor,
component = null,
sideTool = sideTool,
canCloseContent = canCloseContent,
shouldBeAvailable = shouldBeAvailable,
contentFactory = contentFactory,
icon = icon,
stripeTitle = stripeTitle,
hideOnEmptyContent = hideOnEmptyContent,
))
}
}
data class ToolWindowBalloonShowOptions(val toolWindowId: String,
val type: MessageType,
@NlsContexts.PopupContent val htmlBody: String,
val icon: Icon? = null,
val listener: HyperlinkListener? = null,
val balloonCustomizer: Consumer<BalloonBuilder>? = null)