Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions assets/ContainerComparison.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" version="26.0.2">
<diagram name="Page-1" id="BjPpnATlAqmnPM9V4Ykc">
<mxGraphModel dx="1185" dy="658" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="800" pageHeight="800" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="WUuY3x_TO1SyaEHNx0RS-2" value="&lt;h1 style=&quot;margin-top: 0px;&quot;&gt;FuzzyMatchContainer&lt;/h1&gt;Used to collect, score and display possible options in the popup." style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1">
<mxGeometry x="250" y="20" width="300" height="90" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-3" value="File Based" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="40.5" y="160" width="239.5" height="150" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-4" value="FuzzyScore" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-3" vertex="1">
<mxGeometry y="30" width="239.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-5" value="FilePath (action and display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-3" vertex="1">
<mxGeometry y="60" width="239.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-6" value="Filename (scoring and display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-3" vertex="1">
<mxGeometry y="90" width="239.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-11" value="Module (action and display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-3" vertex="1">
<mxGeometry y="120" width="239.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-7" value="Row Based" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="522.5" y="160" width="237.5" height="150" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-13" value="RowNumber (action and display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-7" vertex="1">
<mxGeometry y="30" width="237.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-9" value="FilePath (action and display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-7" vertex="1">
<mxGeometry y="60" width="237.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-10" value="Filename (display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-7" vertex="1">
<mxGeometry y="90" width="237.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-12" value="Module (action and display)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-7" vertex="1">
<mxGeometry y="120" width="237.5" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-14" value="&lt;b&gt;Action&lt;/b&gt;&lt;br&gt;Go to file" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="29" y="340" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-15" value="&lt;b&gt;Action&lt;/b&gt;&lt;br&gt;1. Go to file&lt;br&gt;2. Scroll to row" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="511.25" y="340" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-16" value="Scoring&lt;br&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Find the best file&lt;br&gt;&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="100.75" y="420" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-18" value="&lt;b&gt;Preview&lt;/b&gt;&lt;br&gt;1. Load file&lt;br&gt;2. Scroll to class" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="171.5" y="340" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-19" value="&lt;b&gt;Preview&lt;/b&gt;&lt;br&gt;1. Load file&lt;br&gt;2. Scroll to row" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="651.25" y="340" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-20" value="Filtering&lt;br&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Find all files&lt;br&gt;&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="578.75" y="420" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-21" value="Common" style="swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="160" width="140" height="120" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-22" value="FilePath" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-21" vertex="1">
<mxGeometry y="30" width="140" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-23" value="Filename" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-21" vertex="1">
<mxGeometry y="60" width="140" height="30" as="geometry" />
</mxCell>
<mxCell id="WUuY3x_TO1SyaEHNx0RS-24" value="Module" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" parent="WUuY3x_TO1SyaEHNx0RS-21" vertex="1">
<mxGeometry y="90" width="140" height="30" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-1" value="&lt;b&gt;getDisplayString&lt;/b&gt;&lt;br&gt;Display" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="260" y="600" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-2" value="&lt;b&gt;getFileUri&lt;/b&gt;&lt;br&gt;Action&lt;br&gt;Preview" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="420" y="600" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-3" value="&lt;b&gt;getScore&lt;/b&gt;&lt;br&gt;Scoring" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="100.25" y="600" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-5" value="Methods" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=24;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="300" y="540" width="200" height="30" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-15" value="&lt;div&gt;&lt;b&gt;getRow&lt;/b&gt;&lt;/div&gt;Action&lt;br&gt;Preview" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="578.75" y="600" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-16" value="Using base path instead of module would simplify the handling" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;" vertex="1" parent="1">
<mxGeometry x="330" y="300" width="140" height="60" as="geometry" />
</mxCell>
<mxCell id="nkHttpiEGHfKr55FSMCi-17" value="Separate ordered containers" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;" vertex="1" parent="1">
<mxGeometry x="20" y="110" width="120" height="60" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
67 changes: 21 additions & 46 deletions src/main/kotlin/com/mituuz/fuzzier/Fuzzier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -67,59 +66,35 @@ 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)
}
}
}

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) {
Expand Down Expand Up @@ -149,13 +124,13 @@ open class Fuzzier : FuzzyAction() {

RECENTLY_SEARCHED_FILES -> InitialViewHandler.getRecentlySearchedFiles(fuzzierSettingsService)
else -> {
DefaultListModel<FuzzyMatchContainer>()
DefaultListModel<FuzzyContainer>()
}
}

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)
Expand All @@ -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<FuzzyMatchContainer>()
var listModel = DefaultListModel<FuzzyContainer>()

val stringEvaluator = getStringEvaluator()

Expand All @@ -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)
Expand Down Expand Up @@ -227,7 +202,7 @@ open class Fuzzier : FuzzyAction() {

private fun process(
project: Project, stringEvaluator: StringEvaluator, searchString: String,
listModel: DefaultListModel<FuzzyMatchContainer>, task: Future<*>?
listModel: DefaultListModel<FuzzyContainer>, task: Future<*>?
) {
val moduleManager = ModuleManager.getInstance(project)
if (fuzzierSettingsService.state.isProject) {
Expand All @@ -239,7 +214,7 @@ open class Fuzzier : FuzzyAction() {

private fun processProject(
project: Project, stringEvaluator: StringEvaluator,
searchString: String, listModel: DefaultListModel<FuzzyMatchContainer>, task: Future<*>?
searchString: String, listModel: DefaultListModel<FuzzyContainer>, task: Future<*>?
) {
val filesToIterate = ConcurrentHashMap.newKeySet<FuzzierUtil.IterationFile>()
FuzzierUtil.fileIndexToIterationFile(filesToIterate, ProjectFileIndex.getInstance(project), project.name, task)
Expand All @@ -248,7 +223,7 @@ open class Fuzzier : FuzzyAction() {

private fun processModules(
moduleManager: ModuleManager, stringEvaluator: StringEvaluator,
searchString: String, listModel: DefaultListModel<FuzzyMatchContainer>, task: Future<*>?
searchString: String, listModel: DefaultListModel<FuzzyContainer>, task: Future<*>?
) {
val filesToIterate = ConcurrentHashMap.newKeySet<FuzzierUtil.IterationFile>()
for (module in moduleManager.modules) {
Expand All @@ -262,7 +237,7 @@ open class Fuzzier : FuzzyAction() {
*/
private fun processFiles(
filesToIterate: ConcurrentHashMap.KeySetView<FuzzierUtil.IterationFile, Boolean>,
stringEvaluator: StringEvaluator, listModel: DefaultListModel<FuzzyMatchContainer>,
stringEvaluator: StringEvaluator, listModel: DefaultListModel<FuzzyContainer>,
searchString: String, task: Future<*>?
) {
val ss = FuzzierUtil.cleanSearchString(searchString, fuzzierSettingsService.state.ignoredCharacters)
Expand All @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mituuz/fuzzier/FuzzierVCS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading