diff --git a/grid/impl/src/run/actions/ChangePageSizeAction.kt b/grid/impl/src/run/actions/ChangePageSizeAction.kt index 936a9d592a3c..d68bb07f4a26 100644 --- a/grid/impl/src/run/actions/ChangePageSizeAction.kt +++ b/grid/impl/src/run/actions/ChangePageSizeAction.kt @@ -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()) + } +} diff --git a/grid/impl/src/run/actions/ChangePageSizeActionGroup.kt b/grid/impl/src/run/actions/ChangePageSizeActionGroup.kt index 6082ceb5bd48..8b86b7bb09bf 100644 --- a/grid/impl/src/run/actions/ChangePageSizeActionGroup.kt +++ b/grid/impl/src/run/actions/ChangePageSizeActionGroup.kt @@ -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