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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations