use of com.intellij.openapi.vcs.checkin.CheckinHandler 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.openapi.vcs.checkin.CheckinHandler 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.openapi.vcs.checkin.CheckinHandler in project intellij-community by JetBrains.
the class TaskCheckinHandlerFactory method createHandler.
@NotNull
@Override
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull final CommitContext commitContext) {
return new CheckinHandler() {
@Override
public void checkinSuccessful() {
final String message = panel.getCommitMessage();
final Project project = panel.getProject();
final TaskManagerImpl manager = (TaskManagerImpl) TaskManager.getManager(project);
if (manager.getState().saveContextOnCommit) {
Task task = findTaskInRepositories(message, manager);
if (task == null) {
task = manager.createLocalTask(message);
}
final LocalTask localTask = manager.addTask(task);
localTask.setUpdated(new Date());
ApplicationManager.getApplication().invokeLater(() -> WorkingContextManager.getInstance(project).saveContext(localTask), project.getDisposed());
}
}
};
}
use of com.intellij.openapi.vcs.checkin.CheckinHandler in project intellij-community by JetBrains.
the class CvsCheckinHandlerFactory method createVcsHandler.
@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
return new CheckinHandler() {
@Nullable
public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
final Project project = panel.getProject();
final CvsVcs2 cvs = CvsVcs2.getInstance(project);
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
final Collection<VirtualFile> roots = panel.getRoots();
final Collection<FilePath> files = new HashSet<>();
for (VirtualFile root : roots) {
final VcsRoot vcsRoot = vcsManager.getVcsRootObjectFor(root);
if (vcsRoot == null || vcsRoot.getVcs() != cvs) {
continue;
}
files.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(root));
}
return new AdditionalOptionsPanel(CvsConfiguration.getInstance(project), files, project);
}
};
}
use of com.intellij.openapi.vcs.checkin.CheckinHandler in project intellij-community by JetBrains.
the class ExternalToolsCheckinHandlerFactory method createHandler.
@NotNull
@Override
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
final ToolsProjectConfig config = ToolsProjectConfig.getInstance(panel.getProject());
return new CheckinHandler() {
@Override
public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
final JLabel label = new JLabel(ToolsBundle.message("tools.after.commit.description"));
ComboboxWithBrowseButton listComponent = new ComboboxWithBrowseButton();
final JComboBox comboBox = listComponent.getComboBox();
comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), null));
comboBox.setRenderer(new ListCellRendererWrapper<Object>() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof ToolsGroup) {
setText(StringUtil.notNullize(((ToolsGroup) value).getName(), ToolsBundle.message("tools.unnamed.group")));
} else if (value instanceof Tool) {
setText(" " + StringUtil.notNullize(((Tool) value).getName()));
} else {
setText(ToolsBundle.message("tools.list.item.none"));
}
}
});
listComponent.getButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Object item = comboBox.getSelectedItem();
String id = null;
if (item instanceof Tool) {
id = ((Tool) item).getActionId();
}
final ToolSelectDialog dialog = new ToolSelectDialog(panel.getProject(), id, new ToolsPanel());
if (!dialog.showAndGet()) {
return;
}
comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), dialog.getSelectedTool()));
}
});
BorderLayout layout = new BorderLayout();
layout.setVgap(3);
final JPanel panel = new JPanel(layout);
panel.add(label, BorderLayout.NORTH);
panel.add(listComponent, BorderLayout.CENTER);
listComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 0));
if (comboBox.getItemCount() == 0 || (comboBox.getItemCount() == 1 && comboBox.getItemAt(0) == NONE_TOOL)) {
return null;
}
return new RefreshableOnComponent() {
@Override
public JComponent getComponent() {
return panel;
}
@Override
public void refresh() {
String id = config.getAfterCommitToolsId();
if (id == null) {
comboBox.setSelectedIndex(-1);
} else {
for (int i = 0; i < comboBox.getItemCount(); i++) {
final Object itemAt = comboBox.getItemAt(i);
if (itemAt instanceof Tool && id.equals(((Tool) itemAt).getActionId())) {
comboBox.setSelectedIndex(i);
return;
}
}
}
}
@Override
public void saveState() {
Object item = comboBox.getSelectedItem();
config.setAfterCommitToolId(item instanceof Tool ? ((Tool) item).getActionId() : null);
}
@Override
public void restoreState() {
refresh();
}
};
}
@Override
public void checkinSuccessful() {
final String id = config.getAfterCommitToolsId();
if (id == null) {
return;
}
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(final DataContext context) {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
ToolAction.runTool(id, context);
}
});
}
});
}
};
}
Aggregations