use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class FormReferencesSearcher method processReferencesInUIForms.
private static boolean processReferencesInUIForms(Processor<PsiReference> processor, PsiManager psiManager, PsiField field, GlobalSearchScope scope1, LocalSearchScope filterScope) {
GlobalSearchScope scope = GlobalSearchScope.projectScope(psiManager.getProject()).intersectWith(scope1);
final AccessToken token = ReadAction.start();
PsiClass containingClass = field.getContainingClass();
if (containingClass == null)
return true;
String fieldName;
try {
fieldName = field.getName();
} finally {
token.finish();
}
final List<PsiFile> files = FormClassIndex.findFormsBoundToClass(psiManager.getProject(), containingClass, scope);
return processReferencesInFiles(files, psiManager, fieldName, field, filterScope, processor);
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class HgRollbackEnvironment method rollbackChanges.
public void rollbackChanges(List<Change> changes, List<VcsException> vcsExceptions, @NotNull RollbackProgressListener listener) {
if (changes == null || changes.isEmpty()) {
return;
}
List<FilePath> toDelete = new ArrayList<>();
List<FilePath> filePaths = new LinkedList<>();
for (Change change : changes) {
ContentRevision contentRevision;
if (Change.Type.DELETED == change.getType()) {
contentRevision = change.getBeforeRevision();
} else {
contentRevision = change.getAfterRevision();
}
if (contentRevision != null) {
filePaths.add(contentRevision.getFile());
if (Change.Type.MOVED == change.getType()) {
toDelete.add(contentRevision.getFile());
}
}
}
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
revert(filePaths);
for (FilePath file : toDelete) {
listener.accept(file);
try {
final File ioFile = file.getIOFile();
if (ioFile.exists()) {
if (!ioFile.delete()) {
//noinspection ThrowableInstanceNeverThrown
vcsExceptions.add(new VcsException("Unable to delete file: " + file));
}
}
} catch (Exception e) {
//noinspection ThrowableInstanceNeverThrown
vcsExceptions.add(new VcsException("Unable to delete file: " + file, e));
}
}
} finally {
token.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class HgUpdateCommand method execute.
@Nullable
public HgCommandResult execute() {
List<String> arguments = new LinkedList<>();
if (clean) {
arguments.add("--clean");
}
if (!StringUtil.isEmptyOrSpaces(revision)) {
arguments.add("--rev");
arguments.add(revision);
}
final HgPromptCommandExecutor executor = new HgPromptCommandExecutor(project);
executor.setShowOutput(true);
HgCommandResult result;
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
result = executor.executeInCurrentThread(repo, "update", arguments);
if (!clean && hasUncommittedChangesConflict(result)) {
final String message = "<html>Your uncommitted changes couldn't be merged into the requested changeset.<br>" + "Would you like to perform force update and discard them?";
if (showDiscardChangesConfirmation(project, message) == Messages.OK) {
arguments.add("-C");
result = executor.executeInCurrentThread(repo, "update", arguments);
}
}
} finally {
token.finish();
}
VfsUtil.markDirtyAndRefresh(false, true, false, repo);
return result;
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class ExternalSystemImportingTestCase method getModule.
protected Module getModule(final String name) {
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
Module m = ModuleManager.getInstance(myProject).findModuleByName(name);
assertNotNull("Module " + name + " not found", m);
return m;
} finally {
accessToken.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-community by JetBrains.
the class SearchEverywhereAction method doNavigate.
private void doNavigate(final int index) {
final DataManager dataManager = DataManager.getInstance();
if (dataManager == null)
return;
final Project project = CommonDataKeys.PROJECT.getData(dataManager.getDataContext(getField().getTextEditor()));
assert project != null;
final SearchListModel model = getModel();
if (isMoreItem(index)) {
final String pattern = myPopupField.getText();
WidgetID wid = null;
if (index == model.moreIndex.classes)
wid = WidgetID.CLASSES;
else if (index == model.moreIndex.files)
wid = WidgetID.FILES;
else if (index == model.moreIndex.settings)
wid = WidgetID.SETTINGS;
else if (index == model.moreIndex.actions)
wid = WidgetID.ACTIONS;
else if (index == model.moreIndex.symbols)
wid = WidgetID.SYMBOLS;
else if (index == model.moreIndex.runConfigurations)
wid = WidgetID.RUN_CONFIGURATIONS;
if (wid != null) {
final WidgetID widgetID = wid;
myCurrentWorker.doWhenProcessed(() -> {
myCalcThread = new CalcThread(project, pattern, true);
myPopupActualWidth = 0;
myCurrentWorker = myCalcThread.insert(index, widgetID);
});
return;
}
}
final String pattern = getField().getText();
final Object value = myList.getSelectedValue();
saveHistory(project, pattern, value);
IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(getField().getTextEditor());
if (myPopup != null && myPopup.isVisible()) {
myPopup.cancel();
}
if (value instanceof BooleanOptionDescription) {
final BooleanOptionDescription option = (BooleanOptionDescription) value;
option.setOptionState(!option.isOptionEnabled());
myList.revalidate();
myList.repaint();
getGlobalInstance().doWhenFocusSettlesDown(() -> {
getGlobalInstance().requestFocus(getField(), true);
});
return;
}
if (value instanceof OptionsTopHitProvider) {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> getField().setText("#" + ((OptionsTopHitProvider) value).getId() + " "));
return;
}
Runnable onDone = null;
AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
if (value instanceof PsiElement) {
onDone = () -> NavigationUtil.activateFileWithPsiElement((PsiElement) value, true);
return;
} else if (isVirtualFile(value)) {
onDone = () -> OpenSourceUtil.navigate(true, new OpenFileDescriptor(project, (VirtualFile) value));
return;
} else if (isActionValue(value) || isSetting(value) || isRunConfiguration(value)) {
focusManager.requestDefaultFocus(true);
final Component comp = myContextComponent;
final AnActionEvent event = myActionEvent;
IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> {
Component c = comp;
if (c == null) {
c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
}
if (isRunConfiguration(value)) {
ChooseRunConfigurationPopup.ItemWrapper itemWrapper = (ChooseRunConfigurationPopup.ItemWrapper) value;
RunnerAndConfigurationSettings settings = ObjectUtils.tryCast(itemWrapper.getValue(), RunnerAndConfigurationSettings.class);
if (settings != null) {
Executor executor = findExecutor(settings);
if (executor != null) {
itemWrapper.perform(project, executor, dataManager.getDataContext(c));
}
}
} else {
GotoActionAction.openOptionOrPerformAction(value, pattern, project, c, event);
if (isToolWindowAction(value))
return;
}
});
return;
} else if (value instanceof Navigatable) {
onDone = () -> OpenSourceUtil.navigate(true, (Navigatable) value);
return;
}
} finally {
token.finish();
final ActionCallback callback = onFocusLost();
if (onDone != null) {
callback.doWhenDone(onDone);
}
}
focusManager.requestDefaultFocus(true);
}
Aggregations