author | wenzelm |
Wed, 31 Jul 2013 21:13:05 +0200 | |
changeset 52816 | c608e0ade554 |
parent 52815 | eaad5fe7bb1b |
child 52974 | 908e8a36e975 |
permissions | -rw-r--r-- |
50208 | 1 |
/* Title: Tools/jEdit/src/isabelle.scala |
50183 | 2 |
Author: Makarius |
3 |
||
50208 | 4 |
Convenience operations for Isabelle/jEdit. |
50183 | 5 |
*/ |
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
50198
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
12 |
import org.gjt.sp.jedit.{jEdit, View, Buffer} |
50183 | 13 |
import org.gjt.sp.jedit.textarea.JEditTextArea |
50208 | 14 |
import org.gjt.sp.jedit.gui.DockableWindowManager |
50183 | 15 |
|
16 |
||
50208 | 17 |
object Isabelle |
50183 | 18 |
{ |
50208 | 19 |
/* dockable windows */ |
20 |
||
21 |
private def wm(view: View): DockableWindowManager = view.getDockableWindowManager |
|
22 |
||
50299 | 23 |
def docked_theories(view: View): Option[Theories_Dockable] = |
24 |
wm(view).getDockableWindow("isabelle-theories") match { |
|
25 |
case dockable: Theories_Dockable => Some(dockable) |
|
50208 | 26 |
case _ => None |
27 |
} |
|
28 |
||
51533 | 29 |
def docked_timing(view: View): Option[Timing_Dockable] = |
30 |
wm(view).getDockableWindow("isabelle-timing") match { |
|
31 |
case dockable: Timing_Dockable => Some(dockable) |
|
32 |
case _ => None |
|
33 |
} |
|
34 |
||
50208 | 35 |
def docked_output(view: View): Option[Output_Dockable] = |
36 |
wm(view).getDockableWindow("isabelle-output") match { |
|
37 |
case dockable: Output_Dockable => Some(dockable) |
|
38 |
case _ => None |
|
39 |
} |
|
40 |
||
41 |
def docked_raw_output(view: View): Option[Raw_Output_Dockable] = |
|
42 |
wm(view).getDockableWindow("isabelle-raw-output") match { |
|
43 |
case dockable: Raw_Output_Dockable => Some(dockable) |
|
44 |
case _ => None |
|
45 |
} |
|
46 |
||
47 |
def docked_protocol(view: View): Option[Protocol_Dockable] = |
|
48 |
wm(view).getDockableWindow("isabelle-protocol") match { |
|
49 |
case dockable: Protocol_Dockable => Some(dockable) |
|
50 |
case _ => None |
|
51 |
} |
|
52 |
||
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50341
diff
changeset
|
53 |
def docked_monitor(view: View): Option[Monitor_Dockable] = |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50341
diff
changeset
|
54 |
wm(view).getDockableWindow("isabelle-monitor") match { |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50341
diff
changeset
|
55 |
case dockable: Monitor_Dockable => Some(dockable) |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50341
diff
changeset
|
56 |
case _ => None |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50341
diff
changeset
|
57 |
} |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
50341
diff
changeset
|
58 |
|
50208 | 59 |
|
52815
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
60 |
/* continuous checking */ |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
61 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
62 |
private val CONTINUOUS_CHECKING = "editor_continuous_checking" |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
63 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
64 |
def continuous_checking: Boolean = PIDE.options.bool(CONTINUOUS_CHECKING) |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
65 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
66 |
def continuous_checking_=(b: Boolean) |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
67 |
{ |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
68 |
Swing_Thread.require() |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
69 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
70 |
if (continuous_checking != b) { |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
71 |
PIDE.options.bool(CONTINUOUS_CHECKING) = b |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
72 |
PIDE.options_changed() |
52816
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
73 |
PIDE.flush_buffers() |
52815
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
74 |
} |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
75 |
} |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
76 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
77 |
def set_continuous_checking() { continuous_checking = true } |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
78 |
def reset_continuous_checking() { continuous_checking = false } |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
79 |
def toggle_continuous_checking() { continuous_checking = !continuous_checking } |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
80 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
81 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
82 |
/* required document nodes */ |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
83 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
84 |
private def node_required_update(view: View, toggle: Boolean = false, set: Boolean = false) |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
85 |
{ |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
86 |
Swing_Thread.require() |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
87 |
PIDE.document_model(view.getBuffer) match { |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
88 |
case Some(model) => |
52816
c608e0ade554
home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents:
52815
diff
changeset
|
89 |
model.node_required = (if (toggle) !model.node_required else set) |
52815
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
90 |
case None => |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
91 |
} |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
92 |
} |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
93 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
94 |
def set_node_required(view: View) { node_required_update(view, set = true) } |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
95 |
def reset_node_required(view: View) { node_required_update(view, set = false) } |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
96 |
def toggle_node_required(view: View) { node_required_update(view, toggle = true) } |
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
97 |
|
eaad5fe7bb1b
actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents:
51533
diff
changeset
|
98 |
|
50198
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
99 |
/* font size */ |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
100 |
|
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
101 |
def change_font_size(view: View, change: Int => Int) |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
102 |
{ |
50775 | 103 |
val size = change(jEdit.getIntegerProperty("view.fontsize", 16)) max 5 min 250 |
50206 | 104 |
jEdit.setIntegerProperty("view.fontsize", size) |
50198
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
105 |
jEdit.propertiesChanged() |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
106 |
jEdit.saveSettings() |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
107 |
view.getStatus.setMessageAndClear("Text font size: " + size) |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
108 |
} |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
109 |
|
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
110 |
def increase_font_size(view: View): Unit = change_font_size(view, i => i + ((i / 10) max 1)) |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
111 |
def decrease_font_size(view: View): Unit = change_font_size(view, i => i - ((i / 10) max 1)) |
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
112 |
|
0c7b351a6871
added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents:
50187
diff
changeset
|
113 |
|
50341
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
114 |
/* structured insert */ |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
115 |
|
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
116 |
def insert_line_padding(text_area: JEditTextArea, text: String) |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
117 |
{ |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
118 |
val buffer = text_area.getBuffer |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
119 |
JEdit_Lib.buffer_edit(buffer) { |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
120 |
val text1 = |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
121 |
if (text_area.getSelectionCount == 0) { |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
122 |
def pad(range: Text.Range): String = |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
123 |
if (JEdit_Lib.try_get_text(buffer, range) == Some("\n")) "" else "\n" |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
124 |
|
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
125 |
val caret = JEdit_Lib.point_range(buffer, text_area.getCaretPosition) |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
126 |
val before_caret = JEdit_Lib.point_range(buffer, caret.start - 1) |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
127 |
pad(before_caret) + text + pad(caret) |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
128 |
} |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
129 |
else text |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
130 |
text_area.setSelectedText(text1) |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
131 |
} |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
132 |
} |
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
133 |
|
0c65a7cfc0f3
provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents:
50299
diff
changeset
|
134 |
|
50183 | 135 |
/* control styles */ |
136 |
||
137 |
def control_sub(text_area: JEditTextArea) |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
138 |
{ Token_Markup.edit_control_style(text_area, Symbol.sub_decoded) } |
50183 | 139 |
|
140 |
def control_sup(text_area: JEditTextArea) |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
141 |
{ Token_Markup.edit_control_style(text_area, Symbol.sup_decoded) } |
50183 | 142 |
|
143 |
def control_isub(text_area: JEditTextArea) |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
144 |
{ Token_Markup.edit_control_style(text_area, Symbol.isub_decoded) } |
50183 | 145 |
|
146 |
def control_isup(text_area: JEditTextArea) |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
147 |
{ Token_Markup.edit_control_style(text_area, Symbol.isup_decoded) } |
50183 | 148 |
|
149 |
def control_bold(text_area: JEditTextArea) |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
150 |
{ Token_Markup.edit_control_style(text_area, Symbol.bold_decoded) } |
50183 | 151 |
|
152 |
def control_reset(text_area: JEditTextArea) |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
153 |
{ Token_Markup.edit_control_style(text_area, "") } |
50183 | 154 |
|
155 |
||
156 |
/* block styles */ |
|
157 |
||
158 |
private def enclose_input(text_area: JEditTextArea, s1: String, s2: String) |
|
159 |
{ |
|
160 |
s1.foreach(text_area.userInput(_)) |
|
161 |
s2.foreach(text_area.userInput(_)) |
|
162 |
s2.foreach(_ => text_area.goToPrevCharacter(false)) |
|
163 |
} |
|
164 |
||
165 |
def input_bsub(text_area: JEditTextArea) |
|
166 |
{ enclose_input(text_area, Symbol.bsub_decoded, Symbol.esub_decoded) } |
|
167 |
||
168 |
def input_bsup(text_area: JEditTextArea) |
|
169 |
{ enclose_input(text_area, Symbol.bsup_decoded, Symbol.esup_decoded) } |
|
170 |
} |
|
171 |