mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
CR-IC-2522 BeforeCommitDialogHandler
This commit is contained in:
@@ -59,7 +59,5 @@
|
||||
<extensionPoint name="vcs.rootFinder" interface="com.intellij.openapi.vcs.VcsRootFinder" area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint name="logProvider" interface="com.intellij.vcs.log.VcsLogProvider" area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint name="beforeCommitDialog" interface="com.intellij.openapi.vcs.checkin.BeforeCommitDialogHandler"/>
|
||||
</extensionPoints>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
<applicationService serviceInterface="com.intellij.openapi.vcs.impl.CheckinHandlersManager"
|
||||
serviceImplementation="com.intellij.openapi.vcs.impl.CheckinHandlersManagerImpl"/>
|
||||
<pathMacroFilter implementation="com.intellij.openapi.vcs.VcsPathMacroFilter"/>
|
||||
|
||||
<beforeCommitDialog implementation="com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog$MyBeforeCommitDialogHandler" order="last"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
|
||||
+17
-1
@@ -15,12 +15,28 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.checkin;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.CommitExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BeforeCheckinDialogHandler {
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated see {@link #beforeCommitDialogShown(com.intellij.openapi.project.Project, java.util.List, Iterable, boolean)}
|
||||
* @return false to cancel commit
|
||||
*/
|
||||
public boolean beforeCommitDialogShownCallback(Iterable<CommitExecutor> executors, boolean showVcsCommit) {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false to cancel commit
|
||||
*/
|
||||
public abstract boolean beforeCommitDialogShownCallback(Iterable<CommitExecutor> executors, boolean showVcsCommit);
|
||||
public boolean beforeCommitDialogShown(@NotNull Project project, @NotNull List<Change> changes, @NotNull Iterable<CommitExecutor> executors, boolean showVcsCommit) {
|
||||
//noinspection deprecation
|
||||
return beforeCommitDialogShownCallback(executors, showVcsCommit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.checkin;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.CommitExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BeforeCommitDialogHandler {
|
||||
public static final ExtensionPointName<BeforeCommitDialogHandler> EP_NAME = ExtensionPointName.create("com.intellij.beforeCommitDialog");
|
||||
|
||||
/**
|
||||
* @return false to cancel commit
|
||||
*/
|
||||
public abstract boolean beforeCommitDialogShownCallback(@NotNull Project project,
|
||||
@NotNull List<Change> changes,
|
||||
@NotNull Iterable<CommitExecutor> executors,
|
||||
boolean showVcsCommit);
|
||||
}
|
||||
@@ -23,11 +23,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author irengrig
|
||||
* Date: 1/28/11
|
||||
* Time: 6:00 PM
|
||||
*/
|
||||
public abstract class CheckinHandlersManager {
|
||||
public static CheckinHandlersManager getInstance() {
|
||||
return ServiceManager.getService(CheckinHandlersManager.class);
|
||||
@@ -39,16 +34,29 @@ public abstract class CheckinHandlersManager {
|
||||
*
|
||||
* @return the list of registered factories
|
||||
*/
|
||||
public abstract List<BaseCheckinHandlerFactory> getRegisteredCheckinHandlerFactories(AbstractVcs[] allActiveVcss);
|
||||
public abstract List<BaseCheckinHandlerFactory> getRegisteredCheckinHandlerFactories(AbstractVcs<?>[] allActiveVcss);
|
||||
|
||||
public abstract List<VcsCheckinHandlerFactory> getMatchingVcsFactories(@NotNull final List<AbstractVcs> keys);
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated to remove in IDEA 13
|
||||
*/
|
||||
public abstract List<VcsCheckinHandlerFactory> getMatchingVcsFactories(@NotNull final List<AbstractVcs> keys);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated to remove in IDEA 13, use EP {@link com.intellij.openapi.vcs.checkin.CheckinHandlerFactory#EP_NAME}
|
||||
* Registers a factory which provides callbacks to run before and after VCS checkin operations.
|
||||
*
|
||||
* @param factory the factory to register.
|
||||
*/
|
||||
public abstract void registerCheckinHandlerFactory(BaseCheckinHandlerFactory factory);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Deprecated
|
||||
/**
|
||||
* @deprecated to remove in IDEA 13, use EP {@link com.intellij.openapi.vcs.checkin.CheckinHandlerFactory#EP_NAME}
|
||||
* Unregister a factory which provides callbacks to run before and after VCS checkin operations.
|
||||
*
|
||||
* @param factory the factory to unregister.
|
||||
|
||||
+21
-38
@@ -48,6 +48,8 @@ import com.intellij.ui.SplitterWithSecondHideable;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.OnOffListener;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -142,39 +144,19 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
|
||||
private final MyUpdateButtonsRunnable myUpdateButtonsRunnable = new MyUpdateButtonsRunnable(this);
|
||||
|
||||
static final class MyBeforeCommitDialogHandler extends BeforeCommitDialogHandler {
|
||||
@Override
|
||||
public boolean beforeCommitDialogShownCallback(@NotNull Project project,
|
||||
@NotNull List<Change> changes,
|
||||
@NotNull Iterable<CommitExecutor> executors,
|
||||
boolean showVcsCommit) {
|
||||
List<VcsCheckinHandlerFactory> factoryList = CheckinHandlersManager.getInstance().getMatchingVcsFactories(
|
||||
Arrays.asList(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss()));
|
||||
for (BaseCheckinHandlerFactory factory : factoryList) {
|
||||
BeforeCheckinDialogHandler handler = factory.createSystemReadyHandler(project);
|
||||
if (handler != null && !handler.beforeCommitDialogShownCallback(executors, showVcsCommit)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean commit(final Project project, final List<Change> changes, final LocalChangeList initialSelection,
|
||||
final List<CommitExecutor> executors, final boolean showVcsCommit, final String comment,
|
||||
@Nullable CommitResultHandler customResultHandler) {
|
||||
for (BeforeCommitDialogHandler handler : BeforeCommitDialogHandler.EP_NAME.getExtensions()) {
|
||||
if (!handler.beforeCommitDialogShownCallback(project, changes, executors, showVcsCommit)) {
|
||||
for (BaseCheckinHandlerFactory factory : getCheckInFactories(project)) {
|
||||
BeforeCheckinDialogHandler handler = factory.createSystemReadyHandler(project);
|
||||
if (handler != null && !handler.beforeCommitDialogShown(project, changes, executors, showVcsCommit)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final ChangeListManager manager = ChangeListManager.getInstance(project);
|
||||
final LocalChangeList defaultList = manager.getDefaultChangeList();
|
||||
final ArrayList<LocalChangeList> changeLists = new ArrayList<LocalChangeList>(manager.getChangeListsCopy());
|
||||
CommitChangeListDialog dialog =
|
||||
new CommitChangeListDialog(project, changes, initialSelection, executors, showVcsCommit, defaultList, changeLists, null, false,
|
||||
comment, customResultHandler);
|
||||
CommitChangeListDialog dialog = new CommitChangeListDialog(project, changes, initialSelection, executors, showVcsCommit, manager.getDefaultChangeList(), manager.getChangeListsCopy(), null,
|
||||
false, comment, customResultHandler);
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
dialog.show();
|
||||
}
|
||||
@@ -184,6 +166,11 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
return dialog.isOK();
|
||||
}
|
||||
|
||||
private static List<BaseCheckinHandlerFactory> getCheckInFactories(Project project) {
|
||||
return CheckinHandlersManager.getInstance().getRegisteredCheckinHandlerFactories(
|
||||
ProjectLevelVcsManager.getInstance(project).getAllActiveVcss());
|
||||
}
|
||||
|
||||
public static void commitPaths(final Project project, Collection<FilePath> paths, final LocalChangeList initialSelection,
|
||||
@Nullable final CommitExecutor executor, final String comment) {
|
||||
final ChangeListManager manager = ChangeListManager.getInstance(project);
|
||||
@@ -207,7 +194,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
|
||||
public static List<CommitExecutor> collectExecutors(Project project, Collection<Change> changes) {
|
||||
List<CommitExecutor> result = new ArrayList<CommitExecutor>();
|
||||
for (AbstractVcs vcs : getAffectedVcses(project, changes)) {
|
||||
for (AbstractVcs<?> vcs : getAffectedVcses(project, changes)) {
|
||||
result.addAll(vcs.getCommitExecutors());
|
||||
}
|
||||
result.addAll(ChangeListManager.getInstance(project).getRegisteredExecutors());
|
||||
@@ -405,9 +392,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
boolean afterVisible = false;
|
||||
Box beforeBox = Box.createVerticalBox();
|
||||
Box afterBox = Box.createVerticalBox();
|
||||
final List<BaseCheckinHandlerFactory> handlerFactories = CheckinHandlersManager.getInstance().getRegisteredCheckinHandlerFactories(
|
||||
ProjectLevelVcsManager.getInstance(project).getAllActiveVcss());
|
||||
for (BaseCheckinHandlerFactory factory : handlerFactories) {
|
||||
for (BaseCheckinHandlerFactory factory : getCheckInFactories(project)) {
|
||||
final CheckinHandler handler = factory.createHandler(this, myCommitContext);
|
||||
if (CheckinHandler.DUMMY.equals(handler)) continue;
|
||||
|
||||
@@ -540,6 +525,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
// check for null since can be called from constructor before field initialization
|
||||
if (myWarningLabel != null) {
|
||||
myWarningLabel.setVisible(false);
|
||||
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
|
||||
final VcsException updateException = ((ChangeListManagerImpl)ChangeListManager.getInstance(myProject)).getUpdateException();
|
||||
if (updateException != null) {
|
||||
final String[] messages = updateException.getMessages();
|
||||
@@ -553,8 +539,8 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
}
|
||||
|
||||
private void updateVcsOptionsVisibility() {
|
||||
final List<AbstractVcs> affectedVcses = getAffectedVcses(myProject, myBrowser.getSelectedChangeList().getChanges());
|
||||
for(Map.Entry<AbstractVcs, JPanel> entry: myPerVcsOptionsPanels.entrySet()) {
|
||||
Collection<AbstractVcs<?>> affectedVcses = getAffectedVcses(myProject, myBrowser.getSelectedChangeList().getChanges());
|
||||
for (Map.Entry<AbstractVcs, JPanel> entry : myPerVcsOptionsPanels.entrySet()) {
|
||||
entry.getValue().setVisible(affectedVcses.contains(entry.getKey()));
|
||||
}
|
||||
}
|
||||
@@ -1104,15 +1090,12 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
return myBrowserExtender.getAffectedVcses();
|
||||
}
|
||||
|
||||
private static List<AbstractVcs> getAffectedVcses(Project project, final Collection<Change> changes) {
|
||||
Set<AbstractVcs> result = new HashSet<AbstractVcs>();
|
||||
private static Collection<AbstractVcs<?>> getAffectedVcses(Project project, final Collection<Change> changes) {
|
||||
Set<AbstractVcs<?>> result = new THashSet<AbstractVcs<?>>();
|
||||
for (Change change : changes) {
|
||||
final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project);
|
||||
if (vcs != null) {
|
||||
result.add(vcs);
|
||||
}
|
||||
ContainerUtilRt.addIfNotNull(result, ChangesUtil.getVcsForChange(change, project));
|
||||
}
|
||||
return new ArrayList<AbstractVcs>(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-10
@@ -29,11 +29,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author irengrig
|
||||
* Date: 1/28/11
|
||||
* Time: 5:21 PM
|
||||
*/
|
||||
public class CheckinHandlersManagerImpl extends CheckinHandlersManager {
|
||||
private final List<BaseCheckinHandlerFactory> myRegisteredBeforeCheckinHandlers;
|
||||
private final MultiMap<VcsKey, VcsCheckinHandlerFactory> myVcsMap;
|
||||
@@ -48,13 +43,13 @@ public class CheckinHandlersManagerImpl extends CheckinHandlersManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseCheckinHandlerFactory> getRegisteredCheckinHandlerFactories(AbstractVcs[] allActiveVcss) {
|
||||
final ArrayList<BaseCheckinHandlerFactory> list =
|
||||
public List<BaseCheckinHandlerFactory> getRegisteredCheckinHandlerFactories(AbstractVcs<?>[] allActiveVcss) {
|
||||
final List<BaseCheckinHandlerFactory> list =
|
||||
new ArrayList<BaseCheckinHandlerFactory>(myRegisteredBeforeCheckinHandlers.size() + allActiveVcss.length);
|
||||
list.addAll(myRegisteredBeforeCheckinHandlers);
|
||||
for (AbstractVcs vcs : allActiveVcss) {
|
||||
final Collection<VcsCheckinHandlerFactory> factories = myVcsMap.get(vcs.getKeyInstanceMethod());
|
||||
if (! factories.isEmpty()) {
|
||||
if (!factories.isEmpty()) {
|
||||
list.addAll(factories);
|
||||
}
|
||||
}
|
||||
@@ -63,10 +58,10 @@ public class CheckinHandlersManagerImpl extends CheckinHandlersManager {
|
||||
|
||||
@Override
|
||||
public List<VcsCheckinHandlerFactory> getMatchingVcsFactories(@NotNull List<AbstractVcs> vcsList) {
|
||||
final SmartList<VcsCheckinHandlerFactory> result = new SmartList<VcsCheckinHandlerFactory>();
|
||||
final List<VcsCheckinHandlerFactory> result = new SmartList<VcsCheckinHandlerFactory>();
|
||||
for (AbstractVcs vcs : vcsList) {
|
||||
final Collection<VcsCheckinHandlerFactory> factories = myVcsMap.get(vcs.getKeyInstanceMethod());
|
||||
if (! factories.isEmpty()) {
|
||||
if (!factories.isEmpty()) {
|
||||
result.addAll(factories);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user