<commit_before>/*
 * WorkbenchPane.java
 *
 * Copyright (C) 2020 by RStudio, PBC
 *
 * 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.ui;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.Command;
import org.rstudio.core.client.Debug;
import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.dom.DomUtils;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.WorkbenchView;
import org.rstudio.studio.client.workbench.events.ActivatePaneEvent;

import java.util.ArrayList;

public abstract class WorkbenchPane extends ToolbarPane
                                 implements WorkbenchView,
                                            WorkbenchTab
{
   protected WorkbenchPane(String title)
   {
      title_ = title;
      events_ = null;
   }

   protected WorkbenchPane(String title, EventBus events)
   {
      title_ = title;
      events_ = events;
   }

   public void prefetch(Command continuation)
   {
      continuation.execute();
   }

   public String getTitle()
   {
      return title_;
   }

   // hook for subclasses to be notified right before & after they are selected
   public void onBeforeUnselected()
   {
   }
   public void onBeforeSelected()
   {
   }
   public void onSelected()
   {
   }

   @Override
   public void setFocus()
   {
      ArrayList<Element> focusableElements = DomUtils.getFocusableElements(getElement());
      if (!focusableElements.isEmpty())
         focusableElements.get(0).focus();
      else
         Debug.logWarning("Could not set focus, no focusable element on " + title_ + " pane");
   }

   @Override
   public boolean isSuppressed()
   {
      return false;
   }

   @Override
   public boolean closeable()
   {
      return false;
   }
   
   @Override
   public void confirmClose(Command onConfirmed)
   {
      onConfirmed.execute();
   }

   @Override
   public void bringToFront()
   {
      if (events_ != null && !StringUtil.isNullOrEmpty(title_))
         events_.fireEvent(new ActivatePaneEvent(title_));
      super.bringToFront();
   }

   private String title_;
   protected final EventBus events_;
}<commit_msg>manually add focus-visible attribute to element<commit_after>/*
 * WorkbenchPane.java
 *
 * Copyright (C) 2020 by RStudio, PBC
 *
 * 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.ui;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.Command;
import org.rstudio.core.client.Debug;
import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.dom.DomUtils;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.WorkbenchView;
import org.rstudio.studio.client.workbench.events.ActivatePaneEvent;

import java.util.ArrayList;

public abstract class WorkbenchPane extends ToolbarPane
                                 implements WorkbenchView,
                                            WorkbenchTab
{
   protected WorkbenchPane(String title)
   {
      title_ = title;
      events_ = null;
   }

   protected WorkbenchPane(String title, EventBus events)
   {
      title_ = title;
      events_ = events;
   }

   public void prefetch(Command continuation)
   {
      continuation.execute();
   }

   public String getTitle()
   {
      return title_;
   }

   // hook for subclasses to be notified right before & after they are selected
   public void onBeforeUnselected()
   {
   }
   public void onBeforeSelected()
   {
   }
   public void onSelected()
   {
   }

   @Override
   public void setFocus()
   {
      ArrayList<Element> focusableElements = DomUtils.getFocusableElements(getElement());
      if (!focusableElements.isEmpty())
      {
         Element el = focusableElements.get(0);
         el.focus();
         el.addClassName("focus-visible");
         addRemoveFocusVisibleHandler(el);
      }
      else
         Debug.logWarning("Could not set focus, no focusable element on " + title_ + " pane");
   }

   @Override
   public boolean isSuppressed()
   {
      return false;
   }

   @Override
   public boolean closeable()
   {
      return false;
   }
   
   @Override
   public void confirmClose(Command onConfirmed)
   {
      onConfirmed.execute();
   }

   @Override
   public void bringToFront()
   {
      if (events_ != null && !StringUtil.isNullOrEmpty(title_))
         events_.fireEvent(new ActivatePaneEvent(title_));
      super.bringToFront();
   }

   private native void addRemoveFocusVisibleHandler(Element el) /*-{
      el.addEventListener('blur', function(e) {
         el.classList.remove('focus-visible');
      });

   }-*/;

   private String title_;
   protected final EventBus events_;
}
{'fraction_non_alphanumeric': 0.08950779471010685, 'fraction_numerical': 0.0028025923979681207, 'mean_word_length': 2.865944482058226, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7392769', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1605, 'n_words': 440}