-
Notifications
You must be signed in to change notification settings - Fork 4
Added a toggle Action Button to allow the user to switch the labelling of warnings in the plugin #134
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
base: main
Are you sure you want to change the base?
Added a toggle Action Button to allow the user to switch the labelling of warnings in the plugin #134
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.adrienpessu.sarifviewer.actions | ||
|
||
import com.github.adrienpessu.sarifviewer.toolWindow.SarifViewerWindowFactory | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
|
||
class RuleIDorDescriptionAction : AnAction("Toggle Rule ID or Description") { | ||
|
||
var myToolWindow: SarifViewerWindowFactory.MyToolWindow? = null | ||
|
||
override fun actionPerformed(e: AnActionEvent) { | ||
myToolWindow?.toggleRuleIdOrDescription() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import com.contrastsecurity.sarif.SarifSchema210 | |||||
import com.fasterxml.jackson.databind.ObjectMapper | ||||||
import com.github.adrienpessu.sarifviewer.actions.OpenLocalAction | ||||||
import com.github.adrienpessu.sarifviewer.actions.RefreshAction | ||||||
import com.github.adrienpessu.sarifviewer.actions.RuleIDorDescriptionAction | ||||||
import com.github.adrienpessu.sarifviewer.configurable.Settings | ||||||
import com.github.adrienpessu.sarifviewer.configurable.SettingsState | ||||||
import com.github.adrienpessu.sarifviewer.exception.SarifViewerException | ||||||
|
@@ -82,11 +83,14 @@ class SarifViewerWindowFactory : ToolWindowFactory { | |||||
init { | ||||||
val actionManager = ActionManager.getInstance() | ||||||
|
||||||
val toggleRuleIdOrDescriptionAction = actionManager.getAction("RuleIDorDescriptionAction") | ||||||
(toggleRuleIdOrDescriptionAction as RuleIDorDescriptionAction).myToolWindow = this | ||||||
val openLocalFileAction = actionManager.getAction("OpenLocalFileAction") | ||||||
(openLocalFileAction as OpenLocalAction).myToolWindow = this | ||||||
val refreshAction = actionManager.getAction("RefreshAction") | ||||||
(refreshAction as RefreshAction).myToolWindow = this | ||||||
val actions = ArrayList<AnAction>() | ||||||
actions.add(toggleRuleIdOrDescriptionAction) | ||||||
actions.add(openLocalFileAction) | ||||||
actions.add(refreshAction) | ||||||
|
||||||
|
@@ -98,6 +102,8 @@ class SarifViewerWindowFactory : ToolWindowFactory { | |||||
internal var currentBranch: GitLocalBranch? = null | ||||||
|
||||||
private var localMode = false | ||||||
private lateinit var extractSarifFromFile: HashMap<String, MutableList<Leaf>> | ||||||
private lateinit var selectedFile: File | ||||||
private val service = toolWindow.project.service<SarifService>() | ||||||
private val project = toolWindow.project | ||||||
private var main = ScrollPaneFactory.createScrollPane() | ||||||
|
@@ -380,14 +386,21 @@ class SarifViewerWindowFactory : ToolWindowFactory { | |||||
treeBuilding(map) | ||||||
} | ||||||
|
||||||
fun toggleRuleIdOrDescription() { | ||||||
if (localMode) { | ||||||
currentView.ruleIdToggle = !currentView.ruleIdToggle | ||||||
extractSarifFromFile = extractSarifFromFile(selectedFile) | ||||||
treeBuilding(extractSarifFromFile) | ||||||
} | ||||||
} | ||||||
fun openLocalFile() { | ||||||
val fileChooser = JFileChooser() | ||||||
fileChooser.fileFilter = FileNameExtensionFilter("SARIF files", "sarif") | ||||||
SwingUtilities.invokeLater { | ||||||
val returnValue = fileChooser.showOpenDialog(null) | ||||||
if (returnValue == JFileChooser.APPROVE_OPTION) { | ||||||
val selectedFile: File = fileChooser.selectedFile | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
without that the selectedFile attribute is never initiated and the toggle doesn't refresh the tree |
||||||
val extractSarifFromFile = extractSarifFromFile(selectedFile) | ||||||
extractSarifFromFile = extractSarifFromFile(selectedFile) | ||||||
treeBuilding(extractSarifFromFile) | ||||||
localMode = true | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
<resource-bundle>messages.MyBundle</resource-bundle> | ||
|
||
<actions> | ||
<action id="RuleIDorDescriptionAction" icon="AllIcons.Actions.Diff" class="com.github.adrienpessu.sarifviewer.actions.RuleIDorDescriptionAction" text="Toggle Rule ID or Description"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the |
||
</action> | ||
<action id="OpenLocalFileAction" icon="AllIcons.Actions.MenuOpen" class="com.github.adrienpessu.sarifviewer.actions.OpenLocalAction" text="Open local SARIF file"> | ||
</action> | ||
<action id="RefreshAction" icon="AllIcons.Actions.ForceRefresh" class="com.github.adrienpessu.sarifviewer.actions.RefreshAction" text="Refresh from GitHub"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.