<commit_before>/*
 * PresentationPane.java
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.studio.client.workbench.views.presentation;

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.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

import org.rstudio.core.client.CommandWithArg;
import org.rstudio.core.client.command.ShortcutManager;
import org.rstudio.core.client.dom.WindowEx;
import org.rstudio.core.client.events.NativeKeyDownEvent;
import org.rstudio.core.client.resources.CoreResources;
import org.rstudio.core.client.theme.res.ThemeResources;
import org.rstudio.core.client.theme.res.ThemeStyles;
import org.rstudio.core.client.widget.FullscreenPopupPanel;
import org.rstudio.core.client.widget.AnchorableFrame;
import org.rstudio.core.client.widget.Toolbar;
import org.rstudio.core.client.widget.ToolbarButton;
import org.rstudio.core.client.widget.ToolbarPopupMenu;
import org.rstudio.studio.client.common.AutoGlassPanel;
import org.rstudio.studio.client.common.GlobalDisplay;
import org.rstudio.studio.client.common.SimpleRequestCallback;
import org.rstudio.studio.client.common.icons.StandardIcons;
import org.rstudio.studio.client.common.presentation.SlideNavigationMenu;
import org.rstudio.studio.client.common.presentation.SlideNavigationToolbarMenu;
import org.rstudio.studio.client.rsconnect.RSConnect;
import org.rstudio.studio.client.rsconnect.model.StaticHtmlGenerator;
import org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton;
import org.rstudio.studio.client.server.ServerError;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.ui.WorkbenchPane;
import org.rstudio.studio.client.workbench.views.presentation.model.PresentationRPubsSource;
import org.rstudio.studio.client.workbench.views.presentation.model.PresentationServerOperations;

public class PresentationPane extends WorkbenchPane implements Presentation.Display
{
   @Inject
   public PresentationPane(Commands commands, Session session,
         PresentationServerOperations server, GlobalDisplay display)
   {
      super("Presentation");
      commands_ = commands;
      session_ = session;
      server_ = server;
      display_ = display;
      ensureWidget();
      
      initPresentationCallbacks();
   }
   
   @Override
   protected Toolbar createMainToolbar()
   {
      boolean isTutorial =
                 session_.getSessionInfo().getPresentationState().isTutorial();
      
      Toolbar toolbar = new Toolbar();
      
      slideNavigationMenu_ = new SlideNavigationToolbarMenu(toolbar); 
      slideNavigationMenu_.setEditButtonVisible(!isTutorial);
      
      toolbar.addLeftSeparator();
      
      toolbar.addLeftWidget(commands_.presentationFullscreen().createToolbarButton());
     
      // More
      if (!isTutorial)
      { 
         ToolbarPopupMenu moreMenu = new ToolbarPopupMenu();
         moreMenu.addItem(commands_.clearPresentationCache().createMenuItem(false));
         moreMenu.addSeparator();
         moreMenu.addItem(commands_.presentationViewInBrowser().createMenuItem(false));
         moreMenu.addItem(commands_.presentationSaveAsStandalone().createMenuItem(false));
         
         ToolbarButton moreButton = new ToolbarButton("More",
                                                      StandardIcons.INSTANCE.more_actions(),
                                                      moreMenu);

         toolbar.addRightWidget(moreButton);

         // Create the publish button and wire it to our HTML generator
         publishButton_ = new RSConnectPublishButton(
               RSConnect.CONTENT_TYPE_HTML, false, false);
         publishButton_.setHtmlGenerator(new StaticHtmlGenerator()
         {
            @Override
            public void generateStaticHtml(String title, String comment,
                  final CommandWithArg<String> onCompleted)
            {
               server_.createPresentationRPubsSource(
                  new SimpleRequestCallback<PresentationRPubsSource>() {
                     
                     @Override
                     public void onResponseReceived(
                           PresentationRPubsSource source)
                     {
                        onCompleted.execute(source.getSourceFilePath());
                     }
                     
                     @Override
                     public void onError(ServerError error)
                     {
                        display_.showErrorMessage("Error Saving Presentation",
                          Presentation.getErrorMessage(error));
                     }
               });
            }
         });
         toolbar.addRightSeparator();
         toolbar.addRightWidget(publishButton_);
      }
      else<commit_msg>show progress while generating static HTML for presentations<commit_after>/*
 * PresentationPane.java
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.studio.client.workbench.views.presentation;

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.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

import org.rstudio.core.client.CommandWithArg;
import org.rstudio.core.client.command.ShortcutManager;
import org.rstudio.core.client.dom.WindowEx;
import org.rstudio.core.client.events.NativeKeyDownEvent;
import org.rstudio.core.client.resources.CoreResources;
import org.rstudio.core.client.theme.res.ThemeResources;
import org.rstudio.core.client.theme.res.ThemeStyles;
import org.rstudio.core.client.widget.FullscreenPopupPanel;
import org.rstudio.core.client.widget.AnchorableFrame;
import org.rstudio.core.client.widget.Toolbar;
import org.rstudio.core.client.widget.ToolbarButton;
import org.rstudio.core.client.widget.ToolbarPopupMenu;
import org.rstudio.studio.client.common.AutoGlassPanel;
import org.rstudio.studio.client.common.GlobalDisplay;
import org.rstudio.studio.client.common.SimpleRequestCallback;
import org.rstudio.studio.client.common.icons.StandardIcons;
import org.rstudio.studio.client.common.presentation.SlideNavigationMenu;
import org.rstudio.studio.client.common.presentation.SlideNavigationToolbarMenu;
import org.rstudio.studio.client.rsconnect.RSConnect;
import org.rstudio.studio.client.rsconnect.model.StaticHtmlGenerator;
import org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton;
import org.rstudio.studio.client.server.ServerError;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.ui.WorkbenchPane;
import org.rstudio.studio.client.workbench.views.presentation.model.PresentationRPubsSource;
import org.rstudio.studio.client.workbench.views.presentation.model.PresentationServerOperations;

public class PresentationPane extends WorkbenchPane implements Presentation.Display
{
   @Inject
   public PresentationPane(Commands commands, Session session,
         PresentationServerOperations server, GlobalDisplay display)
   {
      super("Presentation");
      commands_ = commands;
      session_ = session;
      server_ = server;
      display_ = display;
      ensureWidget();
      
      initPresentationCallbacks();
   }
   
   @Override
   protected Toolbar createMainToolbar()
   {
      boolean isTutorial =
                 session_.getSessionInfo().getPresentationState().isTutorial();
      
      Toolbar toolbar = new Toolbar();
      
      slideNavigationMenu_ = new SlideNavigationToolbarMenu(toolbar); 
      slideNavigationMenu_.setEditButtonVisible(!isTutorial);
      
      toolbar.addLeftSeparator();
      
      toolbar.addLeftWidget(commands_.presentationFullscreen().createToolbarButton());
     
      // More
      if (!isTutorial)
      { 
         ToolbarPopupMenu moreMenu = new ToolbarPopupMenu();
         moreMenu.addItem(commands_.clearPresentationCache().createMenuItem(false));
         moreMenu.addSeparator();
         moreMenu.addItem(commands_.presentationViewInBrowser().createMenuItem(false));
         moreMenu.addItem(commands_.presentationSaveAsStandalone().createMenuItem(false));
         
         ToolbarButton moreButton = new ToolbarButton("More",
                                                      StandardIcons.INSTANCE.more_actions(),
                                                      moreMenu);

         toolbar.addRightWidget(moreButton);

         // Create the publish button and wire it to our HTML generator
         publishButton_ = new RSConnectPublishButton(
               RSConnect.CONTENT_TYPE_HTML, false, false);
         publishButton_.setHtmlGenerator(new StaticHtmlGenerator()
         {
            @Override
            public void generateStaticHtml(String title, String comment,
                  final CommandWithArg<String> onCompleted)
            {
               final Command htmlGenComplete = 
                     display_.showProgress("Publishing Presentation...");
               server_.createPresentationRPubsSource(
                  new SimpleRequestCallback<PresentationRPubsSource>() {
                     
                     @Override
                     public void onResponseReceived(
                           PresentationRPubsSource source)
                     {
                        htmlGenComplete.execute();
                        onCompleted.execute(source.getSourceFilePath());
                     }
                     
                     @Override
                     public void onError(ServerError error)
                     {
                        htmlGenComplete.execute();
                        display_.showErrorMessage("Error Saving Presentation",
                          Presentation.getErrorMessage(error));
                     }
               });
            }
         });
         toolbar.addRightSeparator();
         toolbar.addRightWidget(publishButton_);
      }
      else
{'fraction_non_alphanumeric': 0.08749270894092159, 'fraction_numerical': 0.0014998750104157988, 'mean_word_length': 2.8604052750080413, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5456092', 'n_tokens_mistral': 3249, 'n_tokens_neox': 3180, 'n_words': 561}