-
Notifications
You must be signed in to change notification settings - Fork 21
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
Markdown Rendering in the What's New Panel #432
Changes from all commits
9ee9356
f9a0fcf
cb8dab5
a8bdc6b
9a04906
4ff0d3c
7839e03
e88b058
c7bcdaf
85f12da
0e4f3be
06f3b2a
37f1b00
8bd4eea
af7b9b5
25b11bd
b1bd591
4068600
cad5bba
7caf5b1
d45568a
61b1957
0a62c70
e26d91e
2a4348d
1580f11
728a44a
ef81fb1
c153bb4
89e8992
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2023 Slack Technologies, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.slack.sgp.intellij.ui | ||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.Disposer | ||
import com.intellij.openapi.wm.ToolWindow | ||
import com.intellij.testFramework.LightVirtualFile | ||
import com.intellij.ui.content.ContentFactory | ||
import com.intellij.ui.content.ContentManagerEvent | ||
import com.intellij.ui.content.ContentManagerListener | ||
import java.awt.BorderLayout | ||
import javax.swing.JComponent | ||
import javax.swing.JPanel | ||
import org.intellij.lang.annotations.Language | ||
import org.intellij.plugins.markdown.ui.preview.html.MarkdownUtil | ||
import org.intellij.plugins.markdown.ui.preview.jcef.MarkdownJCEFHtmlPanel | ||
|
||
/** | ||
* The WhatsNewPanelFactory class takes the markdown file string from SkateService and displays it | ||
* in a tool window. It uses MarkdownJCEFHtmlPanel and has dependency on intellij markdown plugin to | ||
* properly format the markdown file and its contents | ||
*/ | ||
class WhatsNewPanelFactory : DumbAware { | ||
|
||
// Function that creates the tool window | ||
fun createToolWindowContent( | ||
toolWindow: ToolWindow, | ||
project: Project, | ||
markdownFileString: String, | ||
parentDisposable: Disposable | ||
) { | ||
|
||
val toolWindowContent = WhatsNewPanelContent(project, markdownFileString, parentDisposable) | ||
val content = | ||
ContentFactory.getInstance().createContent(toolWindowContent.contentPanel, "", false) | ||
toolWindow.contentManager.addContent(content) | ||
toolWindow.contentManager.addContentManagerListener( | ||
object : ContentManagerListener { | ||
override fun contentRemoved(event: ContentManagerEvent) { | ||
if (event.content.component == toolWindowContent.contentPanel) { | ||
Disposer.dispose(parentDisposable) | ||
toolWindow.contentManager.removeContentManagerListener(this) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
private class WhatsNewPanelContent( | ||
project: Project, | ||
@Language("Markdown") markdownFileString: String, | ||
parentDisposable: Disposable | ||
) { | ||
|
||
// Actual panel box for What's New at Slack | ||
val contentPanel: JPanel = | ||
JPanel().apply { | ||
layout = BorderLayout(0, 20) | ||
add(createWhatsNewPanel(project, markdownFileString, parentDisposable), BorderLayout.CENTER) | ||
} | ||
|
||
// Control Panel that takes in the current project, markdown string, and a Disposable. | ||
private fun createWhatsNewPanel( | ||
project: Project, | ||
@Language("Markdown") markdownFileString: String, | ||
parentDisposable: Disposable | ||
): JComponent { | ||
// to take in the parsed Changelog: | ||
// val parsedChangelog = ChangelogParser.readFile(markdownFileString) | ||
// then, pass in parsedChangelog instead of markdownFileString | ||
|
||
val file = LightVirtualFile("changelog.md", markdownFileString) | ||
|
||
val panel = MarkdownJCEFHtmlPanel(project, file) | ||
Disposer.register(parentDisposable, panel) | ||
val html = runReadAction { | ||
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. for my own knowledge, what's 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 believe that 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. Got it, so looking at that first one it's more that it guarantees safe access if we're not on the main thread? |
||
MarkdownUtil.generateMarkdownHtml(file, markdownFileString, project) | ||
} | ||
|
||
panel.setHtml(html, 0) | ||
return panel.component | ||
} | ||
} | ||
} |
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.
Can do this in a separate PR but let's make sure we connect these pieces to only show changes since the last update
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.
Yes for sure, should I delete these todo comments for now?
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.
I'd say leave 'em until we actually connect the parser to the previously seen state