Skip to content

Commit

Permalink
take over 'Escape' and 'Backspace' in keyboard widget
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Jul 27, 2015
1 parent bedaf6b commit df45a62
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
Expand Up @@ -227,6 +227,12 @@ public void add(NativeEvent event)
add(new KeyCombination(event.getKeyCode(), getModifierValue(event)));
}

public void pop()
{
if (keyCombinations_ != null && keyCombinations_.size() > 0)
keyCombinations_.remove(keyCombinations_.size() - 1);
}

public void add(int keyCode, int modifiers)
{
add(new KeyCombination(keyCode, modifiers));
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
Expand Down Expand Up @@ -406,38 +407,67 @@ private void filter(String query)
private void onShortcutCellPreview(CellPreviewEvent<CommandBinding> preview)
{
NativeEvent event = preview.getNativeEvent();

String type = event.getType();
if (type.equals("focus") || type.equals("blur"))
if (type.equals("focus"))
{
setEscapeDisabled(true);
buffer_.clear();
}
else if (type.equals("blur"))
{
setEscapeDisabled(false);
buffer_.clear();
}
else if (event.getType().equals("keydown"))
{
if (KeyboardHelper.isModifierKey(event.getKeyCode()))
return;

buffer_.add(event);
Element target = event.getEventTarget().cast();
target.setInnerHTML(buffer_.toString());
Element rowEl = DomUtils.findParentElement(target, new ElementPredicate()
{
@Override
public boolean test(Element el)
{
return el.getTagName().toLowerCase().equals("tr");
}
});

// Provide a visual cue that this row has changed
Element rowEl = DomUtils.findParentElement(
target,
new ElementPredicate()
{
@Override
public boolean test(Element el)
{
return el.getTagName().toLowerCase().equals("tr");
}
});
if (event.getKeyCode() == KeyCodes.KEY_BACKSPACE)
{
// Stop event propagation to prevent browser 'Back'.
event.stopPropagation();
event.preventDefault();

buffer_.pop();
target.setInnerHTML(buffer_.toString());
return;
}

if (rowEl != null)
if (event.getKeyCode() == KeyCodes.KEY_ESCAPE)
{
// add modified row style
rowEl.addClassName(RES.dataGridStyle().modifiedRow());
String keyString = "";
KeySequence sequence = preview.getValue().getKeySequence();
if (sequence != null)
keyString = sequence.toString();

String current = target.getInnerHTML();
if (current.equals(keyString))
{
closeDialog();
return;
}

target.setInnerHTML(keyString);
rowEl.removeClassName(RES.dataGridStyle().modifiedRow());
return;
}

buffer_.add(event);
target.setInnerHTML(buffer_.toString());
rowEl.addClassName(RES.dataGridStyle().modifiedRow());

// Add the new command binding to later be accepted + registered
CommandBinding oldBinding = preview.getValue();
CommandBinding newBinding = new CommandBinding(
Expand Down Expand Up @@ -588,7 +618,6 @@ public Object getKey(CommandBinding item)
private final SearchWidget searchWidget_;

private List<CommandBinding> originalBindings_;
private Map<String, CommandBinding> originalBindingsMap_;

// Columns ----
private TextColumn<CommandBinding> nameColumn_;
Expand Down

0 comments on commit df45a62

Please sign in to comment.