public UpdateInfoTree( @NotNull ContentManager contentManager, @NotNull Project project, UpdatedFiles updatedFiles, String rootName, ActionInfo actionInfo) { super(contentManager, "reference.toolWindows.versionControl"); myActionInfo = actionInfo; myFileStatusListener = new FileStatusListener() { public void fileStatusesChanged() { myTree.repaint(); } public void fileStatusChanged(@NotNull VirtualFile virtualFile) { myTree.repaint(); } }; myProject = project; myUpdatedFiles = updatedFiles; myRootName = rootName; myFileStatusManager = FileStatusManager.getInstance(myProject); myFileStatusManager.addFileStatusListener(myFileStatusListener); createTree(); init(); myTreeExpander = new DefaultTreeExpander(myTree); myTreeIterable = new MyTreeIterable(); }
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); WolfTheProblemSolver.getInstance(project).addProblemListener(listener); ActionManager.getInstance().addAnActionListener(listener); final MessageBusConnection connection = project.getMessageBus().connect(); 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); } } }
@Override protected boolean approximatelyHasRoots(final VcsContext dataContext) { final FilePath[] paths = dataContext.getSelectedFilePaths(); if (paths.length == 0) return false; final FileStatusManager fsm = FileStatusManager.getInstance(dataContext.getProject()); for (final FilePath path : paths) { VirtualFile file = path.getVirtualFile(); if (file == null) { continue; } FileStatus status = fsm.getStatus(file); if (isApplicableRoot(file, status, dataContext)) { return true; } } return false; }
public void dispose() { super.dispose(); Disposer.dispose(myRoot); if (myFileStatusListener != null) { myFileStatusManager.removeFileStatusListener(myFileStatusListener); myFileStatusListener = null; } }
private void disposeListeners() { FileStatusManager.getInstance(myProject).removeFileStatusListener(myFileStatusListener); VirtualFileManager.getInstance().removeVirtualFileListener(myFileListener); VirtualFileManager.getInstance().removeVirtualFileManagerListener(myVirtualFileManagerListener); myProject .getComponent(ProjectLevelVcsManager.class) .removeVcsListener(myDirectoryMappingListener); ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListListener); myMessageBusConnection.disconnect(); }
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(); } }
protected boolean isEnabled( @NotNull Project project, @NotNull com.assembla.git.GitVcs vcs, @NotNull VirtualFile... vFiles) { for (VirtualFile file : vFiles) { if (FileStatusManager.getInstance(project).getStatus(file) == FileStatus.UNKNOWN) return false; } return true; }
protected void customizeCellRenderer( JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value instanceof VirtualFile) { VirtualFile virtualfile = (VirtualFile) value; String fileName = virtualfile.getName(); setIcon(IconUtilEx.getIcon(virtualfile, 2, project)); FileStatus filestatus = FileStatusManager.getInstance(project).getStatus(virtualfile); TextAttributes textattributes = new TextAttributes(filestatus.getColor(), null, null, EffectType.LINE_UNDERSCORE, 0); append(fileName, SimpleTextAttributes.fromTextAttributes(textattributes)); } }
@Nullable private static FileStatus getModelFileStatus( @NotNull EditableSModel ed, @NotNull Project project) { DataSource ds = ed.getSource(); IFile file = null; if (ds instanceof FileDataSource) { file = ((FileDataSource) ds).getFile(); } else if (ds instanceof FilePerRootDataSource) { file = ((FilePerRootDataSource) ds).getFile(FilePerRootDataSource.HEADER_FILE); } VirtualFile vf = VirtualFileUtils.getVirtualFile(file); return (vf == null ? null : FileStatusManager.getInstance(project).getStatus(vf)); }
public synchronized void dispose() { if (!(myInitialized)) { return; } myInitialized = false; if (myGlobalModelListener != null) { GlobalSModelEventsManager.getInstance().removeGlobalModelListener(myGlobalModelListener); } FileStatusManager.getInstance(myRegistry.getProject()) .removeFileStatusListener(myFileStatusListener); myTree.removeTreeNodeListener(myTreeNodeListener); myMap.removeListener(myFeatureListener); myQueue.dispose(); }
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); WolfTheProblemSolver.getInstance(project).removeProblemListener(listener); ActionManager.getInstance().removeAnActionListener(listener); final MessageBusConnection connection = (MessageBusConnection) panel.getClientProperty(BUS); panel.putClientProperty(BUS, null); if (connection != null) { connection.disconnect(); } } }
private void checkForMultipleCopiesNotMove(boolean somethingChanged) { final MultiMap<FilePath, Pair<Change, String>> moves = new MultiMap<FilePath, Pair<Change, String>>() { @NotNull protected Collection<Pair<Change, String>> createCollection() { return new LinkedList<Pair<Change, String>>(); } }; for (LocalChangeList changeList : myMap.values()) { final Collection<Change> changes = changeList.getChanges(); for (Change change : changes) { if (change.isMoved() || change.isRenamed()) { moves.putValue( change.getBeforeRevision().getFile(), Pair.create(change, changeList.getName())); } } } for (FilePath filePath : moves.keySet()) { final List<Pair<Change, String>> copies = (List<Pair<Change, String>>) moves.get(filePath); if (copies.size() == 1) continue; Collections.sort(copies, MyChangesAfterRevisionComparator.getInstance()); for (int i = 0; i < (copies.size() - 1); i++) { somethingChanged = true; final Pair<Change, String> item = copies.get(i); final Change oldChange = item.getFirst(); final Change newChange = new Change(null, oldChange.getAfterRevision()); final LocalChangeListImpl list = (LocalChangeListImpl) myMap.get(item.getSecond()); list.removeChange(oldChange); list.addChange(newChange); final VcsKey key = myIdx.getVcsFor(oldChange); myIdx.changeRemoved(oldChange); myIdx.changeAdded(newChange, key); } } if (somethingChanged) { FileStatusManager.getInstance(myProject).fileStatusesChanged(); } }
public synchronized void init() { if (myInitialized) { return; } myInitialized = true; myMap.addListener(myFeatureListener); myTree.addTreeNodeListener(myTreeNodeListener); FileStatusManager.getInstance(myRegistry.getProject()) .addFileStatusListener(myFileStatusListener); if (myGlobalModelListener != null) { GlobalSModelEventsManager.getInstance().addGlobalModelListener(myGlobalModelListener); } ModelAccess.instance() .runReadInEDT( new Runnable() { public void run() { registerNodeRecursively(myTree.getRootNode()); } }); }
private void installListeners() { FileStatusManager.getInstance(myProject) .addFileStatusListener(myFileStatusListener = new FileStatusChangeListener()); VirtualFileManager.getInstance() .addVirtualFileListener(myFileListener = new FileChangesListener()); VirtualFileManager.getInstance() .addVirtualFileManagerListener(myVirtualFileManagerListener = new RefreshListener()); myDirectoryMappingListener = new VcsListener() { public void directoryMappingChanged() { rebuildTreeLater(); } }; myProject.getComponent(ProjectLevelVcsManager.class).addVcsListener(myDirectoryMappingListener); ChangeListManager.getInstance(myProject) .addChangeListListener(myChangeListListener = new ChangeListUpdateListener()); myMessageBusConnection = myBus.connect(); myMessageBusConnection.subscribe( FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void fileOpened(FileEditorManager source, VirtualFile file) { if (myProjectView.isAutoscrollFromSource(getId())) { selectNode(file, false); } } @Override public void selectionChanged(FileEditorManagerEvent event) { if (myProjectView.isAutoscrollFromSource(getId())) { VirtualFile newFile = event.getNewFile(); if (newFile != null) { selectNode(newFile, false); } } } }); }
private static boolean annotate(@NotNull final EditorComponent editorComponent, boolean dryRun) { final LeftEditorHighlighter leftEditorHighlighter = editorComponent.getLeftEditorHighlighter(); if (findAnnotationColumn(editorComponent) != null) { if (!(dryRun)) { leftEditorHighlighter.removeLeftColumn(findAnnotationColumn(editorComponent)); } return true; } final SNode root = editorComponent.getEditedNode(); SModel model = check_19hp0u_a0d0b(root); SModelDescriptor modelDescriptor = check_19hp0u_a0e0b(model); if (!((modelDescriptor instanceof EditableSModelDescriptor))) { return false; } IFile modelFile = ((EditableSModelDescriptor) modelDescriptor).getModelFile(); if (modelFile == null) { return false; } final VirtualFile file = VirtualFileUtils.getVirtualFile(modelFile); final Project project = ProjectHelper.toIdeaProject(editorComponent.getOperationContext().getProject()); final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file); if (vcs == null) { return false; } _FunctionTypes._return_P1_E0<? extends Boolean, ? super FileStatus> checkFileStatus = new _FunctionTypes._return_P1_E0<Boolean, FileStatus>() { public Boolean invoke(FileStatus fs) { return fs == FileStatus.UNKNOWN || fs == FileStatus.ADDED || fs == FileStatus.IGNORED; } }; if (checkFileStatus.invoke(FileStatusManager.getInstance(project).getStatus(file))) { return false; } final AnnotationProvider annotationProvider = vcs.getAnnotationProvider(); if (annotationProvider == null) { return false; } if (dryRun) { return true; } Task.Backgroundable annotateTask = new Task.Backgroundable( project, "Retrieving annotations", true, BackgroundFromStartOption.getInstance()) { private FileAnnotation myFileAnnotation; private VcsException myException; public void run(@NotNull ProgressIndicator indicator) { try { myFileAnnotation = annotationProvider.annotate(file); } catch (VcsException e) { myException = e; } } @Override public void onCancel() { onSuccess(); } @Override public void onSuccess() { if (myException != null) { AbstractVcsHelper.getInstance(project) .showErrors(Arrays.asList(myException), "Exception on retrieving annotation"); } if (myFileAnnotation != null) { ModelAccess.instance() .runReadAction( new Runnable() { public void run() { AnnotationColumn annotationColumn = new AnnotationColumn( leftEditorHighlighter, root, myFileAnnotation, vcs, file); leftEditorHighlighter.addLeftColumn(annotationColumn); } }); } } }; ProgressManager.getInstance().run(annotateTask); return true; }
protected void statusChanged(FileStatusManager fsm, @NotNull SNode node) { fsm.fileStatusChanged(myNodeFileSystem.getFileFor(myMPSProject.getRepository(), node)); }
private void update(boolean force) { final Wrappers._boolean _force = new Wrappers._boolean(force); myQueue.assertSoftlyIsCommandThread(); if (!(myDifference.isEnabled())) { return; } IFile modelFile = myModelDescriptor.getSource().getFile(); if (!(modelFile.exists())) { return; } VirtualFile modelVFile = VirtualFileUtils.getVirtualFile(modelFile); if (modelVFile == null || ProjectLevelVcsManager.getInstance(myProject).getVcsFor(modelVFile) == null) { return; } FileStatus status = FileStatusManager.getInstance(myProject).getStatus(modelVFile); if (ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) { status = FileStatus.MERGED_WITH_CONFLICTS; } if (myDifference.getChangeSet() != null) { ModelAccess.instance() .runReadAction( new Runnable() { public void run() { if (myDifference.getChangeSet().getNewModel() != myModelDescriptor.getSModel()) { _force.value = true; } } }); } if (myStatusOnLastUpdate == status && !(_force.value)) { return; } myDifference.removeChangeSet(); myStatusOnLastUpdate = status; if (FileStatus.NOT_CHANGED == status && !(_force.value)) { return; } final Wrappers._T<SModel> baseVersionModel = new Wrappers._T<SModel>(null); if (BaseVersionUtil.isAddedFileStatus(status) || ConflictsUtil.isModelOrModuleConflicting(myModelDescriptor, myProject)) { baseVersionModel.value = new jetbrains.mps.smodel.SModel(myModelDescriptor.getSModelReference()); } else { String content = BaseVersionUtil.getBaseVersionContent(modelVFile, myProject); if (content == null && status != FileStatus.NOT_CHANGED) { LOG.error("Base version content is null while file status is " + status); } if (content == null) { return; } try { baseVersionModel.value = ModelPersistence.readModel(content, false); } catch (ModelReadException e) { LOG.warning("", e); return; } } ModelAccess.instance() .runReadAction( new Runnable() { public void run() { synchronized (ChangesTracking.this) { if (!(myDisposed)) { ChangeSet changeSet = ChangeSetBuilder.buildChangeSet( baseVersionModel.value, myModelDescriptor.getSModel(), true); myDifference.setChangeSet((ChangeSetImpl) changeSet); buildCaches(); } } } }); }
@Override public void initComponent() { myClassLoaderManager.addReloadHandler(myReloadListener); FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener); GlobalSModelEventsManager.getInstance().addGlobalModelListener(myListener); }
@Override public void disposeComponent() { GlobalSModelEventsManager.getInstance().removeGlobalModelListener(myListener); FileStatusManager.getInstance(myProject).removeFileStatusListener(myFileStatusListener); myClassLoaderManager.removeReloadHandler(myReloadListener); }