preselect first line in show usages popup

This commit is contained in:
Alexey Kudravtsev
2012-08-27 14:13:21 +04:00
parent 8030cec37b
commit bbd60e05fc
2 changed files with 23 additions and 2 deletions
@@ -860,6 +860,9 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
window.setLocation(rectangle.getLocation());
}
if (!data.isEmpty()) {
TableScrollingUtil.ensureSelectionExists(table);
}
table.setSize(dimension);
//table.setPreferredSize(dimension);
//table.setMaximumSize(dimension);
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.util.Pair;
import org.intellij.lang.annotations.JdkConstants;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
@@ -62,9 +63,26 @@ public class TableScrollingUtil {
}
}
public static void ensureSelectionExists(@NotNull JTable list) {
int size = list.getModel().getRowCount();
if (size == 0) {
list.clearSelection();
return;
}
int selectedIndex = list.getSelectedRow();
boolean reselect = false;
if (selectedIndex < 0 || selectedIndex >= size) { // fit index to [0, size-1] range
selectedIndex = 0;
reselect = true;
}
ensureIndexIsVisible(list, selectedIndex, 0);
if (reselect) {
list.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
}
}
private static Rectangle getCellBounds(JTable table, int top, int bottom) {
Rectangle cellBounds = table.getCellRect(top, 0, true).union(table.getCellRect(bottom,0,true));
return cellBounds;
return table.getCellRect(top, 0, true).union(table.getCellRect(bottom,0,true));
}
private static int getVisibleRowCount(JTable list) {