-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat][#4] Add basic lint status widget to status bar.
Show status icon and text.
- Loading branch information
Showing
8 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
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
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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/widgets/LintStatusEnum.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,8 @@ | ||
package com.github.blarc.gitlab.template.lint.plugin.widgets | ||
|
||
enum class LintStatusEnum(val text: String, val tooltip: String) { | ||
INVALID("Invalid", "Gitlab CI yaml is invalid!"), | ||
VALID("Valid", "Gitlab CI yaml is valid."), | ||
RUNNING("Running", "Gitlab CI linter is running."), | ||
WAITING("Waiting", "Gitlab CI linter is waiting.") | ||
} |
46 changes: 46 additions & 0 deletions
46
...n/kotlin/com/github/blarc/gitlab/template/lint/plugin/widgets/LintStatusRepresentation.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,46 @@ | ||
package com.github.blarc.gitlab.template.lint.plugin.widgets | ||
|
||
import com.github.blarc.gitlab.template.lint.plugin.GitlabLintRunner | ||
import com.intellij.icons.AllIcons | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.ui.popup.ListPopup | ||
import com.intellij.openapi.wm.StatusBar | ||
import com.intellij.openapi.wm.StatusBarWidget | ||
import com.intellij.util.Consumer | ||
import org.jetbrains.annotations.Nullable | ||
import java.awt.event.MouseEvent | ||
import javax.swing.Icon | ||
|
||
class LintStatusPresentation(private val statusBar: StatusBar) : StatusBarWidget.MultipleTextValuesPresentation { | ||
override fun getTooltipText(): String { | ||
val status = statusBar.project?.service<GitlabLintRunner>()?.status ?: return LintStatusEnum.WAITING.tooltip | ||
return status.tooltip | ||
} | ||
|
||
override fun getClickConsumer(): Consumer<MouseEvent>? { | ||
return null | ||
} | ||
|
||
@Nullable("Null means the widget is unable to show the popup.") | ||
override fun getPopupStep(): ListPopup? { | ||
return null | ||
} | ||
|
||
override fun getSelectedValue(): String { | ||
val status = statusBar.project?.service<GitlabLintRunner>()?.status ?: return LintStatusEnum.WAITING.text | ||
return status.text | ||
} | ||
|
||
|
||
override fun getIcon(): Icon { | ||
return when (statusBar.project?.service<GitlabLintRunner>()?.status) { | ||
LintStatusEnum.INVALID -> AllIcons.General.ExclMark | ||
LintStatusEnum.VALID -> AllIcons.General.InspectionsOK | ||
LintStatusEnum.RUNNING -> AllIcons.General.InlineRefreshHover | ||
else -> { | ||
AllIcons.General.InspectionsPause | ||
} | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/widgets/LintStatusWidget.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,30 @@ | ||
package com.github.blarc.gitlab.template.lint.plugin.widgets | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.wm.StatusBar | ||
import com.intellij.openapi.wm.StatusBarWidget | ||
import com.intellij.openapi.wm.WindowManager | ||
|
||
class LintStatusWidget(project: Project) : StatusBarWidget { | ||
|
||
private var statusBar = WindowManager.getInstance().getStatusBar(project) | ||
|
||
companion object { | ||
const val ID = "LintStatus" | ||
} | ||
|
||
override fun ID(): String = ID | ||
|
||
override fun install(statusBar: StatusBar) { | ||
statusBar.updateWidget(ID) | ||
} | ||
|
||
override fun getPresentation(): StatusBarWidget.WidgetPresentation { | ||
return LintStatusPresentation(statusBar) | ||
} | ||
|
||
override fun dispose() { | ||
println("Hello") | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...in/kotlin/com/github/blarc/gitlab/template/lint/plugin/widgets/LintStatusWidgetFactory.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,21 @@ | ||
package com.github.blarc.gitlab.template.lint.plugin.widgets | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.wm.StatusBar | ||
import com.intellij.openapi.wm.StatusBarWidget | ||
import com.intellij.openapi.wm.StatusBarWidgetFactory | ||
|
||
class LintStatusWidgetFactory : StatusBarWidgetFactory { | ||
|
||
override fun getId(): String = LintStatusWidget.ID | ||
|
||
override fun getDisplayName(): String = "Lint Status" | ||
|
||
override fun isAvailable(project: Project): Boolean = true | ||
|
||
override fun createWidget(project: Project): StatusBarWidget = LintStatusWidget(project) | ||
|
||
override fun disposeWidget(widget: StatusBarWidget) {} | ||
|
||
override fun canBeEnabledOn(statusBar: StatusBar): Boolean = true | ||
} |
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