diff --git a/max_opened_projects/README.md b/max_opened_projects/README.md index c839d86c1..14643f701 100644 --- a/max_opened_projects/README.md +++ b/max_opened_projects/README.md @@ -4,18 +4,10 @@ ## Quickstart Maximum Open Projects Sample implements a `ProjectManagerListener` with two methods applied to check if the current projects have been opened or closed. -Each method refers to the `ProjectCountingService` service registered as an `com.intellij.applicationService` extension point. +Each method refers to the `ProjectCountingService` [light service][docs:plugin_services:light_services]. It provides methods to increase and decrease the global counter of the currently opened projects in the IDE. After opening each one, a message dialog is presented to the user with the current number. -### Extension Points - -| Name | Implementation | Extension Point Class | -|-----------------------------------|-------------------------------------------------------|-----------------------| -| `com.intellij.applicationService` | [ProjectCountingService][file:ProjectCountingService] | n/a | - -*Reference: [Plugin Extension Points in IntelliJ SDK Docs][docs:ep]* - ### Application Listeners | Name | Implementation | Listener Class | @@ -26,7 +18,7 @@ After opening each one, a message dialog is presented to the user with the curre [docs]: https://plugins.jetbrains.com/docs/intellij/ [docs:plugin_services]: https://plugins.jetbrains.com/docs/intellij/plugin-services.html -[docs:ep]: https://plugins.jetbrains.com/docs/intellij/plugin-extensions.html +[docs:plugin_services:light_services]: https://plugins.jetbrains.com/docs/intellij/plugin-services.html#light-services [docs:listeners]: https://plugins.jetbrains.com/docs/intellij/plugin-listeners.html [file:ProjectCountingService]: ./src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java diff --git a/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java b/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java index 1e9a68273..0568b2e60 100644 --- a/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java +++ b/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java @@ -1,45 +1,31 @@ -// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.intellij.sdk.maxOpenProjects; +import com.intellij.openapi.components.Service; + /** * Application service implementation to keep a running count of how many projects are open at a given time. */ -public class ProjectCountingService { +@Service +public final class ProjectCountingService { - /** - * Sets the maximum allowed number of opened projects. - */ - private final static int MAX_OPEN_PRJ_LIMIT = 3; + private final static int MAX_OPEN_PROJECTS_LIMIT = 3; - /** - * The count of open projects must always be >= 0. - */ private int myOpenProjectCount = 0; public void incrProjectCount() { - validateProjectCount(); myOpenProjectCount++; } public void decrProjectCount() { - myOpenProjectCount--; - validateProjectCount(); + if (myOpenProjectCount > 0) { + myOpenProjectCount--; + } } public boolean projectLimitExceeded() { - return myOpenProjectCount > MAX_OPEN_PRJ_LIMIT; - } - - public int getProjectCount() { - return myOpenProjectCount; - } - - /** - * Anti-bugging to ensure the count of open projects never goes below zero. - */ - private void validateProjectCount() { - myOpenProjectCount = Math.max(myOpenProjectCount, 0); + return myOpenProjectCount > MAX_OPEN_PROJECTS_LIMIT; } } diff --git a/max_opened_projects/src/main/resources/META-INF/plugin.xml b/max_opened_projects/src/main/resources/META-INF/plugin.xml index 355fd9b5f..2a75befeb 100644 --- a/max_opened_projects/src/main/resources/META-INF/plugin.xml +++ b/max_opened_projects/src/main/resources/META-INF/plugin.xml @@ -1,4 +1,4 @@ - + @@ -40,8 +40,4 @@ topic="com.intellij.openapi.project.ProjectManagerListener"/> - - - -