override fun actionPerformed()

in src/main/kotlin/mobi/hsz/idea/gitignore/actions/IgnoreFileAction.kt [61:96]


    override fun actionPerformed(e: AnActionEvent) {
        val files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY) ?: return
        val project = e.getData(CommonDataKeys.PROJECT) ?: return

        (ignoreFile?.let {
            Utils.getPsiFile(project, it)
        } ?: fileType?.let {
            getIgnoreFile(project, it)
        })?.let { ignore ->
            val paths = mutableSetOf<String>()

            files.forEach { file ->
                val path = getPath(ignore.virtualFile.parent, file)
                if (path.isEmpty()) {
                    Utils.getModuleRootForFile(file, project)?.let { baseDir ->
                        Notify.show(
                            project,
                            IgnoreBundle.message("action.ignoreFile.addError", Utils.getRelativePath(baseDir, file)),
                            IgnoreBundle.message("action.ignoreFile.addError.to", Utils.getRelativePath(baseDir, ignore.virtualFile)),
                            NotificationType.ERROR
                        )
                    }
                } else {
                    paths.add(path)
                }
            }

            Utils.openFile(project, ignore)

            try {
                AppendFileCommandAction(project, ignore, paths).execute()
            } catch (e: Throwable) {
                e.printStackTrace()
            }
        }
    }