generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from orangain/menu-to-disable-plugin
Add context menu to temporarily disable formatting
- Loading branch information
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/io/github/orangain/prettyjsonlog/action/ToggleEnabledAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.github.orangain.prettyjsonlog.action | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.LangDataKeys | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.diagnostic.thisLogger | ||
import com.intellij.openapi.project.DumbAwareToggleAction | ||
import io.github.orangain.prettyjsonlog.service.EphemeralStateService | ||
|
||
class ToggleEnabledAction : DumbAwareToggleAction() { | ||
override fun isSelected(e: AnActionEvent): Boolean { | ||
val consoleView = e.getData(LangDataKeys.CONSOLE_VIEW) ?: return false | ||
val project = e.project ?: return false | ||
val service = project.service<EphemeralStateService>() | ||
return service.isEnabled(consoleView) | ||
} | ||
|
||
override fun setSelected(e: AnActionEvent, state: Boolean) { | ||
thisLogger().debug("setSelected: $state") | ||
val consoleView = e.getData(LangDataKeys.CONSOLE_VIEW) ?: return | ||
val project = e.project ?: return | ||
val service = project.service<EphemeralStateService>() | ||
service.setEnabled(consoleView, state) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/io/github/orangain/prettyjsonlog/console/MyConsoleFolding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/io/github/orangain/prettyjsonlog/service/EphemeralStateService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.orangain.prettyjsonlog.service | ||
|
||
import com.intellij.execution.ui.ConsoleView | ||
import com.intellij.openapi.components.Service | ||
import java.util.* | ||
|
||
@Service(Service.Level.PROJECT) | ||
class EphemeralStateService { | ||
private val enabledMap = WeakHashMap<ConsoleView, Boolean>() | ||
|
||
/** | ||
* Returns true if the formatting is enabled for the given console view. | ||
*/ | ||
fun isEnabled(consoleView: ConsoleView): Boolean { | ||
return enabledMap[consoleView] ?: true // default is true | ||
} | ||
|
||
/** | ||
* Sets the enabled state of the formatting for the given console view. | ||
*/ | ||
fun setEnabled(consoleView: ConsoleView, value: Boolean) { | ||
enabledMap[consoleView] = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
applicationActivated=Application activated | ||
action.io.github.orangain.prettyjsonlog.action.ToggleEnabledAction.text=Formatting Enabled | ||
action.io.github.orangain.prettyjsonlog.action.ToggleEnabledAction.description=Enable or disable formatting of JSON logs in the console |