diff --git a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties
index 427f9c831216..ac8b6431e4c2 100644
--- a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties
+++ b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties
@@ -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={0}
hg4idea.status.currentBranch.description=Current mercurial branch
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
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.form
index 79ffd1b867bb..4dcb91491827 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.form
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.form
@@ -34,7 +34,7 @@
-
+
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.java
index 4759010fdcf3..0fdacc8fe5ce 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationIdePanel.java
@@ -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();
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.form
index 2a0505454315..5a5ecc9f5bb2 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.form
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.form
@@ -8,7 +8,7 @@
-
+
@@ -21,7 +21,7 @@
-
+
@@ -31,7 +31,7 @@
-
+
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.java
index bf0d3df8cdc5..127b91943ca3 100644
--- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.java
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutableDialog.java
@@ -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;
+ });
}
}
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutablePathPanel.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutablePathPanel.java
new file mode 100644
index 000000000000..bbf397d7a4ef
--- /dev/null
+++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSetExecutablePathPanel.java
@@ -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 okListeners = new HashSet();
+
+ 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);
+ }
+
+}