mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[Tables] PY-80450 Improve UI and Wording for Page Size Selection #PY-80450 Ready for Merge
* Made page size actions toggleable * Changed UI to change the default page size (cherry picked from commit a4e5914bb7ce4cd3e2b0e0c28086886aa00a93ae) GitOrigin-RevId: d5e3704cf0a5065a2f9f22aa76b25b5acf97336f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f15749d013
commit
0c856ddc6c
@@ -204,10 +204,8 @@ action.Console.TableResult.ToggleFilters.text=Show Filter
|
||||
action.Console.TableResult.ResetView.text=Reset View
|
||||
group.Console.TableResult.Options.text=Show Options Menu
|
||||
action.ChangePageSize.text.all=All
|
||||
action.ChangePageSize.description.all=Show all rows
|
||||
action.ChangePageSize.description.some=Change page size to {0}
|
||||
action.SetDefaultPageSize.text=Set Default Page Size
|
||||
action.SetDefaultPageSize.text.2=Change Default: {0}
|
||||
action.ChangePageSize.text.default=Default
|
||||
action.SetDefaultPageSize.text=Set as Default
|
||||
action.CountRows.text=Count Rows
|
||||
action.CountRows.description=Click to update (runs SELECT COUNT(*) FROM \u2026)
|
||||
action.CountRows.querying=Querying\u2026
|
||||
|
||||
@@ -2,17 +2,20 @@ package com.intellij.database.run.actions
|
||||
|
||||
import com.intellij.database.DataGridBundle
|
||||
import com.intellij.database.DatabaseDataKeys
|
||||
import com.intellij.database.datagrid.DataGrid
|
||||
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 com.intellij.openapi.actionSystem.ToggleAction
|
||||
import com.intellij.openapi.util.text.HtmlBuilder
|
||||
import com.intellij.openapi.util.text.HtmlChunk
|
||||
import com.intellij.ui.ColorUtil
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.annotations.Nls
|
||||
|
||||
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
|
||||
class ChangePageSizeActionNew(private val myPageSize: Int, isDefault: Boolean = false) :
|
||||
ToggleAction(
|
||||
/* text = */ formatPageSize(myPageSize, isDefault, DataGridBundle.message("action.ChangePageSize.text.all")),
|
||||
) {
|
||||
override fun getActionUpdateThread(): ActionUpdateThread {
|
||||
return ActionUpdateThread.BGT
|
||||
@@ -21,19 +24,36 @@ class ChangePageSizeAction(private val myPageSize: Int) :
|
||||
override fun update(e: AnActionEvent) {
|
||||
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
|
||||
e.presentation.setEnabledAndVisible(grid != null)
|
||||
super.update(e)
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY)
|
||||
if (grid == null) return
|
||||
setPageSizeAndReload(myPageSize, grid)
|
||||
override fun isSelected(e: AnActionEvent): Boolean {
|
||||
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY) ?: return false
|
||||
return getCurrentPageSize(grid) == myPageSize
|
||||
}
|
||||
|
||||
override fun setSelected(e: AnActionEvent, state: Boolean) {
|
||||
if (state) {
|
||||
val grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY) ?: return
|
||||
setPageSizeAndReload(myPageSize, grid)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentPageSize(grid: DataGrid?): Int {
|
||||
return grid?.dataHookup?.pageModel?.pageSize ?: GridPagingModel.UNLIMITED_PAGE_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatPageSize(pageSize: Int, defaultText: @Nls String): @Nls String {
|
||||
return if (pageSize == GridPagingModel.UNLIMITED_PAGE_SIZE) {
|
||||
defaultText
|
||||
} else {
|
||||
format(pageSize.toLong())
|
||||
private fun formatPageSize(pageSize: Int, isDefault: Boolean, defaultText: @Nls String): @Nls String {
|
||||
val formattedPageSize = format(pageSize.toLong())
|
||||
val pageSizeText = if (pageSize == GridPagingModel.UNLIMITED_PAGE_SIZE) defaultText else formattedPageSize
|
||||
val builder = HtmlBuilder().append(pageSizeText).append(" ")
|
||||
if (isDefault) {
|
||||
builder.append(
|
||||
HtmlChunk.text(DataGridBundle.message("action.ChangePageSize.text.default"))
|
||||
.wrapWith(HtmlChunk.font(ColorUtil.toHtmlColor(UIUtil.getContextHelpForeground())))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return builder.wrapWith(HtmlChunk.html()).toString()
|
||||
}
|
||||
@@ -32,10 +32,10 @@ class ChangePageSizeActionGroup : DefaultActionGroup(), CustomComponentAction, D
|
||||
|
||||
init {
|
||||
isPopup = true
|
||||
setActions(DEFAULT_PAGE_SIZES, false)
|
||||
setActions(DEFAULT_PAGE_SIZES, false, GridPagingModel.UNLIMITED_PAGE_SIZE)
|
||||
}
|
||||
|
||||
private fun setActions(sizes: MutableList<Int>, isSinglePage: Boolean) {
|
||||
private fun setActions(sizes: MutableList<Int>, isSinglePage: Boolean, defaultPageSize: Int) {
|
||||
removeAll()
|
||||
|
||||
if (isSinglePage) {
|
||||
@@ -43,11 +43,10 @@ class ChangePageSizeActionGroup : DefaultActionGroup(), CustomComponentAction, D
|
||||
}
|
||||
|
||||
addSeparator(DataGridBundle.message("separator.page.size"))
|
||||
|
||||
for (pageSize in sizes) {
|
||||
add(ChangePageSizeAction(pageSize))
|
||||
add(ChangePageSizeActionNew(pageSize, pageSize == defaultPageSize))
|
||||
}
|
||||
add(ChangePageSizeAction(GridPagingModel.UNLIMITED_PAGE_SIZE))
|
||||
add(ChangePageSizeActionNew(GridPagingModel.UNLIMITED_PAGE_SIZE, GridPagingModel.UNLIMITED_PAGE_SIZE == defaultPageSize))
|
||||
add(SetCustomPageSizeAction())
|
||||
add(Separator())
|
||||
add(SetDefaultPageSizeAction())
|
||||
@@ -109,18 +108,18 @@ class ChangePageSizeActionGroup : DefaultActionGroup(), CustomComponentAction, D
|
||||
component.repaint()
|
||||
}
|
||||
|
||||
|
||||
val pageSizes: MutableList<Int> = ArrayList<Int>(DEFAULT_PAGE_SIZES)
|
||||
pageSizes.add(GridUtilCore.getPageSize(settings))
|
||||
if (state.pageSize > 0) {
|
||||
pageSizes.add(state.pageSize * 2)
|
||||
val halfSize = state.pageSize / 2
|
||||
if (halfSize > 0) pageSizes.add(halfSize)
|
||||
ContainerUtil.removeAll(pageSizes, state.pageSize)
|
||||
pageSizes.add(state.pageSize)
|
||||
}
|
||||
ContainerUtil.removeDuplicates(pageSizes)
|
||||
ContainerUtil.sort(pageSizes)
|
||||
setActions(pageSizes, state.showCountAllAction)
|
||||
|
||||
setActions(pageSizes, state.showCountAllAction, state.defaultPageSize)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -178,7 +177,7 @@ private fun getActionState(grid: DataGrid): ChangePageSizeActionState {
|
||||
}
|
||||
|
||||
val showCountRowsAction = isSinglePage && pageModel.isTotalRowCountUpdateable() && !querying && grid.isReady()
|
||||
return ChangePageSizeActionState(text, description, tooltip, enabled, pageModel.getPageSize(), showCountRowsAction)
|
||||
return ChangePageSizeActionState(text, description, tooltip, enabled, pageModel.getPageSize(), showCountRowsAction, GridHelper.get(grid).getDefaultPageSize())
|
||||
}
|
||||
|
||||
private fun updateIsTotalRowCountUpdateable(grid: DataGrid) {
|
||||
@@ -192,6 +191,7 @@ private class ChangePageSizeActionState(
|
||||
val enabled: Boolean,
|
||||
val pageSize: Int,
|
||||
val showCountAllAction: Boolean,
|
||||
val defaultPageSize: Int = GridPagingModel.UNLIMITED_PAGE_SIZE,
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
@@ -2,17 +2,12 @@ package com.intellij.database.run.actions;
|
||||
|
||||
import com.intellij.database.DataGridBundle;
|
||||
import com.intellij.database.DatabaseDataKeys;
|
||||
import com.intellij.database.datagrid.DataGrid;
|
||||
import com.intellij.database.datagrid.GridHelper;
|
||||
import com.intellij.database.datagrid.GridUtilCore;
|
||||
import com.intellij.database.run.actions.SetCustomPageSizeAction.SetPageSizeDialogWrapper;
|
||||
import com.intellij.database.datagrid.*;
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.database.run.actions.ChangePageSizeUtilKt.setPageSizeAndReload;
|
||||
|
||||
public class SetDefaultPageSizeAction extends DumbAwareAction {
|
||||
|
||||
public SetDefaultPageSizeAction() {
|
||||
@@ -27,9 +22,7 @@ public class SetDefaultPageSizeAction extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setEnabledAndVisible(true);
|
||||
GridHelper helper = GridHelper.get(grid);
|
||||
String pageSize = helper.isLimitDefaultPageSize() ? String.valueOf(helper.getDefaultPageSize()) : DataGridBundle.message("action.ChangePageSize.text.all");
|
||||
e.getPresentation().setText(DataGridBundle.message("action.SetDefaultPageSize.text.2", pageSize));
|
||||
e.getPresentation().setText(DataGridBundle.message("action.SetDefaultPageSize.text"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,32 +34,11 @@ public class SetDefaultPageSizeAction extends DumbAwareAction {
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
DataGrid grid = e.getData(DatabaseDataKeys.DATA_GRID_KEY);
|
||||
if (grid == null) return;
|
||||
new SetPageSizeDialogWrapper(getEventProject(e)) {
|
||||
|
||||
@Override
|
||||
protected int getPageSize() {
|
||||
return GridHelper.get(grid).getDefaultPageSize();
|
||||
}
|
||||
int pageSize = grid.getDataHookup().getPageModel().getPageSize();
|
||||
GridHelper helper = GridHelper.get(grid);
|
||||
|
||||
@Override
|
||||
protected boolean isLimitPageSize() {
|
||||
return GridHelper.get(grid).isLimitDefaultPageSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
super.doOKAction();
|
||||
GridHelper helper = GridHelper.get(grid);
|
||||
int pageSize = getMyForm().getPageSize();
|
||||
if (GridUtilCore.isPageSizeUnlimited(pageSize)) {
|
||||
helper.setLimitDefaultPageSize(false);
|
||||
}
|
||||
else {
|
||||
helper.setLimitDefaultPageSize(true);
|
||||
helper.setDefaultPageSize(pageSize);
|
||||
}
|
||||
setPageSizeAndReload(pageSize, grid);
|
||||
}
|
||||
}.show();
|
||||
helper.setDefaultPageSize(pageSize);
|
||||
helper.setLimitDefaultPageSize(!GridUtilCore.isPageSizeUnlimited(pageSize));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user