IDEA-62095 Unable to import to subversion using "share" - add commit message prefix into the share dialog

This commit is contained in:
irengrig
2012-09-14 14:18:10 +04:00
parent dc7fe587d8
commit 4cfcc3b26e
13 changed files with 236 additions and 63 deletions
@@ -29,11 +29,11 @@ public class SeparatorFactory {
}
@Deprecated
public static JComponent createSeparator(String textWithMnemonic, @Nullable JComponent labelFor, boolean boldFont, boolean smallFont) {
public static TitledSeparatorWithMnemonic createSeparator(String textWithMnemonic, @Nullable JComponent labelFor, boolean boldFont, boolean smallFont) {
return new TitledSeparatorWithMnemonic(textWithMnemonic, labelFor);
}
public static JComponent createSeparator(String textWithMnemonic, @Nullable JComponent labelFor) {
public static TitledSeparatorWithMnemonic createSeparator(String textWithMnemonic, @Nullable JComponent labelFor) {
return new TitledSeparatorWithMnemonic(textWithMnemonic, labelFor);
}
@@ -0,0 +1,48 @@
/*
* Copyright 2000-2012 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.openapi.vcs;
import com.intellij.openapi.actionSystem.TypeSafeDataProvider;
import javax.swing.*;
import java.awt.*;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 9/14/12
* Time: 11:46 AM
*/
public abstract class AbstractDataProviderPanel extends JPanel implements TypeSafeDataProvider {
public AbstractDataProviderPanel(GridBagLayout layout) {
super(layout);
}
protected AbstractDataProviderPanel(LayoutManager layout, boolean isDoubleBuffered) {
super(layout, isDoubleBuffered);
}
protected AbstractDataProviderPanel(LayoutManager layout) {
super(layout);
}
protected AbstractDataProviderPanel(boolean isDoubleBuffered) {
super(isDoubleBuffered);
}
protected AbstractDataProviderPanel() {
}
}
@@ -29,9 +29,9 @@ import java.util.Collection;
* included in the checkin operation, getting/setting the commit message and so on).
* The active check-in dialog can be retrieved from the using {@link Refreshable#PANEL_KEY}
*
* @see com.intellij.openapi.vcs.checkin.BaseCheckinHandlerFactory#createHandler(CheckinProjectPanel, CommitContext)
* @see com.intellij.openapi.vcs.checkin.BaseCheckinHandlerFactory#createHandler(CommitMessageI, CommitContext)
*/
public interface CheckinProjectPanel extends Refreshable {
public interface CheckinProjectPanel extends Refreshable, CommitMessageI {
JComponent getComponent();
JComponent getPreferredFocusedComponent();
@@ -83,13 +83,6 @@ public interface CheckinProjectPanel extends Refreshable {
*/
Collection<VirtualFile> getRoots();
/**
* Sets the description for the check-in.
*
* @param currentDescription the description text.
*/
void setCommitMessage(final String currentDescription);
void setWarning(final String s);
/**
@@ -101,16 +94,4 @@ public interface CheckinProjectPanel extends Refreshable {
String getCommitMessage();
String getCommitActionName();
/**
* @return <code>true</code> if commit message is checked for spelling errors; <code>false</code> otherwise
*/
boolean isCheckCommitMessageSpelling();
/**
* Allows to define whether commit message should be checked for spelling errors.
*
* @param checkSpelling <code>true</code> if commit message should be checked for spelling errors; <code>false</code> otherwise
*/
void setCheckCommitMessageSpelling(boolean checkSpelling);
}
@@ -0,0 +1,43 @@
/*
* Copyright 2000-2012 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.openapi.vcs;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 9/14/12
* Time: 11:25 AM
*/
public interface CommitMessageI {
/**
* @return <code>true</code> if commit message is checked for spelling errors; <code>false</code> otherwise
*/
boolean isCheckSpelling();
/**
* Allows to define whether commit message should be checked for spelling errors.
*
* @param checkSpelling <code>true</code> if commit message should be checked for spelling errors; <code>false</code> otherwise
*/
void setCheckSpelling(boolean checkSpelling);
/**
* Sets the description for the check-in.
*
* @param currentDescription the description text.
*/
void setCommitMessage(String currentDescription);
}
@@ -59,4 +59,5 @@ public interface VcsDataKeys {
DataKey<Object> LABEL_BEFORE = DataKey.create("LABEL_BEFORE");
DataKey<Object> LABEL_AFTER = DataKey.create("LABEL_AFTER");
DataKey<String> PRESET_COMMIT_MESSAGE = DataKey.create("PRESET_COMMIT_MESSAGE");
DataKey<CommitMessageI> COMMIT_MESSAGE_CONTROL = DataKey.create("COMMIT_MESSAGE_CONTROL");
}
@@ -3,7 +3,8 @@ package com.intellij.openapi.vcs.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.CommitMessageI;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.ui.Refreshable;
import org.jetbrains.annotations.Nullable;
@@ -21,26 +22,30 @@ public class CheckCommitMessageSpellingAction extends ToggleAction implements Du
@Override
public boolean isSelected(AnActionEvent e) {
CheckinProjectPanel checkinPanel = getCheckinPanel(e);
return checkinPanel == null || checkinPanel.isCheckCommitMessageSpelling();
CommitMessageI checkinPanel = getCheckinPanel(e);
return checkinPanel != null && checkinPanel.isCheckSpelling();
}
@Override
public void setSelected(AnActionEvent e, boolean state) {
CheckinProjectPanel checkinPanel = getCheckinPanel(e);
CommitMessageI checkinPanel = getCheckinPanel(e);
if (checkinPanel != null) {
checkinPanel.setCheckCommitMessageSpelling(state);
checkinPanel.setCheckSpelling(state);
}
}
@Nullable
private static CheckinProjectPanel getCheckinPanel(@Nullable AnActionEvent e) {
private static CommitMessageI getCheckinPanel(@Nullable AnActionEvent e) {
if (e == null) {
return null;
}
Refreshable data = Refreshable.PANEL_KEY.getData(e.getDataContext());
if (data instanceof CheckinProjectPanel) {
return (CheckinProjectPanel)data;
if (data instanceof CommitMessageI) {
return (CommitMessageI)data;
}
CommitMessageI commitMessageI = VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.getDataContext());
if (commitMessageI != null) {
return commitMessageI;
}
return null;
}
@@ -17,12 +17,13 @@ package com.intellij.openapi.vcs.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.actions.ContentChooser;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.ui.Refreshable;
import java.util.ArrayList;
import java.util.Collections;
@@ -44,24 +45,32 @@ public class ShowMessageHistoryAction extends AnAction implements DumbAware {
public void update(AnActionEvent e) {
super.update(e);
final CheckinProjectPanel panel = (CheckinProjectPanel)CheckinProjectPanel.PANEL_KEY.getData(e.getDataContext());
final DataContext dc = e.getDataContext();
final Project project = PlatformDataKeys.PROJECT.getData(dc);
Object panel = CheckinProjectPanel.PANEL_KEY.getData(dc);
if (! (panel instanceof CommitMessageI)) {
panel = VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(dc);
}
if (panel == null) {
if (project == null || panel == null) {
e.getPresentation().setVisible(false);
e.getPresentation().setEnabled(false);
}
else {
e.getPresentation().setVisible(true);
final ArrayList<String> recentMessages = VcsConfiguration.getInstance(panel.getProject()).getRecentMessages();
final ArrayList<String> recentMessages = VcsConfiguration.getInstance(project).getRecentMessages();
e.getPresentation().setEnabled(!recentMessages.isEmpty());
}
}
public void actionPerformed(AnActionEvent e) {
final CheckinProjectPanel panel = (CheckinProjectPanel)CheckinProjectPanel.PANEL_KEY.getData(e.getDataContext());
CommitMessageI commitMessageI;
final DataContext dc = e.getDataContext();
final Project project = PlatformDataKeys.PROJECT.getData(dc);
final Refreshable panel = CheckinProjectPanel.PANEL_KEY.getData(dc);
commitMessageI = (panel instanceof CommitMessageI) ? (CommitMessageI)panel : VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(dc);
if (panel != null) {
final Project project = panel.getProject();
if (commitMessageI != null && project != null) {
final VcsConfiguration configuration = VcsConfiguration.getInstance(project);
@@ -90,7 +99,7 @@ public class ShowMessageHistoryAction extends AnAction implements DumbAware {
final int selectedIndex = contentChooser.getSelectedIndex();
if (selectedIndex >= 0) {
panel.setCommitMessage(contentChooser.getAllContents().get(selectedIndex));
commitMessageI.setCommitMessage(contentChooser.getAllContents().get(selectedIndex));
}
}
}
@@ -780,13 +780,13 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
}
@Override
public boolean isCheckCommitMessageSpelling() {
public boolean isCheckSpelling() {
VcsConfiguration configuration = VcsConfiguration.getInstance(myProject);
return configuration == null || configuration.CHECK_COMMIT_MESSAGE_SPELLING;
}
@Override
public void setCheckCommitMessageSpelling(boolean checkSpelling) {
public void setCheckSpelling(boolean checkSpelling) {
VcsConfiguration configuration = VcsConfiguration.getInstance(myProject);
if (configuration != null) {
configuration.CHECK_COMMIT_MESSAGE_SPELLING = checkSpelling;
@@ -25,12 +25,8 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.ui.EditorCustomization;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.EditorTextFieldProvider;
import com.intellij.ui.SeparatorFactory;
import com.intellij.openapi.vcs.*;
import com.intellij.ui.*;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.Nullable;
@@ -39,12 +35,14 @@ import java.awt.*;
import java.util.EnumSet;
import java.util.Set;
public class CommitMessage extends JPanel implements Disposable {
public class CommitMessage extends AbstractDataProviderPanel implements Disposable, CommitMessageI {
public static final Key<DataContext> DATA_CONTEXT_KEY = Key.create("commit message data context");
private final EditorTextField myEditorField;
private final Project myProject;
private Consumer<String> myMessageConsumer;
private final TitledSeparatorWithMnemonic mySeparator;
private boolean myCheckSpelling;
public CommitMessage(Project project) {
super(new BorderLayout());
@@ -64,9 +62,9 @@ public class CommitMessage extends JPanel implements Disposable {
JPanel labelPanel = new JPanel(new BorderLayout());
labelPanel.setBorder(BorderFactory.createEmptyBorder());
JComponent separator = SeparatorFactory.createSeparator(VcsBundle.message("label.commit.comment"), myEditorField.getComponent(), true, true);
mySeparator = SeparatorFactory.createSeparator(VcsBundle.message("label.commit.comment"), myEditorField.getComponent(), true, true);
JPanel separatorPanel = new JPanel(new BorderLayout());
separatorPanel.add(separator, BorderLayout.SOUTH);
separatorPanel.add(mySeparator, BorderLayout.SOUTH);
separatorPanel.add(Box.createVerticalGlue(), BorderLayout.NORTH);
labelPanel.add(separatorPanel, BorderLayout.CENTER);
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, getToolbarActions(), true);
@@ -79,6 +77,22 @@ public class CommitMessage extends JPanel implements Disposable {
setBorder(BorderFactory.createEmptyBorder());
}
@Override
public void calcData(DataKey key, DataSink sink) {
if (key.is(VcsDataKeys.COMMIT_MESSAGE_CONTROL.getName())) {
sink.put(VcsDataKeys.COMMIT_MESSAGE_CONTROL, this);
}
}
public void setSeparatorText(final String text) {
mySeparator.setText(text);
}
@Override
public void setCommitMessage(String currentDescription) {
setText(currentDescription);
}
private static EditorTextField createEditorField(final Project project, final boolean checkSpelling) {
EditorTextField editorField = createCommitTextEditor(project, checkSpelling);
editorField.getDocument().putUserData(DATA_CONTEXT_KEY, DataManager.getInstance().getDataContext(editorField.getComponent()));
@@ -130,7 +144,13 @@ public class CommitMessage extends JPanel implements Disposable {
myEditorField.selectAll();
}
@Override
public boolean isCheckSpelling() {
return myCheckSpelling;
}
public void setCheckSpelling(boolean check) {
myCheckSpelling = check;
Editor editor = myEditorField.getEditor();
if (!(editor instanceof EditorEx)) {
return;
@@ -484,7 +484,7 @@ copy.dialog.title=Branch or Tag
move.dialog.title=Move or Rename
select.location.invalid.url.message=Invalid Subversion repository URL: ''{0}''
share.directory.action=Share Directory...
share.directory.commit.message=Directory ''{0}'' created by {1}
share.directory.commit.message={2}\nDirectory ''{0}'' created by {1}
share.directory.title=Share Directory
share.directory.info.message=To complete share operation commit ''{0}''.
share.directory.create.dir.progress.text=Creating remote folder {0}
@@ -136,23 +136,23 @@ public class ShareProjectAction extends BasicAction {
final SVNURL parenUrl = SVNURL.parseURIEncoded(parent);
final SVNURL checkoutUrl;
final SVNRevision revision;
final String commitText = shareDialog.getCommitText();
if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) {
checkoutUrl = parenUrl;
revision = SVNRevision.HEAD;
} else if (ShareDialog.ShareTarget.useProjectName.equals(shareTarget)) {
final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl, file.getName());
final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl, file.getName(), commitText);
revision = pair.getFirst();
checkoutUrl = pair.getSecond();
} else {
final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl, file.getName());
final Pair<SVNRevision, SVNURL> trunkPair = createRemoteFolder(activeVcs, pair.getSecond(), "trunk");
final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl, file.getName(), commitText);
final Pair<SVNRevision, SVNURL> trunkPair = createRemoteFolder(activeVcs, pair.getSecond(), "trunk", commitText);
checkoutUrl = trunkPair.getSecond();
revision = trunkPair.getFirst();
if (shareDialog.createStandardStructure()) {
createRemoteFolder(activeVcs, pair.getSecond(), "branches");
createRemoteFolder(activeVcs, pair.getSecond(), "tags");
createRemoteFolder(activeVcs, pair.getSecond(), "branches", commitText);
createRemoteFolder(activeVcs, pair.getSecond(), "tags", commitText);
}
}
@@ -215,7 +215,10 @@ public class ShareProjectAction extends BasicAction {
return folderEmpty[0];
}
private static Pair<SVNRevision, SVNURL> createRemoteFolder(final SvnVcs vcs, final SVNURL parent, final String folderName) throws SVNException {
private static Pair<SVNRevision, SVNURL> createRemoteFolder(final SvnVcs vcs,
final SVNURL parent,
final String folderName,
String commitText) throws SVNException {
SVNURL url = parent.appendPath(folderName, false);
final String urlText = url.toString();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
@@ -225,7 +228,7 @@ public class ShareProjectAction extends BasicAction {
}
final SVNCommitInfo info =
vcs.createCommitClient().doMkDir(new SVNURL[]{url}, SvnBundle.message("share.directory.commit.message", folderName,
ApplicationNamesInfo.getInstance().getFullProductName()));
ApplicationNamesInfo.getInstance().getFullProductName(), commitText));
return new Pair<SVNRevision, SVNURL>(SVNRevision.create(info.getNewRevision()), url);
}
@@ -85,7 +85,7 @@ import java.util.Map;
public class RepositoryBrowserDialog extends DialogWrapper {
private final Project myProject;
private final SvnVcs myVCS;
protected final SvnVcs myVCS;
private RepositoryBrowserComponent myRepositoryBrowser;
@NonNls public static final String COPY_OF_PREFIX = "CopyOf";
@@ -18,7 +18,13 @@ package org.jetbrains.idea.svn.dialogs;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionPopupMenu;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.ui.EditChangelistSupport;
import com.intellij.openapi.vcs.ui.CommitMessage;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -26,6 +32,8 @@ import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.text.MessageFormat;
public class ShareDialog extends RepositoryBrowserDialog {
@@ -40,6 +48,8 @@ public class ShareDialog extends RepositoryBrowserDialog {
private JRadioButton mySameNameAsLocal;
private JRadioButton myTrunk;
private JCheckBox myCreateStandard;
private CommitMessage myCommitMessage;
private JComponent myPrefferedFocused;
public ShareDialog(Project project, final String name) {
super(project, false, "Point to repository location");
@@ -50,6 +60,7 @@ public class ShareDialog extends RepositoryBrowserDialog {
myTrunk.setToolTipText(MessageFormat.format(ourStandart, myName));
myRepositoriesLabel.setFont(myRepositoriesLabel.getFont().deriveFont(Font.BOLD));
myPrefferedFocused = (JComponent) getRepositoryBrowser().getPreferredFocusedComponent();
}
public void init() {
@@ -67,6 +78,12 @@ public class ShareDialog extends RepositoryBrowserDialog {
});
getOKAction().setEnabled(getRepositoryBrowser().getSelectedURL() != null);
((RepositoryTreeModel) getRepositoryBrowser().getRepositoryTree().getModel()).setShowFiles(false);
getRepositoryBrowser().getPreferredFocusedComponent().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
myPrefferedFocused = (JComponent)getRepositoryBrowser().getPreferredFocusedComponent();
}
});
}
private void updateOptionsTexts(String selectedURL) {
@@ -88,6 +105,11 @@ public class ShareDialog extends RepositoryBrowserDialog {
myCreateStandard.setEnabled(enabled && myTrunk.isSelected());
}
@Override
public JComponent getPreferredFocusedComponent() {
return myPrefferedFocused;
}
protected Action[] createActions() {
return new Action[] {getOKAction(), getCancelAction(), getHelpAction()};
}
@@ -130,8 +152,9 @@ public class ShareDialog extends RepositoryBrowserDialog {
wrapper.add(repositoryPanel, gb);
++ gb.gridy;
gb.fill = GridBagConstraints.NONE;
gb.weightx = 0;
gb.weightx = 1;
gb.weighty = 0;
gb.fill = GridBagConstraints.HORIZONTAL;
wrapper.add(createFolderPanel(), gb);
return wrapper;
}
@@ -150,7 +173,30 @@ public class ShareDialog extends RepositoryBrowserDialog {
return myCreateStandard.isSelected();
}
public String getCommitText() {
return myCommitMessage.getComment();
}
private JComponent createFolderPanel() {
final Project project = myVCS.getProject();
myCommitMessage = new CommitMessage(project) {
@Override
public Dimension getPreferredSize() {
final Dimension superValue = super.getPreferredSize();
return new Dimension(superValue.width, superValue.height > 90 ? superValue.height : 90);
}
@Override
public void addNotify() {
super.addNotify();
myCommitMessage.getEditorField().getFocusTarget().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
myPrefferedFocused = myCommitMessage.getEditorField();
}
});
}
};
final JPanel panel = new JPanel(new GridBagLayout());
final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(1, 1, 1, 1), 0, 0);
@@ -190,6 +236,23 @@ public class ShareDialog extends RepositoryBrowserDialog {
gb.insets.left = 10;
panel.add(myCreateStandard, gb);
++ gb.gridy;
gb.gridx = 0;
gb.insets.top = 1;
gb.insets.left = 1;
gb.weightx = 1;
gb.fill = GridBagConstraints.HORIZONTAL;
final LocalChangeList list = ChangeListManager.getInstance(project).getDefaultChangeList();
String text = list.getComment();
text = StringUtil.isEmptyOrSpaces(text) ? (list.hasDefaultName() ? "" : list.getName()) : text;
myCommitMessage.setText(text);
panel.add(myCommitMessage, gb);
myCommitMessage.setSeparatorText("Commit Comment Prefix");
for (EditChangelistSupport support : Extensions.getExtensions(EditChangelistSupport.EP_NAME, project)) {
support.installSearch(myCommitMessage.getEditorField(), myCommitMessage.getEditorField());
}
myTrunk.setSelected(true);
return panel;