author | wenzelm |
Wed, 31 Jul 2013 10:54:37 +0200 | |
changeset 52807 | b859a180936b |
parent 51534 | 123bd97fcea1 |
permissions | -rw-r--r-- |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/hyperlink.scala |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Munich |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
3 |
Author: Makarius |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
4 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
5 |
Hyperlinks within jEdit buffers for PIDE proof documents. |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
7 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.jedit |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
9 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
10 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
11 |
import isabelle._ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
12 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
13 |
import org.gjt.sp.jedit.{View, jEdit} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
14 |
import org.gjt.sp.jedit.textarea.JEditTextArea |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
15 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
16 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
17 |
object Hyperlink |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
18 |
{ |
51534 | 19 |
def apply(jedit_file: String, line: Int = 0, column: Int = 0): Hyperlink = |
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48921
diff
changeset
|
20 |
File_Link(jedit_file, line, column) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
21 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
22 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
23 |
abstract class Hyperlink |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
24 |
{ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
25 |
def follow(view: View): Unit |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
26 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
27 |
|
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48921
diff
changeset
|
28 |
private case class File_Link(jedit_file: String, line: Int, column: Int) extends Hyperlink |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
29 |
{ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
30 |
override def follow(view: View) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
31 |
{ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
32 |
Swing_Thread.require() |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
33 |
|
49406 | 34 |
JEdit_Lib.jedit_buffer(jedit_file) match { |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
35 |
case Some(buffer) => |
48925 | 36 |
view.goToBuffer(buffer) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
37 |
val text_area = view.getTextArea |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
38 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
39 |
try { |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
40 |
val line_start = text_area.getBuffer.getLineStartOffset(line - 1) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
41 |
text_area.moveCaretPosition(line_start) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
42 |
if (column > 0) text_area.moveCaretPosition(line_start + column - 1) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
43 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
44 |
catch { |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
45 |
case _: ArrayIndexOutOfBoundsException => |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
46 |
case _: IllegalArgumentException => |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
47 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
48 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
49 |
case None => |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
50 |
val args = |
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48921
diff
changeset
|
51 |
if (line <= 0) Array(jedit_file) |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48921
diff
changeset
|
52 |
else if (column <= 0) Array(jedit_file, "+line:" + line.toInt) |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48921
diff
changeset
|
53 |
else Array(jedit_file, "+line:" + line.toInt + "," + column.toInt) |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48921
diff
changeset
|
54 |
jEdit.openFiles(view, null, args) |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
55 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
56 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
57 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
diff
changeset
|
58 |