Skip to content

Commit

Permalink
Fixing PKGS-796, small QoL changes
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 7a9279dcf2781f89057e90d880de1c4025203cf7
  • Loading branch information
Lamberto Basti authored and intellij-monorepo-bot committed Jul 21, 2021
1 parent 0d54d0a commit 400c3d9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class PackageSearchUnresolvedReferenceQuickFix(private val ref: PsiReference) :

override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
PackageSearchToolWindowFactory.activateToolWindow(project) {
project.packageSearchDataService
.setSearchQuery(ref.canonicalText)
project.packageSearchDataService.setSearchQuery(ref.canonicalText)
PackageSearchEventsLogger.logRunQuickFix(FUSGroupIds.QuickFixTypes.UnresolvedReference, file?.fileType?.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ internal class PackageSearchDataService(
targetModules = targetModules,
selectedPackage = selectedPackageModel,
filterOptions = filterOptions,
traceInfo = traceInfo
traceInfo = traceInfo,
searchQuery = searchQuery
)

logDebug(traceInfo, "PKGSDataService#onDataChanged()") { "Sending data changes through" }
Expand Down Expand Up @@ -325,7 +326,7 @@ internal class PackageSearchDataService(

val queryTokens = query.split("\\b".toRegex())
.filter { it.isNotBlank() }
.map { it.toLowerCase(Locale.ROOT) }
.map { it.lowercase(Locale.ROOT) }

return queryTokens.any { searchableInfo.contains(it) }
}
Expand Down Expand Up @@ -432,7 +433,7 @@ internal class PackageSearchDataService(
val moduleNames = if (selectedModules.size == 1) {
selectedModules.first().projectModule.name
} else {
PackageSearchBundle.message("packagesearch.ui.toolwindow.allModules").toLowerCase()
PackageSearchBundle.message("packagesearch.ui.toolwindow.allModules").lowercase()
}

val title = if (isSearching) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ internal data class RootDataModel(
val knownRepositoriesInTargetModules: KnownRepositories.InTargetModules,
val selectedPackage: SelectedPackageModel<*>?,
val filterOptions: FilterOptions,
val traceInfo: TraceInfo
val traceInfo: TraceInfo,
val searchQuery: String
) {

companion object {
Expand All @@ -28,7 +29,8 @@ internal data class RootDataModel(
knownRepositoriesInTargetModules = KnownRepositories.InTargetModules.EMPTY,
selectedPackage = null,
filterOptions = FilterOptions(),
traceInfo = TraceInfo.EMPTY
traceInfo = TraceInfo.EMPTY,
searchQuery = ""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@ import com.jetbrains.packagesearch.intellij.plugin.ui.toolwindow.panels.manageme
import com.jetbrains.packagesearch.intellij.plugin.ui.toolwindow.panels.management.packages.computePackagesTableItems
import com.jetbrains.packagesearch.intellij.plugin.ui.updateAndRepaint
import com.jetbrains.packagesearch.intellij.plugin.ui.util.scaled
import com.jetbrains.packagesearch.intellij.plugin.util.AppUI
import com.jetbrains.packagesearch.intellij.plugin.util.lifecycleScope
import com.jetbrains.packagesearch.intellij.plugin.util.logDebug
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.awt.Dimension
import javax.swing.BorderFactory
import javax.swing.JScrollPane
Expand Down Expand Up @@ -155,7 +152,8 @@ internal class PackageManagementPanel(
allKnownRepositories = data.allKnownRepositories,
filterOptions = data.filterOptions,
tableData = tableData,
traceInfo = data.traceInfo
traceInfo = data.traceInfo,
searchQuery = data.searchQuery
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.jetbrains.packagesearch.intellij.plugin.ui.toolwindow.panels.management.packages

import com.intellij.ide.ui.LafManagerListener
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.application.AppUIExecutor
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.IdeFocusManager
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.SearchTextField
import com.intellij.ui.components.JBPanelWithEmptyText
import com.intellij.ui.components.JBScrollPane
import com.intellij.util.ui.JBUI
Expand Down Expand Up @@ -35,14 +35,14 @@ import com.jetbrains.packagesearch.intellij.plugin.util.AppUI
import com.jetbrains.packagesearch.intellij.plugin.util.TraceInfo
import com.jetbrains.packagesearch.intellij.plugin.util.lifecycleScope
import com.jetbrains.packagesearch.intellij.plugin.util.logDebug
import com.jetbrains.packagesearch.intellij.plugin.util.lookAndFeelFlow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.miginfocom.swing.MigLayout
import java.awt.BorderLayout
Expand Down Expand Up @@ -86,6 +86,10 @@ internal class PackagesListPanel(
}
}

private val textChangedListener = SearchTextFieldTextChangedListener {
project.lifecycleScope.launch(Dispatchers.AppUI) { searchClient.setSearchQuery(searchTextField.text) }
}

private val packagesPanel = PackageSearchUI.borderPanel {
layout = BoxLayout(this, BoxLayout.Y_AXIS)
}
Expand Down Expand Up @@ -178,20 +182,10 @@ internal class PackagesListPanel(

registerForUiEvents()

callbackFlow {
val conn = project.messageBus.simpleConnect()
conn.subscribe(
LafManagerListener.TOPIC,
LafManagerListener { trySend(Unit) }
)
awaitClose { conn.disconnect() }
}.onEach {
withContext(Dispatchers.AppUI) {
updateLaf()
}
}.launchIn(project.lifecycleScope)
project.lookAndFeelFlow.onEach { updateLaf() }
.launchIn(project.lifecycleScope)

updateLaf()
project.lifecycleScope.launch { updateLaf() }
}

fun setIsBusy(isBusy: Boolean) {
Expand Down Expand Up @@ -232,11 +226,13 @@ internal class PackagesListPanel(
val knownRepositoriesInTargetModules: KnownRepositories.InTargetModules,
val allKnownRepositories: KnownRepositories.All,
val tableData: List<PackagesTableItem<*>>,
val traceInfo: TraceInfo
val traceInfo: TraceInfo,
val searchQuery: String
)

override suspend fun display(viewModel: ViewModel) = withContext(Dispatchers.AppUI) {

searchTextField.setTextWithoutFiringListeners(viewModel.searchQuery)
onlyStableCheckBox.isSelected = viewModel.filterOptions.onlyStable
onlyKotlinMpCheckBox.isSelected = viewModel.filterOptions.onlyKotlinMultiplatform

Expand Down Expand Up @@ -265,8 +261,8 @@ internal class PackagesListPanel(
)

tableScrollPane.isVisible = viewModel.packageModels.isNotEmpty()
listPanel.updateAndRepaint()

listPanel.updateAndRepaint()
packagesTable.updateAndRepaint()
packagesPanel.updateAndRepaint()
}
Expand All @@ -276,11 +272,7 @@ internal class PackagesListPanel(
IdeFocusManager.getInstance(project).requestFocus(searchTextField, false)
}

searchTextField.addDocumentListener(object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
AppUIExecutor.onUiThread().execute { searchClient.setSearchQuery(searchTextField.text) }
}
})
searchTextField.addDocumentListener(textChangedListener)

onlyStableCheckBox.addItemListener { e ->
val selected = e.stateChange == ItemEvent.SELECTED
Expand All @@ -295,7 +287,7 @@ internal class PackagesListPanel(
}
}

private fun updateLaf() {
private suspend fun updateLaf() = withContext(Dispatchers.AppUI) {
@Suppress("MagicNumber") // Dimension constants
with(searchTextField) {
textEditor.putClientProperty("JTextField.Search.Gap", 6.scaled())
Expand All @@ -314,4 +306,16 @@ internal class PackagesListPanel(
@Suppress("MagicNumber") // Dimension constants
minimumSize = Dimension(200.scaled(), minimumSize.height)
}

private fun PackagesSmartSearchField.setTextWithoutFiringListeners(searchQuery: String) {
removeDocumentListener(textChangedListener)
text = searchQuery
addDocumentListener(textChangedListener)
}
}

@Suppress("FunctionName")
fun SearchTextFieldTextChangedListener(action: (DocumentEvent) -> Unit) =
object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) = action(e)
}

0 comments on commit 400c3d9

Please sign in to comment.