com.intellij.openapi.vcs.FileStatusManager Java Examples

The following examples show how to use com.intellij.openapi.vcs.FileStatusManager. 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: LafManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void fireUpdate() {

    UISettings.getInstance().fireUISettingsChanged();
    EditorFactory.getInstance().refreshAllEditors();

    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    for (Project openProject : openProjects) {
      FileStatusManager.getInstance(openProject).fileStatusesChanged();
      DaemonCodeAnalyzer.getInstance(openProject).restart();
    }
    for (IdeFrame frame : WindowManagerEx.getInstanceEx().getAllProjectFrames()) {
      if (frame instanceof IdeFrameEx) {
        ((IdeFrameEx)frame).updateView();
      }
    }
    ActionToolbarImpl.updateAllToolbarsImmediately();
  }
 
Example #3
Source File: ProjectListBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ProjectListBuilder(final Project project,
                          final CommanderPanel panel,
                          final AbstractTreeStructure treeStructure,
                          final Comparator comparator,
                          final boolean showRoot) {
  super(project, panel.getList(), panel.getModel(), treeStructure, comparator, showRoot);

  myList.setCellRenderer(new ColoredCommanderRenderer(panel));
  myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, myProject);

  myPsiTreeChangeListener = new MyPsiTreeChangeListener();
  PsiManager.getInstance(myProject).addPsiTreeChangeListener(myPsiTreeChangeListener);
  myFileStatusListener = new MyFileStatusListener();
  FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener);
  myCopyPasteListener = new MyCopyPasteListener();
  CopyPasteManager.getInstance().addContentChangedListener(myCopyPasteListener);
  buildRoot();
}
 
Example #4
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 #5
Source File: LineStatusTrackerManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void projectOpened() {
  StartupManager.getInstance(myProject).registerPreStartupActivity(new Runnable() {
    @Override
    public void run() {
      final MyFileStatusListener fileStatusListener = new MyFileStatusListener();
      final EditorFactoryListener editorFactoryListener = new MyEditorFactoryListener();
      final MyVirtualFileListener virtualFileListener = new MyVirtualFileListener();

      final FileStatusManager fsManager = FileStatusManager.getInstance(myProject);
      fsManager.addFileStatusListener(fileStatusListener, myDisposable);

      final EditorFactory editorFactory = EditorFactory.getInstance();
      editorFactory.addEditorFactoryListener(editorFactoryListener, myDisposable);

      final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
      virtualFileManager.addVirtualFileListener(virtualFileListener, myDisposable);
    }
  });
}
 
Example #6
Source File: Switcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(@Nonnull JList<? extends FileInfo> list, FileInfo value, int index, boolean selected, boolean hasFocus) {
  Project project = mySwitcherPanel.project;
  VirtualFile virtualFile = value.getFirst();
  String renderedName = value.getNameForRendering();
  setIcon(VfsIconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_READ_STATUS, project));

  FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(virtualFile);
  open = FileEditorManager.getInstance(project).isFileOpen(virtualFile);

  boolean hasProblem = WolfTheProblemSolver.getInstance(project).isProblemFile(virtualFile);
  TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, hasProblem ? JBColor.red : null, EffectType.WAVE_UNDERSCORE, Font.PLAIN);
  append(renderedName, SimpleTextAttributes.fromTextAttributes(attributes));

  // calc color the same way editor tabs do this, i.e. including EPs
  Color color = EditorTabPresentationUtil.getFileBackgroundColor(project, virtualFile);

  if (!selected && color != null) {
    setBackground(color);
  }
  SpeedSearchUtil.applySpeedSearchHighlighting(mySwitcherPanel, this, false, selected);

  IdeDocumentHistoryImpl.appendTimestamp(project, this, virtualFile);
}
 
Example #7
Source File: TfsFileUtil.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
/**
 * Recursively look for files that have a status UNKNOWN
 *
 * @param files
 * @param fileStatusManager
 * @return
 */
public static boolean findUnknownFiles(final VirtualFile[] files, final FileStatusManager fileStatusManager) {
    for (VirtualFile file : files) {
        // if directory then check children
        if (file.isDirectory()) {
            if (findUnknownFiles(file.getChildren(), fileStatusManager)) {
                return true;
            }
        } else {
            final FileStatus fileStatus = fileStatusManager.getStatus(file);
            if (fileStatus == FileStatus.UNKNOWN) {
                return true;
            }
        }
    }
    return false;
}
 
Example #8
Source File: NavigationItemFileStatus.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static FileStatus getPsiElementFileStatus(PsiElement psiElement) {
  if (!psiElement.isPhysical()) return FileStatus.NOT_CHANGED;
  PsiFile contFile = psiElement.getContainingFile();
  if (contFile == null) return FileStatus.NOT_CHANGED;
  VirtualFile vFile = contFile.getVirtualFile();
  return vFile != null ? FileStatusManager.getInstance(psiElement.getProject()).getStatus(vFile) : FileStatus.NOT_CHANGED;
}
 
Example #9
Source File: BookmarkItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void setupRenderer(SimpleColoredComponent renderer, Project project, Bookmark bookmark, boolean selected) {
  VirtualFile file = bookmark.getFile();
  if (!file.isValid()) {
    return;
  }

  PsiManager psiManager = PsiManager.getInstance(project);

  PsiElement fileOrDir = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);
  if (fileOrDir != null) {
    renderer.setIcon(IconDescriptorUpdaters.getIcon(fileOrDir, 0));
  }

  String description = bookmark.getDescription();
  if (description != null) {
    renderer.append(description + " ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
  }

  FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
  TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
  renderer.append(file.getName(), SimpleTextAttributes.fromTextAttributes(attributes));
  if (bookmark.getLine() >= 0) {
    renderer.append(":", SimpleTextAttributes.GRAYED_ATTRIBUTES);
    renderer.append(String.valueOf(bookmark.getLine() + 1), SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }

  if (!selected) {
    FileColorManager colorManager = FileColorManager.getInstance(project);
    if (fileOrDir instanceof PsiFile) {
      Color color = colorManager.getRendererBackground((PsiFile)fileOrDir);
      if (color != null) {
        renderer.setBackground(color);
      }
    }
  }
}
 
Example #10
Source File: ProjectListBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  super.dispose();
  PsiManager.getInstance(myProject).removePsiTreeChangeListener(myPsiTreeChangeListener);
  FileStatusManager.getInstance(myProject).removeFileStatusListener(myFileStatusListener);
  CopyPasteManager.getInstance().removeContentChangedListener(myCopyPasteListener);
}
 
Example #11
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 #12
Source File: HierarchyTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
HierarchyTreeBuilder(@Nonnull Project project,
                     final JTree tree,
                     final DefaultTreeModel treeModel,
                     final HierarchyTreeStructure treeStructure,
                     final Comparator<NodeDescriptor> comparator) {
  super(tree, treeModel, treeStructure, comparator);

  initRootNode();
  PsiManager.getInstance(project).addPsiTreeChangeListener(new MyPsiTreeChangeListener(), this);
  FileStatusManager.getInstance(project).addFileStatusListener(new MyFileStatusListener(), this);
}
 
Example #13
Source File: FileNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Color getColor() {
  if (myColor == null) {
    myColor = FileStatusManager.getInstance(myProject).getStatus(myVFile).getColor();
    if (myColor == null) {
      myColor = NOT_CHANGED;
    }
  }
  return myColor == NOT_CHANGED ? null : myColor;
}
 
Example #14
Source File: ColorAndFontOptions.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void applyChangesToEditors() {
  EditorFactory.getInstance().refreshAllEditors();

  TodoConfiguration.getInstance().colorSettingsChanged();
  Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
  for (Project openProject : openProjects) {
    FileStatusManager.getInstance(openProject).fileStatusesChanged();
    DaemonCodeAnalyzer.getInstance(openProject).restart();
    BookmarkManager.getInstance(openProject).colorsChanged();
  }
}
 
Example #15
Source File: TodoTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the builder. Subclasses should don't forget to call this method after constructor has
 * been invoked.
 */
public final void init() {
  myTreeStructure = createTreeStructure();
  myTreeStructure.setTreeBuilder(this);

  try {
    rebuildCache();
  }
  catch (IndexNotReadyException ignore) {
  }

  FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener);
}
 
Example #16
Source File: ImplementationViewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateRenderer(final Project project) {
  myFileChooser.setRenderer(new ListCellRendererWrapper<FileDescriptor>() {
    @Override
    public void customize(JList list, FileDescriptor value, int index, boolean selected, boolean hasFocus) {
      final PsiFile file = value.myFile;
      setIcon(getIconForFile(file));
      final VirtualFile vFile = file.getVirtualFile();
      setForeground(FileStatusManager.getInstance(project).getStatus(vFile).getColor());
      //noinspection ConstantConditions
      setText(value.getPresentableName(vFile));
    }
  });
}
 
Example #17
Source File: NavBarListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void subscribeTo(NavBarPanel panel) {
  if (panel.getClientProperty(LISTENER) != null) {
    unsubscribeFrom(panel);
  }

  final NavBarListener listener = new NavBarListener(panel);
  final Project project = panel.getProject();
  panel.putClientProperty(LISTENER, listener);
  KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
  FileStatusManager.getInstance(project).addFileStatusListener(listener);
  PsiManager.getInstance(project).addPsiTreeChangeListener(listener);

  final MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(AnActionListener.TOPIC, listener);
  connection.subscribe(ProblemListener.TOPIC, listener);
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
  connection.subscribe(NavBarModelListener.NAV_BAR, listener);
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
  panel.putClientProperty(BUS, connection);
  panel.addKeyListener(listener);

  if (panel.isInFloatingMode()) {
    final Window window = SwingUtilities.windowForComponent(panel);
    if (window != null) {
      window.addWindowFocusListener(listener);
    }
  }
}
 
Example #18
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 #19
Source File: NavBarListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void unsubscribeFrom(NavBarPanel panel) {
  final NavBarListener listener = (NavBarListener)panel.getClientProperty(LISTENER);
  panel.putClientProperty(LISTENER, null);
  if (listener != null) {
    final Project project = panel.getProject();
    KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener);
    FileStatusManager.getInstance(project).removeFileStatusListener(listener);
    PsiManager.getInstance(project).removePsiTreeChangeListener(listener);
    final MessageBusConnection connection = (MessageBusConnection)panel.getClientProperty(BUS);
    panel.putClientProperty(BUS, null);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
 
Example #20
Source File: KnowledgeViewTreeBuilder.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public KnowledgeViewTreeBuilder(@Nonnull Project project,
                                @Nonnull JTree tree,
                                @Nonnull DefaultTreeModel treeModel,
                                @Nullable Comparator<NodeDescriptor> comparator,
                                @Nonnull KnowledgeViewPanelTreeStructure treeStructure) {
  super(project, tree, treeModel, treeStructure, comparator);

  final MessageBusConnection connection = project.getMessageBus().connect(this);

  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
    @Override
    public void rootsChanged(ModuleRootEvent event) {
      queueUpdate();
    }
  });

  connection.subscribe(BookmarksListener.TOPIC, new MyBookmarksListener());

  PsiManager.getInstance(project).addPsiTreeChangeListener(createPsiTreeChangeListener(project), this);
  FileStatusManager.getInstance(project).addFileStatusListener(new MyFileStatusListener(), this);
  CopyPasteManager.getInstance().addContentChangedListener(new CopyPasteUtil.DefaultCopyPasteListener(getUpdater()), this);

  WolfTheProblemSolver.getInstance(project).addProblemListener(new MyProblemListener(), this);

  setCanYieldUpdate(true);

  initRootNode();
}
 
Example #21
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 #22
Source File: ProjectTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ProjectTreeBuilder(@Nonnull Project project,
                          @Nonnull JTree tree,
                          @Nonnull DefaultTreeModel treeModel,
                          @Nullable Comparator<NodeDescriptor> comparator,
                          @Nonnull ProjectAbstractTreeStructureBase treeStructure) {
  super(project, tree, treeModel, treeStructure, comparator);

  final MessageBusConnection connection = project.getMessageBus().connect(this);

  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
    @Override
    public void rootsChanged(ModuleRootEvent event) {
      queueUpdate();
    }
  });

  connection.subscribe(BookmarksListener.TOPIC, new MyBookmarksListener());

  PsiManager.getInstance(project).addPsiTreeChangeListener(createPsiTreeChangeListener(project), this);
  FileStatusManager.getInstance(project).addFileStatusListener(new MyFileStatusListener(), this);
  CopyPasteManager.getInstance().addContentChangedListener(new CopyPasteUtil.DefaultCopyPasteListener(getUpdater()), this);

  connection.subscribe(ProblemListener.TOPIC, new MyProblemListener());

  setCanYieldUpdate(true);

  initRootNode();
}
 
Example #23
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 #24
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 #25
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 #26
Source File: ExcludedEntriesConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void apply() {
  myConfiguration.removeAllExcludeEntryDescriptions();
  for (ExcludeEntryDescription description : myExcludeEntryDescriptions) {
    myConfiguration.addExcludeEntryDescription(description.copy(myProject));
  }
  FileStatusManager.getInstance(myProject).fileStatusesChanged(); // refresh exclude from compile status
}
 
Example #27
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 #28
Source File: AbstractTreeNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Color getFileStatusColor(final FileStatus status) {
  if (FileStatus.NOT_CHANGED.equals(status) && !myProject.isDefault()) {
    final VirtualFile vf = getVirtualFile();
    if (vf != null && vf.isDirectory()) {
      return FileStatusManager.getInstance(myProject).getRecursiveStatus(vf).getColor();
    }
  }
  return status.getColor();
}
 
Example #29
Source File: ExcludeFromCompileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  VirtualFile file = getSelectedFile();

  if (file != null && file.isValid()) {
    ExcludeEntryDescription description = new ExcludeEntryDescription(file, false, true, myProject);
    CompilerManager.getInstance(myProject).getExcludedEntriesConfiguration().addExcludeEntryDescription(description);
    FileStatusManager.getInstance(myProject).fileStatusesChanged();
  }
}
 
Example #30
Source File: P4Vcs.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the specified file path represents a file which exists in the VCS repository (is neither
 * unversioned nor scheduled for addition).
 * This method is called only for directories which are mapped to this VCS in the project configuration.
 *
 * @param path the path to check.
 * @return true if the corresponding file exists in the repository, false otherwise.
 */
@Override
public boolean fileExistsInVcs(FilePath path) {
    // TODO if this ends up being called as we expect, then delete this overridden method.

    final VirtualFile virtualFile = path.getVirtualFile();
    if (virtualFile != null) {
        final FileStatus fileStatus = FileStatusManager.getInstance(myProject).getStatus(virtualFile);
        LOG.info("Checking if file exists in VCS; if so, then it will use the `VcsHandleType` to edit the file.  File: [" + path + "]; status: " + fileStatus);
        return fileStatus != FileStatus.UNKNOWN && fileStatus != FileStatus.ADDED;
    }
    return true;
}