diff --git a/max_opened_projects/gradle/wrapper/gradle-wrapper.properties b/max_opened_projects/gradle/wrapper/gradle-wrapper.properties index d7caaeb7a..17cd5120e 100644 --- a/max_opened_projects/gradle/wrapper/gradle-wrapper.properties +++ b/max_opened_projects/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ # Copyright 2000-2020 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. +# distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/max_opened_projects/settings.gradle b/max_opened_projects/settings.gradle index 8b2350906..60d0c29b4 100644 --- a/max_opened_projects/settings.gradle +++ b/max_opened_projects/settings.gradle @@ -1,4 +1,4 @@ // Copyright 2000-2020 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. -rootProject.name = 'maxOpenPrj' +rootProject.name = 'maxOpenProjects' diff --git a/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenPrj/ProjectCountingService.java b/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java similarity index 64% rename from max_opened_projects/src/main/java/org/intellij/sdk/maxOpenPrj/ProjectCountingService.java rename to max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java index 936ab146b..cd8b77f5a 100644 --- a/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenPrj/ProjectCountingService.java +++ b/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectCountingService.java @@ -1,6 +1,6 @@ // Copyright 2000-2020 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. -package org.intellij.sdk.maxOpenPrj; +package org.intellij.sdk.maxOpenProjects; /** * Application service implementation to keep a running count of @@ -12,14 +12,14 @@ public class ProjectCountingService { // The count of open projects must always be >= 0 private int myOpenProjectCount = 0; - public void incrProjectCount() { - myOpenProjectCount = verifyProjectCount(myOpenProjectCount); + public void incrProjectCount() { + validateProjectCount(); myOpenProjectCount++; } public void decrProjectCount() { myOpenProjectCount--; - myOpenProjectCount = verifyProjectCount(myOpenProjectCount); + validateProjectCount(); } public boolean projectLimitExceeded() { @@ -32,12 +32,9 @@ public class ProjectCountingService { /** * Anti-bugging to ensure the count of open projects never goes below zero. - * @param openProjectCount The count of currently open projects - * @return 0 if openProjectCount<0 - * openProjectCount otherwise */ - private int verifyProjectCount(int openProjectCount) { - return openProjectCount<0 ? 0 : openProjectCount; + private void validateProjectCount() { + myOpenProjectCount = Math.max(myOpenProjectCount, 0); } } diff --git a/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenPrj/ProjectOpenCloseListener.java b/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectOpenCloseListener.java similarity index 59% rename from max_opened_projects/src/main/java/org/intellij/sdk/maxOpenPrj/ProjectOpenCloseListener.java rename to max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectOpenCloseListener.java index 27264c71b..62e1112bf 100644 --- a/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenPrj/ProjectOpenCloseListener.java +++ b/max_opened_projects/src/main/java/org/intellij/sdk/maxOpenProjects/ProjectOpenCloseListener.java @@ -1,22 +1,19 @@ // Copyright 2000-2020 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. -package org.intellij.sdk.maxOpenPrj; +package org.intellij.sdk.maxOpenProjects; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManagerListener; import com.intellij.openapi.ui.Messages; -import org.intellij.sdk.utils.SdkBalloonHelper; import org.jetbrains.annotations.NotNull; /** * Listener to detect project open and close. - * Depends on org.intellij.sdk.maxOpenPrj.ProjectCountingService - * Depends on org.intellij.sdk.utils.SdkBalloonHelper + * Depends on org.intellij.sdk.maxOpenProjects.ProjectCountingService */ public class ProjectOpenCloseListener implements ProjectManagerListener { - private static final String MAX_OPEN_PROJ_DISCLAIM = "\nThis is an IntelliJ Platform SDK demo message.\n\n"; /** * Invoked on project open. @@ -35,9 +32,9 @@ public class ProjectOpenCloseListener implements ProjectManagerListener { if (projectCountingService.projectLimitExceeded()) { // Transitioned to outside the limit String title = String.format("Opening Project \"%s\"", project.getName()); - String message = MAX_OPEN_PROJ_DISCLAIM + "The number of open projects exceeds the SDK plugin max_opened_projects limit."; - SdkBalloonHelper balloonHelper = SdkBalloonHelper.getSdkBalloonHelper(); - balloonHelper.showBalloon(project, title, message); + String message = "
The number of open projects exceeds the SDK plugin max_opened_projects limit.

" + + "This is not an error

"; + Messages.showMessageDialog(project, message, title, Messages.getInformationIcon()); } } @@ -52,18 +49,8 @@ public class ProjectOpenCloseListener implements ProjectManagerListener { if (ApplicationManager.getApplication().isUnitTestMode()) return; // Get the counting service ProjectCountingService projectCountingService = ServiceManager.getService(ProjectCountingService.class); - // Was the count above the limit? - boolean previouslyOverCount = projectCountingService.projectLimitExceeded(); // Decrement the count because a project just closed projectCountingService.decrProjectCount(); - // See if the total # of projects no longer violates the limit. - if (!projectCountingService.projectLimitExceeded() && previouslyOverCount) { - // Transitioned to within the limit. - String title = String.format("\"%s\" Has Been Closed", project.getName()); - String message = MAX_OPEN_PROJ_DISCLAIM + "The number of open projects is below the SDK plugin max_opened_projects limit."; - SdkBalloonHelper balloonHelper = SdkBalloonHelper.getSdkBalloonHelper(); - balloonHelper.showBalloon(project, title, message); - } } } diff --git a/max_opened_projects/src/main/java/org/intellij/sdk/utils/SdkBalloonHelper.java b/max_opened_projects/src/main/java/org/intellij/sdk/utils/SdkBalloonHelper.java deleted file mode 100644 index 407dd281a..000000000 --- a/max_opened_projects/src/main/java/org/intellij/sdk/utils/SdkBalloonHelper.java +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2000-2020 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. - -package org.intellij.sdk.utils; - -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.ui.popup.Balloon; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.openapi.wm.IdeFrame; -import com.intellij.openapi.wm.WindowManager; -import com.intellij.openapi.wm.ex.WindowManagerEx; -import com.intellij.openapi.wm.impl.WindowManagerImpl; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; - -/** - * This is just a utility class to help communicate the state of this plugin using Popups - * - * @see Popup documentation - */ -public class SdkBalloonHelper { - - public static SdkBalloonHelper getSdkBalloonHelper() { - return new SdkBalloonHelper(); - } - - /** - * This method constructs a Balloon-type popup and displays it in the middle of a Project window. - * - * @param project The Project to host the Balloon. - * @param title A short description of what the Balloon conveys - * @param message Detailed information to display in HTML format - */ - public void showBalloon(@Nullable Project project, @NotNull String title, @NotNull String message) { - - // Create a component to hold the message in HTML format - JLabel component = new JLabel("" + message + ""); - - // Construct the balloon using the component - final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(component) - .setShadow(true) - .setHideOnClickOutside(true) - .setHideOnAction(false) - .setFillColor(UIUtil.getControlColor()) - .setTitle(title) - .setFadeoutTime(6000) - .createBalloon(); - - // Ensure the project is open. If not, find a visible Project to display the balloon. - Project displayProject = findValidProject(project); - if (displayProject == null) return; - - // Get the UI element to display the balloon - JRootPane pane = getProjectRootPane(displayProject); - if (pane == null) return; - - // This is a special case for the message when closing a project. - // The closed project is no longer visible, so the next... - // Consequently register it for disposal with the project that will display it -// Disposer.register(displayProject, balloon); - - // Show the balloon in the middle of the project's window - it will disappear per the animation - balloon.showInCenterOf(pane); - } - - /** - * This function verifies that the provided Project is still open. - * If the Project is not open (closed, or in some state of disposal,) - * the function tries to find the next most-recently opened Project. - * - * @param dodgyProject The Project to be verified as open - * @return dodgyProject if it is verified as open, - * Or the last Project listed in ProjectManager's list of open Projects. - * Or null if no other Projects are open. (Edge case when IDE is closing.) - */ - @Nullable - private Project findValidProject(@Nullable Project dodgyProject) { - Project validProject = dodgyProject; - if ((dodgyProject == null) || !dodgyProject.isOpen()) { - // Find the next most-recently opened Project that is still open. - IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance(); - IdeFrame ideFrameFromFocusMgr = focusManager.getLastFocusedFrame(); - Project focusMgrProject = ideFrameFromFocusMgr.getProject(); - System.out.println("\n\nFocus Mgr last focused frame -> project: " + focusMgrProject.toString() + "\n"); - - - final WindowManager windowManager = WindowManagerImpl.getInstance(); - IdeFrame[] allIdeFrames = windowManager.getAllProjectFrames(); - for (int i=0; i project: %s", i, allIdeFrames[i].getProject().toString())); - } - - String outcome = String.format("\n\nUsing Win Mgr getIdeFrame(null): "); - String focusProject; - IdeFrame focusFrame = windowManager.getIdeFrame(null); - if (focusFrame != null) { - focusProject = String.format("%s", focusFrame.getProject().toString()); - } else { - focusProject = String.format("No focused project found"); - } - System.out.println(outcome + focusProject); - - outcome = String.format("\n\nUsing Win Mgr findFrameFor(null): "); - focusFrame = ((WindowManagerImpl) windowManager).findFrameFor(null); - if (focusFrame != null) { - focusProject = String.format("%s", focusFrame.getProject().toString()); - } else { - focusProject = String.format("No focused project found"); - } - System.out.println(outcome + focusProject); - - ProjectManager projectManager = ProjectManager.getInstance(); - Project[] allProjects = projectManager.getOpenProjects(); - validProject = allProjects.length > 0 ? allProjects[allProjects.length - 1] : null; - System.out.println("\n\nProjMgr allProjects[last]: " + validProject.toString()); - } - return validProject; - } - - /** - * This function gets the JRootPane for an open Project - * - * @param project The open Project - * @return A valid JRootPane for the Project - * Otherwise null - */ - @Nullable - private JRootPane getProjectRootPane(@Nullable Project project) { - JRootPane projectPane = null; - if ((project != null) && project.isOpen()) { - // Get the frame for the project, then the JRootPane - final WindowManager manager = WindowManager.getInstance(); - final JFrame frame = manager.getFrame(project); - projectPane = frame != null ? frame.getRootPane() : null; - } - return projectPane; - } - -} 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 417b3b94a..3de5f48f9 100644 --- a/max_opened_projects/src/main/resources/META-INF/plugin.xml +++ b/max_opened_projects/src/main/resources/META-INF/plugin.xml @@ -3,7 +3,7 @@ - org.intellij.sdk.maxOpenPrj + org.intellij.sdk.maxOpenProjects SDK: Maximum Open Projects Sample @@ -36,10 +36,10 @@ IntelliJ Platform SDK - + - + \ No newline at end of file