Search in sources :

Example 36 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class BaseAnalysisActionDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTitledSeparator.setText(myAnalysisNoon);
    //include test option
    myInspectTestSource.setSelected(myAnalysisOptions.ANALYZE_TEST_SOURCES);
    myInspectTestSource.setVisible(ModuleUtil.isSupportedRootType(myProject, JavaSourceRootType.TEST_SOURCE));
    //module scope if applicable
    myModuleButton.setText(AnalysisScopeBundle.message("scope.option.module.with.mnemonic", myModuleName));
    boolean useModuleScope = false;
    if (myModuleName != null) {
        useModuleScope = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.MODULE;
        myModuleButton.setSelected(myRememberScope && useModuleScope);
    }
    myModuleButton.setVisible(myModuleName != null && ModuleManager.getInstance(myProject).getModules().length > 1);
    boolean useUncommitedFiles = false;
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    final boolean hasVCS = !changeListManager.getAffectedFiles().isEmpty();
    if (hasVCS) {
        useUncommitedFiles = myAnalysisOptions.SCOPE_TYPE == AnalysisScope.UNCOMMITTED_FILES;
        myUncommitedFilesButton.setSelected(myRememberScope && useUncommitedFiles);
    }
    myUncommitedFilesButton.setVisible(hasVCS);
    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
    model.addElement(ALL);
    final List<? extends ChangeList> changeLists = changeListManager.getChangeListsCopy();
    for (ChangeList changeList : changeLists) {
        model.addElement(changeList.getName());
    }
    myChangeLists.setRenderer(new ListCellRendererWrapper<String>() {

        @Override
        public void customize(JList list, String value, int index, boolean selected, boolean hasFocus) {
            int availableWidth = myPanel.getWidth() - myUncommitedFilesButton.getWidth() - JBUI.scale(10);
            if (availableWidth <= 0) {
                availableWidth = JBUI.scale(200);
            }
            if (list.getFontMetrics(list.getFont()).stringWidth(value) < availableWidth) {
                setText(value);
            } else {
                setText(StringUtil.trimLog(value, 50));
            }
        }
    });
    myChangeLists.setModel(model);
    myChangeLists.setEnabled(myUncommitedFilesButton.isSelected());
    myChangeLists.setVisible(hasVCS);
    //file/package/directory/module scope
    if (myFileName != null) {
        myFileButton.setText(myFileName);
        myFileButton.setMnemonic(myFileName.charAt(getSelectedScopeMnemonic()));
    } else {
        myFileButton.setVisible(false);
    }
    VirtualFile file = PsiUtilBase.getVirtualFile(myContext);
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    boolean searchInLib = file != null && (fileIndex.isInLibraryClasses(file) || fileIndex.isInLibrarySource(file));
    String preselect = StringUtil.isEmptyOrSpaces(myAnalysisOptions.CUSTOM_SCOPE_NAME) ? FindSettings.getInstance().getDefaultScopeName() : myAnalysisOptions.CUSTOM_SCOPE_NAME;
    if (searchInLib && GlobalSearchScope.projectScope(myProject).getDisplayName().equals(preselect)) {
        preselect = GlobalSearchScope.allScope(myProject).getDisplayName();
    }
    if (GlobalSearchScope.allScope(myProject).getDisplayName().equals(preselect) && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM) {
        myAnalysisOptions.CUSTOM_SCOPE_NAME = preselect;
        searchInLib = true;
    }
    //custom scope
    myCustomScopeButton.setSelected(myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.CUSTOM);
    myScopeCombo.init(myProject, searchInLib, true, preselect);
    myScopeCombo.setCurrentSelection(false);
    //correct selection
    myProjectButton.setSelected(myRememberScope && myAnalysisOptions.SCOPE_TYPE == AnalysisScope.PROJECT || myFileName == null);
    myFileButton.setSelected(myFileName != null && (!myRememberScope || myAnalysisOptions.SCOPE_TYPE != AnalysisScope.PROJECT && !useModuleScope && myAnalysisOptions.SCOPE_TYPE != AnalysisScope.CUSTOM && !useUncommitedFiles));
    myScopeCombo.setEnabled(myCustomScopeButton.isSelected());
    final ActionListener radioButtonPressed = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            onScopeRadioButtonPressed();
        }
    };
    final Enumeration<AbstractButton> enumeration = myGroup.getElements();
    while (enumeration.hasMoreElements()) {
        enumeration.nextElement().addActionListener(radioButtonPressed);
    }
    //additional panel - inspection profile chooser
    JPanel wholePanel = new JPanel(new BorderLayout());
    wholePanel.add(myPanel, BorderLayout.NORTH);
    final JComponent additionalPanel = getAdditionalActionSettings(myProject);
    if (additionalPanel != null) {
        wholePanel.add(additionalPanel, BorderLayout.CENTER);
    }
    new RadioUpDownListener(myProjectButton, myModuleButton, myUncommitedFilesButton, myFileButton, myCustomScopeButton);
    return wholePanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) RadioUpDownListener(com.intellij.refactoring.util.RadioUpDownListener) ActionListener(java.awt.event.ActionListener) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 37 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class ChangeListTodosTreeStructure method accept.

@Override
public boolean accept(final PsiFile psiFile) {
    if (!psiFile.isValid())
        return false;
    VirtualFile file = psiFile.getVirtualFile();
    ChangeListManager listManager = ChangeListManager.getInstance(myProject);
    FileStatus status = listManager.getStatus(file);
    if (status == FileStatus.NOT_CHANGED)
        return false;
    FilePath filePath = VcsUtil.getFilePath(file);
    final Collection<Change> changes = listManager.getDefaultChangeList().getChanges();
    for (Change change : changes) {
        ContentRevision afterRevision = change.getAfterRevision();
        if (afterRevision != null && afterRevision.getFile().equals(filePath)) {
            return (myTodoFilter != null && myTodoFilter.accept(mySearchHelper, psiFile) || (myTodoFilter == null && mySearchHelper.getTodoItemsCount(psiFile) > 0));
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) FileStatus(com.intellij.openapi.vcs.FileStatus) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 38 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class FormatChangedTextUtil method getChangedFilesFromDirs.

@NotNull
public static List<PsiFile> getChangedFilesFromDirs(@NotNull Project project, @NotNull List<PsiDirectory> dirs) {
    ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    Collection<Change> changes = ContainerUtil.newArrayList();
    for (PsiDirectory dir : dirs) {
        changes.addAll(changeListManager.getChangesIn(dir.getVirtualFile()));
    }
    return getChangedFiles(project, changes);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class CommonCheckinFilesAction method getInitiallySelectedChangeList.

@Nullable
@Override
protected LocalChangeList getInitiallySelectedChangeList(@NotNull VcsContext context, @NotNull Project project) {
    ChangeListManager manager = ChangeListManager.getInstance(project);
    LocalChangeList defaultChangeList = manager.getDefaultChangeList();
    LocalChangeList result = null;
    for (FilePath root : getRoots(context)) {
        if (root.getVirtualFile() == null)
            continue;
        Collection<Change> changes = manager.getChangesIn(root);
        if (defaultChangeList != null && containsAnyChange(defaultChangeList, changes)) {
            return defaultChangeList;
        }
        result = changes.stream().findFirst().map(manager::getChangeList).orElse(null);
    }
    return ObjectUtils.chooseNotNull(result, defaultChangeList);
}
Also used : LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class BaseAnalysisActionDialog method getScope.

@NotNull
public AnalysisScope getScope(@NotNull AnalysisUIOptions uiOptions, @NotNull AnalysisScope defaultScope, @NotNull Project project, Module module) {
    AnalysisScope scope;
    if (isProjectScopeSelected()) {
        scope = new AnalysisScope(project);
        uiOptions.SCOPE_TYPE = AnalysisScope.PROJECT;
    } else {
        final SearchScope customScope = getCustomScope();
        if (customScope != null) {
            scope = new AnalysisScope(customScope, project);
            uiOptions.SCOPE_TYPE = AnalysisScope.CUSTOM;
            uiOptions.CUSTOM_SCOPE_NAME = customScope.getDisplayName();
        } else if (isModuleScopeSelected()) {
            scope = new AnalysisScope(module);
            uiOptions.SCOPE_TYPE = AnalysisScope.MODULE;
        } else if (isUncommitedFilesSelected()) {
            final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
            List<VirtualFile> files;
            if (myChangeLists.getSelectedItem() == ALL) {
                files = changeListManager.getAffectedFiles();
            } else {
                files = new ArrayList<>();
                for (ChangeList list : changeListManager.getChangeListsCopy()) {
                    if (!Comparing.strEqual(list.getName(), (String) myChangeLists.getSelectedItem()))
                        continue;
                    final Collection<Change> changes = list.getChanges();
                    for (Change change : changes) {
                        final ContentRevision afterRevision = change.getAfterRevision();
                        if (afterRevision != null) {
                            final VirtualFile vFile = afterRevision.getFile().getVirtualFile();
                            if (vFile != null) {
                                files.add(vFile);
                            }
                        }
                    }
                }
            }
            scope = new AnalysisScope(project, new HashSet<>(files));
            uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES;
        } else {
            scope = defaultScope;
            //just not project scope
            uiOptions.SCOPE_TYPE = defaultScope.getScopeType();
        }
    }
    uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources();
    scope.setIncludeTestSource(isInspectTestSources());
    FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName());
    return scope;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) SearchScope(com.intellij.psi.search.SearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)77 VirtualFile (com.intellij.openapi.vfs.VirtualFile)65 Test (org.junit.Test)57 Change (com.intellij.openapi.vcs.changes.Change)42 File (java.io.File)28 LocalChangeList (com.intellij.openapi.vcs.changes.LocalChangeList)24 ConflictVersion (org.jetbrains.idea.svn.conflict.ConflictVersion)23 TreeConflictDescription (org.jetbrains.idea.svn.conflict.TreeConflictDescription)23 ArrayList (java.util.ArrayList)11 VcsException (com.intellij.openapi.vcs.VcsException)6 NotNull (org.jetbrains.annotations.NotNull)4 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)3 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)2 Nullable (org.jetbrains.annotations.Nullable)2 AccessToken (com.intellij.openapi.application.AccessToken)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 FileNodeDescriptor (com.intellij.openapi.fileChooser.ex.FileNodeDescriptor)1 FileSystemTreeImpl (com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl)1 Project (com.intellij.openapi.project.Project)1