Search in sources :

Example 1 with NativeEventHandler

use of org.rstudio.core.client.dom.DomUtils.NativeEventHandler in project rstudio by rstudio.

the class ChunkOptionsPopupPanel method makeInputBox.

private TextBox makeInputBox(final String option, final boolean enquote) {
    final TextBox box = new TextBox();
    box.getElement().setAttribute("placeholder", "Default");
    box.setWidth("40px");
    DomUtils.addKeyHandlers(box, new NativeEventHandler() {

        @Override
        public void onNativeEvent(NativeEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    String text = box.getText().trim();
                    boolean isEmpty = StringUtil.isNullOrEmpty(text);
                    if (enquote && !isEmpty) {
                        text = StringUtil.ensureQuoted(text);
                        text = text.replaceAll("\\\\", "\\\\\\\\");
                    }
                    if (isEmpty)
                        unset(option);
                    else
                        set(option, text);
                    synchronize();
                }
            });
        }
    });
    return box;
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) NativeEventHandler(org.rstudio.core.client.dom.DomUtils.NativeEventHandler) TextBox(com.google.gwt.user.client.ui.TextBox) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 TextBox (com.google.gwt.user.client.ui.TextBox)1 NativeEventHandler (org.rstudio.core.client.dom.DomUtils.NativeEventHandler)1