如何创建PhpStorm热键以在自定义框架中切换控制器和视图/模板

时间:2016-10-26 11:36:07

标签: phpstorm

框架布局如下所示

/modules/module_name/controller_name.php
/modules/module_name/templates/controller_name.php

控制器和(视图/模板)始终具有相同的名称。

是否有创建热键在两者之间切换?

1 个答案:

答案 0 :(得分:2)

我使用以下操作创建了一个插件并且运行良好。

 @Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    String fileName = vFile != null ? vFile.getName() : null;
    if(fileName == null){
        return;
    }
    String filePath = vFile.getPath();
    String fileDirectory = filePath.replace(fileName,"");

    String newPath;
    if(fileDirectory.contains(File.separator+"templates"+File.separator)){
        newPath = filePath.replace("templates"+File.separator+fileName,fileName);
    }else{
        newPath = filePath.replace(fileName,"templates"+File.separator+fileName);
    }
    VirtualFile newVFile = com.intellij.openapi.vfs.LocalFileSystem.getInstance().findFileByPath(newPath);
    if (newVFile == null) {
        return;
    }
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    fileEditorManager.openFile(newVFile,true,true);
}