• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 package com.sk.ng;
16 
17 import com.intellij.notification.NotificationType;
18 import com.intellij.openapi.actionSystem.AnAction;
19 import com.intellij.openapi.actionSystem.AnActionEvent;
20 import com.intellij.openapi.actionSystem.PlatformDataKeys;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.vfs.VirtualFile;
23 import com.sk.dialog.GenerateDialog;
24 import com.sk.utils.FileUtil;
25 import com.sk.utils.GenNotification;
26 
27 /**
28  * 项目文件入口
29  *
30  * @author: xudong
31  * @see: tool conversion plug-in
32  * @version: v1.0.0
33  * @since 2022-02-21
34  */
35 public class GenDTS extends AnAction {
36 
37     @Override
actionPerformed(AnActionEvent anActionEvent)38     public void actionPerformed(AnActionEvent anActionEvent) {
39         Project project = anActionEvent.getProject();
40         // 获取需要处理的.d.ts文件绝对路径
41         VirtualFile file = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE);
42         if (file == null) {
43             GenNotification.notifyMessage(project, "", "file is not exist", NotificationType.ERROR);
44             return;
45         }
46         if (project == null) {
47             return;
48         }
49         String destPath = file.getPath();
50         String directoryPath = file.getParent().getPath();
51         String fileName = file.getName();
52         GenerateDialog wrapper = new GenerateDialog(project, destPath, directoryPath, fileName);
53         wrapper.showAndGet();
54     }
55 
56 
57     @Override
update(AnActionEvent event)58     public void update(AnActionEvent event) {
59         // 根据所选文件名,判断是否显示生成菜单项
60         VirtualFile file = event.getData(PlatformDataKeys.VIRTUAL_FILE);
61         if (file == null) {
62             event.getPresentation().setEnabledAndVisible(false);
63         } else {
64             event.getPresentation().setEnabledAndVisible(FileUtil.patternFileName(file.getName()));
65         }
66     }
67 }
68