author | blanchet |
Thu, 20 Nov 2014 17:29:18 +0100 | |
changeset 59018 | ec8ea2465d2a |
parent 57920 | c1953856cfca |
child 59390 | 7cab7fdf6048 |
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} |
|
57920
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
13 |
import java.awt.event.{KeyEvent, KeyAdapter, 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 |
||
56422 | 25 |
private case class Documentation(name: String, title: String, path: Path) |
52445 | 26 |
{ |
57912 | 27 |
override def toString: String = |
52445 | 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 |
{ |
57912 | 33 |
override def toString: String = 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 { |
|
56423
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
38 |
case Doc.Section(text, _) => |
52445 | 39 |
root.add(new DefaultMutableTreeNode(text)) |
56422 | 40 |
case Doc.Doc(name, title, path) => |
52445 | 41 |
root.getLastChild.asInstanceOf[DefaultMutableTreeNode] |
56422 | 42 |
.add(new DefaultMutableTreeNode(Documentation(name, title, path))) |
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 |
|
57920
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
50 |
override def focusOnDefaultComponent { tree.requestFocusInWindow } |
54687
795f8d3e06c9
no keyboard control -- avoid confusion about meaning of selection;
wenzelm
parents:
54686
diff
changeset
|
51 |
|
52445 | 52 |
if (!OperatingSystem.isMacOSLF) |
53 |
tree.putClientProperty("JTree.lineStyle", "Angled") |
|
54 |
tree.getSelectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION) |
|
57920
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
55 |
|
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
56 |
private def action(node: DefaultMutableTreeNode) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
57 |
{ |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
58 |
node.getUserObject match { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
59 |
case Text_File(_, path) => |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
60 |
PIDE.editor.goto_file(view, Isabelle_System.platform_path(path)) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
61 |
case Documentation(_, _, path) => |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
62 |
if (path.is_file) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
63 |
PIDE.editor.goto_file(view, Isabelle_System.platform_path(path)) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
64 |
else { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
65 |
Future.fork { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
66 |
try { Doc.view(path) } |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
67 |
catch { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
68 |
case exn: Throwable => |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
69 |
GUI.error_dialog(view, |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
70 |
"Documentation error", GUI.scrollable_text(Exn.message(exn))) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
71 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
72 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
73 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
74 |
case _ => |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
75 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
76 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
77 |
|
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
78 |
tree.addKeyListener(new KeyAdapter { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
79 |
override def keyPressed(e: KeyEvent) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
80 |
{ |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
81 |
if (e.getKeyCode == KeyEvent.VK_ENTER) { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
82 |
e.consume |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
83 |
val path = tree.getSelectionPath |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
84 |
if (path != null) { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
85 |
path.getLastPathComponent match { |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
86 |
case node: DefaultMutableTreeNode => action(node) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
87 |
case _ => |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
88 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
89 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
90 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
91 |
} |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
92 |
}) |
54686
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
93 |
tree.addMouseListener(new MouseAdapter { |
57920
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
94 |
override def mouseClicked(e: MouseEvent) |
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
95 |
{ |
54686
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
96 |
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
|
97 |
if (click != null && e.getClickCount == 1) { |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
98 |
(click.getLastPathComponent, tree.getLastSelectedPathComponent) match { |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
99 |
case (node: DefaultMutableTreeNode, node1: DefaultMutableTreeNode) if node == node1 => |
57920
c1953856cfca
clarified focus and key handling -- more like SideKick;
wenzelm
parents:
57912
diff
changeset
|
100 |
action(node) |
52445 | 101 |
case _ => |
102 |
} |
|
103 |
} |
|
54686
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
104 |
} |
070d5e856798
directly react on click, assuming that document view operation is mostly idempotent;
wenzelm
parents:
53177
diff
changeset
|
105 |
}) |
56423
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
106 |
|
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
107 |
{ |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
108 |
var expand = true |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
109 |
var visible = 0 |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
110 |
def make_visible(row: Int) { visible += 1; tree.expandRow(row) } |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
111 |
for ((entry, row) <- docs.zipWithIndex) { |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
112 |
entry match { |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
113 |
case Doc.Section(_, important) => |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
114 |
expand = important |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
115 |
make_visible(row) |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
116 |
case _ => |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
117 |
if (expand) make_visible(row) |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
118 |
} |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
119 |
} |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
120 |
tree.setRootVisible(false) |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
121 |
tree.setVisibleRowCount(visible) |
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
wenzelm
parents:
56422
diff
changeset
|
122 |
} |
52445 | 123 |
|
124 |
private val tree_view = new JScrollPane(tree) |
|
125 |
tree_view.setMinimumSize(new Dimension(100, 50)) |
|
126 |
||
127 |
set_content(tree_view) |
|
128 |
} |