mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix: browse button in the HgSetExecutableDialog. Made a common class for path selector - HgSetExecutablePathPanel.
This commit is contained in:
@@ -22,8 +22,8 @@ hg4idea.revert=Revert
|
||||
hg4idea.commit=Commit
|
||||
|
||||
hg4idea.configuration.title=Mercurial Configuration
|
||||
hg4idea.configuration.description=Path to hg executable
|
||||
hg4idea.configuration.executable.error=\"{0}\" doesn't appear to be a valid hg executable
|
||||
hg4idea.configuration.description=Full path to hg executable
|
||||
hg4idea.configuration.executable.error=\"{0}\" doesn\'t appear to be a valid hg executable
|
||||
|
||||
hg4idea.command.executable.error=Error executing \"{0}\". Make sure you have setup the right executable in Mercurial configuration
|
||||
|
||||
@@ -54,4 +54,3 @@ hg4idea.status.currentBranch.text=<html><b>{0}</b></html>
|
||||
hg4idea.status.currentBranch.description=<html>Current mercurial branch</html>
|
||||
hg4idea.warning.no-default-update-path=Skipped \"{0}\". No default update path.
|
||||
hg4idea.merge.please-commit=Merged heads, please commit repository \"{0}\"
|
||||
hg4idea.error.invalidExecutable=\"{0}\" is not a valid mercurial executable
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<text value="&Specify executable path"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42f2c" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="pathSelector">
|
||||
<component id="42f2c" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="pathSelector" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="100" height="-1"/>
|
||||
|
||||
@@ -45,14 +45,6 @@ public class HgConfigurationIdePanel {
|
||||
this.globalSettings = globalSettings;
|
||||
loadSettings();
|
||||
|
||||
String title = HgVcsMessages.message("hg4idea.configuration.title");
|
||||
String description = HgVcsMessages.message("hg4idea.configuration.description");
|
||||
|
||||
pathSelector.addBrowseFolderListener(
|
||||
title, description, null,
|
||||
new FileChooserDescriptor(true, false, false, false, false, false)
|
||||
);
|
||||
|
||||
final ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
pathSelector.setEnabled(selectRadioButton.isSelected());
|
||||
@@ -109,54 +101,7 @@ public class HgConfigurationIdePanel {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// GUI initializer generated by IntelliJ IDEA GUI Designer
|
||||
// >>> IMPORTANT!! <<<
|
||||
// DO NOT EDIT OR ADD ANY CODE HERE!
|
||||
$$$setupUI$$$();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer
|
||||
* >>> IMPORTANT!! <<<
|
||||
* DO NOT edit this method OR call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
basePanel = new JPanel();
|
||||
basePanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
final JPanel panel1 = new JPanel();
|
||||
panel1.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
|
||||
basePanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
|
||||
panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Path to hg executable"));
|
||||
autoRadioButton = new JRadioButton();
|
||||
autoRadioButton.setSelected(true);
|
||||
autoRadioButton.setText("Autodetect hg in PATH");
|
||||
autoRadioButton.setMnemonic('A');
|
||||
autoRadioButton.setDisplayedMnemonicIndex(0);
|
||||
panel1.add(autoRadioButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
selectRadioButton = new JRadioButton();
|
||||
selectRadioButton.setEnabled(true);
|
||||
selectRadioButton.setText("Specify executable path");
|
||||
selectRadioButton.setMnemonic('S');
|
||||
selectRadioButton.setDisplayedMnemonicIndex(0);
|
||||
panel1.add(selectRadioButton, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
pathSelector = new TextFieldWithBrowseButton();
|
||||
pathSelector.setEnabled(false);
|
||||
panel1.add(pathSelector, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, new Dimension(100, -1), null, null, 0, false));
|
||||
final Spacer spacer1 = new Spacer();
|
||||
basePanel.add(spacer1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
|
||||
ButtonGroup buttonGroup;
|
||||
buttonGroup = new ButtonGroup();
|
||||
buttonGroup.add(autoRadioButton);
|
||||
buttonGroup.add(selectRadioButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return basePanel;
|
||||
private void createUIComponents() {
|
||||
pathSelector = new HgSetExecutablePathPanel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="40fef" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="hgExecutablePath">
|
||||
<component id="c91cc" class="org.zmlx.hg4idea.ui.HgSetExecutablePathPanel" binding="hgExecutablePath" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="9" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="400" height="-1"/>
|
||||
@@ -21,7 +21,7 @@
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Full path to hg executable or 'hg' if PATH has it:"/>
|
||||
<text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.configuration.description"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c771f" class="javax.swing.JLabel" binding="errorLabel">
|
||||
@@ -31,7 +31,7 @@
|
||||
<properties>
|
||||
<font style="2"/>
|
||||
<foreground awt-color="red"/>
|
||||
<text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.error.invalidExecutable"/>
|
||||
<text resource-bundle="org/zmlx/hg4idea/HgVcsMessages" key="hg4idea.configuration.executable.error"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="4c273">
|
||||
|
||||
@@ -14,24 +14,15 @@ package org.zmlx.hg4idea.ui;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.uiDesigner.core.GridConstraints;
|
||||
import com.intellij.uiDesigner.core.GridLayoutManager;
|
||||
import com.intellij.uiDesigner.core.Spacer;
|
||||
import org.zmlx.hg4idea.HgVcsMessages;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import java.util.ResourceBundle;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class HgSetExecutableDialog extends DialogWrapper {
|
||||
private JPanel centerPanel;
|
||||
private TextFieldWithBrowseButton hgExecutablePath;
|
||||
private HgSetExecutablePathPanel hgExecutablePath;
|
||||
private JLabel infoLabel;
|
||||
private JLabel errorLabel;
|
||||
|
||||
@@ -47,76 +38,19 @@ public class HgSetExecutableDialog extends DialogWrapper {
|
||||
|
||||
public void setBadHgPath(String hgPath) {
|
||||
hgExecutablePath.setText(hgPath);
|
||||
errorLabel.setText(HgVcsMessages.message("hg4idea.error.invalidExecutable", hgPath));
|
||||
errorLabel.setText(HgVcsMessages.message("hg4idea.configuration.executable.error", hgPath));
|
||||
}
|
||||
|
||||
public String getNewHgPath() {
|
||||
return hgExecutablePath.getText();
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// GUI initializer generated by IntelliJ IDEA GUI Designer
|
||||
// >>> IMPORTANT!! <<<
|
||||
// DO NOT EDIT OR ADD ANY CODE HERE!
|
||||
$$$setupUI$$$();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer
|
||||
* >>> IMPORTANT!! <<<
|
||||
* DO NOT edit this method OR call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
centerPanel = new JPanel();
|
||||
centerPanel.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||
hgExecutablePath = new TextFieldWithBrowseButton();
|
||||
centerPanel.add(hgExecutablePath, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(400, -1), null, 0, false));
|
||||
infoLabel = new JLabel();
|
||||
infoLabel.setText("Full path to hg executable or 'hg' if PATH has it:");
|
||||
centerPanel.add(infoLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
errorLabel = new JLabel();
|
||||
errorLabel.setFont(new Font(errorLabel.getFont().getName(), Font.ITALIC, errorLabel.getFont().getSize()));
|
||||
errorLabel.setForeground(Color.red);
|
||||
this.$$$loadLabelText$$$(errorLabel, ResourceBundle.getBundle("org/zmlx/hg4idea/HgVcsMessages").getString("hg4idea.error.invalidExecutable"));
|
||||
centerPanel.add(errorLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
final Spacer spacer1 = new Spacer();
|
||||
centerPanel.add(spacer1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$loadLabelText$$$(JLabel component, String text) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
boolean haveMnemonic = false;
|
||||
char mnemonic = '\0';
|
||||
int mnemonicIndex = -1;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (text.charAt(i) == '&') {
|
||||
i++;
|
||||
if (i == text.length()) break;
|
||||
if (!haveMnemonic && text.charAt(i) != '&') {
|
||||
haveMnemonic = true;
|
||||
mnemonic = text.charAt(i);
|
||||
mnemonicIndex = result.length();
|
||||
}
|
||||
private void createUIComponents() {
|
||||
hgExecutablePath = new HgSetExecutablePathPanel();
|
||||
hgExecutablePath.addOKListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
errorLabel.setText("");
|
||||
}
|
||||
result.append(text.charAt(i));
|
||||
}
|
||||
component.setText(result.toString());
|
||||
if (haveMnemonic) {
|
||||
component.setDisplayedMnemonic(mnemonic);
|
||||
component.setDisplayedMnemonicIndex(mnemonicIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return centerPanel;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.zmlx.hg4idea.ui;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.zmlx.hg4idea.HgVcsMessages;
|
||||
import org.zmlx.hg4idea.command.HgVersionCommand;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* HgSetExecutablePathPanel is a {@link com.intellij.openapi.ui.TextFieldWithBrowseButton}, which opens a file chooser for hg executable
|
||||
* and checks validity of the selected file to be an hg executable.
|
||||
*/
|
||||
class HgSetExecutablePathPanel extends TextFieldWithBrowseButton {
|
||||
|
||||
private Set<ActionListener> okListeners = new HashSet<ActionListener>();
|
||||
|
||||
HgSetExecutablePathPanel() {
|
||||
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
|
||||
public void validateSelectedFiles(VirtualFile[] files) throws Exception {
|
||||
HgVersionCommand command = new HgVersionCommand();
|
||||
String path = files[0].getPath();
|
||||
if (!command.isValid(path)) {
|
||||
throw new ConfigurationException(HgVcsMessages.message("hg4idea.configuration.executable.error", path));
|
||||
}
|
||||
for (ActionListener okListener : okListeners) {
|
||||
okListener.actionPerformed(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
addBrowseFolderListener(HgVcsMessages.message("hg4idea.configuration.title"), HgVcsMessages.message("hg4idea.configuration.description"), null, descriptor);
|
||||
}
|
||||
|
||||
void addOKListener(ActionListener listener) {
|
||||
okListeners.add(listener);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user