Commit 91ba4fd3 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Initial commit

parents
<idea-plugin>
<!-- 插件相关信息, 会展示在IDEA插件的描述中 -->
<!-- 插件唯一id, 遵循使用包名的原则 -->
<id>com.duanledexianxianxian.plugin.sample</id>
<!-- 插件名称 -->
<name>sample</name>
<!-- 插件版本 -->
<version>1.0</version>
<!-- 开发者信息 -->
<vendor email="fengyuchenglun@foxmail.com" url="https://github.com/fengyuchenglun">fengyuchenglun</vendor>
<!-- 插件的描述 -->
<description>
This is IDEA plugin. Just for test and study.
</description>
<!-- 插件版本变更信息 -->
<change-notes>
This is IDEA plugin. Just for test and study.
</change-notes>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<!-- 插件兼容IDEA的最大和最小build号,不配置则不做限制 -->
<idea-version since-build="173.0"/>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!-- uncomment to enable plugin in all products
<depends>com.intellij.modules.lang</depends>
-->
<depends>com.intellij.modules.platform</depends>
<!-- 声明该插件对IDEA core或其他插件的扩展 -->
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<applicationService serviceInterface="com.duanledexianxianxian.plugin.service.application.SampleApplication"
serviceImplementation="com.duanledexianxianxian.plugin.service.application.impl.SampleApplicationImpl"/>
<applicationService serviceInterface="com.duanledexianxianxian.plugin.service.application.MyCounter"
serviceImplementation="com.duanledexianxianxian.plugin.service.application.impl.MyCounterImpl"/>
</extensions>
<!-- Actions: 如添加一个文件右击菜单按钮 -->
<actions>
<!-- Add your actions here -->
</actions>
<project-components>
<component>
<implementation-class>com.duanledexianxianxian.plugin.component.project.MaxProject</implementation-class>
</component>
</project-components>
</idea-plugin>
\ No newline at end of file
package com.duanledexianxianxian.plugin.component.project;
import com.duanledexianxianxian.plugin.constant.AppConstants;
import com.duanledexianxianxian.plugin.service.application.MyCounter;
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;
/**
* @author duanledexianxianxian
* @date 2019/10/11 0:08
* @since 1.0.0
*/
public class MaxProject implements ProjectComponent {
public MaxProject(Project project) {
}
@Override
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 " + AppConstants.MAX_CNT +
" projects!", "Error", Messages.getErrorIcon());
ProjectManager PM = ProjectManager.getInstance();
Project[] AllProjects = PM.getOpenProjects();
Project project = AllProjects[AllProjects.length - 1];
PM.closeProject(project);
}
}
@Override
public void projectClosed() {
// called when project is being closed
MyCounter commandCounter = ServiceManager.getService(MyCounter.class);
commandCounter.decreaseCounter();
}
@Override
public void initComponent() {
// TODO: insert component initialization logic here
}
@Override
public void disposeComponent() {
// TODO: insert component disposal logic here
}
@NotNull
@Override
public String getComponentName() {
return "MaxProject";
}
}
package com.duanledexianxianxian.plugin.constant;
/**
* @author duanledexianxianxian
* @date 2019/10/11 0:24
* @since 1.0.0
*/
public class AppConstants {
public static int MAX_CNT = 1;
}
package com.duanledexianxianxian.plugin.service.application;
import com.intellij.openapi.components.ServiceManager;
/**
* The interface My counter.
*/
public interface MyCounter {
/**
* Gets instance.
*
* @return the instance
*/
static MyCounter getInstance() {
return ServiceManager.getService(MyCounter.class);
}
/**
* Increase counter int.
*
* @return the int
*/
int increaseCounter();
/**
* Decrease counter int.
*
* @return the int
*/
int decreaseCounter();
}
package com.duanledexianxianxian.plugin.service.application;
import com.intellij.openapi.components.ServiceManager;
/**
* @author fengyuchenglun
*/
public interface SampleApplication {
static SampleApplication getInstance() {
return ServiceManager.getService(SampleApplication.class);
}
}
package com.duanledexianxianxian.plugin.service.application.impl;
import com.duanledexianxianxian.plugin.service.application.MyCounter;
import static com.duanledexianxianxian.plugin.constant.AppConstants.MAX_CNT;
/**
* The type My counter.
*
* @author fengyuchenglun
* @version 1.0.0
*/
public class MyCounterImpl implements MyCounter {
/**
* Sets the maximum allowed number of opened projects.
*/
private int count = 0;
/**
* Instantiates a new My counter.
*/
public MyCounterImpl() {
}
/**
* Increase counter int.
*
* @return the int
*/
@Override
public int increaseCounter() {
count++;
return (count > MAX_CNT) ? -1 : count;
}
/**
* Decrease counter int.
*
* @return the int
*/
@Override
public int decreaseCounter() {
count--;
return (count > MAX_CNT) ? -1 : count;
}
}
package com.duanledexianxianxian.plugin.service.application.impl;
import com.duanledexianxianxian.plugin.service.application.SampleApplication;
/**
* @author fengyuchenglun
*/
public class SampleApplicationImpl implements SampleApplication {
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment