com.intellij.openapi.project.ProjectManager Java Examples
The following examples show how to use
com.intellij.openapi.project.ProjectManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventLog.java From consulo with Apache License 2.0 | 6 votes |
@Inject public EventLog(Application application) { myModel = new LogModel(null, application); application.getMessageBus().connect().subscribe(Notifications.TOPIC, new NotificationsAdapter() { @Override public void notify(@Nonnull Notification notification) { final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length == 0) { myModel.addNotification(notification); } for (Project p : openProjects) { getProjectComponent(p).printNotification(notification); } } }); }
Example #2
Source File: EnforcedPlainTextFileTypeManager.java From consulo with Apache License 2.0 | 6 votes |
private static void fireRootsChanged(final Collection<VirtualFile> files, final boolean isAdded) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (Project project : ProjectManager.getInstance().getOpenProjects()) { ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(EmptyRunnable.getInstance(), false, true); ProjectPlainTextFileTypeManager projectPlainTextFileTypeManager = ProjectPlainTextFileTypeManager.getInstance(project); for (VirtualFile file : files) { if (projectPlainTextFileTypeManager.hasProjectContaining(file)) { if (isAdded) { projectPlainTextFileTypeManager.addFile(file); } else { projectPlainTextFileTypeManager.removeFile(file); } } } } } }); }
Example #3
Source File: IdeaModifiableModelsProvider.java From consulo with Apache License 2.0 | 6 votes |
@Override public LibraryTable.ModifiableModel getLibraryTableModifiableModel() { final Project[] projects = ProjectManager.getInstance().getOpenProjects(); for (Project project : projects) { if (!project.isInitialized()) { continue; } StructureConfigurableContext context = getProjectStructureContext(project); LibraryTableModifiableModelProvider provider = context != null ? context.createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL) : null; final LibraryTable.ModifiableModel modifiableModel = provider != null ? provider.getModifiableModel() : null; if (modifiableModel != null) { return modifiableModel; } } return LibraryTablesRegistrar.getInstance().getLibraryTable().getModifiableModel(); }
Example #4
Source File: DesktopIdeFrameImpl.java From consulo with Apache License 2.0 | 6 votes |
private void setupCloseAction() { myJFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); myJFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(@Nonnull final WindowEvent e) { if (isTemporaryDisposed()) return; final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length > 1 || openProjects.length == 1 && TopApplicationMenuUtil.isMacSystemMenu) { if (myProject != null && myProject.isOpen()) { ProjectUtil.closeAndDispose(myProject); } ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed(); WelcomeFrame.showIfNoProjectOpened(); } else { Application.get().exit(); } } }); }
Example #5
Source File: LookupDocumentSavingVetoer.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean maySaveDocument(@Nonnull Document document, boolean isSaveExplicit) { if (ApplicationManager.getApplication().isDisposed() || isSaveExplicit) { return true; } for (Project project : ProjectManager.getInstance().getOpenProjects()) { if (!project.isInitialized() || project.isDisposed()) { continue; } LookupEx lookup = LookupManager.getInstance(project).getActiveLookup(); if (lookup != null) { Editor editor = InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor()); if (editor.getDocument() == document) { return false; } } } return true; }
Example #6
Source File: IntellijLanguageClient.java From lsp4intellij with Apache License 2.0 | 6 votes |
@Override public void initComponent() { try { // Adds project listener. ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new LSPProjectManagerListener()); // Adds editor listener. EditorFactory.getInstance().addEditorFactoryListener(new LSPEditorListener(), this); // Adds VFS listener. VirtualFileManager.getInstance().addVirtualFileListener(new VFSListener()); // Adds document event listener. ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, new LSPFileDocumentManagerListener()); // in case if JVM forcefully exit. Runtime.getRuntime().addShutdownHook(new Thread(() -> projectToLanguageWrappers.values().stream() .flatMap(Collection::stream).filter(RUNNING).forEach(s -> s.stop(true)))); LOG.info("Intellij Language Client initialized successfully"); } catch (Exception e) { LOG.warn("Fatal error occurred when initializing Intellij language client.", e); } }
Example #7
Source File: FileTemplateManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Inject public FileTemplateManagerImpl(@Nonnull FileTypeManager typeManager, FileTemplateSettings projectSettings, ExportableFileTemplateSettings defaultSettings, ProjectManager pm, final Project project) { myTypeManager = (FileTypeManagerEx)typeManager; myProjectSettings = projectSettings; myDefaultSettings = defaultSettings; myProject = project; myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") { @Nonnull @Override public String getTemplatesDir() { return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR); } @Nonnull @Override public Project getProject() { return project; } }; }
Example #8
Source File: DesktopSaveAndSyncHandlerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void refreshOpenFiles() { List<VirtualFile> files = ContainerUtil.newArrayList(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) { if (file instanceof NewVirtualFile) { files.add(file); } } } if (!files.isEmpty()) { // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish RefreshQueue.getInstance().refresh(false, false, null, files); } }
Example #9
Source File: IMWindowFactory.java From SmartIM4IntelliJ with Apache License 2.0 | 6 votes |
public File getWorkDir() { Project p = this.project; if (p == null) { p = ProjectManager.getInstance().getDefaultProject(); Project[] ps = ProjectManager.getInstance().getOpenProjects(); if (ps != null) { for (Project t : ps) { if (!t.isDefault()) { p = t; } } } } File dir = new File(p.getBasePath(), Project.DIRECTORY_STORE_FOLDER); return dir; }
Example #10
Source File: ConsoleLog.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
@Override public void notify(@NotNull Notification notification) { try { final ProjectManager projectManager = ProjectManager.getInstance(); if(projectManager != null) { final Project[] openProjects = projectManager.getOpenProjects(); if(openProjects.length == 0) { if(myModel != null) { myModel.addNotification(notification); } } for(Project p : openProjects) { ConsoleLogProjectTracker consoleLogProjectTracker = getProjectComponent(p); if(consoleLogProjectTracker != null) { consoleLogProjectTracker.printNotification(notification); } } } else { PluginManager.getLogger().error("Project Manager could not be retrieved"); } } catch(Exception e) { PluginManager.getLogger().error("Could not Notify to Console Log Project Tracker", e); } }
Example #11
Source File: BlazeProjectOpenProcessor.java From intellij with Apache License 2.0 | 6 votes |
@Nullable @Override public Project doOpenProject( VirtualFile file, @Nullable Project projectToClose, boolean forceOpenInNewFrame) { ProjectManager pm = ProjectManager.getInstance(); if (projectToClose != null) { pm.closeProject(projectToClose); } try { VirtualFile ideaSubdirectory = getIdeaSubdirectory(file); if (ideaSubdirectory == null) { return null; } VirtualFile projectSubdirectory = ideaSubdirectory.getParent(); return pm.loadAndOpenProject(projectSubdirectory.getPath()); } catch (IOException | JDOMException e) { return null; } }
Example #12
Source File: ExternalSystemFacadeManager.java From consulo with Apache License 2.0 | 6 votes |
/** * @return gradle api facade to use * @throws Exception in case of inability to return the facade */ @Nonnull public RemoteExternalSystemFacade getFacade(@javax.annotation.Nullable Project project, @Nonnull String externalProjectPath, @Nonnull ProjectSystemId externalSystemId) throws Exception { if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } IntegrationKey key = new IntegrationKey(project, externalSystemId, externalProjectPath); final RemoteExternalSystemFacade facade = myFacadeWrappers.get(key); if (facade == null) { final RemoteExternalSystemFacade newFacade = (RemoteExternalSystemFacade)Proxy.newProxyInstance( ExternalSystemFacadeManager.class.getClassLoader(), new Class[]{RemoteExternalSystemFacade.class, Consumer.class}, new MyHandler(key) ); myFacadeWrappers.putIfAbsent(key, newFacade); } return myFacadeWrappers.get(key); }
Example #13
Source File: WakaTime.java From jetbrains-wakatime with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void checkApiKey() { ApplicationManager.getApplication().invokeLater(new Runnable(){ public void run() { // prompt for apiKey if it does not already exist Project project = null; try { project = ProjectManager.getInstance().getDefaultProject(); } catch (Exception e) { } ApiKey apiKey = new ApiKey(project); if (apiKey.getApiKey().equals("")) { apiKey.promptForApiKey(); } log.debug("Api Key: " + obfuscateKey(ApiKey.getApiKey())); } }); }
Example #14
Source File: ExcludeRootsCache.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull String[] getExcludedUrls() { return ReadAction.compute(() -> { CachedUrls cache = myCache; long actualModCount = Arrays.stream(ProjectManager.getInstance().getOpenProjects()).map(ProjectRootManager::getInstance).mapToLong(ProjectRootManager::getModificationCount).sum(); String[] urls; if (cache != null && actualModCount == cache.myModificationCount) { urls = cache.myUrls; } else { Collection<String> excludedUrls = new THashSet<>(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { for (Module module : ModuleManager.getInstance(project).getModules()) { urls = ModuleRootManager.getInstance(module).getExcludeRootUrls(); ContainerUtil.addAll(excludedUrls, urls); } } urls = ArrayUtilRt.toStringArray(excludedUrls); Arrays.sort(urls); myCache = new CachedUrls(actualModCount, urls); } return urls; }); }
Example #15
Source File: FlutterSdkUtil.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@NotNull public static String[] getKnownFlutterSdkPaths() { final Set<String> paths = new HashSet<>(); // scan current projects for existing flutter sdk settings for (Project project : ProjectManager.getInstance().getOpenProjects()) { final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project); if (flutterSdk != null) { paths.add(flutterSdk.getHomePath()); } } // use the list of paths they've entered in the past final String[] knownPaths = PropertiesComponent.getInstance().getValues(FLUTTER_SDK_KNOWN_PATHS); if (knownPaths != null) { paths.addAll(Arrays.asList(knownPaths)); } // search the user's path final String fromUserPath = locateSdkFromPath(); if (fromUserPath != null) { paths.add(fromUserPath); } return paths.toArray(new String[0]); }
Example #16
Source File: NamedScopeDescriptor.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean matches(@Nonnull PsiFile psiFile) { Pair<NamedScopesHolder, NamedScope> resolved = resolveScope(psiFile.getProject()); if (resolved == null) { resolved = resolveScope(ProjectManager.getInstance().getDefaultProject()); } if (resolved != null) { PackageSet fileSet = resolved.second.getValue(); if (fileSet != null) { return fileSet.contains(psiFile, resolved.first); } } if (myFileSet != null) { NamedScopesHolder holder = DependencyValidationManager.getInstance(psiFile.getProject()); return myFileSet.contains(psiFile, holder); } return false; }
Example #17
Source File: LightPlatformCodeInsightTestCase.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static Document setupFileEditorAndDocument(@Nonnull String fileName, @Nonnull String fileText) throws IOException { EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET); EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET); PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting(); deleteVFile(); myVFile = getSourceRoot().createChildData(null, fileName); VfsUtil.saveText(myVFile, fileText); final FileDocumentManager manager = FileDocumentManager.getInstance(); final Document document = manager.getDocument(myVFile); assertNotNull("Can't create document for '" + fileName + "'", document); manager.reloadFromDisk(document); document.insertString(0, " "); document.deleteString(0, 1); myFile = getPsiManager().findFile(myVFile); assertNotNull("Can't create PsiFile for '" + fileName + "'. Unknown file type most probably.", myFile); assertTrue(myFile.isPhysical()); myEditor = createEditor(myVFile); myVFile.setCharset(CharsetToolkit.UTF8_CHARSET); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); return document; }
Example #18
Source File: FlutterSdkUtil.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@NotNull public static String[] getKnownFlutterSdkPaths() { final Set<String> paths = new HashSet<>(); // scan current projects for existing flutter sdk settings for (Project project : ProjectManager.getInstance().getOpenProjects()) { final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project); if (flutterSdk != null) { paths.add(flutterSdk.getHomePath()); } } // use the list of paths they've entered in the past final String[] knownPaths = PropertiesComponent.getInstance().getValues(FLUTTER_SDK_KNOWN_PATHS); if (knownPaths != null) { paths.addAll(Arrays.asList(knownPaths)); } // search the user's path final String fromUserPath = locateSdkFromPath(); if (fromUserPath != null) { paths.add(fromUserPath); } return paths.toArray(new String[0]); }
Example #19
Source File: ManageCodeStyleSchemesDialog.java From consulo with Apache License 2.0 | 5 votes |
private static void showStatus(final Component component, final String message, MessageType messageType) { BalloonBuilder balloonBuilder = JBPopupFactory.getInstance() .createHtmlTextBalloonBuilder(message, messageType.getDefaultIcon(), messageType.getPopupBackground(), null); balloonBuilder.setFadeoutTime(5000); final Balloon balloon = balloonBuilder.createBalloon(); final Rectangle rect = component.getBounds(); final Point p = new Point(rect.x, rect.y + rect.height); final RelativePoint point = new RelativePoint(component, p); balloon.show(point, Balloon.Position.below); Disposer.register(ProjectManager.getInstance().getDefaultProject(), balloon); }
Example #20
Source File: TranslatingCompilerFilesMonitorImpl.java From consulo with Apache License 2.0 | 5 votes |
public boolean isIgnoredOrUnderIgnoredDirectory(ProjectManager projectManager, VirtualFile file) { FileTypeManager fileTypeManager = FileTypeManager.getInstance(); if (fileTypeManager.isFileIgnored(file)) { return true; } //optimization: if file is in content of some project it's definitely not ignored boolean isInContent = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { for (Project project : projectManager.getOpenProjects()) { if (project.isInitialized() && ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) { return true; } } return false; } }); if (isInContent) { return false; } VirtualFile current = file.getParent(); while (current != null) { if (fileTypeManager.isFileIgnored(current)) { return true; } current = current.getParent(); } return false; }
Example #21
Source File: EnforcedPlainTextFileTypeManager.java From consulo with Apache License 2.0 | 5 votes |
private boolean syncWithOpenProjects() { boolean success = true; Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); for (Project openProject : openProjects) { if (!myProcessedProjects.contains(openProject)) { if (!syncWithProject(openProject)) success = false; } } return success; }
Example #22
Source File: ArchetypePropertiesStep.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
private void initComponents() { myEnvironmentForm = new MavenEnvironmentForm(); Project project = myProjectOrNull == null ? ProjectManager.getInstance().getDefaultProject() : myProjectOrNull; myEnvironmentForm.getData(MavenProjectsManager.getInstance(project).getGeneralSettings().clone()); myEnvironmentPanel.add(myEnvironmentForm.createComponent(), BorderLayout.CENTER); //AS TODO: If we keep on using the archetype properties we might add a description to the Required Properties //AS TODO: but then we need to copy this class over and add the description to the dialog. myMavenPropertiesPanel = new MavenPropertiesPanel(myAvailableProperties); myPropertiesPanel.add(myMavenPropertiesPanel); doFillIn.setSelected(true); artifactName.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent keyEvent) { super.keyReleased(keyEvent); if(doFillIn.isSelected()) { updateProperties(); } } } ); artifactName.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent focusEvent) { super.focusLost(focusEvent); if(doFillIn.isSelected()) { updateProperties(); } } } ); }
Example #23
Source File: L2GitUtil.java From azure-devops-intellij with MIT License | 5 votes |
@Nullable Project findProjectByBaseDirLocation(@NotNull File directory) { return ContainerUtil.find(ProjectManager.getInstance().getOpenProjects(), project -> { VirtualFile baseDir = project.getBaseDir(); return baseDir != null && FileUtil.filesEqual(VfsUtilCore.virtualToIoFile(baseDir), directory); }); }
Example #24
Source File: IgnoreFileBasedIndexProjectHandler.java From idea-gitignore with MIT License | 5 votes |
/** * Constructor. * * @param project current project * @param projectManager project manager instance * @param index index instance */ public IgnoreFileBasedIndexProjectHandler(@NotNull final Project project, @NotNull ProjectManager projectManager, @NotNull final FileBasedIndex index) { this.project = project; this.projectManager = projectManager; this.index = index; StartupManager.getInstance(project).registerPreStartupActivity(() -> { index.registerIndexableSet(IgnoreFileBasedIndexProjectHandler.this, project); project.getMessageBus().syncPublisher(REFRESH_STATUSES).refresh(); }); }
Example #25
Source File: PsiCopyPasteManager.java From consulo with Apache License 2.0 | 5 votes |
@Inject public PsiCopyPasteManager(Application application, CopyPasteManager copyPasteManager) { myCopyPasteManager = (CopyPasteManagerEx) copyPasteManager; application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() { @Override public void projectClosing(@Nonnull Project project) { if (myRecentData != null && myRecentData.getProject() == project) { myRecentData = null; } } }); }
Example #26
Source File: HttpExchangeUtil.java From idea-php-toolbox with MIT License | 5 votes |
@Nullable public static Project getProject(@NotNull String name) { for(Project project: ProjectManager.getInstance().getOpenProjects()) { if(name.equals(project.getName())) { return project; } } return null; }
Example #27
Source File: ShowSettingsAction.java From consulo with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); } myShowSettingsUtil.showSettingsDialog(project); }
Example #28
Source File: PathMacroConfigurable.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void apply() throws ConfigurationException { myEditor.commit(); final Project[] projects = ProjectManager.getInstance().getOpenProjects(); for (Project project : projects) { ProjectStorageUtil.checkUnknownMacros((ProjectEx)project, false); } }
Example #29
Source File: FileUtils.java From lsp4intellij with Apache License 2.0 | 5 votes |
/** * This can be used to instantly apply a language server definition without restarting the IDE. */ public static void reloadAllEditors() { Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); for (Project project : openProjects) { reloadEditors(project); } }
Example #30
Source File: NewProjectAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess private static void generateProjectAsync(Project project, @Nonnull NewProjectPanel panel) { // leave current step panel.finish(); NewModuleWizardContext context = panel.getWizardContext(); final File location = new File(context.getPath()); final int childCount = location.exists() ? location.list().length : 0; if (!location.exists() && !location.mkdirs()) { Messages.showErrorDialog(project, "Cannot create directory '" + location + "'", "Create Project"); return; } final VirtualFile baseDir = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location)); baseDir.refresh(false, true); if (childCount > 0) { int rc = Messages.showYesNoDialog(project, "The directory '" + location + "' is not empty. Continue?", "Create New Project", Messages.getQuestionIcon()); if (rc == Messages.NO) { return; } } RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent()); UIAccess uiAccess = UIAccess.current(); ProjectManager.getInstance().openProjectAsync(baseDir, uiAccess).doWhenDone((openedProject) -> { uiAccess.give(() -> NewOrImportModuleUtil.doCreate(panel, openedProject, baseDir)); }); }