author | wenzelm |
Mon, 03 Mar 2014 10:59:33 +0100 | |
changeset 55877 | 65c9968286d5 |
parent 54687 | 795f8d3e06c9 |
child 56422 | 7490555d7dff |
permissions | -rw-r--r-- |
52445 | 1 |
/* Title: Tools/jEdit/src/documentation_dockable.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Dockable window for Isabelle documentation. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
import java.awt.{Dimension, GridLayout} |
|
54686
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
13 |
import java.awt.event.{MouseEvent, MouseAdapter} |
54687
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
14 |
import javax.swing.{JTree, JScrollPane, JComponent} |
52445 | 15 |
import javax.swing.tree.{DefaultMutableTreeNode, TreeSelectionModel} |
16 |
import javax.swing.event.{TreeSelectionEvent, TreeSelectionListener} |
|
17 |
||
18 |
import org.gjt.sp.jedit.{View, OperatingSystem} |
|
19 |
||
20 |
||
21 |
class Documentation_Dockable(view: View, position: String) extends Dockable(view, position) |
|
22 |
{ |
|
23 |
private val docs = Doc.contents() |
|
24 |
||
25 |
private case class Documentation(name: String, title: String) |
|
26 |
{ |
|
27 |
override def toString = |
|
28 |
"<html><b>" + HTML.encode(name) + "</b>: " + HTML.encode(title) + "</html>" |
|
29 |
} |
|
30 |
||
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
31 |
private case class Text_File(name: String, path: Path) |
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52447
diff
changeset
|
32 |
{ |
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
33 |
override def toString = name |
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52447
diff
changeset
|
34 |
} |
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52447
diff
changeset
|
35 |
|
52445 | 36 |
private val root = new DefaultMutableTreeNode |
37 |
docs foreach { |
|
38 |
case Doc.Section(text) => |
|
39 |
root.add(new DefaultMutableTreeNode(text)) |
|
40 |
case Doc.Doc(name, title) => |
|
41 |
root.getLastChild.asInstanceOf[DefaultMutableTreeNode] |
|
42 |
.add(new DefaultMutableTreeNode(Documentation(name, title))) |
|
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
43 |
case Doc.Text_File(name: String, path: Path) => |
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52447
diff
changeset
|
44 |
root.getLastChild.asInstanceOf[DefaultMutableTreeNode] |
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
45 |
.add(new DefaultMutableTreeNode(Text_File(name, path.expand))) |
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52447
diff
changeset
|
46 |
} |
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52447
diff
changeset
|
47 |
|
52445 | 48 |
private val tree = new JTree(root) |
54687
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
49 |
|
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
50 |
for (cond <- |
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
51 |
List(JComponent.WHEN_FOCUSED, |
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
52 |
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, |
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
53 |
JComponent.WHEN_IN_FOCUSED_WINDOW)) tree.setInputMap(cond, null) |
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
54 |
|
52445 | 55 |
if (!OperatingSystem.isMacOSLF) |
56 |
tree.putClientProperty("JTree.lineStyle", "Angled") |
|
57 |
tree.getSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION) |
|
54686
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
58 |
tree.addMouseListener(new MouseAdapter { |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
59 |
override def mouseClicked(e: MouseEvent) { |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
60 |
val click = tree.getPathForLocation(e.getX, e.getY) |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
61 |
if (click != null && e.getClickCount == 1) { |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
62 |
(click.getLastPathComponent, tree.getLastSelectedPathComponent) match { |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
63 |
case (node: DefaultMutableTreeNode, node1: DefaultMutableTreeNode) if node == node1 => |
52445 | 64 |
node.getUserObject match { |
52447
9a74000426e2
more robust Doc.view invocation: avoid executing process on GUI thread, but show errors as dialog;
wenzelm
parents:
52445
diff
changeset
|
65 |
case Documentation(name, _) => |
9a74000426e2
more robust Doc.view invocation: avoid executing process on GUI thread, but show errors as dialog;
wenzelm
parents:
52445
diff
changeset
|
66 |
default_thread_pool.submit(() => |
9a74000426e2
more robust Doc.view invocation: avoid executing process on GUI thread, but show errors as dialog;
wenzelm
parents:
52445
diff
changeset
|
67 |
try { Doc.view(name) } |
52543
6f5678b97c4e
eliminated pointless catch of unlikely exceptions, which may occur in Doc.contents already;
wenzelm
parents:
52542
diff
changeset
|
68 |
catch { |
6f5678b97c4e
eliminated pointless catch of unlikely exceptions, which may occur in Doc.contents already;
wenzelm
parents:
52542
diff
changeset
|
69 |
case exn: Throwable => |
6f5678b97c4e
eliminated pointless catch of unlikely exceptions, which may occur in Doc.contents already;
wenzelm
parents:
52542
diff
changeset
|
70 |
GUI.error_dialog(view, |
6f5678b97c4e
eliminated pointless catch of unlikely exceptions, which may occur in Doc.contents already;
wenzelm
parents:
52542
diff
changeset
|
71 |
"Documentation error", GUI.scrollable_text(Exn.message(exn))) |
6f5678b97c4e
eliminated pointless catch of unlikely exceptions, which may occur in Doc.contents already;
wenzelm
parents:
52542
diff
changeset
|
72 |
}) |
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
73 |
case Text_File(_, path) => |
55877 | 74 |
PIDE.editor.goto_file(view, Isabelle_System.platform_path(path)) |
52445 | 75 |
case _ => |
76 |
} |
|
77 |
case _ => |
|
78 |
} |
|
79 |
} |
|
54686
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
80 |
} |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
81 |
}) |
52445 | 82 |
tree.setRootVisible(false) |
83 |
tree.setVisibleRowCount(docs.length) |
|
84 |
(0 until docs.length).foreach(tree.expandRow) |
|
85 |
||
86 |
private val tree_view = new JScrollPane(tree) |
|
87 |
tree_view.setMinimumSize(new Dimension(100, 50)) |
|
88 |
||
89 |
set_content(tree_view) |
|
90 |
} |