Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Update for api change and stop using adaptors that will be deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
mgziminsky committed May 19, 2019
1 parent 0827918 commit 5148f54
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ targetCompatibility = "1.8"
tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }

intellij {
version "14"
version "15.0.4"
pluginName 'MiniMap'
updateSinceUntilBuild = false
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/net/vektah/codeglance/EditorPanelInjector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerAdapter
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
Expand All @@ -19,7 +20,7 @@ import javax.swing.JPanel
/**
* Injects a panel into any newly created editors.
*/
class EditorPanelInjector(private val project: Project) : FileEditorManagerAdapter() {
class EditorPanelInjector(private val project: Project) : FileEditorManagerListener {
private val logger = Logger.getInstance(javaClass)
private var config: Config = ServiceManager.getService(ConfigService::class.java).state!!

Expand Down Expand Up @@ -84,4 +85,10 @@ class EditorPanelInjector(private val project: Project) : FileEditorManagerAdapt
Disposer.register(editor, Disposable { panel.remove(glancePanel) })
}
}


override fun selectionChanged(event: FileEditorManagerEvent) {}

override fun fileClosed(source: FileEditorManager, file: VirtualFile) {}

}
19 changes: 12 additions & 7 deletions src/main/java/net/vektah/codeglance/GlancePanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.editor.FoldRegion
import com.intellij.openapi.editor.colors.ColorKey
import com.intellij.openapi.editor.event.DocumentAdapter
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.editor.event.SelectionEvent
import com.intellij.openapi.editor.event.SelectionListener
import com.intellij.openapi.editor.event.VisibleAreaListener
import com.intellij.openapi.editor.ex.EditorEx
Expand All @@ -45,7 +45,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vfs.PersistentFSConstants
import com.intellij.ui.JBColor
import com.intellij.util.ui.UIUtil
import net.vektah.codeglance.concurrent.DirtyLock
import net.vektah.codeglance.config.Config
import net.vektah.codeglance.config.ConfigService
Expand Down Expand Up @@ -81,7 +80,7 @@ class GlancePanel(private val project: Project, textEditor: TextEditor) : JPanel
private val componentListener: ComponentListener
private val documentListener: DocumentListener
private val areaListener: VisibleAreaListener
private val selectionListener: SelectionListener = SelectionListener { repaint() }
private val selectionListener: SelectionListener

private val updateTask: ReadTask

Expand All @@ -105,8 +104,10 @@ class GlancePanel(private val project: Project, textEditor: TextEditor) : JPanel
}
editor.contentComponent.addComponentListener(componentListener)

documentListener = object : DocumentAdapter() {
override fun documentChanged(documentEvent: DocumentEvent?) = updateImage()
documentListener = object : DocumentListener {
override fun beforeDocumentChange(event: DocumentEvent) {}

override fun documentChanged(event: DocumentEvent) = updateImage()
}
editor.document.addDocumentListener(documentListener)

Expand All @@ -123,9 +124,12 @@ class GlancePanel(private val project: Project, textEditor: TextEditor) : JPanel
}
editor.scrollingModel.addVisibleAreaListener(areaListener)

selectionListener = object : SelectionListener {
override fun selectionChanged(e: SelectionEvent) = repaint()
}
editor.selectionModel.addSelectionListener(selectionListener)

updateTask = object : ReadTask {
updateTask = object : ReadTask() {
override fun onCanceled(indicator: ProgressIndicator) = updateImage()

override fun computeInReadAction(indicator: ProgressIndicator) {
Expand Down Expand Up @@ -266,7 +270,8 @@ class GlancePanel(private val project: Project, textEditor: TextEditor) : JPanel
}

if (buf == null || buf?.width!! < width || buf?.height!! < height) {
buf = UIUtil.createImage(width, height, BufferedImage.TYPE_4BYTE_ABGR)
// TODO: Add handling for HiDPI scaling and switch back to UIUtil.createImage
buf = BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR)
}

val g = buf!!.createGraphics()
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/vektah/codeglance/render/Minimap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ package net.vektah.codeglance.render
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.util.ui.UIUtil
import net.vektah.codeglance.config.Config
import java.awt.AlphaComposite
import java.awt.image.BufferedImage
Expand All @@ -44,7 +43,6 @@ class Minimap(private val config: Config) {
* Internal worker function to update the minimap image
*
* @param editor The editor being drawn
* @param hl The syntax highlighter to use for the language this document is in.
*/
fun update(editor: EditorEx, scrollstate: ScrollState, indicator: ProgressIndicator?) {
logger.debug("Updating file image.")
Expand All @@ -53,7 +51,8 @@ class Minimap(private val config: Config) {
if (img != null) img!!.flush()
// Create an image that is a bit bigger then the one we need so we don't need to re-create it again soon.
// Documents can get big, so rather then relative sizes lets just add a fixed amount on.
img = UIUtil.createImage(config.width, scrollstate.documentHeight + (100 * config.pixelsPerLine), BufferedImage.TYPE_4BYTE_ABGR)
// TODO: Add handling for HiDPI scaling and switch back to UIUtil.createImage
img = BufferedImage(config.width, scrollstate.documentHeight + (100 * config.pixelsPerLine), BufferedImage.TYPE_4BYTE_ABGR)
logger.debug("Created new image")
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@
</ul>
]]></change-notes>

<idea-version since-build="139" until-build="143.*"/>
<!--Earlier versions of 143 had broken kotlin modules...-->
<idea-version since-build="143.2287.1"/>

<depends>com.intellij.modules.platform</depends>

Expand Down

0 comments on commit 5148f54

Please sign in to comment.