Skip to content

Commit

Permalink
Add preview font size setting (#68)
Browse files Browse the repository at this point in the history
* Add preview font size setting and tests

* Add change notes, increment version and update dependencies

* Add settings changes to change log

* Clear up changelog commetn

* Increase font ranges
  • Loading branch information
MituuZ authored Jun 16, 2024
1 parent fb730a9 commit 04480ff
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 19 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.23"
id("org.jetbrains.intellij") version "1.17.3"
id("org.jetbrains.kotlin.jvm") version "2.0.0"
id("org.jetbrains.intellij") version "1.17.4"
}

group = "com.mituuz"
version = "0.23.0"
version = "0.24.0"

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testImplementation("org.mockito:mockito-core:5.11.0")
testImplementation("org.mockito:mockito-core:5.12.0")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
}
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## Version 0.24.0
- Add an option to change the font size for the preview window
- Some dependency updates
- Separate settings sections

## Version 0.23.0
- Add an option to show recently used files when opening the popup
- Fix mover not working correctly
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mituuz/fuzzier/FuzzyAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ abstract class FuzzyAction : AnAction() {
fuzzierSettingsService.state.fileListSpacing.let {
renderer.border = BorderFactory.createEmptyBorder(it, 0, it, 0)
}
fuzzierSettingsService.state.fontSize.let {
fuzzierSettingsService.state.fileListFontSize.let {
renderer.font = renderer.font.deriveFont(it.toFloat())
}
return renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.intellij.util.ui.FormBuilder
import com.intellij.openapi.ui.ComboBox
import com.mituuz.fuzzier.components.FuzzierSettingsComponent.SettingsComponent
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType.*
import com.mituuz.fuzzier.settings.FuzzierSettingsService
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode
import java.awt.Component
Expand Down Expand Up @@ -107,12 +106,20 @@ class FuzzierSettingsComponent {
""".trimIndent(),
false)

val fontSize = SettingsComponent(JBIntSpinner(14, 4, 20), "File list font size",
val fileListFontSize = SettingsComponent(JBIntSpinner(14, 4, 30), "File list font size",
"""
Controls the font size of the file list in the search and selector popups.
""".trimIndent(),
false)

val previewFontSize = SettingsComponent(JBIntSpinner(0, 0, 30), "Preview font size",
"""
Controls the font size of the preview in the search and selector popups.
<br>
When value is zero, use the current font size of the editor.
""".trimIndent(),
false)

val fileListSpacing = SettingsComponent(JBIntSpinner(0, 0, 10), "File list vertical spacing",
"""
Controls the vertical spacing between the file list items in the search and selector popups.
Expand Down Expand Up @@ -179,15 +186,21 @@ class FuzzierSettingsComponent {
init {
setupComponents()
jPanel = FormBuilder.createFormBuilder()
.addComponent(JBLabel("<html><strong>General settings</strong></html>"))
.addComponent(exclusionSet)

.addSeparator()
.addComponent(newTabSelect)
.addComponent(recentFileModeSelector)
.addComponent(prioritizeShortDirs)
.addComponent(debounceTimerValue)
.addComponent(filenameTypeSelector)
.addComponent(fileListLimit)
.addComponent(fontSize)

.addSeparator()
.addComponent(JBLabel("<html><strong>Popup styling</strong></html>"))
.addComponent(fileListFontSize)
.addComponent(previewFontSize)
.addComponent(fileListSpacing)

.addSeparator()
Expand All @@ -199,9 +212,12 @@ class FuzzierSettingsComponent {
.addComponent(matchWeightStreakModifier)
.addComponent(matchWeightFilename)

.addSeparator()
.addComponent(startTestBench)
.addComponent(testBench)
.addComponentFillVertically(JPanel(), 0)

.addSeparator()
.addComponent(resetWindowDimension)
.panel
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package com.mituuz.fuzzier.components

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.colors.EditorColorsManager
Expand All @@ -37,6 +38,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorTextField
import com.mituuz.fuzzier.settings.FuzzierSettingsService
import kotlin.math.min

class PreviewEditor(project: Project?) : EditorTextField(
Expand All @@ -45,6 +47,7 @@ class PreviewEditor(project: Project?) : EditorTextField(
) {
private val toBeContinued: String = "\n\n\n--- End of Fuzzier Preview ---\n--- Open file to see full content ---\n\n\n"
private val fileCutOff: Int = 70000
private val settingsState = service<FuzzierSettingsService>().state

companion object {
fun getDefaultFileType(): FileType {
Expand All @@ -62,6 +65,12 @@ class PreviewEditor(project: Project?) : EditorTextField(

val globalScheme = EditorColorsManager.getInstance().globalScheme
this.font = globalScheme.getFont(null)

val previewFontSize = settingsState.previewFontSize
if (previewFontSize != 0) {
this.font = this.font.deriveFont(previewFontSize.toFloat())
}

return editor
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class FuzzierSettingsConfigurable : Configurable {
component.debounceTimerValue.getIntSpinner().value = state.debouncePeriod
component.filenameTypeSelector.getFilenameTypeComboBox().selectedIndex = state.filenameType.ordinal
component.fileListLimit.getIntSpinner().value = state.fileListLimit
component.fontSize.getIntSpinner().value = state.fontSize
component.fileListFontSize.getIntSpinner().value = state.fileListFontSize
component.previewFontSize.getIntSpinner().value = state.previewFontSize
component.fileListSpacing.getIntSpinner().value = state.fileListSpacing

component.tolerance.getIntSpinner().value = state.tolerance
Expand All @@ -74,7 +75,8 @@ class FuzzierSettingsConfigurable : Configurable {
|| state.debouncePeriod != component.debounceTimerValue.getIntSpinner().value
|| state.filenameType != component.filenameTypeSelector.getFilenameTypeComboBox().selectedItem
|| state.fileListLimit != component.fileListLimit.getIntSpinner().value
|| state.fontSize != component.fontSize.getIntSpinner().value
|| state.fileListFontSize != component.fileListFontSize.getIntSpinner().value
|| state.previewFontSize != component.previewFontSize.getIntSpinner().value
|| state.fileListSpacing != component.fileListSpacing.getIntSpinner().value

|| state.tolerance != component.tolerance.getIntSpinner().value
Expand All @@ -97,7 +99,8 @@ class FuzzierSettingsConfigurable : Configurable {
state.debouncePeriod = component.debounceTimerValue.getIntSpinner().value as Int
state.filenameType = FilenameType.entries.toTypedArray()[component.filenameTypeSelector.getFilenameTypeComboBox().selectedIndex]
state.fileListLimit = component.fileListLimit.getIntSpinner().value as Int
state.fontSize = component.fontSize.getIntSpinner().value as Int
state.fileListFontSize = component.fileListFontSize.getIntSpinner().value as Int
state.previewFontSize = component.previewFontSize.getIntSpinner().value as Int
state.fileListSpacing = component.fileListSpacing.getIntSpinner().value as Int

state.tolerance = component.tolerance.getIntSpinner().value as Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class FuzzierSettingsService : PersistentStateComponent<FuzzierSettingsService.S
var fileListLimit: Int = 50

var filenameType: FilenameType = FILE_PATH_ONLY
var fontSize = 14
var fileListFontSize = 14
var previewFontSize = 0
var fileListSpacing = 0

var tolerance = 0
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
</extensions>

<change-notes><![CDATA[
<h2>Version 0.23.0</h2>
- Add an option to show recently used files when opening the popup<br>
- Fix mover not working correctly<br>
- Refactor module handling<br>
<h2>Version 0.24.0</h2>
- Add an option to change the font size for the preview window<br>
- Some dependency updates<br>
- Separate settings sections<br>
]]>
</change-notes>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class FuzzierSettingsConfigurableTest {
state.debouncePeriod = 140
state.filenameType = FILENAME_WITH_PATH_STYLED
state.fileListLimit = 200
state.fontSize = 15
state.fileListFontSize = 15
state.previewFontSize = 0
state.fileListSpacing = 2

state.tolerance = 4
Expand All @@ -68,7 +69,8 @@ class FuzzierSettingsConfigurableTest {
state.debouncePeriod = 140
state.filenameType = FILENAME_WITH_PATH_STYLED
state.fileListLimit = 200
state.fontSize = 15
state.fileListFontSize = 15
state.previewFontSize = 0
state.fileListSpacing = 2

state.tolerance = 4
Expand All @@ -80,7 +82,7 @@ class FuzzierSettingsConfigurableTest {

val settingsConfigurable = FuzzierSettingsConfigurable()
settingsConfigurable.createComponent()
state.fontSize = 16
state.fileListFontSize = 16
assertTrue(settingsConfigurable.isModified())
}
}

0 comments on commit 04480ff

Please sign in to comment.