@@ -10,6 +10,7 @@ import com.intellij.openapi.wm.ToolWindow
1010import com.intellij.openapi.wm.ToolWindowManager
1111import com.intellij.openapi.wm.WindowManager
1212import com.intellij.ui.table.JBTable
13+ import com.intellij.ui.util.preferredHeight
1314import no.spk.fiskeoye.plugin.component.LabelIcon
1415import no.spk.fiskeoye.plugin.enum.ScrollDirection
1516import no.spk.fiskeoye.plugin.icons.FiskeoyeIcons.Bitbucket
@@ -20,19 +21,29 @@ import no.spk.fiskeoye.plugin.ui.FileContentPanel
2021import no.spk.fiskeoye.plugin.ui.FilenamePanel
2122import no.spk.fiskeoye.plugin.ui.FiskeoyePanel
2223import java.awt.Desktop
24+ import java.awt.Dimension
2325import java.awt.Window
2426import java.awt.datatransfer.StringSelection
2527import java.net.URI
2628import java.net.URL
29+ import javax.swing.JEditorPane
30+ import javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS
31+ import javax.swing.JTable.AUTO_RESIZE_OFF
32+ import javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
2733import javax.swing.table.DefaultTableModel
34+ import javax.swing.text.html.HTMLEditorKit
2835
2936internal fun scrollTo (table : JBTable , direction : ScrollDirection ) {
3037 val rowIndex = when (direction) {
3138 ScrollDirection .END -> table.rowCount - 1
3239 ScrollDirection .TOP -> 0
3340 }
3441 if (table.rowCount == 0 || rowIndex > table.rowCount) return
42+ if (! table.autoscrolls) {
43+ table.autoscrolls = true
44+ }
3545 table.changeSelection(rowIndex, 0 , false , false )
46+ table.autoscrolls = false
3647}
3748
3849internal fun copy (textToCopy : String ) {
@@ -94,6 +105,7 @@ internal fun openUrlWithBrowser(uri: URI) {
94105
95106internal fun JBTable.clear () {
96107 this .model = DefaultTableModel ()
108+ this .preferredSize = Dimension (0 , 0 )
97109}
98110
99111internal fun JBTable.addMessage (message : String ) {
@@ -111,8 +123,37 @@ internal fun JBTable.hideColumns() {
111123 }
112124}
113125
126+ internal fun JBTable.stringWidth (text : String ): Int {
127+ val fontMetrics = this .getFontMetrics(this .font)
128+ return fontMetrics.stringWidth(text)
129+ }
130+
131+ internal fun JBTable.update (width : Int ) {
132+ val rowHeight = this .rowHeight
133+ val headerHeight = this .tableHeader.preferredSize.height
134+ val height = headerHeight + (rowCount * rowHeight)
135+
136+ val parentWidth = this .parent.width
137+ if (width < parentWidth) {
138+ this .autoResizeMode = AUTO_RESIZE_ALL_COLUMNS
139+ this .preferredHeight = height
140+ return
141+ }
142+
143+ this .autoResizeMode = AUTO_RESIZE_OFF
144+ this .preferredSize = Dimension (width, height)
145+ }
146+
114147internal fun Boolean.toOnOff (): String = if (this ) " on" else " off"
115148
149+ fun htmlToText (html : String ): String {
150+ val editorPane = JEditorPane ().apply {
151+ editorKit = HTMLEditorKit ()
152+ text = html
153+ }
154+ return editorPane.document.getText(0 , editorPane.document.length)
155+ }
156+
116157internal fun getHeaderText (include : String , isExcluded : Boolean , exclude : String , isCaseSensitive : Boolean ): String {
117158 if (include.trim().isEmpty()) return " "
118159 if (isExcluded && exclude.isEmpty() && isCaseSensitive) {
@@ -184,5 +225,9 @@ internal fun getInvalidString(): String {
184225}
185226
186227internal fun getHtmlError (value : String ): String {
187- return " <html><span style=\" color:red;\" >$value <span><html>"
228+ return " <span style=\" color:red;\" >$value <span>"
229+ }
230+
231+ internal fun getHtml (value : String ): String {
232+ return " <html>$value </html>"
188233}
0 commit comments