Search in sources :

Example 1 with ShowHTMLPreviewEvent

use of org.rstudio.studio.client.htmlpreview.events.ShowHTMLPreviewEvent in project rstudio by rstudio.

the class TextEditingTarget method doHtmlPreview.

private void doHtmlPreview(final Provider<HTMLPreviewParams> pParams) {
    // command to show the preview window
    final Command showPreviewWindowCommand = new Command() {

        @Override
        public void execute() {
            HTMLPreviewParams params = pParams.get();
            events_.fireEvent(new ShowHTMLPreviewEvent(params));
        }
    };
    // command to run the preview
    final Command runPreviewCommand = new Command() {

        @Override
        public void execute() {
            final HTMLPreviewParams params = pParams.get();
            server_.previewHTML(params, new SimpleRequestCallback<Boolean>());
        }
    };
    if (pParams.get().isNotebook()) {
        saveThenExecute(null, new Command() {

            @Override
            public void execute() {
                generateNotebook(new Command() {

                    @Override
                    public void execute() {
                        showPreviewWindowCommand.execute();
                        runPreviewCommand.execute();
                    }
                });
            }
        });
    } else // due to popup activation rules but at least it will show up
    if (isNewDoc()) {
        saveThenExecute(null, CommandUtil.join(showPreviewWindowCommand, runPreviewCommand));
    } else // beat the popup blockers) then save & run
    if (dirtyState().getValue()) {
        showPreviewWindowCommand.execute();
        saveThenExecute(null, runPreviewCommand);
    } else // otherwise show the preview window then run the preview
    {
        showPreviewWindowCommand.execute();
        runPreviewCommand.execute();
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ShowHTMLPreviewEvent(org.rstudio.studio.client.htmlpreview.events.ShowHTMLPreviewEvent) HTMLPreviewParams(org.rstudio.studio.client.htmlpreview.model.HTMLPreviewParams)

Aggregations

RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Command (com.google.gwt.user.client.Command)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 ShowHTMLPreviewEvent (org.rstudio.studio.client.htmlpreview.events.ShowHTMLPreviewEvent)1 HTMLPreviewParams (org.rstudio.studio.client.htmlpreview.model.HTMLPreviewParams)1