Skip to content

Commit

Permalink
fix: shortcut bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Jan 22, 2024
1 parent 145508c commit f2976d4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package com.github.dineug.erdeditorintellijplugin.editor
import com.github.dineug.erdeditorintellijplugin.settings.ErdEditorAppSettings
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.readAndWriteAction
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.fileChooser.FileChooserFactory
import com.intellij.openapi.fileChooser.FileSaverDescriptor
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileEditor.FileEditorState
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.UserDataHolderBase
import com.intellij.openapi.vfs.VirtualFile
import kotlinx.coroutines.*
Expand All @@ -29,15 +27,13 @@ import kotlin.time.Duration.Companion.milliseconds

@OptIn(FlowPreview::class)
class ErdEditor(
private val project: Project,
private val file: VirtualFile,
private val docToEditorsMap: HashMap<VirtualFile, HashSet<ErdEditor>>
) : UserDataHolderBase(),
FileEditor,
DumbAware, ErdEditorAppSettings.SettingsChangedListener {

private var isDisposed: Boolean = false
private val logger = thisLogger()

override fun getFile() = file

Expand Down Expand Up @@ -250,11 +246,11 @@ class ErdEditor(
}

override fun isModified(): Boolean {
return false;
return false
}

override fun isValid(): Boolean {
return true;
return true
}

override fun addPropertyChangeListener(listener: PropertyChangeListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ErdEditorProvider : AsyncFileEditorProvider, DumbAware {
NonProjectFileWritingAccessProvider.allowWriting(listOf(file))
}

val editor = ErdEditor(project, file, docToEditorsMap)
val editor = ErdEditor(file, docToEditorsMap)
docToEditorsMap.getOrPut(file) { HashSet() }.add(editor)
return editor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import com.intellij.CommonBundle
import com.intellij.ide.plugins.MultiPanel
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.EditorBundle
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.SystemInfoRt
import com.intellij.openapi.util.registry.Registry
import com.intellij.ui.components.JBLoadingPanel
import com.intellij.ui.jcef.JBCefBrowser
Expand All @@ -28,7 +26,6 @@ class Webview(
private const val CONTENT_KEY = 0
}

private val logger = thisLogger()
private val alarm = Alarm(this)
private val loadingPanel = JBLoadingPanel(BorderLayout(), this).apply {
setLoadingText(CommonBundle.getLoadingTreeNodeText())
Expand All @@ -45,7 +42,7 @@ class Webview(

val jbCefBrowser = JBCefBrowser.createBuilder()
.setEnableOpenDevToolsMenuItem(false)
.setOffScreenRendering(isOffScreenRenderingEnabled())
.setOffScreenRendering(false)
.build()

init {
Expand Down Expand Up @@ -91,22 +88,5 @@ class Webview(
}, jbCefBrowser.cefBrowser)
}

override fun dispose() = Unit;

private fun isOffScreenRenderingEnabled(): Boolean {
// Off-screen rendering prevents keyboard access to the editor on Linux and macOS in old versions,
// therefore disabling it.
// see: https://youtrack.jetbrains.com/issue/JBR-5348
// 17.0.6+10-b829.5
val jvmVersion = System.getProperty("java.vm.version")
val build: Double = try {
jvmVersion.replace("[^-]*-b([0-9]*)".toRegex(), "$1").toDouble()
} catch (e: NumberFormatException) {
0.0
}
// starting from 231.8770.17 / 2023.1.1 EAP off-screen-rendering starts to work
val result = SystemInfoRt.isWindows || build >= 829.9
logger.debug("isOffScreenRenderingEnabled: $result")
return result
}
override fun dispose() = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.cef.CefApp
import org.cef.CefSettings
import org.cef.browser.CefBrowser
import org.cef.browser.CefFrame
import org.cef.browser.CefMessageRouter
import org.cef.callback.CefQueryCallback
import org.cef.handler.CefDisplayHandlerAdapter
import org.cef.handler.CefMessageRouterHandlerAdapter
import org.intellij.lang.annotations.Language
import java.io.BufferedInputStream
Expand Down Expand Up @@ -108,6 +110,41 @@ class WebviewPanel(
messageRouter.dispose()
}
}

object : CefDisplayHandlerAdapter() {
override fun onConsoleMessage(
browser: CefBrowser?,
level: CefSettings.LogSeverity?,
message: String?,
source: String?,
line: Int
): Boolean {
if (level == null || message == null || source == null) {
logger.warn("${file.name}: Some of required message values were null!")
logger.warn("${file.name}: level: $level source: $source:$line\n\tmessage: $message")
} else {
val formattedMessage = "${file.name}: [$level][$source:$line]:\n${message}"

when (level) {
CefSettings.LogSeverity.LOGSEVERITY_ERROR, CefSettings.LogSeverity.LOGSEVERITY_FATAL -> logger.error(formattedMessage)
CefSettings.LogSeverity.LOGSEVERITY_INFO -> logger.info(formattedMessage)
CefSettings.LogSeverity.LOGSEVERITY_WARNING -> logger.warn(formattedMessage)
CefSettings.LogSeverity.LOGSEVERITY_VERBOSE -> logger.debug(formattedMessage)
else -> logger.info(formattedMessage)
}
}
return super.onConsoleMessage(browser, level, message, source, line)
}
}.also { displayHandler ->
webview.jbCefBrowser.jbCefClient.addDisplayHandler(displayHandler, webview.jbCefBrowser.cefBrowser)
Disposer.register(this) {
logger.debug("${file.name}: removing display handler")
webview.jbCefBrowser.jbCefClient.removeDisplayHandler(
displayHandler,
webview.jbCefBrowser.cefBrowser
)
}
}
}

private fun runJS(@Language("JavaScript") js: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class ErdEditorAppSettings : PersistentStateComponent<ErdEditorAppSettings.State
}

override fun loadState(state: State) {
XmlSerializerUtil.copyBean(state, myState);
XmlSerializerUtil.copyBean(state, myState)
}

fun setTheme(state: State) {
XmlSerializerUtil.copyBean(state, myState);
XmlSerializerUtil.copyBean(state, myState)

ApplicationManager.getApplication().messageBus.syncPublisher(SettingsChangedListener.TOPIC)
.onSettingsChange(this)
Expand Down

0 comments on commit f2976d4

Please sign in to comment.