This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Include 'Esc' key option to close editor in config panel, consolidate…

… all shortcut keys rules into CheckKey
  • Loading branch information...
1 parent 33bcdc9 commit f30989daae98296ad53573fd1f490baf6eae33b2 @aeng aeng committed Oct 18, 2011
@@ -38,7 +38,6 @@
import org.zanata.webtrans.client.events.UserConfigChangeHandler;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.ui.HasPager;
-import org.zanata.webtrans.client.ui.UserConfigConstants;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.DocumentInfo;
import org.zanata.webtrans.shared.model.TransUnit;
@@ -160,8 +159,7 @@ public void onDocumentSelected(DocumentSelectionEvent event)
public void onValueChanged(UserConfigChangeEvent event)
{
transUnitNavigationPresenter.getDisplay().setNavModeTooltip(event.getConfigMap());
- tableEditorPresenter.getDisplay().getTargetCellEditor().setNavMode(event.getConfigMap());
- tableEditorPresenter.getDisplay().getTargetCellEditor().setEnterKeyEnabled(event.getConfigMap().get(UserConfigConstants.BUTTON_ENTER));
+ tableEditorPresenter.getDisplay().getTargetCellEditor().updateKeyBehaviour(event.getConfigMap());
}
}));
}
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.zanata.webtrans.client.editor;
+
+import com.google.gwt.dom.client.NativeEvent;
+
+/**
+*
+* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
+*
+* @formatter:off
+* Navigation mode:
+* ALT+UP arrow or J - Previous entry
+* ALT+DOWN arrow or K - Next entry
+* ALT+G - copy from source
+* Enter - Open editor
+*
+* Edit mode:
+* ALT+(UP arrow/J) - Previous entry
+* ALT+(DOWN arrow/K) - Next entry
+* ALT+G - copy from source
+* CTRL+Enter - Save as approved
+* Enter - Save as approved (if isEnterKeySavesEnabled = true)
+*
+**/
+public interface CheckKey
+{
+ static final int KEY_G = 'G';
+ static final int KEY_J = 'J';
+ static final int KEY_K = 'K';
+ static final int KEY_S = 'S';
+
+ public static enum Context
+ {
+ /**
+ * Edit: InlineTargetCellEditor Navigation: TableEditorPresenter
+ */
+ Navigation, Edit;
+ }
+
+ void init(NativeEvent event);
+
+
+ /**
+ * Save as fuzzy shortcut: CTRL+S
+ */
+ boolean isSaveAsFuzzyKey();
+
+ /**
+ * Move to previous state entry: ALT+PageUp
+ */
+ boolean isPreviousStateEntryKey();
+
+ /**
+ * Move to next state entry: ALT+PageDown
+ */
+ boolean isNextStateEntryKey();
+
+ /**
+ * Move to previous entry:
+ * Edit: ALT+(Up/J)
+ * Navigation: ALT+Up or J
+ */
+ boolean isPreviousEntryKey();
+
+ /**
+ * Move to next entry:
+ * Edit: ALT+(Down/K)
+ * Navigation: ALT+Down or K
+ */
+ boolean isNextEntryKey();
+
+ /**
+ * Copy from source: ALT+G
+ *
+ */
+ boolean isCopyFromSourceKey();
+
+ /**
+ * User typing in text area, any keys other than ALT+CTRL
+ *
+ */
+ boolean isUserTyping();
+
+ /**
+ * Close editor: Esc (if isEscKeyCloseEditor = true)
+ *
+ */
+ boolean isCloseEditorKey(boolean isEscKeyCloseEditor);
+
+ /**
+ * Is ENTER key pressed
+ */
+ boolean isEnterKey();
+
+ /**
+ * Save as approved key:
+ * CTRL+ENTER or
+ * ENTER (if isEnterKeySavesEnabled = true AND !shiftKey {Shift+Enter inserts new line})
+ *
+ */
+ boolean isSaveAsApprovedKey(boolean isEnterKeySavesEnabled);
+}
+
+
+
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.zanata.webtrans.client.editor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.event.dom.client.KeyCodes;
+
+/**
+ *
+ * @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
+ *
+ * See org.zanata.webtrans.client.editor.table.CheckKey
+ *
+ **/
+public final class CheckKeyImpl implements CheckKey
+{
+ private Context context;
+ private int keyCode;
+ private boolean shiftKey, altKey, ctrlKey;
+
+ public CheckKeyImpl(Context context)
+ {
+ this.context = context;
+ }
+
+ @Override
+ public void init(NativeEvent event)
+ {
+ keyCode = event.getKeyCode();
+ shiftKey = event.getShiftKey();
+ altKey = event.getAltKey();
+ ctrlKey = event.getCtrlKey();
+ }
+
+ @Override
+ public boolean isSaveAsFuzzyKey()
+ {
+ return ctrlKey && keyCode == KEY_S;
+ }
+
+ @Override
+ public boolean isPreviousStateEntryKey()
+ {
+ return altKey && keyCode == KeyCodes.KEY_PAGEUP;
+ }
+
+ @Override
+ public boolean isNextStateEntryKey()
+ {
+ return altKey && keyCode == KeyCodes.KEY_PAGEDOWN;
+ }
+
+ @Override
+ public boolean isPreviousEntryKey()
+ {
+ if (context == Context.Edit)
+ {
+ return altKey && (keyCode == KeyCodes.KEY_UP || keyCode == KEY_J);
+ }
+ else
+ {
+ return (altKey && keyCode == KeyCodes.KEY_UP) || keyCode == KEY_J;
+ }
+ }
+
+ @Override
+ public boolean isNextEntryKey()
+ {
+ if (context == Context.Edit)
+ {
+ return altKey && (keyCode == KeyCodes.KEY_DOWN || keyCode == KEY_K);
+ }
+ else
+ {
+ return (altKey && keyCode == KeyCodes.KEY_DOWN) || keyCode == KEY_K;
+ }
+ }
+
+ @Override
+ public boolean isCopyFromSourceKey()
+ {
+ return altKey && keyCode == KEY_G;
+ }
+
+ @Override
+ public boolean isUserTyping()
+ {
+ return !altKey && !ctrlKey && keyCode != KeyCodes.KEY_ESCAPE;
+ }
+
+ @Override
+ public boolean isCloseEditorKey(boolean isEscKeyCloseEditor)
+ {
+ return isEscKeyCloseEditor && keyCode == KeyCodes.KEY_ESCAPE;
+ }
+
+ @Override
+ public boolean isEnterKey()
+ {
+ return keyCode == KeyCodes.KEY_ENTER;
+ }
+
+ @Override
+ public boolean isSaveAsApprovedKey(boolean isEnterKeySavesEnabled)
+ {
+ if (isEnterKey())
+ {
+ if (ctrlKey)
+ {
+ return true;
+ }
+ else
+ {
+ return isEnterKeySavesEnabled && !shiftKey;
+ }
+ }
+ return false;
+ }
+}
Oops, something went wrong.

0 comments on commit f30989d

Please sign in to comment.