diff --git a/assets/ContainerComparison.drawio b/assets/ContainerComparison.drawio
new file mode 100644
index 00000000..a866a638
--- /dev/null
+++ b/assets/ContainerComparison.drawio
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build.gradle.kts b/build.gradle.kts
index 48ecd49a..914369a9 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -9,7 +9,7 @@ plugins {
}
// Use same version and group for the jar and the plugin
-val currentVersion = "1.4.0"
+val currentVersion = "1.4.1"
val myGroup = "com.mituuz"
version = currentVersion
group = myGroup
diff --git a/changelog.md b/changelog.md
index 08cd5a0a..db19eab8 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,4 +1,7 @@
# Changelog
+## Version 1.4.1
+- Refactoring match containers
+
## Version 1.4.0
- Add option to ignore characters from search
- Update dependencies
diff --git a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt
index 3295e853..ec9cf271 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt
@@ -37,7 +37,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.rootManager
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.ui.popup.JBPopup
-import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.util.DimensionService
@@ -46,7 +45,7 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.wm.WindowManager
import com.mituuz.fuzzier.components.FuzzyFinderComponent
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.StringEvaluator
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.NONE
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.RECENTLY_SEARCHED_FILES
@@ -67,40 +66,26 @@ import javax.swing.*
import kotlin.coroutines.cancellation.CancellationException
open class Fuzzier : FuzzyAction() {
+ override var popupTitle = "Fuzzy Search"
+ override var dimensionKey = "FuzzySearchPopup"
private var defaultDoc: Document? = null
- open var title: String = "Fuzzy Search"
- private val fuzzyDimensionKey: String = "FuzzySearchPopup"
// Used by FuzzierVCS to check if files are tracked by the VCS
protected var changeListManager: ChangeListManager? = null
override fun runAction(project: Project, actionEvent: AnActionEvent) {
setCustomHandlers()
+
ApplicationManager.getApplication().invokeLater {
defaultDoc = EditorFactory.getInstance().createDocument("")
component = FuzzyFinderComponent(project)
createListeners(project)
createSharedListeners(project)
- val mainWindow = WindowManager.getInstance().getIdeFrame(actionEvent.project)?.component
- mainWindow?.let {
- val screenBounds = it.graphicsConfiguration.bounds
- val dimensionKey = createDimensionKey(fuzzyDimensionKey, screenBounds)
- popup = createPopup(dimensionKey)
-
- if (fuzzierSettingsService.state.resetWindow) {
- DimensionService.getInstance().setSize(dimensionKey, null, null)
- DimensionService.getInstance().setLocation(dimensionKey, null, null)
- fuzzierSettingsService.state.resetWindow = false
- }
+ showPopup(project)
- 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
- }
+ (component as FuzzyFinderComponent).splitPane.dividerLocation =
+ fuzzierSettingsService.state.splitPosition
if (fuzzierSettingsService.state.recentFilesMode != NONE) {
createInitialView(project)
@@ -108,18 +93,8 @@ open class Fuzzier : FuzzyAction() {
}
}
- private fun createPopup(dimensionKey: String): JBPopup {
- val popup: JBPopup = JBPopupFactory
- .getInstance()
- .createComponentPopupBuilder(component, component.searchField)
- .setFocusable(true)
- .setRequestFocus(true)
- .setResizable(true)
- .setDimensionServiceKey(null, dimensionKey, true)
- .setTitle(title)
- .setMovable(true)
- .setShowBorder(true)
- .createPopup()
+ override fun createPopup(): JBPopup {
+ val popup = getInitialPopup()
popup.addListener(object : JBPopupListener {
override fun onClosed(event: LightweightWindowEvent) {
@@ -149,13 +124,13 @@ open class Fuzzier : FuzzyAction() {
RECENTLY_SEARCHED_FILES -> InitialViewHandler.getRecentlySearchedFiles(fuzzierSettingsService)
else -> {
- DefaultListModel()
+ DefaultListModel()
}
}
ApplicationManager.getApplication().invokeLater {
component.fileList.model = listModel
- component.fileList.cellRenderer = getCellRenderer()
+ component.fileList.cellRenderer = getCellRenderer(fuzzierSettingsService.state)
component.fileList.setPaintBusy(false)
if (!component.fileList.isEmpty) {
component.fileList.setSelectedValue(listModel[0], true)
@@ -176,7 +151,7 @@ open class Fuzzier : FuzzyAction() {
// Create a reference to the current task to check if it has been cancelled
val task = currentTask
component.fileList.setPaintBusy(true)
- var listModel = DefaultListModel()
+ var listModel = DefaultListModel()
val stringEvaluator = getStringEvaluator()
@@ -192,7 +167,7 @@ open class Fuzzier : FuzzyAction() {
ApplicationManager.getApplication().invokeLater {
component.fileList.model = listModel
- component.fileList.cellRenderer = getCellRenderer()
+ component.fileList.cellRenderer = getCellRenderer(fuzzierSettingsService.state)
component.fileList.setPaintBusy(false)
if (!component.fileList.isEmpty) {
component.fileList.setSelectedValue(listModel[0], true)
@@ -227,7 +202,7 @@ open class Fuzzier : FuzzyAction() {
private fun process(
project: Project, stringEvaluator: StringEvaluator, searchString: String,
- listModel: DefaultListModel, task: Future<*>?
+ listModel: DefaultListModel, task: Future<*>?
) {
val moduleManager = ModuleManager.getInstance(project)
if (fuzzierSettingsService.state.isProject) {
@@ -239,7 +214,7 @@ open class Fuzzier : FuzzyAction() {
private fun processProject(
project: Project, stringEvaluator: StringEvaluator,
- searchString: String, listModel: DefaultListModel, task: Future<*>?
+ searchString: String, listModel: DefaultListModel, task: Future<*>?
) {
val filesToIterate = ConcurrentHashMap.newKeySet()
FuzzierUtil.fileIndexToIterationFile(filesToIterate, ProjectFileIndex.getInstance(project), project.name, task)
@@ -248,7 +223,7 @@ open class Fuzzier : FuzzyAction() {
private fun processModules(
moduleManager: ModuleManager, stringEvaluator: StringEvaluator,
- searchString: String, listModel: DefaultListModel, task: Future<*>?
+ searchString: String, listModel: DefaultListModel, task: Future<*>?
) {
val filesToIterate = ConcurrentHashMap.newKeySet()
for (module in moduleManager.modules) {
@@ -262,7 +237,7 @@ open class Fuzzier : FuzzyAction() {
*/
private fun processFiles(
filesToIterate: ConcurrentHashMap.KeySetView,
- stringEvaluator: StringEvaluator, listModel: DefaultListModel,
+ stringEvaluator: StringEvaluator, listModel: DefaultListModel,
searchString: String, task: Future<*>?
) {
val ss = FuzzierUtil.cleanSearchString(searchString, fuzzierSettingsService.state.ignoredCharacters)
@@ -278,7 +253,7 @@ open class Fuzzier : FuzzyAction() {
}
}
- private fun openFile(project: Project, fuzzyMatchContainer: FuzzyMatchContainer?, virtualFile: VirtualFile) {
+ private fun openFile(project: Project, fuzzyContainer: FuzzyContainer?, virtualFile: VirtualFile) {
val fileEditorManager = FileEditorManager.getInstance(project)
val currentEditor = fileEditorManager.selectedTextEditor
val previousFile = currentEditor?.virtualFile
@@ -295,10 +270,10 @@ open class Fuzzier : FuzzyAction() {
}
}
}
- if (fuzzyMatchContainer != null) {
- InitialViewHandler.addFileToRecentlySearchedFiles(fuzzyMatchContainer, fuzzierSettingsService)
+ if (fuzzyContainer != null) {
+ InitialViewHandler.addFileToRecentlySearchedFiles(fuzzyContainer, fuzzierSettingsService)
}
- popup?.cancel()
+ popup.cancel()
}
private fun createListeners(project: Project) {
diff --git a/src/main/kotlin/com/mituuz/fuzzier/FuzzierVCS.kt b/src/main/kotlin/com/mituuz/fuzzier/FuzzierVCS.kt
index 34df7e03..b408721d 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/FuzzierVCS.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/FuzzierVCS.kt
@@ -30,7 +30,7 @@ import com.intellij.openapi.vcs.changes.ChangeListManager
* Search for only VCS tracked files
*/
class FuzzierVCS : Fuzzier() {
- override var title: String = "Fuzzy Search (Only VCS Tracked Files)"
+ override var popupTitle: String = "Fuzzy Search (Only VCS Tracked Files)"
override fun updateListContents(project: Project, searchString: String) {
changeListManager = ChangeListManager.getInstance(project)
super.updateListContents(project, searchString)
diff --git a/src/main/kotlin/com/mituuz/fuzzier/FuzzyAction.kt b/src/main/kotlin/com/mituuz/fuzzier/FuzzyAction.kt
index c40247db..6ff4cf8b 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/FuzzyAction.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/FuzzyAction.kt
@@ -38,13 +38,17 @@ import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.keymap.KeymapManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopup
+import com.intellij.openapi.ui.popup.JBPopupFactory
+import com.intellij.openapi.util.DimensionService
+import com.intellij.openapi.wm.WindowManager
import com.mituuz.fuzzier.components.FuzzyComponent
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType.FILE_PATH_ONLY
+import com.mituuz.fuzzier.entities.FuzzyContainer
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType
import com.mituuz.fuzzier.settings.FuzzierSettingsService
import com.mituuz.fuzzier.util.FuzzierUtil
+import com.mituuz.fuzzier.util.FuzzierUtil.Companion.createDimensionKey
import java.awt.Component
+import java.awt.Point
import java.awt.event.ActionEvent
import java.util.*
import java.util.Timer
@@ -53,8 +57,10 @@ import javax.swing.*
import kotlin.concurrent.schedule
abstract class FuzzyAction : AnAction() {
+ open lateinit var dimensionKey: String
+ open lateinit var popupTitle: String
lateinit var component: FuzzyComponent
- protected var popup: JBPopup? = null
+ lateinit var popup: JBPopup
private lateinit var originalDownHandler: EditorActionHandler
private lateinit var originalUpHandler: EditorActionHandler
private var debounceTimer: TimerTask? = null
@@ -73,6 +79,41 @@ abstract class FuzzyAction : AnAction() {
abstract fun runAction(project: Project, actionEvent: AnActionEvent)
+ abstract fun createPopup(): JBPopup
+
+ fun getInitialPopup(): JBPopup {
+ return JBPopupFactory
+ .getInstance()
+ .createComponentPopupBuilder(component, component.searchField)
+ .setFocusable(true)
+ .setRequestFocus(true)
+ .setResizable(true)
+ .setDimensionServiceKey(null, dimensionKey, true)
+ .setTitle(popupTitle)
+ .setMovable(true)
+ .setShowBorder(true)
+ .createPopup()
+ }
+
+ fun showPopup(project: Project) {
+ val mainWindow = WindowManager.getInstance().getIdeFrame(project)?.component
+ mainWindow?.let {
+ val screenBounds = it.graphicsConfiguration.bounds
+ val dimensionKey = createDimensionKey(dimensionKey, screenBounds)
+ popup = createPopup()
+
+ if (fuzzierSettingsService.state.resetWindow) {
+ DimensionService.getInstance().setSize(dimensionKey, null, null)
+ DimensionService.getInstance().setLocation(dimensionKey, null, null)
+ fuzzierSettingsService.state.resetWindow = false
+ }
+
+ val centerX = screenBounds.x + screenBounds.width / 2
+ val centerY = screenBounds.y + screenBounds.height / 2
+ popup.showInScreenCoordinates(it, Point(centerX, centerY))
+ }
+ }
+
fun createSharedListeners(project: Project) {
val inputMap = component.searchField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
@@ -166,7 +207,7 @@ abstract class FuzzyAction : AnAction() {
}
}
- fun getCellRenderer(): ListCellRenderer {
+ fun getCellRenderer(state: FuzzierSettingsService.State): ListCellRenderer {
return object : DefaultListCellRenderer() {
override fun getListCellRendererComponent(
list: JList<*>?,
@@ -177,17 +218,16 @@ abstract class FuzzyAction : AnAction() {
): Component {
val renderer =
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) as JLabel
- val container = value as FuzzyMatchContainer
- val filenameType: FilenameType = if (component.isDirSelector) {
- FILE_PATH_ONLY // Directories are always shown as full paths
- } else {
- fuzzierSettingsService.state.filenameType
+ val container = value as FuzzyContainer
+ renderer.text = when (component.isDirSelector) {
+ true -> container.getDirDisplayString()
+ false -> container.getDisplayString(state)
}
- renderer.text = container.toString(filenameType, fuzzierSettingsService.state.highlightFilename)
- fuzzierSettingsService.state.fileListSpacing.let {
+
+ state.fileListSpacing.let {
renderer.border = BorderFactory.createEmptyBorder(it, 0, it, 0)
}
- fuzzierSettingsService.state.fileListFontSize.let {
+ state.fileListFontSize.let {
renderer.font = renderer.font.deriveFont(it.toFloat())
}
return renderer
diff --git a/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt b/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt
index b5e7a4f6..3a727ef4 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/FuzzyMover.kt
@@ -35,7 +35,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.rootManager
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.ui.popup.JBPopup
-import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.util.DimensionService
@@ -45,9 +44,8 @@ import com.intellij.openapi.wm.WindowManager
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiFile
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.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.StringEvaluator
import com.mituuz.fuzzier.util.FuzzierUtil
import com.mituuz.fuzzier.util.FuzzierUtil.Companion.createDimensionKey
@@ -60,54 +58,31 @@ import javax.swing.*
import kotlin.coroutines.cancellation.CancellationException
class FuzzyMover : FuzzyAction() {
- private val moverDimensionKey: String = "FuzzyMoverPopup"
+ override var popupTitle = "Fuzzy File Mover"
+ override var dimensionKey = "FuzzyMoverPopup"
lateinit var movableFile: PsiFile
lateinit var currentFile: VirtualFile
override fun runAction(project: Project, actionEvent: AnActionEvent) {
setCustomHandlers()
+
ApplicationManager.getApplication().invokeLater {
component = SimpleFinderComponent()
createListeners(project)
createSharedListeners(project)
- val mainWindow = WindowManager.getInstance().getIdeFrame(actionEvent.project)?.component
- mainWindow?.let {
- val screenBounds = it.graphicsConfiguration.bounds
- val dimensionKey = createDimensionKey(moverDimensionKey, screenBounds)
- popup = createPopup(dimensionKey)
-
- val currentEditor = FileEditorManager.getInstance(project).selectedTextEditor
- if (currentEditor != null) {
- currentFile = currentEditor.virtualFile
- component.fileList.setEmptyText("Press enter to use current file: ${currentFile.path}")
- }
-
- if (fuzzierSettingsService.state.resetWindow) {
- DimensionService.getInstance().setSize(dimensionKey, null, null)
- DimensionService.getInstance().setLocation(dimensionKey, null, null)
- fuzzierSettingsService.state.resetWindow = false
- }
-
- val centerX = screenBounds.x + screenBounds.width / 2
- val centerY = screenBounds.y + screenBounds.height / 2
- popup!!.showInScreenCoordinates(it, Point(centerX, centerY))
+ val currentEditor = FileEditorManager.getInstance(project).selectedTextEditor
+ if (currentEditor != null) {
+ currentFile = currentEditor.virtualFile
+ component.fileList.setEmptyText("Press enter to use current file: ${currentFile.path}")
}
+
+ showPopup(project)
}
}
- private fun createPopup(dimensionKey: String): JBPopup {
- val popup = JBPopupFactory
- .getInstance()
- .createComponentPopupBuilder(component, component.searchField)
- .setFocusable(true)
- .setRequestFocus(true)
- .setResizable(true)
- .setDimensionServiceKey(null, dimensionKey, true)
- .setTitle("Fuzzy File Mover")
- .setMovable(true)
- .setShowBorder(true)
- .createPopup()
+ override fun createPopup(): JBPopup {
+ val popup = getInitialPopup()
popup.addListener(object : JBPopupListener {
override fun onClosed(event: LightweightWindowEvent) {
@@ -175,7 +150,7 @@ class FuzzyMover : FuzzyAction() {
val originalFilePath = movableFile.virtualFile.path
if (targetDir != null) {
WriteCommandAction.runWriteCommandAction(project) {
- MoveFilesOrDirectoriesUtil.doMoveFile(movableFile, targetDir)
+ movableFile.virtualFile.move(movableFile.manager, targetDir.virtualFile)
}
val notification = Notification(
"Fuzzier Notification Group",
@@ -185,7 +160,7 @@ class FuzzyMover : FuzzyAction() {
)
Notifications.Bus.notify(notification, project)
ApplicationManager.getApplication().invokeLater {
- popup?.cancel()
+ popup.cancel()
}
completableFuture.complete(null)
} else {
@@ -211,7 +186,7 @@ class FuzzyMover : FuzzyAction() {
// Create a reference to the current task to check if it has been cancelled
val task = currentTask
component.fileList.setPaintBusy(true)
- var listModel = DefaultListModel()
+ var listModel = DefaultListModel()
val stringEvaluator = getStringEvaluator()
@@ -227,7 +202,7 @@ class FuzzyMover : FuzzyAction() {
ApplicationManager.getApplication().invokeLater {
component.fileList.model = listModel
- component.fileList.cellRenderer = getCellRenderer()
+ component.fileList.cellRenderer = getCellRenderer(fuzzierSettingsService.state)
component.fileList.setPaintBusy(false)
if (!component.fileList.isEmpty) {
component.fileList.setSelectedValue(listModel[0], true)
@@ -249,7 +224,7 @@ class FuzzyMover : FuzzyAction() {
}
private fun process(project: Project, stringEvaluator: StringEvaluator, searchString: String,
- listModel: DefaultListModel, task: Future<*>?) {
+ listModel: DefaultListModel, task: Future<*>?) {
val moduleManager = ModuleManager.getInstance(project)
val ss = FuzzierUtil.cleanSearchString(searchString, fuzzierSettingsService.state.ignoredCharacters)
if (fuzzierSettingsService.state.isProject) {
@@ -260,7 +235,7 @@ class FuzzyMover : FuzzyAction() {
}
private fun processProject(project: Project, stringEvaluator: StringEvaluator,
- searchString: String, listModel: DefaultListModel, task: Future<*>?) {
+ searchString: String, listModel: DefaultListModel, task: Future<*>?) {
val contentIterator = if (!component.isDirSelector) {
stringEvaluator.getContentIterator(project.name, searchString, listModel, task)
} else {
@@ -270,7 +245,7 @@ class FuzzyMover : FuzzyAction() {
}
private fun processModules(moduleManager: ModuleManager, stringEvaluator: StringEvaluator,
- searchString: String, listModel: DefaultListModel, task: Future<*>?) {
+ searchString: String, listModel: DefaultListModel, task: Future<*>?) {
for (module in moduleManager.modules) {
val moduleFileIndex = module.rootManager.fileIndex
diff --git a/src/main/kotlin/com/mituuz/fuzzier/components/FuzzierSettingsComponent.kt b/src/main/kotlin/com/mituuz/fuzzier/components/FuzzierSettingsComponent.kt
index 6f2a6b74..80d8b9d0 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/components/FuzzierSettingsComponent.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/components/FuzzierSettingsComponent.kt
@@ -34,7 +34,7 @@ import com.intellij.util.ui.FormBuilder
import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.components.JBTextField
import com.mituuz.fuzzier.components.FuzzierSettingsComponent.SettingsComponent
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType
import com.mituuz.fuzzier.settings.FuzzierSettingsService
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode
import java.awt.Component
diff --git a/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyComponent.kt b/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyComponent.kt
index d909192e..32e400ec 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyComponent.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyComponent.kt
@@ -25,11 +25,12 @@ package com.mituuz.fuzzier.components
import com.intellij.ui.EditorTextField
import com.intellij.ui.components.JBList
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import javax.swing.JPanel
open class FuzzyComponent : JPanel() {
- var fileList = JBList()
+ var fileList = JBList()
var searchField = EditorTextField()
var isDirSelector = false
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyFinderComponent.kt b/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyFinderComponent.kt
index b01fbbd9..e880275f 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyFinderComponent.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/components/FuzzyFinderComponent.kt
@@ -30,6 +30,7 @@ import com.intellij.ui.components.JBScrollPane
import com.intellij.uiDesigner.core.GridConstraints
import com.intellij.uiDesigner.core.GridLayoutManager
import com.intellij.util.ui.JBUI
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import java.awt.BorderLayout
import java.awt.Dimension
@@ -116,7 +117,7 @@ class FuzzyFinderComponent(project: Project) : FuzzyComponent() {
false
)
)
- fileList = JBList()
+ fileList = JBList()
fileList.selectionMode = 0
scrollPane1.setViewportView(fileList)
}
diff --git a/src/main/kotlin/com/mituuz/fuzzier/components/TestBenchComponent.kt b/src/main/kotlin/com/mituuz/fuzzier/components/TestBenchComponent.kt
index a4315f26..6ebce87b 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/components/TestBenchComponent.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/components/TestBenchComponent.kt
@@ -38,6 +38,7 @@ import com.intellij.ui.components.JBTextArea
import com.intellij.ui.table.JBTable
import com.intellij.uiDesigner.core.GridConstraints
import com.intellij.uiDesigner.core.GridLayoutManager
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.StringEvaluator
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.settings.FuzzierSettingsService
@@ -143,14 +144,21 @@ class TestBenchComponent : JPanel() {
currentTask = ApplicationManager.getApplication().executeOnPooledThread {
table.setPaintBusy(true)
- val listModel = DefaultListModel()
+ val listModel = DefaultListModel()
process(project, stringEvaluator, searchString, listModel)
- val sortedList = listModel.elements().toList().sortedByDescending { it.getScore() }
- val data = sortedList.map {
- arrayOf(it.filename, it.filePath, it.score.streakScore, it.score.multiMatchScore,
- it.score.partialPathScore, it.score.filenameScore, it.score.getTotalScore())
+ val sortedList = listModel.elements().toList().sortedByDescending { (it as FuzzyMatchContainer).getScore() }
+ val data: Array> = sortedList.map {
+ arrayOf(
+ (it as FuzzyMatchContainer).filename as Any,
+ it.filePath as Any,
+ it.score.streakScore as Any,
+ it.score.multiMatchScore as Any,
+ it.score.partialPathScore as Any,
+ it.score.filenameScore as Any,
+ it.score.getTotalScore() as Any
+ )
}.toTypedArray()
val tableModel = DefaultTableModel(data, columnNames)
@@ -158,9 +166,9 @@ class TestBenchComponent : JPanel() {
table.setPaintBusy(false)
}
}
-
+
private fun process(project: Project, stringEvaluator: StringEvaluator, searchString: String,
- listModel: DefaultListModel) {
+ listModel: DefaultListModel) {
val moduleManager = ModuleManager.getInstance(project)
if (service().state.isProject) {
processProject(project, stringEvaluator, searchString, listModel)
@@ -170,7 +178,7 @@ class TestBenchComponent : JPanel() {
}
private fun processProject(project: Project, stringEvaluator: StringEvaluator,
- searchString: String, listModel: DefaultListModel) {
+ searchString: String, listModel: DefaultListModel) {
val ss = FuzzierUtil.cleanSearchString(searchString, liveSettingsComponent.ignoredCharacters.getJBTextField().text)
val contentIterator = stringEvaluator.getContentIterator(project.name, ss, listModel, null)
@@ -184,7 +192,7 @@ class TestBenchComponent : JPanel() {
}
private fun processModules(moduleManager: ModuleManager, stringEvaluator: StringEvaluator,
- searchString: String, listModel: DefaultListModel) {
+ searchString: String, listModel: DefaultListModel) {
for (module in moduleManager.modules) {
val moduleFileIndex = module.rootManager.fileIndex
val ss = FuzzierUtil.cleanSearchString(searchString, liveSettingsComponent.ignoredCharacters.getJBTextField().text)
diff --git a/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyContainer.kt b/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyContainer.kt
new file mode 100644
index 00000000..ba0beb92
--- /dev/null
+++ b/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyContainer.kt
@@ -0,0 +1,61 @@
+/*
+MIT License
+
+Copyright (c) 2024 Mitja Leino
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+package com.mituuz.fuzzier.entities
+
+import com.mituuz.fuzzier.settings.FuzzierSettingsService
+
+abstract class FuzzyContainer(val filePath: String, val basePath: String, val filename: String) {
+ /**
+ * Get display string for the popup
+ */
+ abstract fun getDisplayString(state: FuzzierSettingsService.State): String
+
+ /**
+ * Get the complete URI for the file
+ */
+ fun getFileUri() : String {
+ return "$basePath$filePath"
+ }
+
+ /**
+ * Directories always return full path
+ */
+ fun getDirDisplayString(): String {
+ return filePath
+ }
+
+ /**
+ * Display string options
+ */
+ enum class FilenameType(val text: String) {
+ FILE_PATH_ONLY("File path only"),
+ FILENAME_ONLY("Filename only"),
+ FILENAME_WITH_PATH("Filename with (path)"),
+ FILENAME_WITH_PATH_STYLED("Filename with (path) styled")
+ }
+
+ override fun toString(): String {
+ return "FuzzyContainer(filePath='$filePath', basePath='$basePath', filename='$filename')"
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt b/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt
index 5c65887e..6f49959b 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainer.kt
@@ -23,7 +23,6 @@ SOFTWARE.
*/
package com.mituuz.fuzzier.entities
-import com.intellij.openapi.components.service
import com.intellij.util.xmlb.Converter
import com.intellij.util.xmlb.XmlSerializationException
import com.mituuz.fuzzier.settings.FuzzierConfiguration.END_STYLE_TAG
@@ -31,6 +30,7 @@ import com.mituuz.fuzzier.settings.FuzzierConfiguration.startStyleTag
import com.mituuz.fuzzier.settings.FuzzierSettingsService
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
+import java.io.InvalidClassException
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.io.Serializable
@@ -39,37 +39,23 @@ import javax.swing.DefaultListModel
class FuzzyMatchContainer(
val score: FuzzyScore,
- var filePath: String,
- var filename: String,
- private var module: String = ""
-) : Serializable {
- @Transient
- private var initialPath: String? = null
-
- companion object {
- fun createOrderedContainer(
- order: Int,
- filePath: String,
- initialPath: String,
- filename: String
- ): FuzzyMatchContainer {
- val fuzzyScore = FuzzyScore()
- fuzzyScore.filenameScore = order
- val fuzzyMatchContainer = FuzzyMatchContainer(fuzzyScore, filePath, filename)
- fuzzyMatchContainer.initialPath = initialPath
- return fuzzyMatchContainer
- }
- }
-
- fun toString(filenameType: FilenameType, highlight: Boolean): String {
- return when (filenameType) {
+ filePath: String,
+ filename: String,
+ moduleBasePath: String
+) : FuzzyContainer(filePath, moduleBasePath, filename) {
+ override fun getDisplayString(state: FuzzierSettingsService.State): String {
+ return when (state.filenameType) {
FilenameType.FILENAME_ONLY -> filename
FilenameType.FILE_PATH_ONLY -> filePath
FilenameType.FILENAME_WITH_PATH -> "$filename ($filePath)"
- FilenameType.FILENAME_WITH_PATH_STYLED -> getFilenameWithPathStyled(highlight)
+ FilenameType.FILENAME_WITH_PATH_STYLED -> getFilenameWithPathStyled(state.highlightFilename)
}
}
+ fun getFilenameWithPathStyled(highlight: Boolean): String {
+ return "${getStyledFilename(highlight)} ($filePath)"
+ }
+
private fun getStyledFilename(highlight: Boolean): String {
if (highlight) {
return highlight(filename)
@@ -92,21 +78,6 @@ class FuzzyMatchContainer(
return stringBuilder.toString()
}
- private fun getFilenameWithPathStyled(highlight: Boolean): String {
- return "${getStyledFilename(highlight)} ($filePath)"
- }
-
- fun getFileUri(): String {
- val basePath = service().state.modules[module]
- if (basePath != null) {
- return "$basePath$filePath"
- }
- if (initialPath != null && initialPath != "") {
- return "$initialPath$filePath"
- }
- return filePath
- }
-
fun getScore(): Int {
return score.getTotalScore()
}
@@ -118,13 +89,6 @@ class FuzzyMatchContainer(
return score.getTotalScore() + filePath.length * -5
}
- enum class FilenameType(val text: String) {
- FILE_PATH_ONLY("File path only"),
- FILENAME_ONLY("Filename only"),
- FILENAME_WITH_PATH("Filename with (path)"),
- FILENAME_WITH_PATH_STYLED("Filename with (path) styled")
- }
-
class FuzzyScore : Serializable {
var streakScore = 0
var multiMatchScore = 0
@@ -141,33 +105,76 @@ class FuzzyMatchContainer(
return "FuzzyMatchContainer: $filename, score: ${getScore()}, dir score: ${getScoreWithDirLength()}"
}
+ /**
+ * Serializable version of FuzzyMatchContainer
+ *
+ * This is required for SerializedMatchContainerConverter to work correctly
+ */
+ class SerializedMatchContainer : Serializable {
+ companion object {
+ fun fromFuzzyMatchContainer(container: FuzzyMatchContainer): SerializedMatchContainer {
+ val serialized = SerializedMatchContainer()
+ serialized.score = container.score
+ serialized.filePath = container.filePath
+ serialized.filename = container.filename
+ serialized.moduleBasePath = container.basePath
+ return serialized
+ }
+
+ fun fromListModel(listModel: DefaultListModel): DefaultListModel {
+ val serializedList = DefaultListModel()
+ for (i in 0 until listModel.size) {
+ serializedList.addElement(fromFuzzyMatchContainer(listModel[i]))
+ }
+ return serializedList
+ }
+
+ fun toListModel(serializedList: DefaultListModel): DefaultListModel {
+ val listModel = DefaultListModel()
+ for (i in 0 until serializedList.size) {
+ listModel.addElement(serializedList[i].toFuzzyMatchContainer())
+ }
+ return listModel
+ }
+ }
+
+ fun toFuzzyMatchContainer(): FuzzyMatchContainer {
+ return FuzzyMatchContainer(score!!, filePath!!, filename!!, moduleBasePath!!)
+ }
+
+ var score: FuzzyScore? = null
+ var filePath: String? = null
+ var filename: String? = null
+ var moduleBasePath: String? = null
+ }
+
/**
* This is necessary to persists recently used files between IDE restarts
*
* Uses a base 64 encoded string
*
* ```
- * @OptionTag(converter = FuzzyMatchContainer.FuzzyMatchContainerConverter::class)
- * var recentlySearchedFiles: DefaultListModel? = DefaultListModel()
+ * @OptionTag(converter = FuzzyMatchContainer.SerializedMatchContainerConverter::class)
+ * var recentlySearchedFiles: DefaultListModel? = DefaultListModel()
* ```
*
* @see FuzzierSettingsService
*/
- class FuzzyMatchContainerConverter : Converter>() {
- override fun fromString(value: String) : DefaultListModel {
+ class SerializedMatchContainerConverter : Converter>() {
+ override fun fromString(value: String) : DefaultListModel {
// Fallback to an empty list if deserialization fails
try {
val data = Base64.getDecoder().decode(value)
val byteArrayInputStream = ByteArrayInputStream(data)
- return ObjectInputStream(byteArrayInputStream).use { it.readObject() as DefaultListModel }
- } catch (_: XmlSerializationException) {
- return DefaultListModel();
- } catch (_: IllegalArgumentException) {
- return DefaultListModel();
+
+ @Suppress("UNCHECKED_CAST")
+ return ObjectInputStream(byteArrayInputStream).use { it.readObject() as DefaultListModel }
+ } catch (_: Exception) {
+ return DefaultListModel();
}
}
- override fun toString(value: DefaultListModel) : String {
+ override fun toString(value: DefaultListModel) : String {
val byteArrayOutputStream = ByteArrayOutputStream()
ObjectOutputStream(byteArrayOutputStream).use { it.writeObject(value) }
return Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray())
diff --git a/src/main/kotlin/com/mituuz/fuzzier/entities/OrderedContainer.kt b/src/main/kotlin/com/mituuz/fuzzier/entities/OrderedContainer.kt
new file mode 100644
index 00000000..76105740
--- /dev/null
+++ b/src/main/kotlin/com/mituuz/fuzzier/entities/OrderedContainer.kt
@@ -0,0 +1,47 @@
+/*
+MIT License
+
+Copyright (c) 2024 Mitja Leino
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+package com.mituuz.fuzzier.entities
+
+import com.mituuz.fuzzier.settings.FuzzierSettingsService
+
+class OrderedContainer(filePath: String, basePath: String, filename: String) :
+ FuzzyContainer(filePath, basePath, filename) {
+
+ override fun getDisplayString(state: FuzzierSettingsService.State): String {
+ return when (state.filenameType) {
+ FilenameType.FILENAME_ONLY -> filename
+ FilenameType.FILE_PATH_ONLY -> filePath
+ FilenameType.FILENAME_WITH_PATH -> "$filename ($filePath)"
+ FilenameType.FILENAME_WITH_PATH_STYLED -> getFilenameWithPathStyled()
+ }
+ }
+
+ fun getFilenameWithPathStyled(): String {
+ return "$filename ($filePath)"
+ }
+
+ override fun toString(): String {
+ return "OrderedContainer(filePath='$filePath', basePath='$basePath', filename='$filename')"
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/mituuz/fuzzier/entities/RowContainer.kt b/src/main/kotlin/com/mituuz/fuzzier/entities/RowContainer.kt
new file mode 100644
index 00000000..a89472bf
--- /dev/null
+++ b/src/main/kotlin/com/mituuz/fuzzier/entities/RowContainer.kt
@@ -0,0 +1,41 @@
+/*
+MIT License
+
+Copyright (c) 2024 Mitja Leino
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+package com.mituuz.fuzzier.entities
+
+import com.mituuz.fuzzier.settings.FuzzierSettingsService
+
+class RowContainer(
+ filePath: String,
+ basePath: String,
+ filename: String,
+ val rowNumber: Int
+) : FuzzyContainer(filePath, basePath, filename) {
+ override fun getDisplayString(state: FuzzierSettingsService.State): String {
+ return "$filename:$rowNumber"
+ }
+
+ override fun toString(): String {
+ return "RowContainer(filePath='$filePath', basePath='$basePath', filename='$filename', rowNumber=$rowNumber)"
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/mituuz/fuzzier/entities/StringEvaluator.kt b/src/main/kotlin/com/mituuz/fuzzier/entities/StringEvaluator.kt
index b107e1c5..db023a83 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/entities/StringEvaluator.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/entities/StringEvaluator.kt
@@ -42,7 +42,7 @@ class StringEvaluator(
) {
lateinit var scoreCalculator: ScoreCalculator
- fun getContentIterator(moduleName: String, searchString: String, listModel: DefaultListModel,
+ fun getContentIterator(moduleName: String, searchString: String, listModel: DefaultListModel,
task: Future<*>?): ContentIterator {
scoreCalculator = ScoreCalculator(searchString)
return ContentIterator { file: VirtualFile ->
@@ -57,7 +57,7 @@ class StringEvaluator(
return@ContentIterator true
}
if (filePath.isNotBlank()) {
- val fuzzyMatchContainer = createFuzzyContainer(filePath, moduleName, scoreCalculator)
+ val fuzzyMatchContainer = createFuzzyContainer(filePath, moduleBasePath, scoreCalculator)
if (fuzzyMatchContainer != null) {
listModel.addElement(fuzzyMatchContainer)
}
@@ -67,7 +67,7 @@ class StringEvaluator(
}
}
- fun getDirIterator(moduleName: String, searchString: String, listModel: DefaultListModel,
+ fun getDirIterator(moduleName: String, searchString: String, listModel: DefaultListModel,
task: Future<*>?): ContentIterator {
scoreCalculator = ScoreCalculator(searchString)
return ContentIterator { file: VirtualFile ->
@@ -81,7 +81,7 @@ class StringEvaluator(
return@ContentIterator true
}
if (filePath.isNotBlank()) {
- val fuzzyMatchContainer = createFuzzyContainer(filePath, moduleName, scoreCalculator)
+ val fuzzyMatchContainer = createFuzzyContainer(filePath, moduleBasePath, scoreCalculator)
if (fuzzyMatchContainer != null) {
listModel.addElement(fuzzyMatchContainer)
}
@@ -91,7 +91,7 @@ class StringEvaluator(
}
}
- fun evaluateFile(iterationFile: FuzzierUtil.IterationFile, listModel: DefaultListModel,
+ fun evaluateFile(iterationFile: FuzzierUtil.IterationFile, listModel: DefaultListModel,
searchString: String) {
val scoreCalculator = ScoreCalculator(searchString)
val file = iterationFile.file
@@ -104,7 +104,7 @@ class StringEvaluator(
return
}
if (filePath.isNotBlank()) {
- val fuzzyMatchContainer = createFuzzyContainer(filePath, moduleName, scoreCalculator)
+ val fuzzyMatchContainer = createFuzzyContainer(filePath, moduleBasePath, scoreCalculator)
if (fuzzyMatchContainer != null) {
listModel.addElement(fuzzyMatchContainer)
}
@@ -153,15 +153,12 @@ class StringEvaluator(
* @param filePath to evaluate
* @return null if no match can be found
*/
- private fun createFuzzyContainer(filePath: String, module: String,
+ private fun createFuzzyContainer(filePath: String, moduleBasePath: String,
scoreCalculator: ScoreCalculator): FuzzyMatchContainer? {
val filename = filePath.substring(filePath.lastIndexOf("/") + 1)
return when (val score = scoreCalculator.calculateScore(filePath)) {
- null -> {
- null
- }
-
- else -> FuzzyMatchContainer(score, filePath, filename, module)
+ null -> null
+ else -> FuzzyMatchContainer(score, filePath, filename, moduleBasePath)
}
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurable.kt b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurable.kt
index 87b400cc..9de6b513 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurable.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurable.kt
@@ -26,7 +26,7 @@ package com.mituuz.fuzzier.settings
import com.intellij.openapi.components.service
import com.intellij.openapi.options.Configurable
import com.mituuz.fuzzier.components.FuzzierSettingsComponent
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode
import javax.swing.JComponent
diff --git a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt
index d28e0b2d..070b5ecf 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsService.kt
@@ -28,8 +28,8 @@ import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.annotations.OptionTag
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType.FILE_PATH_ONLY
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType.FILE_PATH_ONLY
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.RECENT_PROJECT_FILES
import javax.swing.DefaultListModel
@@ -42,8 +42,8 @@ class FuzzierSettingsService : PersistentStateComponent = HashMap()
var isProject = false
var recentFilesMode: RecentFilesMode = RECENT_PROJECT_FILES
- @OptionTag(converter = FuzzyMatchContainer.FuzzyMatchContainerConverter::class)
- var recentlySearchedFiles: DefaultListModel? = DefaultListModel()
+ @OptionTag(converter = FuzzyMatchContainer.SerializedMatchContainerConverter::class)
+ var recentlySearchedFiles: DefaultListModel? = DefaultListModel()
var splitPosition: Int = 300
var exclusionSet: Set = setOf("/.idea/*", "/.git/*", "/target/*", "/build/*", "/.gradle/*", "/.run/*")
@@ -66,6 +66,11 @@ class FuzzierSettingsService : PersistentStateComponent {
+ val list = recentlySearchedFiles ?: DefaultListModel()
+ return FuzzyMatchContainer.SerializedMatchContainer.toListModel(list)
+ }
}
private var state = State()
diff --git a/src/main/kotlin/com/mituuz/fuzzier/util/FuzzierUtil.kt b/src/main/kotlin/com/mituuz/fuzzier/util/FuzzierUtil.kt
index 3b5e0557..3f428f27 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/util/FuzzierUtil.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/util/FuzzierUtil.kt
@@ -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 com.mituuz.fuzzier.entities.FuzzyContainer
import java.awt.Rectangle
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Future
@@ -93,26 +94,28 @@ class FuzzierUtil {
* @return a sorted and sized list model
*/
fun sortAndLimit(
- listModel: DefaultListModel,
+ listModel: DefaultListModel,
isDirSort: Boolean = false
- ): DefaultListModel {
+ ): DefaultListModel {
val useShortDirPath = isDirSort && prioritizeShorterDirPaths
var comparator = getComparator(useShortDirPath, false)
val priorityQueue = PriorityQueue(listLimit + 1, comparator)
var minimumScore: Int? = null
listModel.elements().toList().forEach {
- if (minimumScore == null || it.getScore() > minimumScore!!) {
- priorityQueue.add(it)
- if (priorityQueue.size > listLimit) {
- priorityQueue.remove()
- minimumScore = priorityQueue.peek().getScore()
+ if (it is FuzzyMatchContainer) {
+ if (minimumScore == null || it.getScore() > minimumScore) {
+ priorityQueue.add(it)
+ if (priorityQueue.size > listLimit) {
+ priorityQueue.remove()
+ minimumScore = priorityQueue.peek().getScore()
+ }
}
}
}
comparator = getComparator(useShortDirPath, true)
- val result = DefaultListModel()
+ val result = DefaultListModel()
result.addAll(priorityQueue.toList().sortedWith(comparator))
return result
diff --git a/src/main/kotlin/com/mituuz/fuzzier/util/InitialViewHandler.kt b/src/main/kotlin/com/mituuz/fuzzier/util/InitialViewHandler.kt
index 00bf6d75..e529131f 100644
--- a/src/main/kotlin/com/mituuz/fuzzier/util/InitialViewHandler.kt
+++ b/src/main/kotlin/com/mituuz/fuzzier/util/InitialViewHandler.kt
@@ -24,7 +24,9 @@ SOFTWARE.
package com.mituuz.fuzzier.util
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
+import com.mituuz.fuzzier.entities.OrderedContainer
import com.mituuz.fuzzier.settings.FuzzierSettingsService
import javax.swing.DefaultListModel
@@ -33,9 +35,9 @@ class InitialViewHandler {
fun getRecentProjectFiles(
fuzzierSettingsService: FuzzierSettingsService, fuzzierUtil: FuzzierUtil,
editorHistoryManager: EditorHistoryManager
- ): DefaultListModel {
+ ): DefaultListModel {
val editorHistory = editorHistoryManager.fileList
- val listModel = DefaultListModel()
+ val listModel = DefaultListModel()
val limit = fuzzierSettingsService.state.fileListLimit
// Start from the end of editor history (most recent file)
@@ -48,23 +50,18 @@ class InitialViewHandler {
i--
continue
}
- val fuzzyMatchContainer = FuzzyMatchContainer.createOrderedContainer(
- i, filePathAndModule.first, filePathAndModule.second, file.name
+ val orderedContainer = OrderedContainer(
+ filePathAndModule.first, filePathAndModule.second, file.name
)
- listModel.addElement(fuzzyMatchContainer)
+ listModel.addElement(orderedContainer)
i--
}
return listModel
}
- fun getRecentlySearchedFiles(fuzzierSettingsService: FuzzierSettingsService): DefaultListModel {
- var listModel = fuzzierSettingsService.state.recentlySearchedFiles
-
- if (listModel == null) {
- listModel = DefaultListModel()
- fuzzierSettingsService.state.recentlySearchedFiles = listModel
- }
+ fun getRecentlySearchedFiles(fuzzierSettingsService: FuzzierSettingsService): DefaultListModel {
+ var listModel = fuzzierSettingsService.state.getRecentlySearchedFilesAsFuzzyMatchContainer()
var i = 0
while (i < listModel.size) {
@@ -76,7 +73,7 @@ class InitialViewHandler {
}
// Reverse the list to show the most recent searches first
- var result = DefaultListModel()
+ var result = DefaultListModel()
var j = 0
while (j < listModel.size) {
@@ -88,17 +85,12 @@ class InitialViewHandler {
return result
}
- fun addFileToRecentlySearchedFiles(fuzzyMatchContainer: FuzzyMatchContainer, fuzzierSettingsService: FuzzierSettingsService) {
- var listModel: DefaultListModel? = fuzzierSettingsService.state.recentlySearchedFiles
-
- if (listModel == null) {
- listModel = DefaultListModel()
- fuzzierSettingsService.state.recentlySearchedFiles = listModel
- }
+ fun addFileToRecentlySearchedFiles(fuzzyContainer: FuzzyContainer, fuzzierSettingsService: FuzzierSettingsService) {
+ var listModel: DefaultListModel = fuzzierSettingsService.state.getRecentlySearchedFilesAsFuzzyMatchContainer()
var i = 0
while (i < listModel.size) {
- if (listModel[i].filePath == fuzzyMatchContainer.filePath) {
+ if (listModel[i].filePath == fuzzyContainer.filePath) {
listModel.remove(i)
} else {
i++
@@ -109,7 +101,10 @@ class InitialViewHandler {
listModel.remove(listModel.size - 1)
}
- listModel.addElement(fuzzyMatchContainer)
+ if (fuzzyContainer is FuzzyMatchContainer) {
+ listModel.addElement(fuzzyContainer)
+ fuzzierSettingsService.state.recentlySearchedFiles = FuzzyMatchContainer.SerializedMatchContainer.fromListModel(listModel)
+ }
}
}
}
\ No newline at end of file
diff --git a/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt b/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
index db3292ca..71b2ec76 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/FuzzyActionTest.kt
@@ -25,14 +25,17 @@ package com.mituuz.fuzzier
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.IdeActions
+import com.intellij.openapi.components.service
import com.intellij.openapi.editor.actionSystem.EditorActionManager
import com.intellij.openapi.project.Project
+import com.intellij.openapi.ui.popup.JBPopup
import com.intellij.testFramework.TestApplicationManager
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.mituuz.fuzzier.components.SimpleFinderComponent
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType.*
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FuzzyScore
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType.*
+import com.mituuz.fuzzier.settings.FuzzierSettingsService
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import java.awt.event.InputEvent
@@ -88,8 +91,8 @@ class FuzzyActionTest {
val action = getAction()
action.setFiletype(FILENAME_ONLY)
action.component = SimpleFinderComponent()
- val renderer = action.getCellRenderer()
- val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd")
+ val renderer = action.getCellRenderer(service().state)
+ val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd", "")
val dummyList = JList()
val component = renderer.getListCellRendererComponent(dummyList, container, 0, false, false) as JLabel
assertNotNull(component)
@@ -101,8 +104,8 @@ class FuzzyActionTest {
val action = getAction()
action.setFiletype(FILENAME_WITH_PATH)
action.component = SimpleFinderComponent()
- val renderer = action.getCellRenderer()
- val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd")
+ val renderer = action.getCellRenderer(service().state)
+ val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd", "")
val dummyList = JList()
val component = renderer.getListCellRendererComponent(dummyList, container, 0, false, false) as JLabel
assertNotNull(component)
@@ -115,8 +118,8 @@ class FuzzyActionTest {
action.setFiletype(FILENAME_WITH_PATH_STYLED)
action.setHighlight(false)
action.component = SimpleFinderComponent()
- val renderer = action.getCellRenderer()
- val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd")
+ val renderer = action.getCellRenderer(service().state)
+ val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd", "")
val dummyList = JList()
val component = renderer.getListCellRendererComponent(dummyList, container, 0, false, false) as JLabel
assertNotNull(component)
@@ -129,8 +132,8 @@ class FuzzyActionTest {
action.setFiletype(FILENAME_WITH_PATH_STYLED)
action.setHighlight(true)
action.component = SimpleFinderComponent()
- val renderer = action.getCellRenderer()
- val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd")
+ val renderer = action.getCellRenderer(service().state)
+ val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd", "")
val dummyList = JList()
val component = renderer.getListCellRendererComponent(dummyList, container, 0, false, false) as JLabel
assertNotNull(component)
@@ -142,8 +145,8 @@ class FuzzyActionTest {
val action = getAction()
action.setFiletype(FILE_PATH_ONLY)
action.component = SimpleFinderComponent()
- val renderer = action.getCellRenderer()
- val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd")
+ val renderer = action.getCellRenderer(service().state)
+ val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd", "")
val dummyList = JList()
val component = renderer.getListCellRendererComponent(dummyList, container, 0, false, false) as JLabel
assertNotNull(component)
@@ -156,8 +159,8 @@ class FuzzyActionTest {
action.setFiletype(FILENAME_ONLY)
action.component = SimpleFinderComponent()
action.component.isDirSelector = true
- val renderer = action.getCellRenderer()
- val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd")
+ val renderer = action.getCellRenderer(service().state)
+ val container = FuzzyMatchContainer(FuzzyScore(), "/src/asd", "asd", "")
val dummyList = JList()
val component = renderer.getListCellRendererComponent(dummyList, container, 0, false, false) as JLabel
assertNotNull(component)
@@ -172,6 +175,10 @@ class FuzzyActionTest {
override fun runAction(project: Project, actionEvent: AnActionEvent) {
}
+ override fun createPopup(): JBPopup {
+ TODO("Not yet implemented")
+ }
+
override fun updateListContents(project: Project, searchString: String) {
}
}
diff --git a/src/test/kotlin/com/mituuz/fuzzier/FuzzyMoverTest.kt b/src/test/kotlin/com/mituuz/fuzzier/FuzzyMoverTest.kt
index 85fd8b94..21328557 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/FuzzyMoverTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/FuzzyMoverTest.kt
@@ -33,6 +33,7 @@ import com.intellij.testFramework.LightVirtualFile
import com.intellij.testFramework.TestApplicationManager
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.mituuz.fuzzier.components.SimpleFinderComponent
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.*
@@ -169,10 +170,10 @@ class FuzzyMoverTest {
myFixture.tearDown()
}
- private fun getListModel(virtualFile: VirtualFile?): ListModel {
- val listModel = DefaultListModel()
+ private fun getListModel(virtualFile: VirtualFile?): ListModel {
+ val listModel = DefaultListModel()
if (virtualFile != null) {
- val container = FuzzyMatchContainer(FuzzyMatchContainer.FuzzyScore(), virtualFile.path, virtualFile.name)
+ val container = FuzzyMatchContainer(FuzzyMatchContainer.FuzzyScore(), virtualFile.path, virtualFile.name, "")
listModel.addElement(container)
}
return listModel
diff --git a/src/test/kotlin/com/mituuz/fuzzier/TestUtil.kt b/src/test/kotlin/com/mituuz/fuzzier/TestUtil.kt
index b6046a17..938da351 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/TestUtil.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/TestUtil.kt
@@ -37,6 +37,7 @@ import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.testFramework.runInEdtAndWait
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.entities.StringEvaluator
import org.mockito.ArgumentMatchers.any
@@ -62,8 +63,8 @@ class TestUtil {
DumbService.getInstance(fixture.project).waitForSmartMode()
}
- fun setUpModuleFileIndex(filesToAdd: List, exclusionList: Set, ignoredFiles: List? = null) : DefaultListModel {
- val filePathContainer = DefaultListModel()
+ fun setUpModuleFileIndex(filesToAdd: List, exclusionList: Set, ignoredFiles: List? = null) : DefaultListModel {
+ val filePathContainer = DefaultListModel()
val factory = IdeaTestFixtureFactory.getFixtureFactory()
val fixtureBuilder = factory.createLightFixtureBuilder(null, "Test")
val fixture = fixtureBuilder.fixture
diff --git a/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt b/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt
index c4b22239..3da915ed 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/entities/FuzzyMatchContainerTest.kt
@@ -44,7 +44,7 @@ class FuzzyMatchContainerTest {
val score = FuzzyScore()
score.highlightCharacters.add(0)
score.highlightCharacters.add(4)
- val container = FuzzyMatchContainer(score, "", "Hello")
+ val container = FuzzyMatchContainer(score, "", "Hello", "")
val res = container.highlight(container.filename)
assertEquals("${startStyleTag}H${END_STYLE_TAG}ell${startStyleTag}o$END_STYLE_TAG", res)
}
@@ -60,7 +60,7 @@ class FuzzyMatchContainerTest {
score.highlightCharacters.add(17) // e
score.highlightCharacters.add(18) // r
- val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt")
+ val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt", "")
val res = container.highlight(container.filename)
val sb = StringBuilder()
@@ -84,27 +84,29 @@ class FuzzyMatchContainerTest {
@Test
fun `Test serialization`() {
val score = FuzzyScore()
- val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt")
+ val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt", "")
+ val serializableContainer = FuzzyMatchContainer.SerializedMatchContainer.fromFuzzyMatchContainer(container)
val byteArrayOutputStream = ByteArrayOutputStream()
- ObjectOutputStream(byteArrayOutputStream).use { it.writeObject(container) }
+ ObjectOutputStream(byteArrayOutputStream).use { it.writeObject(serializableContainer) }
val byteArrayInputStream = ByteArrayInputStream(byteArrayOutputStream.toByteArray())
- val deserialized = ObjectInputStream(byteArrayInputStream).use { it.readObject() as FuzzyMatchContainer }
- assertEquals("", deserialized.filePath)
- assertEquals("FuzzyMatchContainerTest.kt", deserialized.filename)
+ val deserialized = ObjectInputStream(byteArrayInputStream).use { it.readObject() as FuzzyMatchContainer.SerializedMatchContainer }
+ val fmc = deserialized.toFuzzyMatchContainer()
+ assertEquals("", fmc.filePath)
+ assertEquals("FuzzyMatchContainerTest.kt", fmc.filename)
}
@Test
fun `Test default list serialization`() {
val list = DefaultListModel()
val score = FuzzyScore()
- val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt")
+ val container = FuzzyMatchContainer(score, "", "FuzzyMatchContainerTest.kt", "")
list.addElement(container)
- val converter = FuzzyMatchContainer.FuzzyMatchContainerConverter()
- val stringRep = converter.toString(list)
+ val converter = FuzzyMatchContainer.SerializedMatchContainerConverter()
+ val stringRep = converter.toString(FuzzyMatchContainer.SerializedMatchContainer.fromListModel(list))
- val deserialized: DefaultListModel = converter.fromString(stringRep)
+ val deserialized: DefaultListModel = converter.fromString(stringRep)
assertEquals(1, deserialized.size)
assertEquals("", deserialized.get(0).filePath)
assertEquals("FuzzyMatchContainerTest.kt", deserialized.get(0).filename)
@@ -112,8 +114,8 @@ class FuzzyMatchContainerTest {
@Test
fun `Deserialization fails`() {
- val converter = FuzzyMatchContainer.FuzzyMatchContainerConverter()
- val deserialized: DefaultListModel = converter.fromString("This should not work")
+ val converter = FuzzyMatchContainer.SerializedMatchContainerConverter()
+ val deserialized: DefaultListModel = converter.fromString("This should not work")
assertEquals(0, deserialized.size)
}
}
\ No newline at end of file
diff --git a/src/test/kotlin/com/mituuz/fuzzier/entities/OrderedContainerTest.kt b/src/test/kotlin/com/mituuz/fuzzier/entities/OrderedContainerTest.kt
new file mode 100644
index 00000000..85ec7dda
--- /dev/null
+++ b/src/test/kotlin/com/mituuz/fuzzier/entities/OrderedContainerTest.kt
@@ -0,0 +1,26 @@
+package com.mituuz.fuzzier.entities
+
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType
+import com.mituuz.fuzzier.settings.FuzzierSettingsService
+import org.junit.jupiter.api.Assertions.*
+import org.junit.jupiter.api.Test
+
+class OrderedContainerTest {
+ @Test
+ fun testGetDisplayString() {
+ val orderedContainer = OrderedContainer("filePath", "basePath", "filename")
+ val state = FuzzierSettingsService.State()
+
+ state.filenameType = FilenameType.FILENAME_ONLY
+ assertEquals("filename", orderedContainer.getDisplayString(state))
+
+ state.filenameType = FilenameType.FILE_PATH_ONLY
+ assertEquals("filePath", orderedContainer.getDisplayString(state))
+
+ state.filenameType = FilenameType.FILENAME_WITH_PATH
+ assertEquals("filename (filePath)", orderedContainer.getDisplayString(state))
+
+ state.filenameType = FilenameType.FILENAME_WITH_PATH_STYLED
+ assertEquals("filename (filePath)", orderedContainer.getDisplayString(state))
+ }
+}
\ No newline at end of file
diff --git a/src/test/kotlin/com/mituuz/fuzzier/entities/RowContainerTest.kt b/src/test/kotlin/com/mituuz/fuzzier/entities/RowContainerTest.kt
new file mode 100644
index 00000000..c07bafaf
--- /dev/null
+++ b/src/test/kotlin/com/mituuz/fuzzier/entities/RowContainerTest.kt
@@ -0,0 +1,15 @@
+package com.mituuz.fuzzier.entities
+
+import com.mituuz.fuzzier.settings.FuzzierSettingsService
+import org.junit.jupiter.api.Assertions.*
+import org.junit.jupiter.api.Test
+
+class RowContainerTest {
+ @Test
+ fun displayString() {
+ val state = FuzzierSettingsService.State()
+ val container = RowContainer("", "", "filename", 0)
+
+ assertEquals("filename:0", container.getDisplayString(state))
+ }
+}
\ No newline at end of file
diff --git a/src/test/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurableTest.kt b/src/test/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurableTest.kt
index 467347cd..f620005d 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurableTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/settings/FuzzierSettingsConfigurableTest.kt
@@ -25,8 +25,8 @@ package com.mituuz.fuzzier.settings
import com.intellij.openapi.components.service
import com.intellij.testFramework.TestApplicationManager
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer
-import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FilenameType.FILENAME_WITH_PATH_STYLED
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType.FILENAME_WITH_PATH_STYLED
+import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType.FILENAME_ONLY
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.NONE
import com.mituuz.fuzzier.settings.FuzzierSettingsService.RecentFilesMode.RECENT_PROJECT_FILES
import org.junit.jupiter.api.Assertions.*
@@ -122,7 +122,7 @@ class FuzzierSettingsConfigurableTest {
@Test
fun filenameType() {
pre()
- state.filenameType = FuzzyMatchContainer.FilenameType.FILENAME_ONLY
+ state.filenameType = FILENAME_ONLY
assertTrue(settingsConfigurable.isModified())
}
diff --git a/src/test/kotlin/com/mituuz/fuzzier/util/FuzzierUtilTest.kt b/src/test/kotlin/com/mituuz/fuzzier/util/FuzzierUtilTest.kt
index cd865904..de6a0469 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/util/FuzzierUtilTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/util/FuzzierUtilTest.kt
@@ -26,6 +26,7 @@ package com.mituuz.fuzzier.util
import com.intellij.openapi.components.service
import com.intellij.testFramework.TestApplicationManager
import com.mituuz.fuzzier.TestUtil
+import com.mituuz.fuzzier.entities.FuzzyContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer
import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FuzzyScore
import com.mituuz.fuzzier.settings.FuzzierSettingsService
@@ -38,8 +39,8 @@ class FuzzierUtilTest {
@Suppress("unused")
private val testApplicationManager = TestApplicationManager.getInstance()
private val fuzzierUtil = FuzzierUtil()
- private val listModel = DefaultListModel()
- private lateinit var result: DefaultListModel
+ private val listModel = DefaultListModel()
+ private lateinit var result: DefaultListModel
private val testUtil = TestUtil()
@BeforeEach
diff --git a/src/test/kotlin/com/mituuz/fuzzier/util/InitialViewHandlerTest.kt b/src/test/kotlin/com/mituuz/fuzzier/util/InitialViewHandlerTest.kt
index 962365a7..0480e1cd 100644
--- a/src/test/kotlin/com/mituuz/fuzzier/util/InitialViewHandlerTest.kt
+++ b/src/test/kotlin/com/mituuz/fuzzier/util/InitialViewHandlerTest.kt
@@ -113,13 +113,6 @@ class InitialViewHandlerTest {
assertEquals(0, result.size())
}
- @Test
- fun `Recently searched files - Null returns an empty list`() {
- `when`(fuzzierSettingsService.state.recentlySearchedFiles).thenReturn(null)
- val result = InitialViewHandler.getRecentlySearchedFiles(fuzzierSettingsService)
- assertEquals(0, result.size())
- }
-
@Test
fun `Recently searched files - Order of multiple files`() {
val fuzzyMatchContainer1 = mock(FuzzyMatchContainer::class.java)
@@ -127,7 +120,7 @@ class InitialViewHandlerTest {
val listModel = DefaultListModel()
listModel.addElement(fuzzyMatchContainer1)
listModel.addElement(fuzzyMatchContainer2)
- `when`(fuzzierSettingsService.state.recentlySearchedFiles).thenReturn(listModel)
+ `when`(fuzzierSettingsService.state.getRecentlySearchedFilesAsFuzzyMatchContainer()).thenReturn(listModel)
val result = InitialViewHandler.getRecentlySearchedFiles(fuzzierSettingsService)
@@ -142,7 +135,7 @@ class InitialViewHandlerTest {
listModel.addElement(fuzzyMatchContainer)
listModel.addElement(null)
listModel.addElement(null)
- `when`(fuzzierSettingsService.state.recentlySearchedFiles).thenReturn(listModel)
+ `when`(fuzzierSettingsService.state.getRecentlySearchedFilesAsFuzzyMatchContainer()).thenReturn(listModel)
val result = InitialViewHandler.getRecentlySearchedFiles(fuzzierSettingsService)
@@ -153,12 +146,12 @@ class InitialViewHandlerTest {
fun `Add file to recently used files - Null list should default to empty`() {
val fuzzierSettingsServiceInstance: FuzzierSettingsService = service()
val score = FuzzyMatchContainer.FuzzyScore()
- val container = FuzzyMatchContainer(score, "", "")
+ val container = FuzzyMatchContainer(score, "", "", "")
fuzzierSettingsServiceInstance.state.recentlySearchedFiles = null
InitialViewHandler.addFileToRecentlySearchedFiles(container, fuzzierSettingsServiceInstance)
- assertNotNull(fuzzierSettingsServiceInstance.state.recentlySearchedFiles)
- assertEquals(1, fuzzierSettingsServiceInstance.state.recentlySearchedFiles!!.size)
+ assertNotNull(fuzzierSettingsServiceInstance.state.getRecentlySearchedFilesAsFuzzyMatchContainer())
+ assertEquals(1, fuzzierSettingsServiceInstance.state.getRecentlySearchedFilesAsFuzzyMatchContainer().size)
}
@Test
@@ -166,18 +159,18 @@ class InitialViewHandlerTest {
val fuzzierSettingsServiceInstance: FuzzierSettingsService = service()
val fileListLimit = 2
val score = FuzzyMatchContainer.FuzzyScore()
- val container = FuzzyMatchContainer(score, "", "")
+ val container = FuzzyMatchContainer(score, "", "", "")
val largeList: DefaultListModel = DefaultListModel()
for (i in 0..25) {
- largeList.addElement(FuzzyMatchContainer(score, "" + i, "" + i))
+ largeList.addElement(FuzzyMatchContainer(score, "" + i, "" + i, ""))
}
fuzzierSettingsServiceInstance.state.fileListLimit = fileListLimit
- fuzzierSettingsServiceInstance.state.recentlySearchedFiles = largeList
+ fuzzierSettingsServiceInstance.state.recentlySearchedFiles = FuzzyMatchContainer.SerializedMatchContainer.fromListModel(largeList)
InitialViewHandler.addFileToRecentlySearchedFiles(container, fuzzierSettingsServiceInstance)
- assertEquals(fileListLimit, fuzzierSettingsServiceInstance.state.recentlySearchedFiles!!.size)
+ assertEquals(fileListLimit, fuzzierSettingsServiceInstance.state.getRecentlySearchedFilesAsFuzzyMatchContainer().size)
}
@Test
@@ -185,17 +178,17 @@ class InitialViewHandlerTest {
val fuzzierSettingsServiceInstance: FuzzierSettingsService = service()
val fileListLimit = 20
val score = FuzzyMatchContainer.FuzzyScore()
- val container = FuzzyMatchContainer(score, "", "")
+ val container = FuzzyMatchContainer(score, "", "", "")
val largeList: DefaultListModel = DefaultListModel()
repeat (26) {
- largeList.addElement(FuzzyMatchContainer(score, "", ""))
+ largeList.addElement(FuzzyMatchContainer(score, "", "", ""))
}
fuzzierSettingsServiceInstance.state.fileListLimit = fileListLimit
- fuzzierSettingsServiceInstance.state.recentlySearchedFiles = largeList
+ fuzzierSettingsServiceInstance.state.recentlySearchedFiles = FuzzyMatchContainer.SerializedMatchContainer.fromListModel(largeList)
InitialViewHandler.addFileToRecentlySearchedFiles(container, fuzzierSettingsServiceInstance)
- assertEquals(1, fuzzierSettingsServiceInstance.state.recentlySearchedFiles!!.size)
+ assertEquals(1, fuzzierSettingsServiceInstance.state.getRecentlySearchedFilesAsFuzzyMatchContainer().size)
}
}
\ No newline at end of file