Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Feb 20, 2024
1 parent 03d8ad6 commit c9c775e
Showing 1 changed file with 77 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ internal class ProjectRepositories(val toolWindow: ToolWindow) {
var knownRepositories: Set<GHGitRepositoryMapping> = emptySet()
}

fun createEmptyTextPanel(
text: String,
showGithubSettings: Boolean,
showGhmanagerSettings: Boolean
): JBPanelWithEmptyText {
val emptyTextPanel = JBPanelWithEmptyText()
emptyTextPanel.emptyText.appendText(text)
if (showGithubSettings) {
emptyTextPanel.emptyText.appendLine(
"Go to github accounts Settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"ShowGithubSettings",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
)
}
if (showGhmanagerSettings) {
emptyTextPanel.emptyText.appendLine(
"Go to ghactions-manager Settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"Github.Actions.Manager.Settings.Open",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
)
}
return emptyTextPanel
}

class GhActionsToolWindowFactory : ToolWindowFactory, DumbAware {
private lateinit var settingsService: GhActionsSettingsService
private lateinit var ghActionsService: GhActionsService
Expand Down Expand Up @@ -119,66 +151,42 @@ class GhActionsToolWindowFactory : ToolWindowFactory, DumbAware {
}
}

private fun createNoActiveReposPanel(
disposable: Disposable,
projectRepositories: ProjectRepositories
) =
private fun createNoActiveReposPanel(disposable: Disposable, projectRepositories: ProjectRepositories) =
with(projectRepositories.toolWindow.contentManager) {
LOG.debug("No active repositories in project")
val emptyTextPanel = JBPanelWithEmptyText()
emptyTextPanel.emptyText
.appendText("No repositories configured for GitHub-Actions-Manager")
.appendSecondaryText(
"Go to GitHub-Actions-Manager settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"Github.Actions.Manager.Settings.Open",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
createEmptyTextPanel(
"No repositories configured for GitHub-Actions-Manager",
showGithubSettings = true,
showGhmanagerSettings = true
).let {
addContent(
factory.createContent(it, "Workflows", false)
.apply {
isCloseable = false
setDisposer(disposable)
}
)

addContent(
factory.createContent(emptyTextPanel, "Workflows", false)
.apply {
isCloseable = false
setDisposer(disposable)
}
)
}
}

private fun createNoAccountPanel(
disposable: Disposable,
projectRepositories: ProjectRepositories
) = with(projectRepositories.toolWindow.contentManager) {
LOG.debug("No GitHub account configured")
val emptyTextPanel = JBPanelWithEmptyText()
emptyTextPanel.emptyText
.appendText("GitHub account not configured and no API Token")
.appendLine(
"Go to github Settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"ShowGithubSettings",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
)
.appendLine(
"Go to ghactions-manager Settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"Github.Actions.Manager.Settings.Open",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
createEmptyTextPanel(
"GitHub account not configured and no API Token",
showGithubSettings = true,
showGhmanagerSettings = true
).let {
addContent(
factory.createContent(it, "Workflows", false)
.apply {
isCloseable = false
setDisposer(disposable)
}
)
addContent(factory.createContent(emptyTextPanel, "Workflows", false)
.apply {
isCloseable = false
setDisposer(disposable)
}
)
}
}

private fun createNoReposPanel(
Expand Down Expand Up @@ -225,44 +233,30 @@ class GhActionsToolWindowFactory : ToolWindowFactory, DumbAware {
Disposer.register(parentDisposable, disposable)
setDisposer(disposable)
displayName = repoSettings.customName.ifEmpty { repo.repositoryPath }
val controller = WorkflowToolWindowTabController(
repo, ghAccount, dataContextRepository, this.disposer!!, toolWindow,
)
component.apply {
layout = BorderLayout()
background = UIUtil.getListBackground()
removeAll()
add(controller.panel, BorderLayout.CENTER)
revalidate()
repaint()
}
putUserData(WorkflowToolWindowTabController.KEY, controller)
}
val controller = WorkflowToolWindowTabController(
repo, ghAccount, dataContextRepository, tab.disposer!!, toolWindow,
)
tab.component.apply {
layout = BorderLayout()
background = UIUtil.getListBackground()
removeAll()
add(controller.panel, BorderLayout.CENTER)
revalidate()
repaint()
}
tab.putUserData(WorkflowToolWindowTabController.KEY, controller)
toolWindow.contentManager.addContent(tab)
} else {
val emptyTextPanel = JBPanelWithEmptyText()
emptyTextPanel.emptyText
.appendText("GitHub account not configured for ${repo.repository}, go to settings to fix")
.appendLine(
"Go to github accounts Settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"ShowGithubSettings",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
)
.appendLine(
"Go to ghactions-manager Settings",
SimpleTextAttributes.LINK_ATTRIBUTES,
ActionUtil.createActionListener(
"Github.Actions.Manager.Settings.Open",
emptyTextPanel,
ActionPlaces.UNKNOWN
)
)
toolWindow.contentManager.addContent(
toolWindow.contentManager.factory.createContent(emptyTextPanel, repo.repositoryPath, false)
toolWindow.contentManager.factory.createContent(
createEmptyTextPanel(
"GitHub account not configured for ${repo.repository}, go to settings to fix",
showGithubSettings = true,
showGhmanagerSettings = true
),
repo.repositoryPath, false
)
)
}
}
Expand All @@ -285,7 +279,6 @@ class GhActionsToolWindowFactory : ToolWindowFactory, DumbAware {
}
}
}, 5, TimeUnit.SECONDS)

}

companion object {
Expand Down

0 comments on commit c9c775e

Please sign in to comment.