diff --git a/.gitignore b/.gitignore index db05674b1..ace16c9e1 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ _includes .idea/workspace.xml .idea/tasks.xml .idea/dictionaries + .idea/libraries/Gradle__*.xml # Sensitive or high-churn files: .idea/dataSources.ids diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 000000000..aabdd99a8 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/gradle_wrapper.xml b/.idea/libraries/gradle_wrapper.xml deleted file mode 100644 index 9063eaf07..000000000 --- a/.idea/libraries/gradle_wrapper.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/tasks.xml b/.idea/libraries/tasks.xml deleted file mode 100644 index 28567c398..000000000 --- a/.idea/libraries/tasks.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 1d921d38b..b5c42a85e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index d92dae7b4..b6fa6239c 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index aac4c972f..58f2fe940 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -12,6 +12,12 @@ + + + + + + \ No newline at end of file diff --git a/attachments/MaxOpenedProjects.zip b/attachments/MaxOpenedProjects.zip deleted file mode 100644 index 2e5f02067..000000000 Binary files a/attachments/MaxOpenedProjects.zip and /dev/null differ diff --git a/basics/plugin_structure/plugin_services.md b/basics/plugin_structure/plugin_services.md index d8b273569..9b595403f 100644 --- a/basics/plugin_structure/plugin_services.md +++ b/basics/plugin_structure/plugin_services.md @@ -55,8 +55,7 @@ This section allows you to download and install a sample plugin illustrating how **To install and run the sample plugin** -* Click [here](/attachments/MaxOpenedProjects.zip) to download the .Zip archive that contains the sample plugin project. -* Extract all files from the .Zip archive to a separate folder. -* Start *IntelliJ IDEA*, on the starting page, click *Open Project*, and then use the *Open Project* dialog box to open the downloaded project *MaxOpenedProjects*. +* Download the included sample plugin project located [here](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/MaxOpenedProjects). +* Start *IntelliJ IDEA*, on the starting page, click *Open Project*, and then use the *Open Project* dialog box to open the project *MaxOpenedProjects*. * On the main menu, choose *Run \| Run* or press Shift+F10. * If necessary, change the [Run/Debug Configurations](http://www.jetbrains.com/idea/help/run-debug-configuration-plugin.html). diff --git a/code_samples/MaxOpenedProjects/MaxOpenedProjects.iml b/code_samples/MaxOpenedProjects/MaxOpenedProjects.iml new file mode 100644 index 000000000..347e916d5 --- /dev/null +++ b/code_samples/MaxOpenedProjects/MaxOpenedProjects.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/code_samples/MaxOpenedProjects/src/META-INF/plugin.xml b/code_samples/MaxOpenedProjects/src/META-INF/plugin.xml new file mode 100644 index 000000000..3e3ce844c --- /dev/null +++ b/code_samples/MaxOpenedProjects/src/META-INF/plugin.xml @@ -0,0 +1,29 @@ + + Plugin name here + short description of the plugin + 1.0 + YourCompany + + + + + + + + + + MyPackage.MaxProject + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code_samples/MaxOpenedProjects/src/MyPackage/MaxProject.java b/code_samples/MaxOpenedProjects/src/MyPackage/MaxProject.java new file mode 100644 index 000000000..dbf179d55 --- /dev/null +++ b/code_samples/MaxOpenedProjects/src/MyPackage/MaxProject.java @@ -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(); + } +} diff --git a/code_samples/MaxOpenedProjects/src/MyPackage/MyCounter.java b/code_samples/MaxOpenedProjects/src/MyPackage/MyCounter.java new file mode 100644 index 000000000..f2e5417a8 --- /dev/null +++ b/code_samples/MaxOpenedProjects/src/MyPackage/MyCounter.java @@ -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; + } + +}