@@ -2,29 +2,27 @@ package net.allape.common
22
33import com.intellij.notification.NotificationGroupManager
44import com.intellij.notification.Notifications
5- import com.intellij.openapi.project.ProjectManager
5+ import com.intellij.openapi.project.Project
66import com.intellij.openapi.ui.MessageType
77import com.intellij.openapi.ui.popup.Balloon
8+ import com.intellij.openapi.wm.IdeFocusManager
89import com.intellij.openapi.wm.ToolWindow
10+ import com.intellij.openapi.wm.ToolWindowManager
911import com.intellij.ui.GotItTooltip
10- import com.intellij.ui.content.Content
1112import net.allape.xftp.XFTP
13+ import net.allape.xftp.XFTPPanel
1214import java.awt.Point
1315import javax.swing.JComponent
1416
1517
1618class XFTPManager {
1719
1820 companion object {
19-
20- lateinit var toolWindow: ToolWindow
21+ const val TOOL_WINDOW_ID = " XFTP"
2122
2223 // 默认的窗口名称
2324 const val DEFAULT_NAME = " Explorer"
2425
25- // 当前打开的窗口
26- val windows: HashMap <Content , XFTP > = HashMap (10 )
27-
2826 /* *
2927 * message中用到的group
3028 */
@@ -49,7 +47,7 @@ class XFTPManager {
4947 fun gotIt (component : JComponent , message : String ) {
5048// JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setTitle("啊哈").setAdText(message)
5149// GotItMessage.createMessage("A", message).setShowCallout(false).show(RelativePoint(component, Point(0,0)), Balloon.Position.above)
52- val tooltips = GotItTooltip (GOT_IT_ID , message, ProjectManager .getInstance().defaultProject )
50+ val tooltips = GotItTooltip (GOT_IT_ID , message, getCurrentSelectedWindow() )
5351 tooltips.showCondition = { true }
5452 tooltips
5553 .withTimeout(3000 )
@@ -59,15 +57,22 @@ class XFTPManager {
5957 }
6058 }
6159
62- /* *
63- * 获取当前选中的窗口, 可能为null
64- */
6560 fun getCurrentSelectedWindow (): XFTP ? {
66- return toolWindow.contentManager.selectedContent?.let { content ->
67- windows[content]
61+ return getCurrentProjectToolWindow()?.let { toolWindow ->
62+ val selectedComponent = toolWindow.contentManager.selectedContent?.component as XFTPPanel ?
63+ return selectedComponent?.xftp
6864 }
6965 }
7066
67+ fun getCurrentProject (): Project ? {
68+ return IdeFocusManager .getGlobalInstance().lastFocusedFrame?.project
69+ }
70+
71+ fun getCurrentProjectToolWindow (): ToolWindow ? {
72+ return getCurrentProject()?.let { project ->
73+ return ToolWindowManager .getInstance(project).getToolWindow(TOOL_WINDOW_ID )
74+ }
75+ }
7176 }
7277
7378}
0 commit comments