moving selection by keys

This commit is contained in:
Dmitry Avdeev
2012-10-11 17:43:20 +04:00
parent 4c7db311db
commit 82a5e1dcfa
6 changed files with 54 additions and 15 deletions
@@ -27,7 +27,6 @@ import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.options.ConfigurationException;
@@ -298,10 +297,9 @@ public class ProjectNameWithTypeStep extends ProjectNameStep {
}
}
};
final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), null);
final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), null);
arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), myNamePathComponent.getNameComponent());
arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), myModuleName);
CustomShortcutSet shortcutSet = new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN);
arrow.registerCustomShortcutSet(shortcutSet, myNamePathComponent.getNameComponent());
arrow.registerCustomShortcutSet(shortcutSet, myModuleName);
}
}
@@ -15,7 +15,7 @@
<properties/>
<border type="none"/>
<children>
<component id="3580d" class="com.intellij.ui.SearchTextField" binding="mySearchField">
<component id="3580d" class="com.intellij.ui.SearchTextField" binding="mySearchField" custom-create="true">
<constraints border-constraint="North"/>
<properties/>
</component>
@@ -82,7 +82,7 @@
<properties>
<contentType value="text/html"/>
<editable value="false"/>
<text value="&lt;html&gt;&#13;&#10; &lt;head&gt;&#13;&#10;&#13;&#10; &lt;/head&gt;&#13;&#10; &lt;body&gt;&#13;&#10; &lt;p style=&quot;margin-top: 0&quot;&gt;&#13;&#10; &#13;&#10; &lt;/p&gt;&#13;&#10; &lt;/body&gt;&#13;&#10;&lt;/html&gt;&#13;&#10;"/>
<text value="&lt;html&gt;&#13;&#10; &lt;head&gt;&#13;&#10; &#13;&#10; &lt;/head&gt;&#13;&#10; &lt;body&gt;&#13;&#10; &lt;/body&gt;&#13;&#10;&lt;/html&gt;&#13;&#10;"/>
</properties>
</component>
</children>
@@ -20,6 +20,9 @@ import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.ide.util.treeView.AlphaComparator;
import com.intellij.ide.util.treeView.NodeDescriptor;
import com.intellij.ide.util.treeView.TreeState;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.ui.Messages;
@@ -53,6 +56,8 @@ import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.*;
import java.util.List;
@@ -211,6 +216,26 @@ public class SelectTemplateStep extends ModuleWizardStep {
else {
myBuilder.expandAll(null);
}
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
InputEvent event = e.getInputEvent();
if (event instanceof KeyEvent) {
int row = myTemplatesTree.getMaxSelectionRow();
switch (((KeyEvent)event).getKeyCode()) {
case KeyEvent.VK_UP:
myTemplatesTree.setSelectionRow(row == 0 ? myTemplatesTree.getRowCount() - 1 : row - 1);
break;
case KeyEvent.VK_DOWN:
myTemplatesTree.setSelectionRow(row < myTemplatesTree.getRowCount() - 1 ? row + 1 : 0);
break;
case KeyEvent.VK_ENTER:
myTemplatesTree.expandRow(row);
}
}
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_ENTER), mySearchField);
}
@Override
@@ -318,6 +343,10 @@ public class SelectTemplateStep extends ModuleWizardStep {
Disposer.dispose(myBuilder);
}
private void createUIComponents() {
mySearchField = new SearchTextField(false);
}
private class GroupNode extends SimpleNode {
private final String myGroup;
private final Collection<ProjectTemplatesFactory> myFactories;
@@ -15,16 +15,15 @@
*/
package com.intellij.ide.actions;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Trinity;
import com.intellij.ui.ComboboxSpeedSearch;
import com.intellij.ui.ComboboxWithBrowseButton;
import com.intellij.ui.ListCellRendererWrapper;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -84,7 +83,7 @@ public class TemplateKindCombo extends ComboboxWithBrowseButton {
}
public void registerUpDownHint(JComponent component) {
final AnAction arrow = new AnAction() {
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (e.getInputEvent() instanceof KeyEvent) {
@@ -92,10 +91,7 @@ public class TemplateKindCombo extends ComboboxWithBrowseButton {
scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0);
}
}
};
final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), null);
final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), null);
arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component);
}.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), component);
}
private void scrollBy(int delta) {
@@ -15,6 +15,8 @@
*/
package com.intellij.openapi.actionSystem;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -34,6 +36,10 @@ public final class CustomShortcutSet implements ShortcutSet {
this(new KeyboardShortcut(keyStroke, null));
}
public CustomShortcutSet() {
myShortcuts = Shortcut.EMPTY_ARRAY;
}
/**
* Creates <code>CustomShortcutSet</code> which contains specified keyboard and
* mouse shortcuts.
@@ -44,6 +50,15 @@ public final class CustomShortcutSet implements ShortcutSet {
myShortcuts = shortcuts.length == 0 ? Shortcut.EMPTY_ARRAY : shortcuts.clone();
}
public CustomShortcutSet(Integer... keyCodes) {
myShortcuts = ContainerUtil.map(keyCodes, new Function<Integer, Shortcut>() {
@Override
public Shortcut fun(Integer integer) {
return new KeyboardShortcut(KeyStroke.getKeyStroke(integer, 0), null);
}
}, Shortcut.EMPTY_ARRAY);
}
@Override
@NotNull
public Shortcut[] getShortcuts(){
@@ -17,6 +17,7 @@ package com.intellij.openapi.actionSystem;
import com.intellij.openapi.util.Comparing;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -30,7 +31,7 @@ public final class KeyboardShortcut extends Shortcut {
/**
* @throws IllegalArgumentException if <code>firstKeyStroke</code> is <code>null</code>
*/
public KeyboardShortcut(@NotNull KeyStroke firstKeyStroke, KeyStroke secondKeyStroke) {
public KeyboardShortcut(@NotNull KeyStroke firstKeyStroke, @Nullable KeyStroke secondKeyStroke) {
myFirstKeyStroke = firstKeyStroke;
mySecondKeyStroke = secondKeyStroke;
}