public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) { if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) { r.run(); } else { final Semaphore semaphore = new Semaphore(); semaphore.down(); DumbService.getInstance(p).smartInvokeLater(() -> { try { r.run(); } finally { semaphore.up(); } }, state); semaphore.waitFor(); } }
@Override public void doAction(AnActionEvent anActionEvent) { terminal.createNewSession(); new Thread(() -> { try { // Wait 0.5 second for the terminal to show up, no wait works ok on WebStorm but not on Android Studio Thread.currentThread().sleep(500L); } catch (InterruptedException e) { e.printStackTrace(); } // Below code without ApplicationManager.getApplication().invokeLater() will throw exception // : IDEA Access is allowed from event dispatch thread only. ApplicationManager.getApplication().invokeLater(() -> { terminal.executeShell(command()); }); }).start(); }
public EduCreateNewStepikProjectDialog(int courseId) { this(); StepicUser user = EduStepicAuthorizedClient.getCurrentUser(); Project defaultProject = ProjectManager.getInstance().getDefaultProject(); ApplicationManager.getApplication().invokeAndWait(() -> ProgressManager.getInstance() .runProcessWithProgressSynchronously(() -> { ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true); execCancelable(() -> { try { Course course = EduStepicConnector.getCourseFromStepik(user, courseId); if (course != null) { setTitle("New Project - " + course.getName()); } setCourse(course); } catch (IOException e) { LOG.warn("Tried to create a project for course with id=" + courseId, e); } return null; }); }, "Getting Available Courses", true, defaultProject) ); }
@Override public boolean isAccepted(PsiClass klass) { return ApplicationManager.getApplication().runReadAction((Computable<Boolean>) () -> { if (isSketchClass(klass)) { final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project); final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(klass); if (virtualFile == null) { return false; } return ! compilerConfiguration.isExcludedFromCompilation(virtualFile) && ! ProjectRootManager.getInstance(project) .getFileIndex() .isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.RESOURCES); } return false; }); }
private static void transformFiles(Course course, Project project) { List<VirtualFile> files = getAllAnswerTaskFiles(course, project); for (VirtualFile answerFile : files) { ApplicationManager.getApplication().runWriteAction(() -> { String answerName = answerFile.getName(); String nameWithoutExtension = FileUtil.getNameWithoutExtension(answerName); String name = FileUtil.getNameWithoutExtension(nameWithoutExtension) + "." + FileUtilRt.getExtension(answerName); VirtualFile parent = answerFile.getParent(); VirtualFile file = parent.findChild(name); try { if (file != null) { file.delete(CCProjectComponent.class); } VirtualFile windowsDescrFile = parent.findChild(FileUtil.getNameWithoutExtension(name) + EduNames.WINDOWS_POSTFIX); if (windowsDescrFile != null) { windowsDescrFile.delete(CCProjectComponent.class); } answerFile.rename(CCProjectComponent.class, name); } catch (IOException e) { LOG.error(e); } }); } }
private static void packCourse(@NotNull final VirtualFile baseDir, String locationDir, String zipName, boolean showMessage) { try { final File zipFile = new File(locationDir, zipName + ".zip"); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); VirtualFile[] courseFiles = baseDir.getChildren(); for (VirtualFile file : courseFiles) { ZipUtil.addFileOrDirRecursively(zos, null, new File(file.getPath()), file.getName(), null, null); } zos.close(); if (showMessage) { ApplicationManager.getApplication().invokeLater( () -> Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(), "Course Archive Was Created Successfully")); } } catch (IOException e1) { LOG.error(e1); } }
@Override public void run() { Bucklescript bucklescript = BucklescriptProjectComponent.getInstance(m_psiFile.getProject()); BsQueryTypesServiceComponent.InferredTypes inferredTypes = bucklescript.queryTypes(m_psiFile.getVirtualFile()); ApplicationManager.getApplication().runReadAction(() -> { for (PsiLet letStatement : m_letExpressions) { PsiElement letParent = letStatement.getParent(); if (letParent instanceof RmlFile) { applyType(inferredTypes, letStatement); } else { PsiModule letModule = PsiTreeUtil.getParentOfType(letStatement, PsiModule.class); if (letModule != null && inferredTypes != null) { BsQueryTypesServiceComponent.InferredTypes inferredModuleTypes = inferredTypes.getModuleType(letModule.getName()); if (inferredModuleTypes != null) { applyType(inferredModuleTypes, letStatement); } } } } }); }
@Override public void run() { MerlinService merlin = ApplicationManager.getApplication().getComponent(MerlinService.class); if (merlin == null) { return; } String filename = m_psiFile.getVirtualFile().getCanonicalPath(); // Update merlin buffer String source = m_psiFile.getText(); int i = 0; for (PsiLet letStatement : m_letStatements) { LogicalPosition position = m_positions.get(i); if (position != null) { List<MerlinType> types = merlin.typeExpression(filename, source, new MerlinPosition(position)); if (!types.isEmpty()) { // System.out.println(letStatement.getLetName().getText() + ": " + types.stream().map(merlinType -> merlinType.type).reduce("", (s, s2) -> s + s2.replaceAll("\n", "").replaceAll("\\s+", "") + ", ")); // Display only the first one, might be wrong !? letStatement.setInferredType(types.get(0).type.replaceAll("\n", "").replaceAll("\\s+", " ")); } } i++; } }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { MerlinService merlin = ApplicationManager.getApplication().getComponent(MerlinService.class); PsiFile originalFile = parameters.getOriginalFile(); String text = originalFile.getText(); LineNumbering lineNumbering = new LineNumbering(text); String suitablePrefix = findSuitablePrefix(parameters, text); MerlinPosition position = lineNumbering.offsetToPosition(parameters.getOffset()); MerlinCompletion completion = merlin.completions(originalFile.getName(), text, position, suitablePrefix); for (MerlinCompletionEntry entry : completion.entries) { resultSet.addElement(LookupElementBuilder. create(entry.name). withIcon(getIcon(entry)). withTypeText(entry.desc)); } }
public Map<String, HotSwapFile> scanForModifiedClasses( DebuggerSession session, HotSwapProgress progress ) { DebuggerManagerThreadImpl.assertIsManagerThread(); Map<String, HotSwapFile> modifiedClasses = new HashMap<>(); List<File> outputRoots = new ArrayList<>(); ApplicationManager.getApplication().runReadAction( () -> { VirtualFile[] allDirs = OrderEnumerator.orderEntries( getIjProject() ).getAllSourceRoots(); for( VirtualFile dir : allDirs ) { outputRoots.add( new File( dir.getPath() ) ); } } ); long timeStamp = getTimeStamp( session ); for( File root : outputRoots ) { String rootPath = FileUtil.toCanonicalPath( root.getPath() ); collectModifiedClasses( root, rootPath, modifiedClasses, progress, timeStamp ); } setTimeStamp( session, System.currentTimeMillis() ); return modifiedClasses; }
@Override public void onProcessList(Set<LogProcess> processList) { ApplicationManager.getApplication().executeOnPooledThread(() -> { final List<LogProcess> sortedList = new ArrayList<>(processList); sortedList.sort((l, r) -> { int c = l.getProcessName().compareTo(r.getProcessName()); if (c == 0) { c = l.getProcessID() < r.getProcessID() ? -1 : 1; } return c; }); UIUtil.invokeLaterIfNeeded(() -> { processListModel.removeAllElements(); for (LogProcess client : sortedList) { processListModel.addElement(client); } }); }); }
@NotNull private HyperlinkAdapter createAuthorizeListener() { return new HyperlinkAdapter() { @Override protected void hyperlinkActivated(HyperlinkEvent e) { ApplicationManager.getApplication().getMessageBus().connect().subscribe(StudySettings.SETTINGS_CHANGED, () -> { StepicUser user = StudySettings.getInstance().getUser(); if (user != null && !user.equals(myStepicUser)) { StudySettings.getInstance().setUser(myStepicUser); myStepicUser = user; updateLoginLabels(myStepicUser); } }); EduStepicConnector.doAuthorize(() -> showDialog()); } }; }
/** * Creates content (including its directory or module) of new lesson in project * * @param project Parameter is used in Java and Kotlin plugins * @param lesson Lesson to create content for. It's already properly initialized and added to course. * @return PsiDirectory of created lesson */ default PsiDirectory createLessonContent(@NotNull Project project, @NotNull Lesson lesson, @Nullable IdeView view, @NotNull PsiDirectory parentDirectory) { final PsiDirectory[] lessonDirectory = new PsiDirectory[1]; ApplicationManager.getApplication().runWriteAction(() -> { String lessonDirName = EduNames.LESSON + lesson.getIndex(); lessonDirectory[0] = DirectoryUtil.createSubdirectories(lessonDirName, parentDirectory, "\\/"); }); if (lessonDirectory[0] != null) { if (view != null) { view.selectElement(lessonDirectory[0]); } } return lessonDirectory[0]; }
@Override public void actionPerformed(AnActionEvent e) { if (e.getProject() != null) { ScanManager scanManager = ScanManagerFactory.getScanManager(e.getProject()); if (scanManager == null) { // Check if the project is supported now ScanManagerFactory scanManagerFactory = ServiceManager.getService(e.getProject(), ScanManagerFactory.class); scanManagerFactory.initScanManager(e.getProject()); scanManager = ScanManagerFactory.getScanManager(e.getProject()); if (scanManager == null) { return; } MessageBus messageBus = ApplicationManager.getApplication().getMessageBus(); messageBus.syncPublisher(Events.ON_IDEA_FRAMEWORK_CHANGE).update(); } scanManager.asyncScanAndUpdateResults(false); } }
public static boolean focusOpenProject(int courseId, int stepId) { Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); for (Project project : openProjects) { if (!project.isDefault()) { StudyTaskManager taskManager = StudyTaskManager.getInstance(project); if (taskManager != null) { Course course = taskManager.getCourse(); RemoteCourse remoteCourse = course instanceof RemoteCourse ? (RemoteCourse)course : null; if (remoteCourse != null && remoteCourse.getId() == courseId) { ApplicationManager.getApplication().invokeLater(() -> { requestFocus(project); navigateToStep(project, course, stepId); }); return true; } } } } return false; }
private static void transformTestFile(@NotNull Project project, int toSubtaskIndex, VirtualFile taskDir) { String subtaskTestFileName = getTestFileName(project, toSubtaskIndex); if (subtaskTestFileName == null) { return; } String nameWithoutExtension = FileUtil.getNameWithoutExtension(subtaskTestFileName); String extension = FileUtilRt.getExtension(subtaskTestFileName); VirtualFile subtaskTestFile = taskDir.findChild(nameWithoutExtension + ".txt"); if (subtaskTestFile != null) { ApplicationManager.getApplication().runWriteAction(() -> { try { subtaskTestFile.rename(project, nameWithoutExtension + "." + extension); } catch (IOException e) { LOG.error(e); } }); } }
/** * 打开类文件 * * @param filePath * @param project */ public static void openFileInPanel(final String filePath, final Project project) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath); if (file != null && file.isValid()) { FileEditorProvider[] providers = FileEditorProviderManager.getInstance() .getProviders(project, file); if (providers.length != 0) { OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file); FileEditorManager.getInstance(project).openTextEditor(descriptor, false); } } } }); }
private void moveMavenModulesToGroup( final Project project, final List<Module> mavenModules, final String[] rootGroup ) { AccessToken token = null; final ModifiableModuleModel modifiableModuleModel; try { token = ApplicationManager.getApplication().acquireReadActionLock(); modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : mavenModules) { module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.MAVEN.name()); final String[] groupPath = modifiableModuleModel.getModuleGroupPath(module); modifiableModuleModel.setModuleGroupPath(module, ArrayUtils.addAll(rootGroup, groupPath)); } } finally { if (token != null) { token.finish(); } } ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModuleModel::commit)); }
@Override public void configure( final Project project, final List<HybrisModuleDescriptor> allModules ) { // todo: remove "UNLOADED" mechanism completely. It is temporary disabled now, so this list should be empty final List<String> unloadedModuleNames = allModules .stream() .filter(e -> e.getImportStatus() == HybrisModuleDescriptor.IMPORT_STATUS.UNLOADED) .map(HybrisModuleDescriptor::getName) .collect(Collectors.toList()); final Set<String> unusedModuleNames = allModules .stream() .filter(e -> e.getImportStatus() == HybrisModuleDescriptor.IMPORT_STATUS.UNUSED) .map(HybrisModuleDescriptor::getName) .collect(Collectors.toSet()); ApplicationManager.getApplication().invokeAndWait(() -> { ModuleManager.getInstance(project).setUnloadedModules(unloadedModuleNames); HybrisProjectSettingsComponent.getInstance(project).getState().setUnusedExtensions(unusedModuleNames); }); }
private void moveGradleModulesToGroup( final Project project, final List<Module> gradleModules, final String[] gradleGroup ) { final ModifiableModuleModel modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : gradleModules) { if (module == null) { // https://youtrack.jetbrains.com/issue/IDEA-177512 continue; } module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.GRADLE.name()); modifiableModuleModel.setModuleGroupPath(module, gradleGroup); } AccessToken token = null; try { token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); modifiableModuleModel.commit(); } finally { if (token != null) { token.finish(); } } }
private void showDiscountOffer(final Project project) { final PropertiesComponent properties = PropertiesComponent.getInstance(); final long lastNotificationTime = properties.getOrInitLong(LAST_DISCOUNT_OFFER_TIME_PROPERTY, 0); final long currentTime = System.currentTimeMillis(); if (currentTime - lastNotificationTime >= DateFormatUtil.MONTH) { properties.setValue(LAST_DISCOUNT_OFFER_TIME_PROPERTY, String.valueOf(currentTime)); final Notification notification = notificationGroup.createNotification( HybrisI18NBundleUtils.message("evaluation.license.discount.offer.bubble.title"), HybrisI18NBundleUtils.message("evaluation.license.discount.offer.bubble.text"), NotificationType.INFORMATION, (myNotification, myHyperlinkEvent) -> goToDiscountOffer(myHyperlinkEvent) ); notification.setImportant(true); Notifications.Bus.notify(notification, project); ApplicationManager.getApplication().invokeLater(() -> { if (!notificationClosingAlarm.isDisposed()) { notificationClosingAlarm.addRequest(notification::hideBalloon, 3000); } }); } }
@Override public void removeAllFiles(@NotNull final Collection<File> files) throws IOException { Validate.notNull(files); if (files.isEmpty()) { return; } final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); for (File file : files) { final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file); if (null != virtualFile) { ApplicationManager.getApplication().runWriteAction(new RemoveFileComputable(virtualFile)); } else { FileUtil.delete(file); } } }
protected void setJdk(@NotNull Project project) { JdkComboBox.JdkComboBoxItem selectedItem = myJdkComboBox.getSelectedItem(); if (selectedItem instanceof JdkComboBox.SuggestedJdkItem) { SdkType type = ((JdkComboBox.SuggestedJdkItem)selectedItem).getSdkType(); String path = ((JdkComboBox.SuggestedJdkItem)selectedItem).getPath(); myModel.addSdk(type, path, sdk -> { myJdkComboBox.reloadModel(new JdkComboBox.ActualJdkComboBoxItem(sdk), project); myJdkComboBox.setSelectedJdk(sdk); }); } try { myModel.apply(); } catch (ConfigurationException e) { LOG.error(e); } ApplicationManager.getApplication().runWriteAction(() -> { ProjectRootManager.getInstance(project).setProjectSdk(myJdkComboBox.getSelectedJdk()); }); }
public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir) { final Course course = getCourse(project); if (course == null) { LOG.warn("Course is null"); Messages.showWarningDialog("Some problems occurred while creating the course", "Error in Course Creation"); return; } else if (course.isAdaptive() && !StudyUtils.isCourseValid(course)) { Messages.showWarningDialog("There is no recommended tasks for this adaptive course", "Error in Course Creation"); return; } StudyTaskManager.getInstance(project).setCourse(course); ApplicationManager.getApplication().runWriteAction(() -> { StudyGenerator.createCourse(course, baseDir); StudyUtils.registerStudyToolWindow(course, project); StudyUtils.openFirstTask(course, project); EduUsagesCollector.projectTypeCreated(course.isAdaptive() ? EduNames.ADAPTIVE : EduNames.STUDY); }); }
@Contract(pure = false) protected void highlightArea( @NotNull final Editor editor, @NotNull final PsiElement impexFullHeaderParameter ) { Validate.notNull(editor); Validate.notNull(impexFullHeaderParameter); if (isAlreadyHighlighted(editor, impexFullHeaderParameter)) { return; } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final PsiElement currentHighlightedElement = highlightedBlocks.remove(editor); if (null != currentHighlightedElement) { modifyHighlightedArea(editor, currentHighlightedElement, true); } highlightedBlocks.put(editor, impexFullHeaderParameter); modifyHighlightedArea(editor, impexFullHeaderParameter, false); } }); }
@Override public void onSuccess() { String message = myResult.getMessage(); StudyStatus status = myResult.getStatus(); myTask.setStatus(status); switch (status) { case Failed: myChecker.onTaskFailed(message); break; case Solved: myChecker.onTaskSolved(message); break; default: StudyCheckUtils.showTestResultPopUp(message, MessageType.WARNING.getPopupBackground(), myProject); } ApplicationManager.getApplication().invokeLater(() -> { StudyUtils.updateToolWindows(myProject); ProjectView.getInstance(myProject).refresh(); for (StudyCheckListener listener : StudyCheckListener.EP_NAME.getExtensions()) { listener.afterCheck(myProject, myTask); } }); myChecker.clearState(); myCheckInProgress.set(false); }
private void updateTestHelper() { StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().runWriteAction(() -> { final VirtualFile baseDir = myProject.getBaseDir(); if (baseDir == null) { return; } final VirtualFile testHelper = baseDir.findChild(EduNames.TEST_HELPER); if (testHelper != null) { StudyUtils.deleteFile(testHelper); } final FileTemplate template = FileTemplateManager.getInstance(myProject).getInternalTemplate(FileUtil.getNameWithoutExtension(EduNames.TEST_HELPER)); try { final PsiDirectory projectDir = PsiManager.getInstance(myProject).findDirectory(baseDir); if (projectDir != null) { FileTemplateUtil.createFromTemplate(template, EduNames.TEST_HELPER, null, projectDir); } } catch (Exception e) { LOG.warn("Failed to create new test helper"); } })); }
@Override public void onTaskFailed(@NotNull String message) { super.onTaskFailed(message); ApplicationManager.getApplication().invokeLater(() -> { VirtualFile taskDir = myTask.getTaskDir(myProject); if (taskDir == null) return; for (Map.Entry<String, TaskFile> entry : myTask.getTaskFiles().entrySet()) { final String name = entry.getKey(); final TaskFile taskFile = entry.getValue(); if (taskFile.getActivePlaceholders().size() < 2) { continue; } final Course course = myTask.getLesson().getCourse(); if (course != null && EduNames.STUDY.equals(course.getCourseMode())) { CommandProcessor.getInstance().runUndoTransparentAction( () -> ApplicationManager.getApplication().runWriteAction( () -> PyStudySmartChecker.runSmartTestProcess(taskDir, new PyStudyTestRunner(myTask, taskDir), name, taskFile, myProject))); } } StudyCheckUtils.navigateToFailedPlaceholder(new StudyState(StudyUtils.getSelectedStudyEditor(myProject)), myTask, taskDir, myProject); }); }
@Nullable public static <T> T execCancelable(@NotNull final Callable<T> callable) { final Future<T> future = ApplicationManager.getApplication().executeOnPooledThread(callable); while (!future.isCancelled() && !future.isDone()) { ProgressManager.checkCanceled(); TimeoutUtil.sleep(500); } T result = null; try { result = future.get(); } catch (InterruptedException | ExecutionException e) { LOG.warn(e.getMessage()); } return result; }
@Nullable @Override public SeedStackNavigatorState getState() { ApplicationManager.getApplication().assertIsDispatchThread(); if (structure != null) { try { state.treeState = new Element("root"); TreeState.createOn(tree).writeExternal(state.treeState); } catch (WriteExternalException e) { SeedStackLog.LOG.warn("Cannot write SeedStack structure state", e); } } return state; }
@Override public void run() { if (sketchDataDirectory == null) { return; } VirtualFile projectResourceDirectory = VfsUtil.findRelativeFile(project.getBaseDir(), "src", "main", "resources"); if (projectResourceDirectory == null) { throw new IllegalStateException("Cannot find directory 'src/main/resources' into which sketch resources are to be copied. Sketch resources cannot be imported."); } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (VirtualFile resourceEntry : sketchDataDirectory.getChildren()) { try { logger.debug("Copying '" + resourceEntry.getPath() + "' into sketch project."); resourceEntry.copy(this, projectResourceDirectory, resourceEntry.getName()); logger.debug("Copy of '" + resourceEntry.getPath() + "' succeeded."); } catch (IOException io) { // @TODO This failure is silent. Spawn a notification to inform the user. logger.error("Whilst importing sketch resources into project, encountered an exception.", io); } } } }); }
private static void processCommandline(final Project project, GeneralCommandLine commandLine) throws ExecutionException { final OSProcessHandler processHandler = new OSProcessHandler(commandLine); ProcessTerminatedListener.attach(processHandler); // processHandler.startNotify();// Don't call this, the command content will not be shown ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { processConsole(project, processHandler); } }); }
/** * show a Notification * * @param message * @param type */ public static void showNotification(final String message, final NotificationType type) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Notification notification = NOTIFICATION_GROUP.createNotification(TITLE, message, type, null); Notifications.Bus.notify(notification); } }); }
private static void focusOnApplicationWindow() { JFrame frame = WindowManager.getInstance().findVisibleFrame(); ApplicationManager.getApplication().invokeLater(() -> { AppIcon.getInstance().requestFocus((IdeFrame)frame); frame.toFront(); }); }
/** * 格式化代码 * * @param project * @param virtualFiles */ public static void reformatCode(final Project project, final VirtualFile virtualFiles) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { PsiFile[] psiFiles = ReformatCodeAction.convertToPsiFiles(new VirtualFile[]{virtualFiles}, project); if (psiFiles != null && psiFiles.length == 1 && psiFiles[0] != null) { new ReformatCodeProcessor(project, psiFiles[0], null, false).run(); } } }); }
private void showPopupBalloon(final String result) { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { JBPopupFactory factory = JBPopupFactory.getInstance(); factory.createHtmlTextBalloonBuilder(result, null, new JBColor(new Color(186, 238, 186), new Color(73, 117, 73)), null) .setFadeoutTime(5000) .createBalloon() .show(factory.guessBestPopupLocation(mEditor) , Balloon.Position.below); } }); }
public void activateToolWindow() { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { ToolWindowManager.getInstance(myProject).getToolWindow(TailRunExecutor.TOOLWINDOWS_ID).activate(null); } }); }
@Override public void initComponent() { logger.debug("Initializing component"); MessageBus bus = ApplicationManager.getApplication().getMessageBus(); connection = bus.connect(); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new TabHighlighterFileEditorListener()); }
public static VirtualFile getGeneratedFilesFolder(@NotNull Project project, @NotNull Module module) { VirtualFile baseDir = project.getBaseDir(); VirtualFile folder = baseDir.findChild(GENERATED_FILES_FOLDER); if (folder != null) { return folder; } final Ref<VirtualFile> generatedRoot = new Ref<>(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { generatedRoot.set(baseDir.createChildDirectory(this, GENERATED_FILES_FOLDER)); VirtualFile contentRootForFile = ProjectRootManager.getInstance(module.getProject()).getFileIndex().getContentRootForFile(generatedRoot.get()); if (contentRootForFile == null) { return; } ModuleRootModificationUtil.updateExcludedFolders(module, contentRootForFile, Collections.emptyList(), Collections.singletonList(generatedRoot.get().getUrl())); } catch (IOException e) { LOG.info("Failed to create folder for generated files", e); } } }); return generatedRoot.get(); }
@Override public void initComponent() { Boolean reasonReformatOnSave = Boolean.valueOf(System.getProperty("reasonReformatOnSave")); if (reasonReformatOnSave) { Notifications.Bus.notify(new RmlNotification("Refmt", "reformat on save is enabled", NotificationType.INFORMATION)); ReformatOnSave handler = new ReformatOnSave(); ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, handler); } }