mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
Unzipped MaxOpenedProjects and added Gradle module
This commit is contained in:
parent
459c3d52a4
commit
74a64dbc58
12
MaxOpenedProjects/MaxOpenedProjects.iml
Normal file
12
MaxOpenedProjects/MaxOpenedProjects.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PLUGIN_MODULE" version="4">
|
||||
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/META-INF/plugin.xml" />
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
29
MaxOpenedProjects/src/META-INF/plugin.xml
Normal file
29
MaxOpenedProjects/src/META-INF/plugin.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<idea-plugin version="2">
|
||||
<name>Plugin name here</name>
|
||||
<description>short description of the plugin</description>
|
||||
<version>1.0</version>
|
||||
<vendor>YourCompany</vendor>
|
||||
<idea-version since-build="8000"/>
|
||||
|
||||
<application-components>
|
||||
<!-- Add your application components here -->
|
||||
</application-components>
|
||||
|
||||
<project-components>
|
||||
<!-- Add your project components here -->
|
||||
<component>
|
||||
<implementation-class>MyPackage.MaxProject</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<actions>
|
||||
<!-- Add your actions here -->
|
||||
</actions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<!-- Add your extensions here -->
|
||||
<applicationService serviceInterface="MyPackage.MyCounter" serviceImplementation="MyPackage.MyCounter">
|
||||
|
||||
</applicationService>
|
||||
</extensions>
|
||||
</idea-plugin>
|
54
MaxOpenedProjects/src/MyPackage/MaxProject.java
Normal file
54
MaxOpenedProjects/src/MyPackage/MaxProject.java
Normal file
@ -0,0 +1,54 @@
|
||||
package MyPackage;
|
||||
|
||||
import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Alexey.Chursin
|
||||
* Date: Aug 13, 2010
|
||||
* Time: 3:50:25 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MaxProject implements ProjectComponent {
|
||||
public MaxProject(Project project) {
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
// TODO: insert component initialization logic here
|
||||
}
|
||||
|
||||
public void disposeComponent() {
|
||||
// TODO: insert component disposal logic here
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "MaxProject";
|
||||
}
|
||||
|
||||
public void projectOpened() {
|
||||
// called when project is opened
|
||||
MyCounter CommandCounter = ServiceManager.getService(MyCounter.class);
|
||||
|
||||
if (CommandCounter.IncreaseCounter() == -1) {
|
||||
Messages.showMessageDialog("The maximum number of opened projects exceeds " + String.valueOf(CommandCounter.MaxCount) +
|
||||
" projects!", "Error", Messages.getErrorIcon());
|
||||
ProjectManager PM=ProjectManager.getInstance();
|
||||
Project[] AllProjects = PM.getOpenProjects();
|
||||
Project project = AllProjects[AllProjects.length-1];
|
||||
PM.closeProject(project);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void projectClosed() {
|
||||
// called when project is being closed
|
||||
MyCounter CommandCounter = ServiceManager.getService(MyCounter.class);
|
||||
CommandCounter.DecreaseCounter();
|
||||
}
|
||||
}
|
29
MaxOpenedProjects/src/MyPackage/MyCounter.java
Normal file
29
MaxOpenedProjects/src/MyPackage/MyCounter.java
Normal file
@ -0,0 +1,29 @@
|
||||
package MyPackage;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Alexey.Chursin
|
||||
* Date: Aug 13, 2010
|
||||
* Time: 3:49:33 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MyCounter {
|
||||
private int Count = 0;
|
||||
// Sets the maximum allowed number of opened projects.
|
||||
public final int MaxCount = 3;
|
||||
public MyCounter(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int IncreaseCounter() {
|
||||
Count++;
|
||||
return (Count > MaxCount) ? -1:Count;
|
||||
}
|
||||
|
||||
public int DecreaseCounter() {
|
||||
Count--;
|
||||
return (Count > MaxCount) ? -1:Count;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user