diff --git a/platform/platform-api/src/com/intellij/ui/AbstractFieldPanel.java b/platform/platform-api/src/com/intellij/ui/AbstractFieldPanel.java index 0dde015809a9..dd034534dd60 100644 --- a/platform/platform-api/src/com/intellij/ui/AbstractFieldPanel.java +++ b/platform/platform-api/src/com/intellij/ui/AbstractFieldPanel.java @@ -1,26 +1,29 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package com.intellij.ui; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonShortcuts; +import com.intellij.openapi.actionSystem.CustomShortcutSet; +import com.intellij.openapi.application.Experiments; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.FixedSizeButton; import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.ui.components.fields.ExtendableTextField; import com.intellij.util.PlatformIcons; import org.jetbrains.annotations.NotNull; @@ -29,6 +32,8 @@ import javax.swing.event.DocumentEvent; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.util.ArrayList; /** @@ -116,12 +121,39 @@ public abstract class AbstractFieldPanel extends JPanel { this.add(myComponent, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); if (myBrowseButtonActionListener != null) { - FixedSizeButton browseButton = new FixedSizeButton(getComponent()); - myDoClickAction = new TextFieldWithBrowseButton.MyDoClickAction(browseButton); - browseButton.setFocusable(false); - browseButton.addActionListener(myBrowseButtonActionListener); - myButtons.add(browseButton); - this.add(browseButton, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 0), 0, 0)); + if (Experiments.isFeatureEnabled("inline.browse.button") && myComponent instanceof ExtendableTextField) { + ExtendableTextField.Extension action = new ExtendableTextField.Extension() { + @Override + public Icon getIcon(boolean hovered) { + return hovered ? AllIcons.General.OpenDiskHover : AllIcons.General.OpenDisk; + } + + @Override + public String getTooltip() { + return UIBundle.message("component.with.browse.button.browse.button.tooltip.text"); + } + + @Override + public Runnable getActionOnClick() { + return () -> myBrowseButtonActionListener.actionPerformed(new ActionEvent(myComponent, ActionEvent.ACTION_PERFORMED, "action")); + } + }; + ((ExtendableTextField)myComponent).addExtension(action); + new DumbAwareAction() { + @Override + public void actionPerformed(AnActionEvent e) { + action.getActionOnClick().run(); + } + }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myComponent); + + } else { + FixedSizeButton browseButton = new FixedSizeButton(getComponent()); + myDoClickAction = new TextFieldWithBrowseButton.MyDoClickAction(browseButton); + browseButton.setFocusable(false); + browseButton.addActionListener(myBrowseButtonActionListener); + myButtons.add(browseButton); + this.add(browseButton, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 0), 0, 0)); + } } if (myViewerDialogTitle != null) { final FixedSizeButton showViewerButton = new FixedSizeButton(getComponent()); diff --git a/platform/platform-api/src/com/intellij/ui/FieldPanel.java b/platform/platform-api/src/com/intellij/ui/FieldPanel.java index 13f6e94759ce..a1acec2724c2 100644 --- a/platform/platform-api/src/com/intellij/ui/FieldPanel.java +++ b/platform/platform-api/src/com/intellij/ui/FieldPanel.java @@ -1,22 +1,20 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package com.intellij.ui; import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.ui.components.JBTextField; +import com.intellij.ui.components.fields.ExtendableTextField; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -26,7 +24,7 @@ public class FieldPanel extends AbstractFieldPanel implements TextAccessor { private final JTextField myTextField; public FieldPanel() { - this(new JBTextField(30)); + this(new ExtendableTextField(30)); } protected FieldPanel(JTextField textField) { @@ -36,7 +34,7 @@ public class FieldPanel extends AbstractFieldPanel implements TextAccessor { } public FieldPanel(String labelText, final String viewerDialogTitle, ActionListener browseButtonActionListener, final Runnable documentListener) { - this(new JBTextField(30), labelText, viewerDialogTitle, browseButtonActionListener, documentListener); + this(new ExtendableTextField(30), labelText, viewerDialogTitle, browseButtonActionListener, documentListener); } public FieldPanel(JTextField textField, String labelText, final String viewerDialogTitle, ActionListener browseButtonActionListener, final Runnable documentListener) {