<commit_before>/*
 * FindOutputPane.java
 *
 * Copyright (C) 2009-19 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.output.find;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import org.rstudio.core.client.CodeNavigationTarget;
import org.rstudio.core.client.DebouncedCommand;
import org.rstudio.core.client.dom.DomUtils;
import org.rstudio.core.client.events.EnsureVisibleEvent;
import org.rstudio.core.client.events.HasSelectionCommitHandlers;
import org.rstudio.core.client.events.SelectionCommitEvent;
import org.rstudio.core.client.events.SelectionCommitHandler;
import org.rstudio.core.client.widget.*;
import org.rstudio.core.client.widget.events.SelectionChangedHandler;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.ui.WorkbenchPane;
import org.rstudio.studio.client.workbench.views.output.find.model.FindResult;
import org.rstudio.studio.client.workbench.views.output.find.events.PreviewReplaceEvent;

import java.util.ArrayList;


public class FindOutputPane extends WorkbenchPane
      implements FindOutputPresenter.Display,
                 HasSelectionCommitHandlers<CodeNavigationTarget>
{
   @Inject
   public FindOutputPane(Commands commands,
                         EventBus eventBus)
   {
      super("Find Results");
      commands_ = commands;
      eventBus_ = eventBus;
      ensureWidget();
   }

   @Override
   protected Toolbar createMainToolbar()
   {
      Toolbar toolbar = new Toolbar("Find Output Tab");

      searchLabel_ = new Label();
      toolbar.addLeftWidget(searchLabel_);

      stopSearch_ = new ToolbarButton(
            ToolbarButton.NoText,
            "Stop find in files",
            commands_.interruptR().getImageResource());
      stopSearch_.setVisible(false);
      toolbar.addRightWidget(stopSearch_);

      showFindButton_ = new LeftRightToggleButton("Find", "Replace", false);
      showFindButton_.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event)
         {
            if (!replaceMode_)
            {
               showFindButton_.setVisible(false);
               showReplaceButton_.setVisible(true);
               setReplaceMode(true);
               setSecondaryToolbarVisible(true);
               if (displayPreview_ == null)
                  createDisplayPreview();
               if (!replaceTextBox_.getValue().isEmpty())
                  displayPreview_.nudge();
            }
         }
      });
      toolbar.addRightWidget(showFindButton_);

      showReplaceButton_ = new LeftRightToggleButton("Find", "Replace", true);
      showReplaceButton_.setVisible(false);
      showReplaceButton_.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event)
         {
            if (replaceMode_)
            {
               showFindButton_.setVisible(true);
               showReplaceButton_.setVisible(false);
               setSecondaryToolbarVisible(false);
               if (!replaceTextBox_.getValue().isEmpty())
               {
                  //setRegexPreviewMode(false);
                  addReplaceMatches(new String());
               }
               setReplaceMode(false);
            }<commit_msg>fix starting display of find/replace buttons<commit_after>/*
 * FindOutputPane.java
 *
 * Copyright (C) 2009-19 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.output.find;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.TableRowElement;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import org.rstudio.core.client.CodeNavigationTarget;
import org.rstudio.core.client.DebouncedCommand;
import org.rstudio.core.client.dom.DomUtils;
import org.rstudio.core.client.events.EnsureVisibleEvent;
import org.rstudio.core.client.events.HasSelectionCommitHandlers;
import org.rstudio.core.client.events.SelectionCommitEvent;
import org.rstudio.core.client.events.SelectionCommitHandler;
import org.rstudio.core.client.widget.*;
import org.rstudio.core.client.widget.events.SelectionChangedHandler;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.ui.WorkbenchPane;
import org.rstudio.studio.client.workbench.views.output.find.model.FindResult;
import org.rstudio.studio.client.workbench.views.output.find.events.PreviewReplaceEvent;

import java.util.ArrayList;


public class FindOutputPane extends WorkbenchPane
      implements FindOutputPresenter.Display,
                 HasSelectionCommitHandlers<CodeNavigationTarget>
{
   @Inject
   public FindOutputPane(Commands commands,
                         EventBus eventBus)
   {
      super("Find Results");
      commands_ = commands;
      eventBus_ = eventBus;
      ensureWidget();
   }

   @Override
   protected Toolbar createMainToolbar()
   {
      Toolbar toolbar = new Toolbar("Find Output Tab");

      searchLabel_ = new Label();
      toolbar.addLeftWidget(searchLabel_);

      stopSearch_ = new ToolbarButton(
            ToolbarButton.NoText,
            "Stop find in files",
            commands_.interruptR().getImageResource());
      stopSearch_.setVisible(false);
      toolbar.addRightWidget(stopSearch_);

      showFindButton_ = new LeftRightToggleButton("Find", "Replace", true);
      showFindButton_.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event)
         {
            if (!replaceMode_)
            {
               showFindButton_.setVisible(false);
               showReplaceButton_.setVisible(true);
               setReplaceMode(true);
               setSecondaryToolbarVisible(true);
               if (displayPreview_ == null)
                  createDisplayPreview();
               if (!replaceTextBox_.getValue().isEmpty())
                  displayPreview_.nudge();
            }
         }
      });
      toolbar.addRightWidget(showFindButton_);

      showReplaceButton_ = new LeftRightToggleButton("Find", "Replace", false);
      showReplaceButton_.setVisible(false);
      showReplaceButton_.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event)
         {
            if (replaceMode_)
            {
               showFindButton_.setVisible(true);
               showReplaceButton_.setVisible(false);
               setSecondaryToolbarVisible(false);
               if (!replaceTextBox_.getValue().isEmpty())
               {
                  //setRegexPreviewMode(false);
                  addReplaceMatches(new String());
               }
               setReplaceMode(false);
            }
{'fraction_non_alphanumeric': 0.09701574716440921, 'fraction_numerical': 0.0019821605550049554, 'mean_word_length': 3.0635346756152124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1468196', 'n_tokens_mistral': 2526, 'n_tokens_neox': 2486, 'n_words': 477}