Java Code Examples for com.intellij.openapi.vcs.FilePath#isDirectory()

The following examples show how to use com.intellij.openapi.vcs.FilePath#isDirectory() . 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: DiffRequestFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static String getTitle(@Nonnull FilePath path1, @Nonnull FilePath path2, @Nonnull String separator) {
  if ((path1.isDirectory() || path2.isDirectory()) && path1.getPath().equals(path2.getPath())) {
    return path1.getPresentableUrl();
  }

  String name1 = path1.getName();
  String name2 = path2.getName();

  if (path1.isDirectory() ^ path2.isDirectory()) {
    if (path1.isDirectory()) name1 += File.separatorChar;
    if (path2.isDirectory()) name2 += File.separatorChar;
  }

  FilePath parent1 = path1.getParentPath();
  FilePath parent2 = path2.getParentPath();
  return getRequestTitle(name1, path1.getPresentableUrl(), parent1 != null ? parent1.getPresentableUrl() : null,
                         name2, path2.getPresentableUrl(), parent2 != null ? parent2.getPresentableUrl() : null,
                         separator);
}
 
Example 2
Source File: ChangesBrowserFilePathNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void render(final ChangesBrowserNodeRenderer renderer, final boolean selected, final boolean expanded, final boolean hasFocus) {
  final FilePath path = (FilePath)userObject;
  if (path.isDirectory() || !isLeaf()) {
    renderer.append(getRelativePath(path), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    if (!isLeaf()) {
      appendCount(renderer);
    }
    renderer.setIcon(AllIcons.Nodes.TreeClosed);
  }
  else {
    if (renderer.isShowFlatten()) {
      renderer.append(path.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
      FilePath parentPath = path.getParentPath();
      renderer.append(spaceAndThinSpace() + FileUtil.getLocationRelativeToUserHome(parentPath.getPresentableUrl()), SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    else {
      renderer.append(getRelativePath(path), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
    renderer.setIcon(path.getFileType().getIcon());
  }
}
 
Example 3
Source File: FileSpecBuildUtil.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public static List<IFileSpec> escapedForFilePathsAnnotated(Collection<FilePath> files, String annotation,
        boolean allowDirectories) {
    if (annotation == null) {
        annotation = "";
    }
    List<String> src = new ArrayList<>(files.size());
    for (FilePath file : files) {
        String path = escapeToP4Path(file.getPath());
        if (allowDirectories && file.isDirectory()) {
            path += "/...";
        }
        src.add(path + annotation);
    }
    return FileSpecBuilder.makeFileSpecList(src);
}
 
Example 4
Source File: VcsFileUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void markFilesDirty(@Nonnull Project project, @Nonnull List<FilePath> affectedFiles) {
  final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
  for (FilePath file : affectedFiles) {
    if (file.isDirectory()) {
      dirty.dirDirtyRecursively(file);
    }
    else {
      dirty.fileDirty(file);
    }
  }
}
 
Example 5
Source File: VcsDiffUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public static void showDiffFor(@Nonnull Project project,
                               @Nonnull final Collection<Change> changes,
                               @Nonnull final String revNumTitle1,
                               @Nonnull final String revNumTitle2,
                               @Nonnull final FilePath filePath) {
  if (filePath.isDirectory()) {
    showChangesDialog(project, getDialogTitle(filePath, revNumTitle1, revNumTitle2), ContainerUtil.newArrayList(changes));
  }
  else {
    if (changes.isEmpty()) {
      DiffManager.getInstance().showDiff(project, new MessageDiffRequest("No Changes Found"));
    }
    else {
      final HashMap<Key, Object> revTitlesMap = new HashMap<>(2);
      revTitlesMap.put(VCS_DIFF_LEFT_CONTENT_TITLE, revNumTitle1);
      revTitlesMap.put(VCS_DIFF_RIGHT_CONTENT_TITLE, revNumTitle2);
      ShowDiffContext showDiffContext = new ShowDiffContext() {
        @Nonnull
        @Override
        public Map<Key, Object> getChangeContext(@Nonnull Change change) {
          return revTitlesMap;
        }
      };
      ShowDiffAction.showDiffForChange(project, changes, 0, showDiffContext);
    }
  }
}
 
Example 6
Source File: VcsDirtyScopeVfsListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public VcsDirtyScopeVfsListener(@Nonnull Project project) {
  myVcsManager = ProjectLevelVcsManager.getInstance(project);

  VcsDirtyScopeManager dirtyScopeManager = VcsDirtyScopeManager.getInstance(project);

  myLock = new Object();
  myQueue = new ArrayList<>();
  myDirtReporter = () -> {
    ArrayList<FilesAndDirs> list;
    synchronized (myLock) {
      list = new ArrayList<>(myQueue);
      myQueue.clear();
    }

    HashSet<FilePath> dirtyFiles = new HashSet<>();
    HashSet<FilePath> dirtyDirs = new HashSet<>();
    for (FilesAndDirs filesAndDirs : list) {
      dirtyFiles.addAll(filesAndDirs.forcedNonRecursive);

      for (FilePath path : filesAndDirs.regular) {
        if (path.isDirectory()) {
          dirtyDirs.add(path);
        }
        else {
          dirtyFiles.add(path);
        }
      }
    }

    if (!dirtyFiles.isEmpty() || !dirtyDirs.isEmpty()) {
      dirtyScopeManager.filePathsDirty(dirtyFiles, dirtyDirs);
    }
  };
  myZipperUpdater = new ZipperUpdater(300, Alarm.ThreadToUse.POOLED_THREAD, this);
  Disposer.register(project, this);
  VirtualFileManager.getInstance().addAsyncFileListener(this, project);
}
 
Example 7
Source File: ChangesBrowserLocallyDeletedNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Image getIcon() {
  Image result = getUserObject().getAddIcon();

  if (result == null) {
    FilePath filePath = getUserObject().getPath();
    result = filePath.isDirectory() || !isLeaf() ? AllIcons.Nodes.TreeClosed : filePath.getFileType().getIcon();
  }

  return result;
}
 
Example 8
Source File: ChangesBrowserChangeNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Image getIcon(@Nonnull Change change, @Nonnull FilePath filePath) {
  Image result = change.getAdditionalIcon();

  if (result == null) {
    result = filePath.isDirectory() || !isLeaf() ? AllIcons.Nodes.TreeClosed : filePath.getFileType().getIcon();
  }

  return result;
}
 
Example 9
Source File: VirtualFileListCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void renderIcon(FilePath path) {
  if (path.isDirectory()) {
    setIcon(AllIcons.Nodes.TreeClosed);
  } else {
    setIcon(path.getFileType().getIcon());
  }
}
 
Example 10
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static StaticFilePath staticFrom(@Nonnull FilePath fp) {
  final String path = fp.getPath();
  if (fp.isNonLocal() && (!FileUtil.isAbsolute(path) || VcsUtil.isPathRemote(path))) {
    return new StaticFilePath(fp.isDirectory(), fp.getIOFile().getPath().replace('\\', '/'), fp.getVirtualFile());
  }
  return new StaticFilePath(fp.isDirectory(), new File(fp.getIOFile().getPath().replace('\\', '/')).getAbsolutePath(), fp.getVirtualFile());
}
 
Example 11
Source File: MoveChangesToAnotherListAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<Change> getChangesForSelectedFiles(@Nonnull Project project,
                                                       @Nonnull VirtualFile[] selectedFiles,
                                                       @Nonnull List<VirtualFile> unversionedFiles,
                                                       @Nonnull List<VirtualFile> changedFiles) {
  List<Change> changes = new ArrayList<>();
  ChangeListManager changeListManager = ChangeListManager.getInstance(project);

  for (VirtualFile vFile : selectedFiles) {
    Change change = changeListManager.getChange(vFile);
    if (change == null) {
      FileStatus status = changeListManager.getStatus(vFile);
      if (FileStatus.UNKNOWN.equals(status)) {
        unversionedFiles.add(vFile);
        changedFiles.add(vFile);
      }
      else if (FileStatus.NOT_CHANGED.equals(status) && vFile.isDirectory()) {
        addAllChangesUnderPath(changeListManager, VcsUtil.getFilePath(vFile), changes, changedFiles);
      }
    }
    else {
      FilePath afterPath = ChangesUtil.getAfterPath(change);
      if (afterPath != null && afterPath.isDirectory()) {
        addAllChangesUnderPath(changeListManager, afterPath, changes, changedFiles);
      }
      else {
        changes.add(change);
        changedFiles.add(vFile);
      }
    }
  }
  return changes;
}
 
Example 12
Source File: HierarchicalFilePathComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(@Nonnull FilePath filePath1, @Nonnull FilePath filePath2) {
  final String path1 = FileUtilRt.toSystemIndependentName(filePath1.getPath());
  final String path2 = FileUtilRt.toSystemIndependentName(filePath2.getPath());

  int index1 = 0;
  int index2 = 0;

  int start = 0;

  while (index1 < path1.length() && index2 < path2.length()) {
    char c1 = path1.charAt(index1);
    char c2 = path2.charAt(index2);

    if (StringUtil.compare(c1, c2, myIgnoreCase) != 0) break;

    if (c1 == '/') start = index1;

    index1++;
    index2++;
  }

  if (index1 == path1.length() && index2 == path2.length()) return 0;
  if (index1 == path1.length()) return -1;
  if (index2 == path2.length()) return 1;

  int end1 = path1.indexOf('/', start + 1);
  int end2 = path2.indexOf('/', start + 1);

  String name1 = end1 == -1 ? path1.substring(start) : path1.substring(start, end1);
  String name2 = end2 == -1 ? path2.substring(start) : path2.substring(start, end2);

  boolean isDirectory1 = end1 != -1 || filePath1.isDirectory();
  boolean isDirectory2 = end2 != -1 || filePath2.isDirectory();

  if (isDirectory1 && !isDirectory2) return -1;
  if (!isDirectory1 && isDirectory2) return 1;

  return StringUtil.compare(name1, name2, myIgnoreCase);
}
 
Example 13
Source File: TabbedShowHistoryAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isEnabled(@Nonnull Project project, @Nonnull FilePath path, @Nonnull VirtualFile fileOrParent) {
  boolean result = false;
  AbstractVcs vcs = ChangesUtil.getVcsForFile(fileOrParent, project);

  if (vcs != null) {
    VcsHistoryProvider provider = vcs.getVcsHistoryProvider();

    result = provider != null &&
             (provider.supportsHistoryForDirectories() || !path.isDirectory()) &&
             AbstractVcs.fileInVcsByFileStatus(project, fileOrParent) &&
             provider.canShowHistoryFor(fileOrParent);
  }

  return result;
}
 
Example 14
Source File: VcsStructureChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void renderIcon(@Nonnull FilePath path) {
  String module = myModules.get(path.getVirtualFile());
  if (module != null) {
    setIcon(AllIcons.Nodes.Module);
  }
  else {
    if (path.isDirectory()) {
      setIcon(AllIcons.Nodes.TreeClosed);
    }
    else {
      setIcon(path.getFileType().getIcon());
    }
  }
}
 
Example 15
Source File: P4ChangelistListener.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private boolean isUnderVcs(final FilePath path) {
    // Only files can be under VCS control.
    if (path.isDirectory()) {
        return false;
    }
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(path);
    return ((vcs != null) && (P4Vcs.VCS_NAME.equals(vcs.getName())));
}
 
Example 16
Source File: VcsGuess.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isFileInBaseDir(@Nonnull FilePath filePath, @Nullable VirtualFile baseDir) {
  VirtualFile parent = filePath.getVirtualFileParent();
  return !filePath.isDirectory() && parent != null && parent.equals(baseDir);
}
 
Example 17
Source File: VcsDirtyScopeImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean equals(@Nonnull FilePath path1, @Nonnull FilePath path2) {
  return path1.isDirectory() == path2.isDirectory() &&
         path1.isNonLocal() == path2.isNonLocal() &&
         path1.getPath().equals(path2.getPath());
}
 
Example 18
Source File: IdeaTextPatchBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@javax.annotation.Nullable
private static AirContentRevision convertRevisionToAir(final ContentRevision cr, final Long ts) {
  if (cr == null) return null;
  final FilePath fp = cr.getFile();
  final StaticPathDescription description = new StaticPathDescription(fp.isDirectory(),
                                                                      ts == null ? fp.getIOFile().lastModified() : ts, fp.getPath());
  if (cr instanceof BinaryContentRevision) {
    return new AirContentRevision() {
      @Override
      public boolean isBinary() {
        return true;
      }
      @Override
      public String getContentAsString() {
        throw new IllegalStateException();
      }
      @Override
      public byte[] getContentAsBytes() throws VcsException {
        return ((BinaryContentRevision) cr).getBinaryContent();
      }
      @Override
      public String getRevisionNumber() {
        return ts != null ? null : cr.getRevisionNumber().asString();
      }
      @Override
      @Nonnull
      public PathDescription getPath() {
        return description;
      }

      @Override
      public Charset getCharset() {
        return null;
      }
    };
  } else {
    return new AirContentRevision() {
      @Override
      public boolean isBinary() {
        return false;
      }
      @Override
      public String getContentAsString() throws VcsException {
        return cr.getContent();
      }
      @Override
      public byte[] getContentAsBytes() throws VcsException {
        throw new IllegalStateException();
      }
      @Override
      public String getRevisionNumber() {
        return ts != null ? null : cr.getRevisionNumber().asString();
      }
      @Override
      @Nonnull
      public PathDescription getPath() {
        return description;
      }

      @Override
      public Charset getCharset() {
        return fp.getCharset();
      }
    };
  }
}
 
Example 19
Source File: DiffRequestFactoryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getContentTitle(@Nonnull FilePath path) {
  if (path.isDirectory()) return path.getPresentableUrl();
  FilePath parent = path.getParentPath();
  return getContentTitle(path.getName(), path.getPresentableUrl(), parent != null ? parent.getPresentableUrl() : null);
}