@Override public void rebuildList() { if (myInRebuildList) return; try { myInRebuildList = true; if (myChangesToDisplay == null) { // changes set not fixed === local changes final ChangeListManager manager = ChangeListManager.getInstance(myProject); myChangeListsMap = new HashMap<Change, LocalChangeList>(); final List<LocalChangeList> lists = manager.getChangeListsCopy(); Collection<Change> allChanges = new ArrayList<Change>(); for (LocalChangeList list : lists) { final Collection<Change> changes = list.getChanges(); allChanges.addAll(changes); for (Change change : changes) { myChangeListsMap.put(change, list); } } myAllChanges = allChanges; // refresh selected list also updateListsInChooser(); } super.rebuildList(); if (myRebuildListListener != null) { myRebuildListListener.run(); } } finally { myInRebuildList = false; } }
public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return; final ShelvedChangeList[] changeLists = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY); List<ShelvedChange> changes = e.getData(ShelvedChangesViewManager.SHELVED_CHANGE_KEY); List<ShelvedBinaryFile> binaryFiles = e.getData(ShelvedChangesViewManager.SHELVED_BINARY_FILE_KEY); if (changes != null && binaryFiles != null && changes.size() == 0 && binaryFiles.size() == 0) { changes = null; binaryFiles = null; } LOG.assertTrue(changeLists != null); final ChangeListManager changeListManager = ChangeListManager.getInstance(project); final List<LocalChangeList> allChangeLists = changeListManager.getChangeListsCopy(); String defaultName = changeLists[0].DESCRIPTION; LocalChangeList list = null; if (changeLists.length == 1) { final LocalChangeList sameNamedList = changeListManager.findChangeList(defaultName); if (sameNamedList != null) { list = sameNamedList; } } if (list == null) { list = changeListManager.getDefaultChangeList(); } final ChangeListChooser chooser = new ChangeListChooser( project, allChangeLists, list, VcsBundle.message("unshelve.changelist.chooser.title"), defaultName); chooser.show(); if (!chooser.isOK()) { return; } FileDocumentManager.getInstance().saveAllDocuments(); final List<ShelvedBinaryFile> finalBinaryFiles = binaryFiles; final List<ShelvedChange> finalChanges = changes; ProgressManager.getInstance() .run( new Task.Backgroundable( project, "Unshelve changes", true, BackgroundFromStartOption.getInstance()) { @Override public void run(@NotNull ProgressIndicator indicator) { for (ShelvedChangeList changeList : changeLists) { ShelveChangesManager.getInstance(project) .unshelveChangeList( changeList, finalChanges, finalBinaryFiles, chooser.getSelectedList()); } } }); }
@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<VirtualFile>(); 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<VirtualFile>(files)); uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES; } else { scope = defaultScope; uiOptions.SCOPE_TYPE = defaultScope.getScopeType(); // just not project scope } } uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources(); scope.setIncludeTestSource(isInspectTestSources()); scope.setScope(getCustomScope()); FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName()); return scope; }
@Override public void run(ContinuationContext context) { final String message; final Intersection intersection; final ChangeListManager listManager = ChangeListManager.getInstance(myProject); final List<LocalChangeList> localChangeLists = listManager.getChangeListsCopy(); if (myMergeAll) { intersection = getMergeAllIntersection(localChangeLists); message = "There are local changes that can potentially intersect with merge changes.\nDo you want to continue?"; } else { intersection = checkIntersection(myLists, localChangeLists); message = "There are local changes that will intersect with merge changes.\nDo you want to continue?"; } if (intersection == null || intersection.getChangesSubset().isEmpty()) return; final LocalChangesAction action; if (!myMergeAll) { final LocalChangesAction[] possibleResults = { LocalChangesAction.shelve, LocalChangesAction.inspect, LocalChangesAction.continueMerge, LocalChangesAction.cancel }; final int result = Messages.showDialog( message, myTitle, new String[] { "Shelve local changes", "Inspect changes", "Continue merge", "Cancel" }, 0, Messages.getQuestionIcon()); action = possibleResults[result]; } else { final LocalChangesAction[] possibleResults = { LocalChangesAction.shelve, LocalChangesAction.continueMerge, LocalChangesAction.cancel }; final int result = Messages.showDialog( message, myTitle, new String[] {"Shelve local changes", "Continue merge", "Cancel"}, 0, Messages.getQuestionIcon()); action = possibleResults[result]; } switch (action) { // shelve case shelve: context.next(new ShelveLocalChanges(intersection)); return; // cancel case cancel: context.cancelEverything(); return; // continue case continueMerge: return; // inspect case inspect: final Collection<Change> changes = (Collection<Change>) intersection.getChangesSubset().values(); final List<FilePath> paths = ChangesUtil.getPaths(changes); Collections.sort(paths, FilePathByPathComparator.getInstance()); // todo rework message IntersectingLocalChangesPanel.showInVersionControlToolWindow( myProject, myTitle + ", local changes intersection", paths, "The following file(s) have local changes that will intersect with merge changes:"); context.cancelEverything(); return; default: } }
@Override protected JComponent createCenterPanel() { myTitledSeparator.setText(myAnalysisNoon); // include test option myInspectTestSource.setSelected(myAnalysisOptions.ANALYZE_TEST_SOURCES); // 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 model = new DefaultComboBoxModel(); model.addElement(ALL); final List<? extends ChangeList> changeLists = changeListManager.getChangeListsCopy(); for (ChangeList changeList : changeLists) { model.addElement(changeList.getName()); } 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); // 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; }