Package org.zanata.webtrans.client.keys

Examples of org.zanata.webtrans.client.keys.KeyShortcut


        eventBus.addHandler(ReviewCommentEvent.TYPE, this);
        registerKeyShortcut();
    }

    private void registerKeyShortcut() {
        KeyShortcut confirmShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER))
                        .setContext(ShortcutContext.TransHistoryPopup)
                        .setHandler(new KeyShortcutEventHandler() {
                            @Override
View Full Code Here


                        targetContentsPresenter
                                .savePendingChangesIfApplicable();
                        eventBus.fireEvent(NavTransUnitEvent.PREV_ENTRY_EVENT);
                    }
                };
        KeyShortcut movePreviousShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.ALT_KEY, KeyCodes.KEY_UP))
                        .addKey(new Keys(Keys.ALT_KEY, 'J'))
                        .setContext(ShortcutContext.Navigation)
                        .setDescription(messages.navigateToPreviousRow())
                        .setPreventDefault(true).setStopPropagation(true)
                        .setHandler(gotoPreRowHandler).build();
        keyShortcutPresenter.register(movePreviousShortcut);

        // navigate to next row shortcut
        KeyShortcutEventHandler gotoNextRowHandler =
                new KeyShortcutEventHandler() {
                    @Override
                    public void onKeyShortcut(KeyShortcutEvent event) {
                        targetContentsPresenter
                                .savePendingChangesIfApplicable();
                        eventBus.fireEvent(NavTransUnitEvent.NEXT_ENTRY_EVENT);
                    }
                };
        KeyShortcut moveNextShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.ALT_KEY, KeyCodes.KEY_DOWN))
                        .addKey(new Keys(Keys.ALT_KEY, 'K'))
                        .setContext(ShortcutContext.Navigation)
                        .setDescription(messages.navigateToNextRow())
                        .setPreventDefault(true).setStopPropagation(true)
                        .setHandler(gotoNextRowHandler).build();
        keyShortcutPresenter.register(moveNextShortcut);

        // Register shortcut Enter to open editor in selected row - if no other
        // input field is in focus
        KeyShortcut startEditingShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER))
                        .setContext(ShortcutContext.Navigation)
                        .setDescription(messages.openEditorInSelectedRow())
                        .setKeyEvent(KeyEvent.KEY_UP)
View Full Code Here

        registerNavigationKeys(targetContentsPresenter);
        registerEditorActionKeys(targetContentsPresenter);
    }

    protected void registerCopyTMKeys() {
        KeyShortcut copyTM1Shortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_1))
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_1))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.copyFromTM(1))
                        .setHandler(new CopyTMKeyShortcutHandler(0)).build();

        KeyShortcut copyTM2Shortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_2))
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_2))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.copyFromTM(2))
                        .setHandler(new CopyTMKeyShortcutHandler(1)).build();

        KeyShortcut copyTM3Shortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_3))
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_3))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.copyFromTM(3))
                        .setHandler(new CopyTMKeyShortcutHandler(2)).build();

        KeyShortcut copyTM4Shortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_4))
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_4))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.copyFromTM(4))
View Full Code Here

        keyShortcutPresenter.register(copyTM4Shortcut);
    }

    protected void registerNavigationKeys(
            final TargetContentsPresenter targetContentsPresenter) {
        KeyShortcut moveNextShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.ALT_KEY, KeyCodes.KEY_DOWN))
                        .addKey(new Keys(Keys.ALT_KEY, 'K'))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.moveToNextRow())
                        .setPreventDefault(true).setStopPropagation(true)
                        .setPreventDefault(true)
                        .setHandler(new KeyShortcutEventHandler() {
                            @Override
                            public void onKeyShortcut(KeyShortcutEvent event) {
                                targetContentsPresenter.moveToNextEntry();
                            }
                        }).build();
        keyShortcutPresenter.register(moveNextShortcut);

        KeyShortcut movePreviousShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.ALT_KEY, KeyCodes.KEY_UP))
                        .addKey(new Keys(Keys.ALT_KEY, 'J'))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.moveToPreviousRow())
View Full Code Here

    }

    protected void registerEditorActionKeys(
            final TargetContentsPresenter targetContentsPresenter) {
        // Register shortcut CTRL+S to save as fuzzy
        KeyShortcut saveFuzzyShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_KEY, 'S'))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.saveAsFuzzy())
                        .setPreventDefault(true).setStopPropagation(true)
                        .setHandler(new KeyShortcutEventHandler() {
                            @Override
                            public void onKeyShortcut(KeyShortcutEvent event) {
                                targetContentsPresenter
                                        .saveAsFuzzy(targetContentsPresenter
                                                .getCurrentTransUnitIdOrNull());
                            }
                        }).build();
        keyShortcutPresenter.register(saveFuzzyShortcut);

        KeyShortcutEventHandler saveAsApprovedKeyShortcutHandler =
                new KeyShortcutEventHandler() {
                    @Override
                    public void onKeyShortcut(KeyShortcutEvent event) {
                        targetContentsPresenter.checkConfirmationBeforeSave();
                    }
                };

        KeyShortcut ctrlEnterShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.saveAsTranslated())
                        .setPreventDefault(true).setStopPropagation(true)
                        .setHandler(saveAsApprovedKeyShortcutHandler).build();
        keyShortcutPresenter.register(ctrlEnterShortcut);
        enterSavesApprovedShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.saveAsTranslated())
                        .setPreventDefault(true).setStopPropagation(true)
                        .setHandler(saveAsApprovedKeyShortcutHandler).build();
        if (configHolder.getState().isEnterSavesApproved()) {
            enterSavesApprovedHandlerRegistration =
                    keyShortcutPresenter.register(enterSavesApprovedShortcut);
        }

        KeyShortcut copySourceShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.ALT_KEY, 'G'))
                        .addAttentionKey(new Keys('G'))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.copyFromSource())
                        .setStopPropagation(true).setPreventDefault(true)
                        .setHandler(new KeyShortcutEventHandler() {
                            @Override
                            public void onKeyShortcut(KeyShortcutEvent event) {
                                targetContentsPresenter
                                        .copySourceForActiveRow();
                            }
                        }).build();
        keyShortcutPresenter.register(copySourceShortcut);

        KeyShortcut switchEditorShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_ALT_KEYS, 'H'))
                        .addAttentionKey(new Keys('H'))
                        .setContext(ShortcutContext.Edit)
                        .setDescription(messages.switchBetweenEditor())
View Full Code Here

        registerKeyShortcut();
    }

    private void registerKeyShortcut() {
        KeyShortcut confirmShortcut =
                KeyShortcut.Builder.builder()
                        .addKey(new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER))
                        .setContext(ShortcutContext.RejectConfirmationPopup)
                        .setHandler(new KeyShortcutEventHandler() {
                            @Override
View Full Code Here

    }

    @Test
    public void testKeyShortcutForAddComment() {
        when(display.getComment()).thenReturn("blah");
        KeyShortcut keyShortcut = keyShortcutCapture.getValue();

        assertThat(keyShortcut.getAllKeys().iterator().next(),
                Matchers.equalTo(new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER)));
        keyShortcut.getHandler().onKeyShortcut(mock(KeyShortcutEvent.class));

        verify(display).getComment();
        verify(dispatcher).execute(Mockito.isA(AddReviewCommentAction.class),
                Mockito.isA(AsyncCallback.class));
    }
View Full Code Here

    public void testCopyTMKeyHandler() {
        keyShortcuts.registerCopyTMKeys();
        verify(keyShortcutPresenter, times(4)).register(
                keyShortcutCaptor.capture());
        List<KeyShortcut> keys = keyShortcutCaptor.getAllValues();
        KeyShortcut copy3TM = keys.get(3);
        ArgumentCaptor<TransMemoryShortcutCopyEvent> eventCaptor =
                ArgumentCaptor.forClass(TransMemoryShortcutCopyEvent.class);

        copy3TM.getHandler().onKeyShortcut(null);

        verify(eventBus).fireEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getIndex(), Matchers.is(3));
    }
View Full Code Here

    @Test
    public void testNextEntryKeyHandler() {
        keyShortcuts.registerNavigationKeys(targetContentsPresenter);
        verify(keyShortcutPresenter, times(4)).register(
                keyShortcutCaptor.capture());
        KeyShortcut nextEntry = keyShortcutCaptor.getAllValues().get(0);

        nextEntry.getHandler().onKeyShortcut(null);

        verify(targetContentsPresenter).moveToNextEntry();
    }
View Full Code Here

    @Test
    public void testPreviousEntryKeyHandler() {
        keyShortcuts.registerNavigationKeys(targetContentsPresenter);
        verify(keyShortcutPresenter, times(4)).register(
                keyShortcutCaptor.capture());
        KeyShortcut prevEntry = keyShortcutCaptor.getAllValues().get(1);

        prevEntry.getHandler().onKeyShortcut(null);

        verify(targetContentsPresenter).moveToPreviousEntry();
    }
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.client.keys.KeyShortcut

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.