diff options
Diffstat (limited to 'plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectLocationDialog.java')
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectLocationDialog.java | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectLocationDialog.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectLocationDialog.java index a6ca6ad54f11..bcbbe79c1b45 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectLocationDialog.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectLocationDialog.java @@ -15,12 +15,15 @@ */ package org.jetbrains.idea.svn.dialogs; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -52,21 +55,30 @@ public class SelectLocationDialog extends DialogWrapper { private final String myDstLabel; private JTextField myDstText; private final boolean myIsShowFiles; + private final boolean myAllowActions; @NonNls private static final String HELP_ID = "vcs.subversion.common"; // todo check that works when authenticated @Nullable public static String selectLocation(Project project, String url) { - SelectLocationDialog dialog = openDialog(project, url, null, null, true, null); + SelectLocationDialog dialog = openDialog(project, url, null, null, true, false, null); return dialog == null || !dialog.isOK() ? null : dialog.getSelectedURL(); } @Nullable + public static Pair<String, SVNURL> selectLocation(Project project, @NotNull SVNURL url) { + SelectLocationDialog dialog = new SelectLocationDialog(project, url, null, null, true, true); + dialog.show(); + + return dialog.isOK() ? Pair.create(dialog.getSelectedURL(), dialog.getRootUrl()) : null; + } + + @Nullable public static String selectCopyDestination(Project project, String url, String dstLabel, String dstName, boolean showFiles) { SelectLocationDialog dialog = - openDialog(project, url, dstLabel, dstName, showFiles, SvnBundle.message("select.location.invalid.url.message", url)); + openDialog(project, url, dstLabel, dstName, showFiles, false, SvnBundle.message("select.location.invalid.url.message", url)); return dialog == null || !dialog.isOK() ? null : SVNPathUtil.append(dialog.getSelectedURL(), dialog.getDestinationName()); } @@ -77,6 +89,7 @@ public class SelectLocationDialog extends DialogWrapper { String dstLabel, String dstName, boolean showFiles, + boolean allowActions, String errorMessage) { try { SVNURL svnUrl = SvnUtil.createUrl(url); @@ -86,8 +99,7 @@ public class SelectLocationDialog extends DialogWrapper { SvnBundle.message("dialog.title.select.repository.location")); return null; } - - SelectLocationDialog dialog = new SelectLocationDialog(project, repositoryUrl, dstLabel, dstName, showFiles); + SelectLocationDialog dialog = new SelectLocationDialog(project, repositoryUrl, dstLabel, dstName, showFiles, allowActions); dialog.show(); return dialog; } @@ -98,13 +110,14 @@ public class SelectLocationDialog extends DialogWrapper { } } - private SelectLocationDialog(Project project, SVNURL url, String dstLabel, String dstName, boolean showFiles) { + private SelectLocationDialog(Project project, SVNURL url, String dstLabel, String dstName, boolean showFiles, boolean allowActions) { super(project, true); myProject = project; myDstLabel = dstLabel; myDstName = dstName; myURL = url; myIsShowFiles = showFiles; + myAllowActions = allowActions; setTitle(SvnBundle.message("dialog.title.select.repository.location")); getHelpAction().setEnabled(true); init(); @@ -146,7 +159,13 @@ public class SelectLocationDialog extends DialogWrapper { protected void init() { super.init(); final String urlString = myURL.toString(); - myRepositoryBrowser.setRepositoryURL(myURL, myIsShowFiles, new UrlOpeningExpander.Factory(urlString, urlString)); + if (myAllowActions) { + // initialize repo browser this way - to make actions work correctly + myRepositoryBrowser.setRepositoryURLs(new SVNURL[]{myURL}, myIsShowFiles, new UrlOpeningExpander.Factory(urlString, urlString), true); + } + else { + myRepositoryBrowser.setRepositoryURL(myURL, myIsShowFiles, new UrlOpeningExpander.Factory(urlString, urlString)); + } myRepositoryBrowser.addChangeListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { getOKAction().setEnabled(isOKActionEnabled()); @@ -162,7 +181,10 @@ public class SelectLocationDialog extends DialogWrapper { protected JComponent createCenterPanel() { JPanel panel = new JPanel(); - panel.setLayout(new GridBagLayout()); + panel.setLayout(new BorderLayout()); + + JPanel browserPanel = new JPanel(); + browserPanel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.insets = new Insets(2, 2, 2, 2); @@ -177,7 +199,7 @@ public class SelectLocationDialog extends DialogWrapper { myRepositoryBrowser = new RepositoryBrowserComponent(SvnVcs.getInstance(myProject)); - panel.add(myRepositoryBrowser, gc); + browserPanel.add(myRepositoryBrowser, gc); if (myDstName != null) { gc.gridy += 1; gc.gridwidth = 1; @@ -187,7 +209,7 @@ public class SelectLocationDialog extends DialogWrapper { gc.weighty = 0; JLabel dstLabel = new JLabel(myDstLabel); - panel.add(dstLabel, gc); + browserPanel.add(dstLabel, gc); gc.gridx += 1; gc.weightx = 1; @@ -196,7 +218,7 @@ public class SelectLocationDialog extends DialogWrapper { myDstText = new JTextField(); myDstText.setText(myDstName); myDstText.selectAll(); - panel.add(myDstText, gc); + browserPanel.add(myDstText, gc); myDstText.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { @@ -217,12 +239,25 @@ public class SelectLocationDialog extends DialogWrapper { gc.gridy += 1; gc.gridwidth = 2; - panel.add(new JSeparator(), gc); + browserPanel.add(new JSeparator(), gc); + } + + if (myAllowActions) { + panel.add(createToolbar(), BorderLayout.NORTH); } + panel.add(browserPanel, BorderLayout.CENTER); return panel; } + @NotNull + private JComponent createToolbar() { + DefaultActionGroup group = new DefaultActionGroup(); + group.add(new RepositoryBrowserDialog.EditLocationAction(myRepositoryBrowser)); + + return ActionManager.getInstance().createActionToolbar(RepositoryBrowserDialog.PLACE_TOOLBAR, group, true).getComponent(); + } + public JComponent getPreferredFocusedComponent() { return (JComponent)myRepositoryBrowser.getPreferredFocusedComponent(); } @@ -246,4 +281,16 @@ public class SelectLocationDialog extends DialogWrapper { public String getSelectedURL() { return myRepositoryBrowser.getSelectedURL(); } + + @Nullable + public SVNURL getRootUrl() { + RepositoryTreeNode node = myRepositoryBrowser.getSelectedNode(); + + // find the most top parent of type RepositoryTreeNode + while (node != null && node.getParent() instanceof RepositoryTreeNode) { + node = (RepositoryTreeNode)node.getParent(); + } + + return node != null ? node.getURL() : null; + } } |