mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
compile .qrc action
This commit is contained in:
@@ -691,6 +691,10 @@
|
||||
description="Create a new directory and __init__.py inside it" icon="/nodes/packageClosed.png">
|
||||
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewDir"/>
|
||||
</action>
|
||||
|
||||
<action id="CompuleQrc" class="com.jetbrains.pyqt.CompileQrcAction" text="Compile .qrc file">
|
||||
<add-to-group group-id="ProjectViewPopupMenuRunGroup" anchor="first"/>
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.spellchecker">
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.jetbrains.pyqt;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.django.run.Runner;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class CompileQrcAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getData(PlatformDataKeys.PROJECT);
|
||||
VirtualFile[] vFiles = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
|
||||
assert vFiles != null;
|
||||
Module module = e.getData(LangDataKeys.MODULE);
|
||||
String path = QtFileType.findQtTool(module, "pyrcc4");
|
||||
if (path == null) {
|
||||
path = QtFileType.findQtTool(module, "pyside-rcc");
|
||||
}
|
||||
if (path == null) {
|
||||
Messages.showErrorDialog(project, "Could not find pyrcc4 or pyside-rcc for selected Python interpreter", "Compile .qrc file");
|
||||
return;
|
||||
}
|
||||
CompileQrcDialog dialog = new CompileQrcDialog(project, vFiles);
|
||||
dialog.show();
|
||||
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
|
||||
return;
|
||||
}
|
||||
List<String> args = new ArrayList<String>(Arrays.asList(path, "-o", dialog.getOutputPath()));
|
||||
for (VirtualFile vFile : vFiles) {
|
||||
args.add(vFile.getPath());
|
||||
}
|
||||
try {
|
||||
Runner.runInPath(project, vFiles[0].getParent().getPath(), true, null, args.toArray(new String[args.size()]));
|
||||
}
|
||||
catch (ExecutionException ex) {
|
||||
Messages.showErrorDialog(project, "Error running " + path + ": " + ex.getMessage(), "Compile .qrc file");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Module module = e.getData(LangDataKeys.MODULE);
|
||||
VirtualFile[] vFiles = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
|
||||
e.getPresentation().setVisible(module != null && filesAreQrc(vFiles));
|
||||
}
|
||||
|
||||
private static boolean filesAreQrc(VirtualFile[] vFiles) {
|
||||
if (vFiles == null || vFiles.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (VirtualFile vFile : vFiles) {
|
||||
if (!"qrc".equals(FileUtil.getExtension(vFile.getName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class CompileQrcDialog extends DialogWrapper {
|
||||
private JPanel myPanel;
|
||||
private TextFieldWithBrowseButton myOutputFileField;
|
||||
|
||||
protected CompileQrcDialog(Project project, VirtualFile[] vFiles) {
|
||||
super(project);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
public String getOutputPath() {
|
||||
return myOutputFileField.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.pyqt.CompileQrcAction.CompileQrcDialog">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" 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>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e3901" 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>
|
||||
<text value="Output file:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="7c6ff">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="5dfb1" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myOutputFileField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -76,35 +76,49 @@ public abstract class QtFileType implements FileType, INativeFileType {
|
||||
|
||||
@Override
|
||||
public boolean openFileInAssociatedApplication(Project project, VirtualFile file) {
|
||||
String qtTool = findQtTool(ModuleUtil.findModuleForFile(file, project), getToolName());
|
||||
if (qtTool == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Runtime.getRuntime().exec(new String[] { qtTool, file.getPath() } );
|
||||
}
|
||||
catch (IOException e) {
|
||||
Messages.showErrorDialog(project, "Failed to run Qt Designer: " + e.getMessage(), "Error");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String findQtTool(Module module, String toolName) {
|
||||
if (SystemInfo.isWindows) {
|
||||
Module module = ModuleUtil.findModuleForFile(file, project);
|
||||
if (module == null) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk == null) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
List<PsiElement> qt4 =
|
||||
ResolveImportUtil.resolveModulesInRootProvider(sdk.getRootProvider(), module, PyQualifiedName.fromComponents("PyQt4"));
|
||||
for (PsiElement psiElement : qt4) {
|
||||
if (psiElement instanceof PsiDirectory) {
|
||||
VirtualFile designer = ((PsiDirectory)psiElement).getVirtualFile().findChild(getToolName() + ".exe");
|
||||
if (designer != null) {
|
||||
try {
|
||||
Runtime.getRuntime().exec(new String[] { designer.getPath(), file.getPath() } );
|
||||
}
|
||||
catch (IOException e) {
|
||||
Messages.showErrorDialog(project, "Failed to run Qt Designer: " + e.getMessage(), "Error");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
String tool = findToolInPackage(toolName, module, sdk, "PyQt4");
|
||||
if (tool != null) {
|
||||
return tool;
|
||||
}
|
||||
|
||||
return findToolInPackage(toolName, module, sdk, "PySide");
|
||||
}
|
||||
// TODO
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String findToolInPackage(String toolName, Module module, Sdk sdk, String name) {
|
||||
List<PsiElement> elements = ResolveImportUtil.resolveModulesInRootProvider(sdk.getRootProvider(), module, PyQualifiedName.fromComponents(name));
|
||||
for (PsiElement psiElement : elements) {
|
||||
if (psiElement instanceof PsiDirectory) {
|
||||
VirtualFile tool = ((PsiDirectory)psiElement).getVirtualFile().findChild(toolName + ".exe");
|
||||
if (tool != null) {
|
||||
return tool.getPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract String getToolName();
|
||||
|
||||
Reference in New Issue
Block a user