Skip to content

Commit

Permalink
Consistent popup (#88)
Browse files Browse the repository at this point in the history
* Improve popup location consistency

* Make popup dimensions system wide instead of being project specific

* Add changelogs and increment version

* Update kotlin-jvm and intellij-platform plugins to 2.1.0

* Make popup dimensions screen bound specific

* Update changenotes
  • Loading branch information
MituuZ authored Nov 9, 2024
1 parent 6d47adc commit 411755b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
15 changes: 7 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlin.jvm") version "2.0.20"
id("org.jetbrains.intellij.platform") version "2.0.1"
id("org.jetbrains.kotlin.jvm") version "2.1.0-RC"
id("org.jetbrains.intellij.platform") version "2.1.0"
id("org.jetbrains.kotlinx.kover") version "0.9.0-RC"
}

// Use same version and group for the jar and the plugin
val currentVersion = "1.1.1"
val currentVersion = "1.2.0"
val myGroup = "com.mituuz"
version = currentVersion
group = myGroup
Expand Down Expand Up @@ -63,11 +63,10 @@ intellijPlatform {

changeNotes = """
<h2>Version $currentVersion</h2>
- Use open version support from 2024.2 onwards<br><br>
<h2>Version 1.1.0</h2>
- Improve task cancelling to avoid InterruptedException and reduce cancelling delay<br>
- Run searches with concurrency<br><br>
To have the most fluid experience it is recommended to NOT highlight filenames in file list and use a low debounce period.
- Make popup dimensions persistent across projects<br>
&emsp;- Popup dimensions are saved per screen bounds (location and size)<br>
- Improve popup location consistency (fixes right screen, left half issue)<br>
- Update kotlin-jvm and intellij-platform plugins to 2.1.0
""".trimIndent()

ideaVersion {
Expand Down
17 changes: 17 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# Changelog
## Version 1.2.0
- Make popup dimensions persistent across projects
- Improve popup location consistency (fixes right screen, left half issue)
- Popup dimensions are saved per screen bounds (location and size)
- Update kotlin-jvm and intellij-platform plugins to 2.1.0

## Version 1.1.1
- Use open version support from 2024.2 onwards<br><br>

## Version 1.1.0
- Improve task cancelling to avoid InterruptedException and reduce cancelling delay<br>
- Run searches with concurrency<br><br>

## Version 1.0.0
- Re-implement project file handling as a backup if no modules are present
- Migrate IntelliJ Platform Gradle Plugin to 2.x

## Version 0.26.2
- Re-implement project file handling as a backup if no modules are present

Expand Down
20 changes: 14 additions & 6 deletions src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ import com.mituuz.fuzzier.components.FuzzyFinderComponent
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.NONE
import com.mituuz.fuzzier.util.FuzzierUtil
import com.mituuz.fuzzier.util.FuzzierUtil.Companion.createDimensionKey
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.apache.commons.lang3.StringUtils
import java.awt.Point
import java.awt.event.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Future
Expand All @@ -77,14 +79,20 @@ open class Fuzzier : FuzzyAction() {

val mainWindow = WindowManager.getInstance().getIdeFrame(actionEvent.project)?.component
mainWindow?.let {
popup = createPopup(project)
val screenBounds = it.graphicsConfiguration.bounds
val dimensionKey = createDimensionKey(fuzzyDimensionKey, screenBounds)
popup = createPopup(dimensionKey)

if (fuzzierSettingsService.state.resetWindow) {
DimensionService.getInstance().setSize(fuzzyDimensionKey, null, project)
DimensionService.getInstance().setLocation(fuzzyDimensionKey, null, project)
DimensionService.getInstance().setSize(dimensionKey, null, null)
DimensionService.getInstance().setLocation(dimensionKey, null, null)
fuzzierSettingsService.state.resetWindow = false
}
popup!!.showInCenterOf(it)

val centerX = screenBounds.x + screenBounds.width / 2
val centerY = screenBounds.y + screenBounds.height / 2
popup!!.showInScreenCoordinates(it, Point(centerX, centerY))

(component as FuzzyFinderComponent).splitPane.dividerLocation =
fuzzierSettingsService.state.splitPosition
}
Expand All @@ -95,14 +103,14 @@ open class Fuzzier : FuzzyAction() {
}
}

private fun createPopup(project: Project): JBPopup {
private fun createPopup(dimensionKey: String): JBPopup {
val popup: JBPopup = JBPopupFactory
.getInstance()
.createComponentPopupBuilder(component, component.searchField)
.setFocusable(true)
.setRequestFocus(true)
.setResizable(true)
.setDimensionServiceKey(project, fuzzyDimensionKey, true)
.setDimensionServiceKey(null, dimensionKey, true)
.setTitle(title)
.setMovable(true)
.setShowBorder(true)
Expand Down
23 changes: 14 additions & 9 deletions src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ import com.intellij.psi.PsiManager
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesUtil
import com.mituuz.fuzzier.components.SimpleFinderComponent
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.util.FuzzierUtil
import com.mituuz.fuzzier.util.FuzzierUtil.Companion.createDimensionKey
import org.apache.commons.lang3.StringUtils
import java.awt.Point
import java.awt.event.*
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Future
import javax.swing.*
import kotlin.coroutines.cancellation.CancellationException

class FuzzyMover : FuzzyAction() {
private val dimensionKey: String = "FuzzyMoverPopup"
private val moverDimensionKey: String = "FuzzyMoverPopup"
lateinit var movableFile: PsiFile
lateinit var currentFile: VirtualFile

Expand All @@ -71,7 +71,9 @@ class FuzzyMover : FuzzyAction() {

val mainWindow = WindowManager.getInstance().getIdeFrame(actionEvent.project)?.component
mainWindow?.let {
popup = createPopup(project)
val screenBounds = it.graphicsConfiguration.bounds
val dimensionKey = createDimensionKey(moverDimensionKey, screenBounds)
popup = createPopup(dimensionKey)

val currentEditor = FileEditorManager.getInstance(project).selectedTextEditor
if (currentEditor != null) {
Expand All @@ -80,23 +82,26 @@ class FuzzyMover : FuzzyAction() {
}

if (fuzzierSettingsService.state.resetWindow) {
DimensionService.getInstance().setSize(dimensionKey, null, project)
DimensionService.getInstance().setLocation(dimensionKey, null, project)
DimensionService.getInstance().setSize(dimensionKey, null, null)
DimensionService.getInstance().setLocation(dimensionKey, null, null)
fuzzierSettingsService.state.resetWindow = false
}
popup!!.showInCenterOf(it)

val centerX = screenBounds.x + screenBounds.width / 2
val centerY = screenBounds.y + screenBounds.height / 2
popup!!.showInScreenCoordinates(it, Point(centerX, centerY))
}
}
}

private fun createPopup(project: Project): JBPopup {
private fun createPopup(dimensionKey: String): JBPopup {
val popup = JBPopupFactory
.getInstance()
.createComponentPopupBuilder(component, component.searchField)
.setFocusable(true)
.setRequestFocus(true)
.setResizable(true)
.setDimensionServiceKey(project, dimensionKey, true)
.setDimensionServiceKey(null, dimensionKey, true)
.setTitle("Fuzzy File Mover")
.setMovable(true)
.setShowBorder(true)
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/com/mituuz/fuzzier/util/FuzzierUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import javax.swing.DefaultListModel
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.FileIndex
import com.intellij.openapi.vfs.VirtualFile
import java.awt.Rectangle
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Future

Expand All @@ -45,6 +46,14 @@ class FuzzierUtil {
data class IterationFile(val file: VirtualFile, val module: String)

companion object {
/**
* Create a dimension key for a specific screen bounds
* Takes the screen position and size into account
*/
fun createDimensionKey(baseDimensionKey: String, screenBounds: Rectangle): String {
return "${baseDimensionKey}_${screenBounds.width}_${screenBounds.height}_${screenBounds.x}_${screenBounds.y}"
}

fun fileIndexToIterationFile(iterationFiles: ConcurrentHashMap.KeySetView<IterationFile, Boolean>,
fileIndex: FileIndex, moduleName: String, task: Future<*>?,
isDir: Boolean = false) {
Expand Down

0 comments on commit 411755b

Please sign in to comment.