Skip to content

Commit

Permalink
Add initial support for python in pycharm.
Browse files Browse the repository at this point in the history
Still testing added support for requirements.txt file and adding required dependencies.
  • Loading branch information
Layoric committed Jul 14, 2021
1 parent 72a3878 commit 2c2d245
Show file tree
Hide file tree
Showing 22 changed files with 648 additions and 246 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
.idea
build
out/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ServiceStackIDEA Changelog

## [Unreleased]
- Add support for Python Add ServiceStack Reference in PyCharm
## [1.1.2]
- Fix WebStorm Add ServiceStack Reference
- Fix Java/Kotlin Add ServiceStack Reference for Intellij + Android Studio
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = ServiceStackIDEA
pluginName = ServiceStack
pluginVersion = 1.1.2
pluginVersion = 1.2.0

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/net/servicestack/idea/AddPythonAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.servicestack.idea;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.util.PlatformUtils;
import org.jetbrains.annotations.NotNull;

import java.io.File;

public class AddPythonAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
Module module = getModule(anActionEvent);
AddPythonRef dialog = new AddPythonRef(module);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setSize(dialog.getPreferredSize());
dialog.setResizable(true);
dialog.setTitle("Add Python ServiceStack Reference");
PsiElement element = LangDataKeys.PSI_ELEMENT.getData(anActionEvent.getDataContext());
INativeTypesHandler defaultTsNativeTypesHandler = new PythonNativeTypesHandler();
if (element instanceof PsiDirectory) {
PsiDirectory selectedDir = (PsiDirectory)element;
dialog.setSelectedDirectory(selectedDir.getVirtualFile().getPath());
String initialName = getInitialFileName(selectedDir.getVirtualFile().getPath(),defaultTsNativeTypesHandler);
dialog.setInitialDtoName(initialName);
}
showDialog(dialog);
}

private void showDialog(AddPythonRef dialog) {
dialog.setVisible(true);
}

private String getInitialFileName(String path, INativeTypesHandler defaultTsNativeTypesHandler) {
String initName = "dtos";
int count = 1;
while(true) {
File existingFile = new File(path + "/" + initName + count +
defaultTsNativeTypesHandler.getFileExtension());
if(existingFile.exists()) {
count++;
} else {
break;
}
}
return initName + count;
}

@Override
public void update(@NotNull AnActionEvent e) {
Module module = getModule(e);
if (module == null) {
e.getPresentation().setEnabled(false);
}

if (!PlatformUtils.isPyCharm()) {
e.getPresentation().setVisible(false);
}

super.update(e);
}

static Module getModule(Project project) {
if (project == null)
return null;
Module[] modules = ModuleManager.getInstance(project).getModules();
if (modules.length > 0) {
return modules[0];
}
return null;
}

static Module getModule(AnActionEvent e) {
Module module = e.getData(LangDataKeys.MODULE);
if (module == null) {
Project project = e.getData(LangDataKeys.PROJECT);
return getModule(project);
} else {
return module;
}
}
}
160 changes: 160 additions & 0 deletions src/main/java/net/servicestack/idea/AddPythonRef.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.servicestack.idea.AddPythonRef">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="436" height="244"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="5ad65" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<maximumSize width="700" height="420"/>
<minimumSize width="400" height="220"/>
<preferredSize width="550" height="220"/>
<requestFocusEnabled value="false"/>
</properties>
<border type="none"/>
<children>
<grid id="dbef3" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="9a2ca">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="5346c" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="3ee77" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="OK"/>
</properties>
</component>
<component id="f964c" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="2312f" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9ccf3" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="72f99"/>
<text value="Address Url"/>
</properties>
</component>
<component id="72f99" class="javax.swing.JTextField" binding="addressUrlTextField" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<toolTipText value="eg, http://example.com/"/>
</properties>
</component>
<component id="4b65a" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="eec01"/>
<text value="Name"/>
</properties>
</component>
<component id="36645" class="javax.swing.JTextField" binding="nameTextField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
<grid id="900b" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<focusable value="false"/>
</properties>
<border type="none"/>
<children>
<component id="3a34f" class="javax.swing.JTextPane" binding="infoTextPane">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="2" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="25"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
<focusCycleRoot value="false"/>
<focusable value="false"/>
<font name="Arial"/>
<opaque value="false"/>
<requestFocusEnabled value="false"/>
<text value="To generate the DTO Service Model types for a specific ServiceStack instance, enter the base URI for the remote ServiceStack server and click OK."/>
</properties>
</component>
<component id="a1edc" class="javax.swing.JTextPane" binding="errorTextPane">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="2" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="25"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
<focusCycleRoot value="false"/>
<focusable value="true"/>
<font name="Arial"/>
<opaque value="false"/>
<visible value="false"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
Loading

0 comments on commit 2c2d245

Please sign in to comment.