Java Code Examples for com.intellij.openapi.vcs.FileStatusManager#getInstance()

The following examples show how to use com.intellij.openapi.vcs.FileStatusManager#getInstance() . 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: MultipleItemAction.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
/**
 * This method enables the action if one or more items are selected.
 *
 * @param project
 * @param files
 * @return
 */
protected boolean isEnabled(final Project project, final VirtualFile[] files) {
    if (files.length == 0 || project == null) {
        return false;
    }

    final FileStatusManager fileStatusManager = FileStatusManager.getInstance(project);
    for (VirtualFile file : files) {
        final FileStatus fileStatus = fileStatusManager.getStatus(file);
        if (fileStatus != FileStatus.NOT_CHANGED && fileStatus != FileStatus.MODIFIED && fileStatus != FileStatus.HIJACKED) {
            return false;
        }
    }

    return true;
}
 
Example 2
Source File: LineStatusTrackerManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean shouldBeInstalled(@javax.annotation.Nullable final VirtualFile virtualFile) {
  if (isDisabled()) return false;

  if (virtualFile == null || virtualFile instanceof LightVirtualFile) return false;
  final FileStatusManager statusManager = FileStatusManager.getInstance(myProject);
  if (statusManager == null) return false;
  if (!myStatusProvider.isSupported(virtualFile)) {
    log("shouldBeInstalled failed: no support found", virtualFile);
    return false;
  }
  final FileStatus status = statusManager.getStatus(virtualFile);
  if (status == FileStatus.NOT_CHANGED || status == FileStatus.ADDED || status == FileStatus.UNKNOWN || status == FileStatus.IGNORED) {
    log("shouldBeInstalled skipped: status=" + status, virtualFile);
    return false;
  }
  return true;
}
 
Example 3
Source File: AddAction.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
private static boolean isEnabled(final Project project, final VirtualFile[] files) {
    if (files.length == 0) {
        return false;
    }

    if (project == null) {
        logger.warn("Cannot enable AddAction because project is unknown (null)");
        return false;
    }

    final FileStatusManager fileStatusManager = FileStatusManager.getInstance(project);
    return TfsFileUtil.findUnknownFiles(files, fileStatusManager);
}
 
Example 4
Source File: CloseIgnoredEditorsAction.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Obtains if editor is allowed to be closed.
 *
 * @return editor is allowed to be closed
 */
@Override
protected boolean isFileToClose(final EditorComposite editor, final EditorWindow window) {
    final Project project = window.getManager().getProject();
    final FileStatusManager fileStatusManager = FileStatusManager.getInstance(project);
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    final VirtualFile fileInEditor = editor.getFile();
    return fileStatusManager != null &&
        fileStatusManager.getStatus(fileInEditor).equals(IgnoreFileStatusProvider.IGNORED) ||
        changeListManager.isIgnoredFile(fileInEditor);
}
 
Example 5
Source File: CoverageListNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CoverageListNode(Project project, 
                        final PsiNamedElement classOrPackage,
                        CoverageSuitesBundle bundle,
                        CoverageViewManager.StateBean stateBean) {
  super(project, classOrPackage);
  myName = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    public String compute() {
      return classOrPackage.getName(); 
    }
  });
  myBundle = bundle;
  myStateBean = stateBean;
  myFileStatusManager = FileStatusManager.getInstance(myProject);
}
 
Example 6
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return color of the {@code file} which corresponds to the
 * file's status
 */
public Color getFileColor(@Nonnull final VirtualFile file) {
  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  Color statusColor = fileStatusManager != null ? fileStatusManager.getStatus(file).getColor() : UIUtil.getLabelForeground();
  if (statusColor == null) statusColor = UIUtil.getLabelForeground();
  return statusColor;
}
 
Example 7
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isChanged(@Nonnull final EditorComposite editor) {
  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  if (fileStatusManager == null) return false;
  FileStatus status = fileStatusManager.getStatus(editor.getFile());
  return status != FileStatus.UNKNOWN && status != FileStatus.NOT_CHANGED;
}
 
Example 8
Source File: EditorChangeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void refreshFileStatus() {
  VirtualFile f = getAffectedDocuments()[0].getFile();
  if (f == null || f instanceof LightVirtualFile) return;

  for (Project each : ProjectManager.getInstance().getOpenProjects()) {
    FileStatusManagerImpl statusManager = (FileStatusManagerImpl)FileStatusManager.getInstance(each);
    statusManager.refreshFileStatusFromDocument(f, getDocument());
  }
}
 
Example 9
Source File: CloseEditorsActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
protected List<Pair<EditorComposite, EditorWindow>> getFilesToClose(final AnActionEvent event) {
  final ArrayList<Pair<EditorComposite, EditorWindow>> res = new ArrayList<>();
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
  final EditorWindow editorWindow = event.getData(EditorWindow.DATA_KEY);
  final EditorWindow[] windows;
  if (editorWindow != null) {
    windows = new EditorWindow[]{editorWindow};
  }
  else {
    windows = editorManager.getWindows();
  }
  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(project);
  if (fileStatusManager != null) {
    for (int i = 0; i != windows.length; ++i) {
      final EditorWindow window = windows[i];
      final EditorComposite[] editors = window.getEditors();
      for (final EditorComposite editor : editors) {
        if (isFileToClose(editor, window)) {
          res.add(Pair.create(editor, window));
        }
      }
    }
  }
  return res;
}
 
Example 10
Source File: FileOrDirectoryTreeNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public SimpleTextAttributes getAttributes() {
  if (!getFilePointer().isValid()) {
    return myInvalidAttributes;
  }
  VirtualFile file = getFilePointer().getFile();
  FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  FileStatus status = fileStatusManager.getStatus(file);
  SimpleTextAttributes attributes = getAttributesFor(status);
  return myFilterAttributes == null ? attributes : SimpleTextAttributes.merge(myFilterAttributes, attributes);
}
 
Example 11
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void projectOpened(@Nonnull MessageBusConnection connection) {
  //myFocusWatcher.install(myWindows.getComponent ());
  getMainSplitters().startListeningFocus();

  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  if (fileStatusManager != null) {
    /*
      Updates tabs colors
     */
    final MyFileStatusListener myFileStatusListener = new MyFileStatusListener();
    fileStatusManager.addFileStatusListener(myFileStatusListener, myProject);
  }
  connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootsListener());

  /*
    Updates tabs names
   */
  final MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
  VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener, myProject);
  /*
    Extends/cuts number of opened tabs. Also updates location of tabs.
   */
  connection.subscribe(UISettingsListener.TOPIC, new MyUISettingsListener());

  StartupManager.getInstance(myProject).registerPostStartupActivity((DumbAwareRunnable)() -> {
    if (myProject.isDisposed()) return;
    setTabsMode(UISettings.getInstance().getEditorTabPlacement() != UISettings.TABS_NONE);

    ToolWindowManager.getInstance(myProject).invokeLater(() -> {
      if (!myProject.isDisposed()) {
        CommandProcessor.getInstance().executeCommand(myProject, () -> {
          ApplicationManager.getApplication().invokeLater(() -> {
            long currentTime = System.nanoTime();
            Long startTime = myProject.getUserData(ProjectImpl.CREATION_TIME);
            if (startTime != null) {
              LOG.info("Project opening took " + (currentTime - startTime) / 1000000 + " ms");
              PluginManagerCore.dumpPluginClassStatistics(LOG);
            }
          }, myProject.getDisposed());
          // group 1
        }, "", null);
      }
    });
  });
}
 
Example 12
Source File: ReplaceFileConfirmationDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ReplaceFileConfirmationDialog(Project project, String actionName) {
  myFileStatusManager = FileStatusManager.getInstance(project);
  myActionName = actionName;
}
 
Example 13
Source File: SelectedFilesHelper.java    From consulo with Apache License 2.0 4 votes vote down vote up
private SelectedFilesHelper(final Project project, final AnActionEvent e) {
  myStatusManager = FileStatusManager.getInstance(project);
  myData = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
  myCheckers = new LinkedList<MyChecker>();
}
 
Example 14
Source File: VirtualFileListCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
public VirtualFileListCellRenderer(final Project project, final boolean ignoreFileStatus) {
  myIgnoreFileStatus = ignoreFileStatus;
  myFileStatusManager = FileStatusManager.getInstance(project);
}