Skip to content
Permalink
Browse files

Merge pull request #5547 from rstudio/bugfix/hyperlinklabel-keyboard-…

…support

Fix keyboard-activation for HyperlinkLabel instances
  • Loading branch information
gtritchie committed Oct 13, 2019
2 parents 748a3ed + 14a8600 commit 13c33fda53555118aeb02cb54b9e78e1debc3107
@@ -21,8 +21,6 @@
import org.rstudio.studio.client.common.GlobalDisplay;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.user.client.ui.Composite;
@@ -54,16 +52,13 @@ public CaptionWithHelp(String caption,
DecorativeImage helpImage = new DecorativeImage(new ImageResource2x(ThemeResources.INSTANCE.help2x()));
helpImage.setStylePrimaryName(styles.helpImage());
helpPanel_.add(helpImage);
HyperlinkLabel link = new HyperlinkLabel(helpCaption);
link.addStyleName(styles.helpLink());
link.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
if (rstudioLinkName_ != null)
globalDisplay_.openRStudioLink(rstudioLinkName_,
includeVersionInfo_);
}
HyperlinkLabel link = new HyperlinkLabel(helpCaption, () ->
{
if (rstudioLinkName_ != null)
globalDisplay_.openRStudioLink(rstudioLinkName_,
includeVersionInfo_);
});
link.addStyleName(styles.helpLink());
helpPanel_.add(link);
panel.add(helpPanel_);
panel.setCellHorizontalAlignment(helpPanel_,
@@ -15,6 +15,7 @@
package org.rstudio.core.client.widget;

import com.google.gwt.aria.client.Roles;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
@@ -26,6 +27,7 @@
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Label;

import org.rstudio.core.client.Debug;
import org.rstudio.core.client.HandlerRegistrations;
import org.rstudio.core.client.theme.res.ThemeStyles;

@@ -54,13 +56,18 @@ public HyperlinkLabel(String caption)
this(caption, null);
}

// must call this before the element is loaded
public void setClickHandler(Command clickHandler)
{
clickHandler_ = clickHandler;
registerClickHandler();
}

@Override
public HandlerRegistration addClickHandler(ClickHandler handler) {
Debug.logWarning("HyperlinkLabel: for keyboard support use setClickHandler instead of addClickHandler");
return super.addClickHandler(handler);
}

private class MouseHandlers implements MouseOverHandler,
MouseOutHandler
{
@@ -107,7 +114,7 @@ private void registerClickHandler()
{
if (isAttached() && clickHandler_ != null)
{
releaseOnUnload_.add(addClickHandler(event -> click()));
releaseOnUnload_.add(super.addClickHandler(event -> click()));

releaseOnUnload_.add(addKeyPressHandler(event -> {
char charCode = event.getCharCode();
@@ -58,7 +58,6 @@
import org.rstudio.studio.client.application.ui.LauncherSessionStatus;
import org.rstudio.studio.client.application.ui.appended.ApplicationEndedPopupPanel;
import org.rstudio.studio.client.application.ui.serializationprogress.ApplicationSerializationProgress;
import org.rstudio.studio.client.application.ui.support.SupportPopupMenu;
import org.rstudio.studio.client.common.StudioResources;
import org.rstudio.studio.client.common.mirrors.ChooseMirrorDialog;
import org.rstudio.studio.client.common.repos.SecondaryReposDialog;
@@ -407,7 +406,6 @@ private void ensureStylesInjected()
BuildPaneResources.INSTANCE.styles().ensureInjected();

ProgressDialog.ensureStylesInjected();
SupportPopupMenu.ensureStylesInjected();
SlideLabel.ensureStylesInjected();
ThemedButton.ensureStylesInjected();
ThemedPopupPanel.ensureStylesInjected();

This file was deleted.

This file was deleted.

@@ -60,7 +60,8 @@ public HelpLink(String caption,
DecorativeImage helpImage = new DecorativeImage(new ImageResource2x(ThemeResources.INSTANCE.help2x()));
helpImage.getElement().getStyle().setMarginRight(4, Unit.PX);
helpPanel.add(helpImage);
helpLink_ = new HyperlinkLabel(caption, () -> {
helpLink_ = new HyperlinkLabel(caption, () ->
{
if (isRStudioLink_) {
RStudioGinjector.INSTANCE.getGlobalDisplay().openRStudioLink(
link_,
@@ -15,7 +15,6 @@

package org.rstudio.studio.client.common.rstudioapi;

import com.google.gwt.user.client.Command;
import org.rstudio.core.client.ElementIds;
import org.rstudio.core.client.MessageDisplay;
import org.rstudio.core.client.MessageDisplay.PromptWithOptionResult;
@@ -94,14 +93,9 @@ private void showDialog(String caption,

if (!StringUtil.isNullOrEmpty(url))
{
HyperlinkLabel link = new HyperlinkLabel(url, new Command() {
@Override
public void execute()
{
RStudioGinjector.INSTANCE.getGlobalDisplay()
.openWindow(url);
}

HyperlinkLabel link = new HyperlinkLabel(url, () ->
{
RStudioGinjector.INSTANCE.getGlobalDisplay().openWindow(url);
});
link.addStyleName(RES.styles().installLink());
verticalPanel.add(link);
@@ -60,9 +60,8 @@ public SshKeyWidget(GitServerOperations server, String textWidth)
HasHorizontalAlignment.ALIGN_LEFT);

HorizontalPanel linkPanel = new HorizontalPanel();
publicKeyLink_ = new HyperlinkLabel("View public key");
publicKeyLink_ = new HyperlinkLabel("View public key", () -> viewPublicKey());
publicKeyLink_.addStyleName(RES.styles().viewPublicKeyLink());
publicKeyLink_.addClickHandler(event -> viewPublicKey());
linkPanel.add(publicKeyLink_);
captionPanel.add(publicKeyLink_);
captionPanel.setCellHorizontalAlignment(
@@ -31,7 +31,6 @@
import org.rstudio.core.client.resources.ImageResource2x;
import org.rstudio.core.client.widget.FileChooserTextBox;
import org.rstudio.core.client.widget.FormLabel;
import org.rstudio.core.client.widget.HyperlinkLabel;
import org.rstudio.core.client.widget.MessageDialog;
import org.rstudio.core.client.widget.TextBoxWithButton;
import org.rstudio.studio.client.application.Desktop;
@@ -110,7 +109,7 @@ public void execute()
onGitExePathChosen);
SessionInfo sessionInfo = session.getSessionInfo();
if (sessionInfo.getAllowVcsExeEdit())
addTextBoxChooser(gitExePathLabel_, null, null, gitExePathChooser_);
addTextBoxChooser(gitExePathLabel_, gitExePathChooser_);

// svn exe path chooser
svnExePathLabel_ = new FormLabel("SVN executable:");
@@ -120,7 +119,7 @@ public void execute()
null,
null);
if (sessionInfo.getAllowVcsExeEdit())
addTextBoxChooser(svnExePathLabel_, null, null, svnExePathChooser_);
addTextBoxChooser(svnExePathLabel_, svnExePathChooser_);

// terminal path
terminalPathLabel_ = new FormLabel("Terminal executable:");
@@ -130,7 +129,7 @@ public void execute()
null,
null);
if (haveTerminalPathPref())
addTextBoxChooser(terminalPathLabel_, null, null, terminalPathChooser_);
addTextBoxChooser(terminalPathLabel_, terminalPathChooser_);

// ssh key widget
sshKeyWidget_ = new SshKeyWidget(server, "330px");
@@ -205,31 +204,18 @@ private boolean haveTerminalPathPref()
return Desktop.isDesktop() && BrowseCap.isLinux();
}

private void addTextBoxChooser(Label captionLabel, HyperlinkLabel link,
String captionPanelStyle, TextBoxWithButton chooser)
private void addTextBoxChooser(Label captionLabel, TextBoxWithButton chooser)
{
String textWidth = "250px";

HorizontalPanel captionPanel = new HorizontalPanel();
captionPanel.setWidth(textWidth);
nudgeRight(captionPanel);
if (captionPanelStyle != null)
captionPanel.addStyleName(captionPanelStyle);

captionPanel.add(captionLabel);
captionPanel.setCellHorizontalAlignment(captionLabel,
HasHorizontalAlignment.ALIGN_LEFT);

if (link != null)
{
HorizontalPanel linkPanel = new HorizontalPanel();
linkPanel.add(link);
captionPanel.add(linkPanel);
captionPanel.setCellHorizontalAlignment(linkPanel,
HasHorizontalAlignment.ALIGN_RIGHT);

}

add(tight(captionPanel));

chooser.setTextWidth(textWidth);

0 comments on commit 13c33fd

Please sign in to comment.
You can’t perform that action at this time.