Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config notification feature #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.vk.kphpstorm.configuration

import com.intellij.ide.util.PropertiesComponent
import com.intellij.notification.*
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
Expand All @@ -20,7 +23,48 @@ class KphpStormStartupActivity : ProjectActivity {
}

private fun showSetupDialog(project: Project) {
if (!KphpStormConfiguration.wasSetupForProject(project) && KphpStormConfiguration.seemsLikeProjectIsKphpBased(project))
if (!KphpStormConfiguration.wasSetupForProject(project) && KphpStormConfiguration.seemsLikeProjectIsKphpBased(project)){
SetupPluginForProjectDialog(project).show()
}else{
showNotification(project)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the notification will appear even if the project is configured

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
}

private fun showNotification(project: Project) {
val notification = NotificationGroupManager.getInstance()
.getNotificationGroup("kphpstorm.plugin.setup.notification")
.createNotification("Transforming to kPHP", NotificationType.INFORMATION)

val dntShow = "DoNotShowAgain"
val isKphp = "isKphpProject"

val propertiesComponent = PropertiesComponent.getInstance(project)
if (propertiesComponent.getBoolean(dntShow, false)) {
return
}

if (propertiesComponent.getBoolean(isKphp, false)) {
return
}

notification.setSuggestionType(true)

notification.addAction(object : NotificationAction("Setup project as kPHP") {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
propertiesComponent.setValue(isKphp, true)
SetupPluginForProjectDialog(project).show()
notification.expire()
}
})

// Turn-off notifications
notification.addAction(object : NotificationAction("Don`t show it again") {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
propertiesComponent.setValue(dntShow, true)
notification.expire()
}
})

Notifications.Bus.notify(notification, project)
}
}
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
<docTagParserExtension tagName="type" implementationClass="com.vk.kphpstorm.exphptype.psi.PhpDocVarTagParserEx" order="first" />
</extensions>

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="kphpstorm.plugin.setup.notification" displayType="BALLOON" toolWindowId="kphp configuration notification"/>
</extensions>

<actions>
<group id="com.vk.kphpstorm" text="KPHPStorm" popup="true" icon="/icons/kphp_logo.svg">
<add-to-group group-id="ToolsMenu" anchor="last"/>
Expand Down