use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class IdeStartupScripts method scheduleStartupScriptsExecution.
private static void scheduleStartupScriptsExecution() {
List<VirtualFile> scripts = getScripts();
LOG.info(scripts.size() + " startup script(s) found");
if (scripts.isEmpty())
return;
final Future<List<Pair<VirtualFile, IdeScriptEngine>>> scriptsAndEnginesFuture = prepareScriptEnginesAsync(scripts);
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
final AtomicBoolean myScriptsExecutionStarted = new AtomicBoolean();
@Override
public void projectOpened(final Project project) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
if (project.isDisposed())
return;
if (!myScriptsExecutionStarted.compareAndSet(false, true))
return;
ProjectManager.getInstance().removeProjectManagerListener(this);
runAllScriptsImpl(project);
});
}
private void runAllScriptsImpl(@NotNull Project project) {
try {
for (Pair<VirtualFile, IdeScriptEngine> pair : scriptsAndEnginesFuture.get()) {
try {
if (pair.second == null) {
LOG.warn(pair.first.getPath() + " not supported (no script engine)");
} else {
runImpl(project, pair.first, pair.second);
}
} catch (Exception e) {
LOG.warn(e);
}
}
} catch (ProcessCanceledException e) {
LOG.warn("... cancelled");
} catch (InterruptedException e) {
LOG.warn("... interrupted");
} catch (Exception e) {
LOG.error(e);
}
}
});
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class RenameHandlerRegistry method getRenameHandler.
@Nullable
public RenameHandler getRenameHandler(DataContext dataContext) {
final Map<String, RenameHandler> availableHandlers = new TreeMap<>();
for (RenameHandler renameHandler : Extensions.getExtensions(RenameHandler.EP_NAME)) {
if (renameHandler.isRenaming(dataContext)) {
availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
}
}
for (RenameHandler renameHandler : myHandlers) {
if (renameHandler.isRenaming(dataContext)) {
availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
}
}
if (availableHandlers.size() == 1)
return availableHandlers.values().iterator().next();
for (Iterator<Map.Entry<String, RenameHandler>> iterator = availableHandlers.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, RenameHandler> entry = iterator.next();
if (entry.getValue() instanceof MemberInplaceRenameHandler) {
iterator.remove();
break;
}
}
if (availableHandlers.size() == 1)
return availableHandlers.values().iterator().next();
if (availableHandlers.size() > 1) {
if (ApplicationManager.getApplication().isUnitTestMode())
return availableHandlers.values().iterator().next();
final String[] strings = ArrayUtil.toStringArray(availableHandlers.keySet());
final HandlersChooser chooser = new HandlersChooser(CommonDataKeys.PROJECT.getData(dataContext), strings);
if (chooser.showAndGet()) {
return availableHandlers.get(chooser.getSelection());
}
throw new ProcessCanceledException();
}
return myDefaultElementRenameHandler.isRenaming(dataContext) ? myDefaultElementRenameHandler : null;
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class SliceManager method runInterruptibly.
void runInterruptibly(@NotNull ProgressIndicator progress, @NotNull Runnable onCancel, @NotNull Runnable runnable) throws ProcessCanceledException {
Disposable disposable = addPsiListener(progress);
try {
progress.checkCanceled();
ProgressManager.getInstance().executeProcessUnderProgress(runnable, progress);
} catch (ProcessCanceledException e) {
progress.cancel();
//reschedule for later
onCancel.run();
throw e;
} finally {
Disposer.dispose(disposable);
}
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class AsyncCompletion method startThread.
@Override
public Future<?> startThread(final ProgressIndicator progressIndicator, final Runnable runnable) {
final Semaphore startSemaphore = new Semaphore();
startSemaphore.down();
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
try {
ApplicationManager.getApplication().runReadAction(() -> {
startSemaphore.up();
ProgressManager.checkCanceled();
runnable.run();
});
} catch (ProcessCanceledException ignored) {
}
}, progressIndicator));
startSemaphore.waitFor();
return future;
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class CompletionThreadingBase method withBatchUpdate.
public static void withBatchUpdate(Runnable runnable) {
if (ourIsInBatchUpdate.get().booleanValue()) {
runnable.run();
return;
}
try {
ourIsInBatchUpdate.set(Boolean.TRUE);
runnable.run();
ProgressManager.checkCanceled();
final CompletionProgressIndicator currentIndicator = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (currentIndicator == null)
throw new ProcessCanceledException();
CompletionThreadingBase threading = currentIndicator.getCompletionThreading();
assert threading != null;
threading.flushBatchResult(currentIndicator);
} finally {
ourIsInBatchUpdate.set(Boolean.FALSE);
}
}
Aggregations