Java Code Examples for com.intellij.openapi.vcs.changes.Change#getType()

The following examples show how to use com.intellij.openapi.vcs.changes.Change#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TFSRollbackEnvironment.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public void rollbackChanges(final List<Change> changes,
                            final List<VcsException> vcsExceptions,
                            @NotNull final RollbackProgressListener listener) {
    logger.info("rollbackChanges started");
    final List<FilePath> localPaths = new ArrayList<FilePath>();

    listener.determinate();
    for (final Change change : changes) {
        final ContentRevision revision = change.getType() == Change.Type.DELETED ? change.getBeforeRevision() : change.getAfterRevision();
        localPaths.add(revision.getFile());
    }

    undoPendingChanges(localPaths, vcsExceptions, listener);
    logger.info("rollbackChanges ended");
}
 
Example 2
Source File: OpenFileInBrowserAction.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
/**
 * Returns true if the action should be enabled, false otherwise
 *
 * @param project, vFile
 * @return
 */
private boolean isEnabled(final ChangeListManager changeListManager, final Project project, final VirtualFile vFile) {
    if (vFile.isDirectory()) {
        /* Empty directories are not yet supported by Git.  Recursive scanning works, but could be error prone
           (e.g.) symbolic links.  Approach here is to always show it. */
        // TODO we may want to revisit this approach
        return true;
    }

    final GitVcs vcs = GitVcs.getInstance(project);

    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(vcs, new VirtualFile[]{vFile})) {
        return false;
    }

    if (changeListManager.isUnversioned(vFile)) {
        return false;
    }

    final Change change = changeListManager.getChange(vFile);
    if (change != null && change.getType() == Change.Type.NEW) {
        // a new file that has not yet been checked in
        return false;
    }

    return true;
}
 
Example 3
Source File: VcsAwareFormatChangedTextUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public List<TextRange> getChangedTextRanges(@Nonnull Project project, @Nonnull PsiFile file) throws FilesTooBigForDiffException {
  Document document = PsiDocumentManager.getInstance(project).getDocument(file);
  if (document == null) return ContainerUtil.emptyList();

  List<TextRange> cachedChangedLines = getCachedChangedLines(project, document);
  if (cachedChangedLines != null) {
    return cachedChangedLines;
  }

  if (ApplicationManager.getApplication().isUnitTestMode()) {
    CharSequence testContent = file.getUserData(TEST_REVISION_CONTENT);
    if (testContent != null) {
      return calculateChangedTextRanges(document, testContent);
    }
  }

  Change change = ChangeListManager.getInstance(project).getChange(file.getVirtualFile());
  if (change == null) {
    return ContainerUtilRt.emptyList();
  }
  if (change.getType() == Change.Type.NEW) {
    return ContainerUtil.newArrayList(file.getTextRange());
  }

  String contentFromVcs = getRevisionedContentFrom(change);
  return contentFromVcs != null ? calculateChangedTextRanges(document, contentFromVcs)
                                : ContainerUtil.<TextRange>emptyList();
}
 
Example 4
Source File: OutdatedVersionNotifier.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateLabelText(final Change c) {
  String comment = myChangeList.getComment();
  int pos = comment.indexOf("\n");
  if (pos >= 0) {
    comment = comment.substring(0, pos).trim() + "...";
  }
  final String formattedDate = DateFormatUtil.formatPrettyDateTime(myChangeList.getCommitDate());
  final boolean dateIsPretty = ! formattedDate.contains("/");
  final String key = c.getType() == Change.Type.DELETED ? "outdated.version.text.deleted" :
                     (dateIsPretty ? "outdated.version.pretty.date.text" : "outdated.version.text");
  myLabel.setText(VcsBundle.message(key, myChangeList.getCommitterName(), formattedDate, comment));
}
 
Example 5
Source File: FormatChangedTextUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Allows to answer if given file or any file below the given directory (any level of nesting) has changes in comparison with VCS.
 *
 * @param file    target directory to check
 * @param project target project
 * @return <code>true</code> if given file or any file below the given directory has changes in comparison with VCS;
 * <code>false</code> otherwise
 */
public static boolean hasChanges(@Nonnull VirtualFile file, @Nonnull Project project) {
  final Collection<Change> changes = ChangeListManager.getInstance(project).getChangesIn(file);
  for (Change change : changes) {
    if (change.getType() == Change.Type.NEW || change.getType() == Change.Type.MODIFICATION) {
      return true;
    }
  }
  return false;
}
 
Example 6
Source File: GitLabOpenInBrowserAction.java    From IDEA-GitLab-Integration with MIT License 5 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
    Project project = e.getData(PlatformDataKeys.PROJECT);
    VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    if (project == null || project.isDefault() || virtualFile == null) {
        setVisibleEnabled(e, false, false);
        return;
    }

    final GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForFile(virtualFile);
    if (gitRepository == null) {
        setVisibleEnabled(e, false, false);
        return;
    }

    ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (changeListManager.isUnversioned(virtualFile)) {
        setVisibleEnabled(e, true, false);
        return;
    }

    Change change = changeListManager.getChange(virtualFile);
    if (change != null && change.getType() == Change.Type.NEW) {
        setVisibleEnabled(e, true, false);
        return;
    }

    setVisibleEnabled(e, true, true);
}
 
Example 7
Source File: ChangeInfoCalculator.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean process(@Nonnull Change item) {
  return item.getType() == Change.Type.MODIFICATION || item.getType() == Change.Type.MOVED;
}
 
Example 8
Source File: ChangeInfoCalculator.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean process(@Nonnull Change item) {
  return item.getType() == Change.Type.NEW;
}
 
Example 9
Source File: ChangeInfoCalculator.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean process(@Nonnull Change item) {
  return item.getType() == Change.Type.DELETED;
}