use of com.intellij.openapi.application.Application in project intellij-plugins by StepicOrg.
the class ProjectFilesUtils method getOrCreateDirectory.
@Nullable
private static VirtualFile getOrCreateDirectory(@NotNull VirtualFile baseDir, @NotNull String directoryPath) {
final VirtualFile[] srcDir = { baseDir.findFileByRelativePath(directoryPath) };
if (srcDir[0] == null) {
Application application = ApplicationManager.getApplication();
application.invokeAndWait(() -> srcDir[0] = application.runWriteAction((Computable<VirtualFile>) () -> {
VirtualFile dir;
try {
String[] paths = directoryPath.split("/");
dir = baseDir;
for (String path : paths) {
VirtualFile child = dir.findChild(path);
if (child == null) {
dir = dir.createChildDirectory(null, path);
} else {
dir = child;
}
}
} catch (IOException e) {
return null;
}
return dir;
}));
}
return srcDir[0];
}
use of com.intellij.openapi.application.Application in project intellij-plugins by StepicOrg.
the class StepikProjectManager method refreshCourse.
private void refreshCourse() {
if (project == null || root == null) {
return;
}
root.setProject(project);
executor.execute(() -> {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
if (isAuthenticated()) {
root.reloadData(project, stepikApiClient);
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Synchronize Project") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (project.isDisposed()) {
return;
}
repairProjectFiles(root);
repairSandbox();
ApplicationManager.getApplication().invokeLater(() -> {
VirtualFileManager.getInstance().syncRefresh();
setSelected(selected, false);
});
}
private void repairSandbox() {
VirtualFile projectDir = project.getBaseDir();
if (projectDir != null && projectDir.findChild(EduNames.SANDBOX_DIR) == null) {
Application application = ApplicationManager.getApplication();
ModifiableModuleModel model = application.runReadAction((Computable<ModifiableModuleModel>) () -> ModuleManager.getInstance(project).getModifiableModel());
application.invokeLater(() -> application.runWriteAction(() -> {
try {
new SandboxModuleBuilder(projectDir.getPath()).createModule(model);
model.commit();
} catch (IOException | ConfigurationException | JDOMException | ModuleWithNameAlreadyExists e) {
logger.warn("Failed repair Sandbox", e);
}
}));
}
}
});
});
}
use of com.intellij.openapi.application.Application in project intellij-plugins by StepicOrg.
the class StepikPyProjectGenerator method createCourseFromGenerator.
private void createCourseFromGenerator(@NotNull Project project) {
generator.generateProject(project);
FileUtil.createDirectory(new File(project.getBasePath(), EduNames.SANDBOX_DIR));
StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
if (projectManager == null) {
logger.warn("failed to generate builders: StepikProjectManager is null");
return;
}
projectManager.setDefaultLang(generator.getDefaultLang());
StudyNode root = projectManager.getProjectRoot();
if (root == null) {
logger.warn("failed to generate builders: Root is null");
return;
}
if (root instanceof StepNode) {
getOrCreateSrcDirectory(project, (StepNode) root, true);
} else {
createSubDirectories(project, generator.getDefaultLang(), root, null);
VirtualFileManager.getInstance().syncRefresh();
}
Application application = ApplicationManager.getApplication();
application.invokeLater(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> application.runWriteAction(() -> {
StudyProjectComponent.getInstance(project).registerStudyToolWindow();
StepikProjectManager.updateAdaptiveSelected(project);
})));
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class SvnAuthenticationNotifier method clearAuthenticationDirectory.
public static void clearAuthenticationDirectory(@NotNull SvnConfiguration configuration) {
final File authDir = new File(configuration.getConfigurationDirectory(), "auth");
if (authDir.exists()) {
final Runnable process = () -> {
final ProgressIndicator ind = ProgressManager.getInstance().getProgressIndicator();
if (ind != null) {
ind.setIndeterminate(true);
ind.setText("Clearing stored credentials in " + authDir.getAbsolutePath());
}
final File[] files = authDir.listFiles((dir, name) -> ourAuthKinds.contains(name));
for (File dir : files) {
if (ind != null) {
ind.setText("Deleting " + dir.getAbsolutePath());
}
FileUtil.delete(dir);
}
};
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode() || !application.isDispatchThread()) {
process.run();
} else {
ProgressManager.getInstance().runProcessWithProgressSynchronously(process, "button.text.clear.authentication.cache", false, configuration.getProject());
}
}
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class BaseSpellChecker method doLoadDictionaryAsync.
private void doLoadDictionaryAsync(Loader loader, Consumer<Dictionary> consumer) {
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
LOG.debug("Loading " + loader.getName());
Application app = ApplicationManager.getApplication();
app.executeOnPooledThread(() -> {
if (app.isDisposed())
return;
CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
LOG.debug(loader.getName() + " loaded!");
consumer.consume(dictionary);
while (!myDictionariesToLoad.isEmpty()) {
if (app.isDisposed())
return;
Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
Loader nextDictionaryLoader = nextDictionary.getFirst();
dictionary = CompressedDictionary.create(nextDictionaryLoader, transform);
LOG.debug(nextDictionaryLoader.getName() + " loaded!");
nextDictionary.getSecond().consume(dictionary);
}
LOG.debug("Loading finished, restarting daemon...");
myLoadingDictionaries.set(false);
UIUtil.invokeLaterIfNeeded(() -> {
if (app.isDisposed())
return;
for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
if (instance != null)
instance.restart();
}
}
});
});
});
}
Aggregations