KTNB-1022, review: Formatting

GitOrigin-RevId: ce60d10a8bcf8eb1dd104a41504acb3484fceb1b
This commit is contained in:
Ilya Muradyan
2025-06-02 21:30:57 +02:00
committed by intellij-monorepo-bot
parent ae20b8ebf8
commit 4804896e7e
2 changed files with 33 additions and 17 deletions

View File

@@ -6,13 +6,14 @@ import com.intellij.database.datagrid.GridPagingModel
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import org.jetbrains.annotations.Nls
class ChangePageSizeAction(private val myPageSize: Int) : DumbAwareAction(if (myPageSize == GridPagingModel.UNLIMITED_PAGE_SIZE) DataGridBundle.message("action.ChangePageSize.text.all") else format(myPageSize.toLong()),
if (myPageSize == GridPagingModel.UNLIMITED_PAGE_SIZE)
DataGridBundle.message("action.ChangePageSize.description.all")
else
DataGridBundle.message("action.ChangePageSize.description.some", format(myPageSize.toLong())),
null) {
class ChangePageSizeAction(private val myPageSize: Int) :
DumbAwareAction(
/* text = */ formatPageSize(myPageSize, DataGridBundle.message("action.ChangePageSize.text.all")),
/* description = */ formatPageSize(myPageSize, DataGridBundle.message("action.ChangePageSize.description.all")),
/* icon = */ null
) {
override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
@@ -28,3 +29,11 @@ class ChangePageSizeAction(private val myPageSize: Int) : DumbAwareAction(if (my
setPageSizeAndReload(myPageSize, grid)
}
}
private fun formatPageSize(pageSize: Int, defaultText: @Nls String): @Nls String {
return if (pageSize == GridPagingModel.UNLIMITED_PAGE_SIZE) {
defaultText
} else {
format(pageSize.toLong())
}
}

View File

@@ -149,16 +149,22 @@ private fun getActionState(grid: DataGrid): ChangePageSizeActionState {
val rowsWereDeleted = totalRowCount < pageEndIdx
val isSinglePage = pageModel.isFirstPage() && pageModel.isLastPage() && !rowsWereDeleted
val text = if (isSinglePage) (format(totalRowCount) +
" " +
(if (totalRowCount == 1L)
DataGridBundle.message("action.Console.TableResult.ChangePageSize.row")
else
DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")))
else if (pageEndIdx == 0)
"0 " + DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")
else
format(pageStartIdx.toLong()) + "-" + format(pageEndIdx.toLong())
val text = when {
isSinglePage -> {
val rowLabel = if (totalRowCount == 1L)
DataGridBundle.message("action.Console.TableResult.ChangePageSize.row")
else
DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")
format(totalRowCount) + " " + rowLabel
}
pageEndIdx == 0 -> {
"0 " + DataGridBundle.message("action.Console.TableResult.ChangePageSize.rows")
}
else -> {
format(pageStartIdx.toLong()) + "-" + format(pageEndIdx.toLong())
}
}
val querying = grid.getDataHookup().getBusyCount() > 0
val enabled = !querying && grid.isReady()
@@ -191,7 +197,8 @@ private class ChangePageSizeActionState(
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false
val state = other as ChangePageSizeActionState
return enabled == state.enabled && pageSize == state.pageSize &&
return enabled == state.enabled &&
pageSize == state.pageSize &&
text == state.text &&
description == state.description &&
tooltip == state.tooltip