├── README.md ├── idea-file-export.iml ├── idea-file-export.jar ├── resources └── META-INF │ └── plugin.xml └── src └── com └── idosth └── file └── export ├── FileExportAction.java ├── MainDialogWrapper.form └── MainDialogWrapper.java /README.md: -------------------------------------------------------------------------------- 1 | # idea-file-export 2 | 计划实现类似eclipse中的export文件的功能, 3 | 主要是给一些有特殊需求比如导出文件目录结构等提供便利 4 | 5 | ## 1.下载项目,调试插件 6 | 将项目Clone到本地后,需要在相应的iml文件中的Module节点下, 7 | 添加项目标识,然后再运行,否则会导致运行时插件不成功 8 | ```xml 9 | 10 | 11 | ``` 12 | 13 | ## 2.使用方式 14 | 下载idea-file-export.jar文件,放到idea安装目录的plugins下面重启即可使用。 15 | 右击需要导出的文件,点击Export即可。 16 | --- 17 | ## 3.TODO 18 | - 添加文件列表功能以供勾选 19 | - 选中文件夹时默认导出所有子目录文件夹 -------------------------------------------------------------------------------- /idea-file-export.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /idea-file-export.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yege2006/idea-file-export/39787046104f5b04e1c641b91fb06e0451d0fd8b/idea-file-export.jar -------------------------------------------------------------------------------- /resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.your.company.unique.plugin.id 3 | Idea File export 4 | 1.1 5 | yege2006 6 | 7 | 计划实现类似eclipse中的export文件的功能, 8 | 主要是给一些有特殊需求比如导出文件目录结构等提供便利 9 | 10 | 11 | 12 | 计划实现类似eclipse中的export文件的功能, 13 | 主要是给一些有特殊需求比如导出文件目录结构等提供便利 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/com/idosth/file/export/FileExportAction.java: -------------------------------------------------------------------------------- 1 | package com.idosth.file.export; 2 | 3 | import com.intellij.openapi.actionSystem.AnAction; 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.actionSystem.PlatformDataKeys; 6 | import com.intellij.openapi.project.Project; 7 | import com.intellij.openapi.ui.Messages; 8 | 9 | /** 10 | * 文件右击菜单Demo,Export按钮,位于剪切复制粘贴组最后 11 | */ 12 | public class FileExportAction extends AnAction { 13 | 14 | @Override 15 | public void actionPerformed(AnActionEvent e) { 16 | MainDialogWrapper dialog = new MainDialogWrapper(e); 17 | dialog.setSize(600, 400); 18 | dialog.setLocationRelativeTo(null); 19 | dialog.setVisible(true); 20 | dialog.requestFocus(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/idosth/file/export/MainDialogWrapper.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 |
127 | -------------------------------------------------------------------------------- /src/com/idosth/file/export/MainDialogWrapper.java: -------------------------------------------------------------------------------- 1 | package com.idosth.file.export; 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent; 4 | import com.intellij.openapi.actionSystem.DataKeys; 5 | import com.intellij.openapi.fileChooser.FileChooser; 6 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.ui.Messages; 9 | import com.intellij.openapi.util.io.FileUtil; 10 | import com.intellij.openapi.vfs.VirtualFile; 11 | import com.intellij.ui.ToolbarDecorator; 12 | import com.intellij.ui.components.JBList; 13 | 14 | import javax.swing.*; 15 | import java.awt.event.KeyEvent; 16 | import java.awt.event.WindowAdapter; 17 | import java.awt.event.WindowEvent; 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | public class MainDialogWrapper extends JDialog { 24 | private JPanel contentPane; 25 | private JButton buttonOK; 26 | private JButton buttonCancel; 27 | private JButton browseBtn; 28 | private JTextField pathEditText; 29 | private JPanel fileListPanel; 30 | private JRadioButton onlyFileRadio; 31 | private JRadioButton structureRadio; 32 | private JLabel pathLabel; 33 | //用于接收选中的文件 34 | private AnActionEvent event; 35 | private String exportModel; 36 | private JBList fieldList; 37 | 38 | MainDialogWrapper(AnActionEvent event) { 39 | this.event = event; 40 | this.setTitle("Export"); 41 | //初始默认选中导出文件带目录结构 42 | structureRadio.setSelected(true); 43 | //设置内容Panel 44 | initListeners(); 45 | setContentPane(contentPane); 46 | setModal(true); 47 | getRootPane().setDefaultButton(buttonOK); 48 | } 49 | 50 | /** 51 | * ok按钮确认导出点击事件 52 | */ 53 | private void onOK() { 54 | String outputPath = pathEditText.getText(); 55 | // 条件校验 56 | if (null == outputPath || "".equals(outputPath)) { 57 | Messages.showErrorDialog(this, "Please Select Save Path!", "Error"); 58 | return; 59 | } 60 | ListModel fileListModel = fieldList.getModel(); 61 | if (fileListModel.getSize() == 0) { 62 | Messages.showErrorDialog(this, "Please Select Export File!", "Error"); 63 | return; 64 | } 65 | try { 66 | for (int i = 0; i < fileListModel.getSize(); i++) { 67 | VirtualFile file = fileListModel.getElementAt(i); 68 | File sourceFile = new File(file.getPath()); 69 | //判断是否需要导出文件目录 70 | if (structureRadio.isSelected()) { 71 | //获取当前项目路径 72 | Project project = event.getProject(); 73 | if (project != null && project.getBasePath() != null) { 74 | 75 | String[] paths = sourceFile.getCanonicalPath().split("\\\\" + project.getName() + "\\\\"); 76 | if (paths.length > 1) { 77 | File targetFile = new File(outputPath + "/" + project.getName() + "/" + paths[1]); 78 | FileUtil.copy(sourceFile, targetFile); 79 | } 80 | } 81 | } else if (onlyFileRadio.isSelected()) { 82 | File targetFile = new File(outputPath + "/" + sourceFile.getName()); 83 | FileUtil.copy(sourceFile, targetFile); 84 | } 85 | } 86 | } catch (IOException e) { 87 | Messages.showErrorDialog(this, "程序出错,请联系作者!", "Error"); 88 | return; 89 | } 90 | dispose(); 91 | } 92 | 93 | private void onCancel() { 94 | dispose(); 95 | } 96 | 97 | private void initListeners() { 98 | 99 | browseBtn.addActionListener(e -> { 100 | //添加文件选择器 101 | FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false); 102 | descriptor.setShowFileSystemRoots(true); 103 | descriptor.setHideIgnored(true); 104 | VirtualFile virtualFile = FileChooser.chooseFile(descriptor, null, null); 105 | if (virtualFile != null && virtualFile.exists()) { 106 | pathEditText.setText(virtualFile.getCanonicalPath()); 107 | } 108 | }); 109 | 110 | //确定点击事件 111 | buttonOK.addActionListener(e -> onOK()); 112 | 113 | //取消点击事件 114 | buttonCancel.addActionListener(e -> onCancel()); 115 | 116 | //关闭点击事件 117 | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 118 | 119 | // 按下ESC关闭事件 120 | contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 121 | addWindowListener(new WindowAdapter() { 122 | @Override 123 | public void windowClosing(WindowEvent e) { 124 | onCancel(); 125 | } 126 | }); 127 | } 128 | 129 | /** 130 | * 自定义Panel 131 | */ 132 | private void createUIComponents() { 133 | //获取选中的虚拟文件 134 | VirtualFile[] data = event.getData(DataKeys.VIRTUAL_FILE_ARRAY); 135 | List fileList = new ArrayList<>(); 136 | for (VirtualFile datum : data) { 137 | if (!datum.isDirectory()) { 138 | fileList.add(datum); 139 | } 140 | } 141 | fieldList = new JBList(fileList); 142 | fieldList.setEmptyText("No File Selected!"); 143 | ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList); 144 | fileListPanel = decorator.createPanel(); 145 | } 146 | } 147 | --------------------------------------------------------------------------------