use of com.intellij.util.PairConsumer in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoFmtCheckinFactory method createHandler.
@Override
@NotNull
public CheckinHandler createHandler(@NotNull CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
return new CheckinHandler() {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
JCheckBox checkBox = new JCheckBox("Go fmt");
return new RefreshableOnComponent() {
@Override
@NotNull
public JComponent getComponent() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(checkBox, BorderLayout.WEST);
return panel;
}
@Override
public void refresh() {
}
@Override
public void saveState() {
PropertiesComponent.getInstance(panel.getProject()).setValue(GO_FMT, Boolean.toString(checkBox.isSelected()));
}
@Override
public void restoreState() {
checkBox.setSelected(enabled(panel));
}
};
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
if (enabled(panel)) {
Ref<Boolean> success = Ref.create(true);
FileDocumentManager.getInstance().saveAllDocuments();
for (PsiFile file : getPsiFiles()) {
VirtualFile virtualFile = file.getVirtualFile();
new GoFmtFileAction().doSomething(virtualFile, ModuleUtilCore.findModuleForPsiElement(file), file.getProject(), "Go fmt", true, result -> {
if (!result)
success.set(false);
});
}
if (!success.get()) {
return showErrorMessage(executor);
}
}
return super.beforeCheckin();
}
@NotNull
private ReturnResult showErrorMessage(@Nullable CommitExecutor executor) {
String[] buttons = new String[] { "&Details...", commitButtonMessage(executor, panel), CommonBundle.getCancelButtonText() };
int answer = Messages.showDialog(panel.getProject(), "<html><body>GoFmt returned non-zero code on some of the files.<br/>" + "Would you like to commit anyway?</body></html>\n", "Go Fmt", null, buttons, 0, 1, UIUtil.getWarningIcon());
if (answer == Messages.OK) {
return ReturnResult.CLOSE_WINDOW;
}
if (answer == Messages.NO) {
return ReturnResult.COMMIT;
}
return ReturnResult.CANCEL;
}
@NotNull
private List<PsiFile> getPsiFiles() {
Collection<VirtualFile> files = panel.getVirtualFiles();
List<PsiFile> psiFiles = ContainerUtil.newArrayList();
PsiManager manager = PsiManager.getInstance(panel.getProject());
for (VirtualFile file : files) {
PsiFile psiFile = manager.findFile(file);
if (psiFile instanceof GoFile) {
psiFiles.add(psiFile);
}
}
return psiFiles;
}
};
}
use of com.intellij.util.PairConsumer in project intellij-community by JetBrains.
the class SvnCheckinHandlerFactory method createVcsHandler.
@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
final Project project = panel.getProject();
final Collection<VirtualFile> commitRoots = panel.getRoots();
return new CheckinHandler() {
private Collection<Change> myChanges = panel.getSelectedChanges();
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
return null;
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
if (executor instanceof LocalCommitExecutor)
return ReturnResult.COMMIT;
final SvnVcs vcs = SvnVcs.getInstance(project);
final MultiMap<String, WorkingCopyFormat> copiesInfo = splitIntoCopies(vcs, myChanges);
final List<String> repoUrls = new ArrayList<>();
for (Map.Entry<String, Collection<WorkingCopyFormat>> entry : copiesInfo.entrySet()) {
if (entry.getValue().size() > 1) {
repoUrls.add(entry.getKey());
}
}
if (!repoUrls.isEmpty()) {
final String join = StringUtil.join(repoUrls, ",\n");
final int isOk = Messages.showOkCancelDialog(project, SvnBundle.message("checkin.different.formats.involved", repoUrls.size() > 1 ? 1 : 0, join), "Subversion: Commit Will Split", Messages.getWarningIcon());
return Messages.OK == isOk ? ReturnResult.COMMIT : ReturnResult.CANCEL;
}
return ReturnResult.COMMIT;
}
@Override
public void includedChangesChanged() {
myChanges = panel.getSelectedChanges();
}
@Override
public void checkinSuccessful() {
if (SvnConfiguration.getInstance(project).isAutoUpdateAfterCommit()) {
final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(SvnVcs.getInstance(project));
final List<FilePath> paths = new ArrayList<>();
for (VirtualFile root : roots) {
boolean take = false;
for (VirtualFile commitRoot : commitRoots) {
if (VfsUtilCore.isAncestor(root, commitRoot, false)) {
take = true;
break;
}
}
if (take) {
paths.add(VcsUtil.getFilePath(root));
}
}
if (paths.isEmpty())
return;
ApplicationManager.getApplication().invokeLater(() -> AutoSvnUpdater.run(new AutoSvnUpdater(project, paths.toArray(new FilePath[paths.size()])), ActionInfo.UPDATE.getActionName()), ModalityState.NON_MODAL);
}
}
};
}
use of com.intellij.util.PairConsumer in project intellij-community by JetBrains.
the class UpdateCopyrightCheckinHandlerFactory method createHandler.
@NotNull
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
return new CheckinHandler() {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
final JCheckBox updateCopyrightCb = new JCheckBox("Update copyright");
return new RefreshableOnComponent() {
public JComponent getComponent() {
return JBUI.Panels.simplePanel().addToLeft(updateCopyrightCb);
}
public void refresh() {
}
public void saveState() {
UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT = updateCopyrightCb.isSelected();
}
public void restoreState() {
updateCopyrightCb.setSelected(UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT);
}
};
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
if (UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT) {
new UpdateCopyrightProcessor(panel.getProject(), null, getPsiFiles()).run();
FileDocumentManager.getInstance().saveAllDocuments();
}
return super.beforeCheckin();
}
private PsiFile[] getPsiFiles() {
final Collection<VirtualFile> files = panel.getVirtualFiles();
final List<PsiFile> psiFiles = new ArrayList<>();
final PsiManager manager = PsiManager.getInstance(panel.getProject());
for (final VirtualFile file : files) {
final PsiFile psiFile = manager.findFile(file);
if (psiFile != null) {
psiFiles.add(psiFile);
}
}
return PsiUtilCore.toPsiFileArray(psiFiles);
}
};
}
Aggregations