Skip to content

Commit d0403ae

Browse files
authored
Search position configuration (#101)
* Add options for search field location * Remove unnecessary private sets * Remove unnecessary private * Use common GridConstraint * Clean up FuzzyFinderComponent * Reset window location and split position when changing the search position * Fix incorrect setter and tests * Fix dimension key shadow bug * Disable reset window button when pressed * Move popup settings to the correct spot * Use a single component for dimensions * Add tests that check for window reset functionality * Make settings cleaner * Update email * Fix default alignment
1 parent a81de59 commit d0403ae

File tree

14 files changed

+287
-87
lines changed

14 files changed

+287
-87
lines changed

build.gradle.kts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
// Use same version and group for the jar and the plugin
13-
val currentVersion = "1.4.2"
13+
val currentVersion = "1.5.0"
1414
val myGroup = "com.mituuz"
1515
version = currentVersion
1616
group = myGroup
@@ -80,8 +80,16 @@ intellijPlatform {
8080

8181
changeNotes = """
8282
<h2>Version $currentVersion</h2>
83-
- Make highlighting speed faster when highlighting sequential matches<br>
84-
- Init JMH benchmarking to be used in the future<br>
83+
<ul>
84+
<li>Allow configuring the default finder popup size</li>
85+
<li>Fix a bug where the correct dimension key wasn't used</li>
86+
<li>Enable changing the search field location on the popup
87+
<ul>
88+
<li>Top, bottom, left and right</li>
89+
</ul>
90+
</li>
91+
<li>Improve mover popup's default size</li>
92+
</ul>
8593
""".trimIndent()
8694

8795
ideaVersion {

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
## Version 1.5.0
3+
- Allow configuring the default finder popup size
4+
- Fix a bug where the correct dimension key wasn't used
5+
- Enable changing the search field location on the popup
6+
- Top, bottom, left and right
7+
- Improve mover popup's default size
8+
29
## Version 1.4.2
310
- Make highlighting speed faster when highlighting sequential matches
411
- Init JMH benchmarking to be used in the future

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ map <Leader>mf <action>(com.mituuz.fuzzier.FuzzyMover)
6464
The plugin can be installed from the [JetBrains Marketplace](https://plugins.jetbrains.com/plugin/23451-fuzzier)
6565

6666
## Contact
67-
I can be reached from <mituuuuz@hotmail.com>
67+
I can be reached at <mitja@mituuz.com>.
6868

6969
## Contributing
7070
I have a tendency to make some larger refactors from time to time,
7171
so I would appreciate it if you would open an issue before starting to work on a feature or a bug fix.
7272

73-
I'll help as I can and can give guidance on how to implement the feature or fix the bug, but cannot guarantee that I will accept the PR.
73+
I'll help as I can and can give guidance on how to implement the feature or fix the bug,
74+
but cannot guarantee that I will accept the PR.

src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ open class Fuzzier : FuzzyAction() {
8989
}
9090
}
9191

92-
override fun createPopup(): JBPopup {
93-
val popup = getInitialPopup()
92+
override fun createPopup(screenDimensionKey: String): JBPopup {
93+
val popup = getInitialPopup(screenDimensionKey)
9494

9595
popup.addListener(object : JBPopupListener {
9696
override fun onClosed(event: LightweightWindowEvent) {

src/main/kotlin/com/mituuz/fuzzier/FuzzyAction.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ abstract class FuzzyAction : AnAction() {
8282

8383
abstract fun runAction(project: Project, actionEvent: AnActionEvent)
8484

85-
abstract fun createPopup(): JBPopup
85+
abstract fun createPopup(screenDimensionKey: String): JBPopup
8686

87-
fun getInitialPopup(): JBPopup {
87+
fun getInitialPopup(screenDimensionKey: String): JBPopup {
8888
return JBPopupFactory
8989
.getInstance()
9090
.createComponentPopupBuilder(component, component.searchField)
9191
.setFocusable(true)
9292
.setRequestFocus(true)
9393
.setResizable(true)
94-
.setDimensionServiceKey(null, dimensionKey, true)
94+
.setDimensionServiceKey(null, screenDimensionKey, true)
9595
.setTitle(popupTitle)
9696
.setMovable(true)
9797
.setShowBorder(true)
@@ -102,18 +102,16 @@ abstract class FuzzyAction : AnAction() {
102102
val mainWindow = WindowManager.getInstance().getIdeFrame(project)?.component
103103
mainWindow?.let {
104104
val screenBounds = it.graphicsConfiguration.bounds
105-
val dimensionKey = createDimensionKey(dimensionKey, screenBounds)
106-
popup = createPopup()
105+
val screenDimensionKey = createDimensionKey(dimensionKey, screenBounds)
107106

108107
if (globalState.resetWindow) {
109-
DimensionService.getInstance().setSize(dimensionKey, null, null)
110-
DimensionService.getInstance().setLocation(dimensionKey, null, null)
108+
DimensionService.getInstance().setSize(screenDimensionKey, component.preferredSize, null)
109+
DimensionService.getInstance().setLocation(screenDimensionKey, null, null)
111110
globalState.resetWindow = false
112111
}
113112

114-
val centerX = screenBounds.x + screenBounds.width / 2
115-
val centerY = screenBounds.y + screenBounds.height / 2
116-
popup.showInScreenCoordinates(it, Point(centerX, centerY))
113+
popup = createPopup(screenDimensionKey)
114+
popup.showInCenterOf(it)
117115
}
118116
}
119117

src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class FuzzyMover : FuzzyAction() {
7777
}
7878
}
7979

80-
override fun createPopup(): JBPopup {
81-
val popup = getInitialPopup()
80+
override fun createPopup(screenDimensionKey: String): JBPopup {
81+
val popup = getInitialPopup(screenDimensionKey)
8282

8383
popup.addListener(object : JBPopupListener {
8484
override fun onClosed(event: LightweightWindowEvent) {

src/main/kotlin/com/mituuz/fuzzier/components/FuzzierGlobalSettingsComponent.kt

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2024 Mitja Leino
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
124
package com.mituuz.fuzzier.components
225

326
import com.intellij.openapi.components.service
@@ -9,7 +32,10 @@ import com.intellij.util.ui.FormBuilder
932
import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType
1033
import com.mituuz.fuzzier.settings.FuzzierGlobalSettingsService
1134
import com.mituuz.fuzzier.settings.FuzzierGlobalSettingsService.RecentFilesMode
35+
import com.mituuz.fuzzier.settings.FuzzierGlobalSettingsService.SearchPosition
1236
import java.awt.Component
37+
import javax.swing.Box
38+
import javax.swing.BoxLayout
1339
import javax.swing.DefaultListCellRenderer
1440
import javax.swing.JButton
1541
import javax.swing.JLabel
@@ -37,6 +63,10 @@ class FuzzierGlobalSettingsComponent {
3763
""".trimIndent(),
3864
false)
3965

66+
67+
/////////////////////////////////////////////////////////////////
68+
// Popup styling and configuration
69+
/////////////////////////////////////////////////////////////////
4070
val filenameTypeSelector = SettingsComponent(ComboBox<FilenameType>(), "Filename type",
4171
"""
4272
Controls how the filename is shown on the file search and selector popups.<br><br>
@@ -73,6 +103,28 @@ class FuzzierGlobalSettingsComponent {
73103
""".trimIndent(),
74104
false)
75105

106+
val dimensionComponent = JPanel().apply {
107+
layout = BoxLayout(this, BoxLayout.X_AXIS)
108+
add(JBLabel("Width: "))
109+
add(JBIntSpinner(700, 100, 4000))
110+
add(Box.createHorizontalStrut(10))
111+
add(JBLabel("Height: "))
112+
add(JBIntSpinner(400, 100, 4000))
113+
}
114+
val defaultDimension = SettingsComponent(dimensionComponent, "Default dimensions",
115+
"""
116+
Default dimensions for the finder popup. Affects reset window behaviour.<br><br>
117+
Min: 100, Max: 4000
118+
""".trimIndent(),
119+
false)
120+
121+
val searchPosition = SettingsComponent(ComboBox<SearchPosition>(), "Search bar location",
122+
"""
123+
Controls where the search bar is located on the popup.
124+
""".trimIndent(),
125+
false)
126+
127+
76128
val fileListLimit = SettingsComponent(JBIntSpinner(50, 1, 5000), "File list limit",
77129
"""
78130
Controls how many files are shown and listed on the popup.
@@ -159,23 +211,25 @@ class FuzzierGlobalSettingsComponent {
159211
init {
160212
setupComponents()
161213
jPanel = FormBuilder.createFormBuilder()
162-
.addComponent(JBLabel("<html><strong>General settings</strong></html>"))
214+
.addComponent(JBLabel("<html><h2>General settings</h2></html>"))
163215
.addComponent(newTabSelect)
164216
.addComponent(recentFileModeSelector)
165217
.addComponent(prioritizeShortDirs)
166218
.addComponent(debounceTimerValue)
167219
.addComponent(fileListLimit)
168220

169221
.addSeparator()
170-
.addComponent(JBLabel("<html><strong>Popup styling</strong></html>"))
222+
.addComponent(JBLabel("<html><h2>Popup styling</h2></html>"))
171223
.addComponent(filenameTypeSelector)
172224
.addComponent(highlightFilename)
173-
.addComponent(fileListFontSize)
225+
.addComponent(searchPosition)
226+
.addComponent(defaultDimension)
174227
.addComponent(previewFontSize)
228+
.addComponent(fileListFontSize)
175229
.addComponent(fileListSpacing)
176230

177231
.addSeparator()
178-
.addComponent(JBLabel("<html><strong>Match settings</strong></html>"))
232+
.addComponent(JBLabel("<html><h2>Match settings</h2></html>"))
179233
.addComponent(tolerance)
180234
.addComponent(multiMatchActive)
181235
.addComponent(matchWeightSingleChar)
@@ -184,11 +238,13 @@ class FuzzierGlobalSettingsComponent {
184238
.addComponent(matchWeightFilename)
185239

186240
.addSeparator()
241+
.addComponent(JBLabel("<html><h2>Test bench</h2></html>"))
187242
.addComponent(startTestBench)
188243
.addComponent(testBench)
189244
.addComponentFillVertically(JPanel(), 0)
190245

191246
.addSeparator()
247+
.addComponent(JBLabel("<html><h2>Reset window</h2></html>"))
192248
.addComponent(resetWindowDimension)
193249
.panel
194250
}
@@ -200,6 +256,8 @@ class FuzzierGlobalSettingsComponent {
200256
}
201257
resetWindowDimension.addActionListener {
202258
service<FuzzierGlobalSettingsService>().state.resetWindow = true
259+
// Disable the button to indicate that the press was registered
260+
resetWindowDimension.isEnabled = false
203261
}
204262

205263
recentFileModeSelector.getRecentFilesTypeComboBox().renderer = object : DefaultListCellRenderer() {
@@ -217,6 +275,24 @@ class FuzzierGlobalSettingsComponent {
217275
recentFileModeSelector.getRecentFilesTypeComboBox().addItem(recentFilesMode)
218276
}
219277

278+
searchPosition.getSearchPositionComboBox().renderer = object : DefaultListCellRenderer() {
279+
override fun getListCellRendererComponent(
280+
list: JList<*>?,
281+
value: Any?,
282+
index: Int,
283+
isSelected: Boolean,
284+
cellHasFocus: Boolean
285+
): Component? {
286+
val renderer = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) as JLabel
287+
val position = value as SearchPosition
288+
renderer.text = position.text
289+
return renderer
290+
}
291+
}
292+
for (sp in SearchPosition.entries) {
293+
searchPosition.getSearchPositionComboBox().addItem(sp)
294+
}
295+
220296
filenameTypeSelector.getFilenameTypeComboBox().renderer = object : DefaultListCellRenderer() {
221297
override fun getListCellRendererComponent(
222298
list: JList<*>?,

0 commit comments

Comments
 (0)