mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-349699 convert StatusBarUpdater to kotlin (to be able to use modern API)
GitOrigin-RevId: d82dd09a6964f67ba74c3536c0f145d230ca649e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8c201653cf
commit
5ccbdb8c44
@@ -1,70 +1,64 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// 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.codeInsight.daemon.impl
|
||||
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer.DaemonListener
|
||||
import com.intellij.lang.annotation.HighlightSeverity
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.wm.WindowManager
|
||||
import com.intellij.util.SingleAlarm
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.StatusBar;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.util.SingleAlarm;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
internal class StatusBarUpdater(private val project: Project) : Disposable {
|
||||
private val myAlarm: SingleAlarm
|
||||
|
||||
final class StatusBarUpdater implements Disposable {
|
||||
private final Project myProject;
|
||||
private final SingleAlarm myAlarm;
|
||||
private fun updateLater() {
|
||||
myAlarm.cancelAndRequest()
|
||||
}
|
||||
|
||||
StatusBarUpdater(Project project) {
|
||||
myProject = project;
|
||||
myAlarm = new SingleAlarm(() -> updateStatus(), 100, this);
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
|
||||
@Override
|
||||
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
|
||||
updateLater();
|
||||
init {
|
||||
myAlarm = SingleAlarm({ updateStatus() }, 100, this)
|
||||
|
||||
project.messageBus.connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener {
|
||||
override fun selectionChanged(event: FileEditorManagerEvent) {
|
||||
updateLater()
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
project.getMessageBus().connect(this).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListener() {
|
||||
@Override
|
||||
public void daemonFinished() {
|
||||
updateLater();
|
||||
project.messageBus.connect(this).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, object : DaemonListener {
|
||||
override fun daemonFinished() {
|
||||
updateLater()
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
private void updateLater() {
|
||||
myAlarm.cancelAndRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
private static final HighlightSeverity MIN = new HighlightSeverity("min", HighlightSeverity.INFORMATION.myVal + 1);
|
||||
private void updateStatus() {
|
||||
Editor editor = FileEditorManager.getInstance(myProject).getSelectedTextEditor();
|
||||
if (editor == null || !editor.getContentComponent().hasFocus()){
|
||||
return;
|
||||
private fun updateStatus() {
|
||||
val editor = FileEditorManager.getInstance(project).selectedTextEditor
|
||||
if (editor == null || !editor.contentComponent.hasFocus()) {
|
||||
return
|
||||
}
|
||||
|
||||
Document document = editor.getDocument();
|
||||
if (document.isInBulkUpdate()) return;
|
||||
val document = editor.document
|
||||
if (document.isInBulkUpdate) return
|
||||
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject);
|
||||
HighlightInfo info = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(document, offset, false, MIN);
|
||||
String text = info != null && info.getDescription() != null ? info.getDescription() : "";
|
||||
val offset = editor.caretModel.offset
|
||||
val codeAnalyzer = DaemonCodeAnalyzer.getInstance(project)
|
||||
val info = (codeAnalyzer as DaemonCodeAnalyzerImpl).findHighlightByOffset(document, offset, false, MIN)
|
||||
val text = if (info != null && info.description != null) info.description else ""
|
||||
|
||||
StatusBar statusBar = WindowManager.getInstance().getStatusBar(editor.getContentComponent(), myProject);
|
||||
if (statusBar != null && !text.equals(statusBar.getInfo())) {
|
||||
statusBar.setInfo(text, "updater");
|
||||
val statusBar = WindowManager.getInstance().getStatusBar(editor.contentComponent, project)
|
||||
if (statusBar != null && text != statusBar.info) {
|
||||
statusBar.setInfo(text, "updater")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val MIN = HighlightSeverity("min", HighlightSeverity.INFORMATION.myVal + 1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user