1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// TLCockpit
// Copyright 2017-2018 Norbert Preining
// Licensed according to GPLv3+
//
// Front end for tlmgr
package TLCockpit
import TLCockpit.ApplicationMain.{stage, tlmgr, tlpkgs}
import TLCockpit.Utils._
import TeXLive.{OsTools, TLPackage}
import scalafx.Includes._
import scalafx.collections.ObservableBuffer
import scalafx.geometry.{HPos, Insets, Orientation}
import scalafx.scene.Cursor
import scalafx.scene.layout.{ColumnConstraints, GridPane, Priority, VBox}
import scalafx.scene.control._
import scalafx.scene.input.MouseEvent
import scalafx.scene.paint.Color
class PkgInfoDialog(tlp: TLPackage) extends Dialog {
val dialog = new Dialog() {
initOwner(stage)
title = s"Package Information for $pkg"
headerText = s"Package Information for $pkg"
resizable = true
}
dialog.dialogPane().buttonTypes = Seq(ButtonType.OK)
val isInstalled = tlp.installed
val grid = new GridPane() {
hgap = 10
vgap = 10
padding = Insets(20)
}
def copyableTextfield(k: String): TextField = {
new TextField() {
text = k
editable = false
style = "-fx-background-color: rgba(0, 0, 0, 0);"
margin = Insets(0)
padding = Insets(0)
}
}
def do_one(k: String, v: String, row: Int): Int = {
grid.add(copyableTextfield(k), 0, row)
grid.add(copyableTextfield(v), 1, row)
// grid.add(new Label(k), 0, row)
// grid.add(new Label(v) {
// wrapText = true
// }, 1, row)
row + 1
}
var crow = 0
val pkg = tlp.name
crow = do_one("package", pkg, crow)
crow = do_one("category", tlp.category, crow)
crow = do_one("shortdesc", tlp.shortdesc.getOrElse(""), crow)
crow = do_one("longdesc", tlp.longdesc.getOrElse(""), crow)
crow = do_one("installed", if (tlp.installed) "Yes" else "No", crow)
crow = do_one("available", if (tlp.available) "Yes" else "No", crow)
if (tlp.installed)
crow = do_one("local revision", tlp.lrev.toString, crow)
if (tlp.available)
crow = do_one("remote revision", tlp.rrev.toString, crow)
val binsizesum = tlp.binsize.values.toList.sum * TeXLive.tlBlockSize
val binsizestr = if (binsizesum > 0) "bin " + humanReadableByteSize(binsizesum) + " " else ""
val runsizestr = if (tlp.runsize > 0) "run " + humanReadableByteSize(tlp.runsize) + " " else ""
val srcsizestr = if (tlp.srcsize > 0) "src " + humanReadableByteSize(tlp.srcsize) + " " else ""
val docsizestr = if (tlp.docsize > 0) "doc " + humanReadableByteSize(tlp.docsize) + " " else ""
crow = do_one("sizes", runsizestr + docsizestr + binsizestr + srcsizestr, crow)
val catdata = tlp.cataloguedata
if (catdata.version.isDefined)
crow = do_one("cat-version", catdata.version.get, crow)
if (catdata.date.isDefined)
crow = do_one("cat-date", catdata.date.get, crow)
if (catdata.license.isDefined)
crow = do_one("cat-license", catdata.license.get, crow)
if (catdata.topics.isDefined)
crow = do_one("cat-topics", catdata.topics.get, crow)
if (catdata.related.isDefined)
crow = do_one("cat-related", catdata.related.get, crow)
// add files section
//println(tlpkgs(pkg))
val docFiles = tlp.docfiles
if (docFiles.nonEmpty) {
// grid.add(new Label("doc files"), 0, crow)
grid.add(copyableTextfield("doc files"), 0, crow)
grid.add(doListView(docFiles.map(s => s.file.replaceFirst("RELOC", "texmf-dist")), isInstalled), 1, crow)
crow += 1
}
val runFiles = tlp.runfiles
if (runFiles.nonEmpty) {
// grid.add(new Label("run files"), 0, crow)
grid.add(copyableTextfield("run files"), 0, crow)
grid.add(doListView(runFiles.map(s => s.replaceFirst("RELOC", "texmf-dist")), false), 1, crow)
crow += 1
}
val srcFiles = tlp.srcfiles
if (srcFiles.nonEmpty) {
// grid.add(new Label("src files"), 0, crow)
grid.add(copyableTextfield("src files"), 0, crow)
grid.add(doListView(srcFiles.map(s => s.replaceFirst("RELOC", "texmf-dist")), false), 1, crow)
crow += 1
}
val binFiles = tlp.binfiles
if (binFiles.nonEmpty) {
// grid.add(new Label("bin files"), 0, crow)
grid.add(copyableTextfield("bin files"), 0, crow)
grid.add(doListView(binFiles.flatMap(_._2).toSeq.map(s => s.replaceFirst("RELOC", "texmf-dist")), false), 1, crow)
crow += 1
}
grid.columnConstraints = Seq(new ColumnConstraints(100, 200, 200), new ColumnConstraints(100, 400, 5000, Priority.Always, HPos.LEFT, true))
dialog.dialogPane().content = grid
dialog.width = 600
// dialog.height = 1500
// dialog
def showAndWait(): Unit = this.dialog.showAndWait()
def doListView(files: Seq[String], clickable: Boolean): scalafx.scene.Node = {
if (files.length <= 5) {
val vb = new VBox()
vb.children = files.map { f =>
val fields = f.split(" ")
val foo = copyableTextfield(fields(0))
if (clickable) {
foo.style = foo.getStyle + "-fx-text-fill: blue;"
foo.onMouseClicked = { me: MouseEvent => OsTools.openFile(tlmgr.tlroot + "/" + fields(0)) }
foo.cursor = Cursor.Hand
}
foo
// new Label(fields(0)) {
// if (clickable) {
// textFill = Color.Blue
// onMouseClicked = { me: MouseEvent => OsTools.openFile(tlmgr.tlroot + "/" + fields(0)) }
// cursor = Cursor.Hand
// }
// }
}
vb
} else {
val vb = new ListView[String] {}
vb.minHeight = 100
vb.prefHeight = 100
vb.maxHeight = 200
vb.vgrow = Priority.Always
vb.orientation = Orientation.Vertical
vb.cellFactory = { p => {
val foo = new ListCell[String]
// ensure tighter spacing similar to the other entires
foo.padding = Insets(0)
foo.item.onChange { (_, _, str) => foo.text = str }
if (clickable) {
foo.textFill = Color.Blue
foo.onMouseClicked = { me: MouseEvent => OsTools.openFile(tlmgr.tlroot + "/" + foo.text.value) }
foo.cursor = Cursor.Hand
}
foo
}
}
// vb.children = docFiles.map { f =>
vb.items = ObservableBuffer(files.map { f =>
val fields = f.split(" ")
fields(0)
})
vb
}
}
}
|