@Override public UpdateInfoTree showUpdateProjectInfo( UpdatedFiles updatedFiles, String displayActionName, ActionInfo actionInfo, boolean canceled) { if (!myProject.isOpen() || myProject.isDisposed()) return null; ContentManager contentManager = getContentManager(); if (contentManager == null) { return null; // content manager is made null during dispose; flag is set later } final UpdateInfoTree updateInfoTree = new UpdateInfoTree(contentManager, myProject, updatedFiles, displayActionName, actionInfo); Content content = ContentFactory.SERVICE .getInstance() .createContent( updateInfoTree, canceled ? VcsBundle.message( "toolwindow.title.update.action.canceled.info", displayActionName) : VcsBundle.message("toolwindow.title.update.action.info", displayActionName), true); Disposer.register(content, updateInfoTree); ContentsUtil.addContent(contentManager, content, true); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS).activate(null); updateInfoTree.expandRootChildren(); return updateInfoTree; }
protected static void showApplyStatus(@NotNull Project project, final ApplyPatchStatus status) { if (status == ApplyPatchStatus.ALREADY_APPLIED) { showError(project, VcsBundle.message("patch.apply.already.applied"), false); } else if (status == ApplyPatchStatus.PARTIAL) { showError(project, VcsBundle.message("patch.apply.partially.applied"), false); } else if (ApplyPatchStatus.SUCCESS.equals(status)) { final String message = VcsBundle.message("patch.apply.success.applied.text"); VcsBalloonProblemNotifier.NOTIFICATION_GROUP .createNotification(message, MessageType.INFO) .notify(project); } }
private Content getOrCreateConsoleContent(final ContentManager contentManager) { final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name"); Content content = contentManager.findContent(displayName); if (content == null) { releaseEditor(); final EditorFactory editorFactory = EditorFactory.getInstance(); final Editor editor = editorFactory.createViewer(editorFactory.createDocument(""), myProject); EditorSettings editorSettings = editor.getSettings(); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); ((EditorEx) editor).getScrollPane().setBorder(null); myEditorAdapter = new EditorAdapter(editor, myProject, false); final JPanel panel = new JPanel(new BorderLayout()); panel.add(editor.getComponent(), BorderLayout.CENTER); content = ContentFactory.SERVICE.getInstance().createContent(panel, displayName, true); contentManager.addContent(content); for (Pair<String, TextAttributes> pair : myPendingOutput) { myEditorAdapter.appendString(pair.first, pair.second); } myPendingOutput.clear(); } return content; }
/** * Collects all files which are located in the passed directory. * * @throws IllegalArgumentException if <code>dir</code> isn't a directory. */ public static void collectFiles( final VirtualFile dir, final List<VirtualFile> files, final boolean recursive, final boolean addDirectories) { if (!dir.isDirectory()) { throw new IllegalArgumentException( VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl())); } final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); VfsUtilCore.visitChildrenRecursively( dir, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { if (file.isDirectory()) { if (addDirectories) { files.add(file); } if (!recursive && !Comparing.equal(file, dir)) { return false; } } else if (fileTypeManager == null || file.getFileType() != FileTypes.UNKNOWN) { files.add(file); } return true; } }); }
public static void showError(final Project project, final String message, final boolean error) { final Application application = ApplicationManager.getApplication(); if (application.isUnitTestMode()) { return; } final String title = VcsBundle.message("patch.apply.dialog.title"); final Runnable messageShower = new Runnable() { @Override public void run() { if (error) { Messages.showErrorDialog(project, message, title); } else { Messages.showInfoMessage(project, message, title); } } }; WaitForProgressToShow.runOrInvokeLaterAboveProgress( new Runnable() { @Override public void run() { messageShower.run(); } }, null, project); }
@CalledInAwt public static void refreshPassedFilesAndMoveToChangelist( @NotNull final Project project, final Collection<FilePath> directlyAffected, final Collection<VirtualFile> indirectlyAffected, final Consumer<Collection<FilePath>> targetChangelistMover) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); for (FilePath filePath : directlyAffected) { lfs.refreshAndFindFileByIoFile(filePath.getIOFile()); } if (project.isDisposed()) return; final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (!directlyAffected.isEmpty() && targetChangelistMover != null) { changeListManager.invokeAfterUpdate( new Runnable() { @Override public void run() { targetChangelistMover.consume(directlyAffected); } }, InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE, VcsBundle.message("change.lists.manager.move.changes.to.list"), new Consumer<VcsDirtyScopeManager>() { @Override public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) { markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected); } }, null); } else { markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected); } }
@CalledInAwt @NotNull private ApplyPatchStatus getApplyPatchStatus(@NotNull final TriggerAdditionOrDeletion trigger) { final Ref<ApplyPatchStatus> refStatus = Ref.create(null); try { setConfirmationToDefault(); CommandProcessor.getInstance() .executeCommand( myProject, new Runnable() { @Override public void run() { // consider pre-check status only if not successful, otherwise we could not // detect already applied status if (createFiles() != ApplyPatchStatus.SUCCESS) { refStatus.set(createFiles()); } addSkippedItems(trigger); trigger.prepare(); refStatus.set(ApplyPatchStatus.and(refStatus.get(), executeWritable())); } }, VcsBundle.message("patch.apply.command"), null); } finally { returnConfirmationBack(); VcsFileListenerContextHelper.getInstance(myProject).clearContext(); } final ApplyPatchStatus status = refStatus.get(); return status == null ? ApplyPatchStatus.ALREADY_APPLIED : status; }
public ShelvedChangeList shelveChanges( final Collection<Change> changes, final String commitMessage, final boolean rollback) throws IOException, VcsException { final List<Change> textChanges = new ArrayList<Change>(); final List<ShelvedBinaryFile> binaryFiles = new ArrayList<ShelvedBinaryFile>(); for (Change change : changes) { if (ChangesUtil.getFilePath(change).isDirectory()) { continue; } if (change.getBeforeRevision() instanceof BinaryContentRevision || change.getAfterRevision() instanceof BinaryContentRevision) { binaryFiles.add(shelveBinaryFile(change)); } else { textChanges.add(change); } } final ShelvedChangeList changeList; try { File patchPath = getPatchPath(commitMessage); ProgressManager.checkCanceled(); final List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch( myProject, textChanges, myProject.getBaseDir().getPresentableUrl(), false); ProgressManager.checkCanceled(); CommitContext commitContext = new CommitContext(); baseRevisionsOfDvcsIntoContext(textChanges, commitContext); myFileProcessor.savePathFile( new CompoundShelfFileProcessor.ContentProvider() { public void writeContentTo(final Writer writer, CommitContext commitContext) throws IOException { UnifiedDiffWriter.write(myProject, patches, writer, "\n", commitContext); } }, patchPath, commitContext); changeList = new ShelvedChangeList( patchPath.toString(), commitMessage.replace('\n', ' '), binaryFiles); myShelvedChangeLists.add(changeList); ProgressManager.checkCanceled(); if (rollback) { new RollbackWorker(myProject, false) .doRollback(changes, true, null, VcsBundle.message("shelve.changes.action")); } } finally { notifyStateChanged(); } return changeList; }
public void setCanGroupByChangeList(final boolean canGroupByChangeList) { myCanGroupByChangeList = canGroupByChangeList; if (myCanGroupByChangeList) { myLoadingChangeListsLabel = new JLabel(VcsBundle.message("update.info.loading.changelists")); add(myLoadingChangeListsLabel, BorderLayout.SOUTH); myGroupByChangeList = VcsConfiguration.getInstance(myProject).UPDATE_GROUP_BY_CHANGELIST; if (myGroupByChangeList) { final CardLayout cardLayout = (CardLayout) myCenterPanel.getLayout(); cardLayout.show(myCenterPanel, CARD_CHANGES); } } }
private static boolean checkNotifyBinaryDiff(final Change selectedChange) { final ContentRevision beforeRevision = selectedChange.getBeforeRevision(); final ContentRevision afterRevision = selectedChange.getAfterRevision(); if (beforeRevision instanceof BinaryContentRevision && afterRevision instanceof BinaryContentRevision) { try { byte[] beforeContent = ((BinaryContentRevision) beforeRevision).getBinaryContent(); byte[] afterContent = ((BinaryContentRevision) afterRevision).getBinaryContent(); if (Arrays.equals(beforeContent, afterContent)) { Messages.showInfoMessage( VcsBundle.message("message.text.binary.versions.are.identical"), VcsBundle.message("message.title.diff")); } else { Messages.showInfoMessage( VcsBundle.message("message.text.binary.versions.are.different"), VcsBundle.message("message.title.diff")); } } catch (VcsException e) { Messages.showInfoMessage(e.getMessage(), VcsBundle.message("message.title.diff")); } return true; } return false; }
public static Image createImage(final JTree tree) { final TreeSelectionModel model = tree.getSelectionModel(); final TreePath[] paths = model.getSelectionPaths(); int count = 0; final List<ChangesBrowserNode> nodes = new ArrayList<ChangesBrowserNode>(); for (final TreePath path : paths) { final ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent(); if (!node.isLeaf()) { nodes.add(node); count += node.getCount(); } } for (TreePath path : paths) { final ChangesBrowserNode element = (ChangesBrowserNode) path.getLastPathComponent(); boolean child = false; for (final ChangesBrowserNode node : nodes) { if (node.isNodeChild(element)) { child = true; break; } } if (!child) { if (element.isLeaf()) count++; } else if (!element.isLeaf()) { count -= element.getCount(); } } final JLabel label = new JLabel(VcsBundle.message("changes.view.dnd.label", count)); label.setOpaque(true); label.setForeground(tree.getForeground()); label.setBackground(tree.getBackground()); label.setFont(tree.getFont()); label.setSize(label.getPreferredSize()); final BufferedImage image = new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) image.getGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); label.paint(g2); g2.dispose(); return image; }
public GroupByChangeListAction() { super( VcsBundle.message("update.info.group.by.changelist"), null, AllIcons.ObjectBrowser.Browser); }
public MyGroupByPackagesAction() { super( VcsBundle.message("action.name.group.by.packages"), null, PlatformIcons.GROUP_BY_PACKAGES); }
@CalledInAwt public static ApplyPatchStatus executePatchGroup( final Collection<PatchApplier> group, final LocalChangeList localChangeList) { if (group.isEmpty()) return ApplyPatchStatus.SUCCESS; // ? final Project project = group.iterator().next().myProject; ApplyPatchStatus result = ApplyPatchStatus.SUCCESS; for (PatchApplier patchApplier : group) { result = ApplyPatchStatus.and(result, patchApplier.nonWriteActionPreCheck()); } final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, "Before patch"); final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(project); final Ref<ApplyPatchStatus> refStatus = new Ref<>(result); try { CommandProcessor.getInstance() .executeCommand( project, new Runnable() { @Override public void run() { for (PatchApplier applier : group) { refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.createFiles())); applier.addSkippedItems(trigger); } trigger.prepare(); if (refStatus.get() == ApplyPatchStatus.SUCCESS) { // all pre-check results are valuable only if not successful; actual status we // can receive after executeWritable refStatus.set(null); } for (PatchApplier applier : group) { refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.executeWritable())); if (refStatus.get() == ApplyPatchStatus.ABORT) break; } } }, VcsBundle.message("patch.apply.command"), null); } finally { VcsFileListenerContextHelper.getInstance(project).clearContext(); LocalHistory.getInstance().putSystemLabel(project, "After patch"); } result = refStatus.get(); result = result == null ? ApplyPatchStatus.FAILURE : result; trigger.processIt(); final Set<FilePath> directlyAffected = new HashSet<>(); final Set<VirtualFile> indirectlyAffected = new HashSet<>(); for (PatchApplier applier : group) { directlyAffected.addAll(applier.getDirectlyAffected()); indirectlyAffected.addAll(applier.getIndirectlyAffected()); } directlyAffected.addAll(trigger.getAffected()); final Consumer<Collection<FilePath>> mover = localChangeList == null ? null : createMover(project, localChangeList); refreshPassedFilesAndMoveToChangelist(project, directlyAffected, indirectlyAffected, mover); if (result == ApplyPatchStatus.FAILURE) { suggestRollback(project, group, beforeLabel); } else if (result == ApplyPatchStatus.ABORT) { rollbackUnderProgress(project, project.getBaseDir(), beforeLabel); } showApplyStatus(project, result); return result; }