3 public class Editor : Object
8 public static Editor singleton()
10 if (_Editor == null) {
11 _Editor= new Editor();
15 public Xcls_save_button save_button;
16 public Xcls_key_edit key_edit;
17 public Xcls_RightEditor RightEditor;
18 public Xcls_view view;
19 public Xcls_buffer buffer;
22 public Xcls_MainWindow window;
23 public string activeEditor;
24 public int pos_root_x;
25 public int pos_root_y;
28 public JsRender.JsRender file;
31 public signal void save ();
32 public JsRender.Node node;
38 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
42 this.activeEditor = "";
51 this.el.homogeneous = false;
52 var child_0 = new Xcls_Box2( _this );
54 this.el.pack_start ( child_0.el , false,true );
55 var child_1 = new Xcls_RightEditor( _this );
57 this.el.pack_end ( child_1.el , true,true );
60 // user defined functions
61 public bool saveContents () {
71 var str = _this.buffer.toString();
76 if (!_this.buffer.checkSyntax()) {
77 print("check syntax failed");
78 //this.get('/StandardErrorDialog').show("Fix errors in code and save..");
82 // LeftPanel.model.changed( str , false);
84 _this.save_button.el.sensitive = false;
89 // find the text for the node..
90 if (ptype == "listener") {
91 this.node.listeners.set(key,str);
94 this.node.props.set(key,str);
105 public void show (JsRender.JsRender file, JsRender.Node node, string ptype, string key)
113 // find the text for the node..
114 if (ptype == "listener") {
115 val = node.listeners.get(key);
118 val = node.props.get(key);
121 this.key_edit.el.text = key;
124 public class Xcls_Box2 : Object
127 private Editor _this;
133 public Xcls_Box2(Editor _owner )
136 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
140 // set gobject values
141 this.el.homogeneous = false;
142 var child_0 = new Xcls_save_button( _this );
144 this.el.pack_start ( child_0.el , false,false );
145 var child_1 = new Xcls_key_edit( _this );
147 this.el.pack_end ( child_1.el , true,true );
150 // user defined functions
152 public class Xcls_save_button : Object
154 public Gtk.Button el;
155 private Editor _this;
161 public Xcls_save_button(Editor _owner )
164 _this.save_button = this;
165 this.el = new Gtk.Button();
169 // set gobject values
170 this.el.label = "Save";
173 this.el.clicked.connect( () => {
174 _this.saveContents();
178 // user defined functions
181 public class Xcls_key_edit : Object
184 private Editor _this;
190 public Xcls_key_edit(Editor _owner )
193 _this.key_edit = this;
194 this.el = new Gtk.Entry();
198 // set gobject values
201 // user defined functions
205 public class Xcls_RightEditor : Object
207 public Gtk.ScrolledWindow el;
208 private Editor _this;
214 public Xcls_RightEditor(Editor _owner )
217 _this.RightEditor = this;
218 this.el = new Gtk.ScrolledWindow( null, null );
222 // set gobject values
223 var child_0 = new Xcls_view( _this );
225 this.el.add ( child_0.el );
229 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
232 // user defined functions
234 public class Xcls_view : Object
236 public Gtk.SourceView el;
237 private Editor _this;
243 public Xcls_view(Editor _owner )
247 this.el = new Gtk.SourceView();
251 // set gobject values
252 this.el.auto_indent = true;
253 this.el.indent_width = 4;
254 this.el.show_line_marks = true;
255 this.el.insert_spaces_instead_of_tabs = true;
256 this.el.show_line_numbers = true;
257 this.el.highlight_current_line = true;
258 var child_0 = new Xcls_buffer( _this );
260 this.el.set_buffer ( child_0.el );
264 var description = Pango.FontDescription.from_string("monospace");
265 description.set_size(8000);
266 this.el.override_font(description);
270 var attrs = new Gtk.SourceMarkAttributes();
271 var pink = Gdk.RGBA();
272 pink.parse ( "pink");
273 attrs.set_background ( pink);
274 attrs.set_icon_name ( "process-stop");
275 attrs.query_tooltip_text.connect(( mark) => {
276 //print("tooltip query? %s\n", mark.name);
280 this.el.set_mark_attributes ("ERR", attrs, 1);
282 var wattrs = new Gtk.SourceMarkAttributes();
283 var blue = Gdk.RGBA();
284 blue.parse ( "#ABF4EB");
285 wattrs.set_background ( blue);
286 wattrs.set_icon_name ( "process-stop");
287 wattrs.query_tooltip_text.connect(( mark) => {
288 //print("tooltip query? %s\n", mark.name);
292 this.el.set_mark_attributes ("WARN", wattrs, 1);
296 var dattrs = new Gtk.SourceMarkAttributes();
297 var purple = Gdk.RGBA();
298 purple.parse ( "#EEA9FF");
299 dattrs.set_background ( purple);
300 dattrs.set_icon_name ( "process-stop");
301 dattrs.query_tooltip_text.connect(( mark) => {
302 //print("tooltip query? %s\n", mark.name);
306 this.el.set_mark_attributes ("DEPR", dattrs, 1);
309 this.el.key_release_event.connect( (event) => {
311 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
312 print("SAVE: ctrl-S pressed");
313 _this.saveContents();
316 // print(event.key.keyval)
323 // user defined functions
324 public void load (string str) {
326 // show the help page for the active node..
327 //this.get('/Help').show();
330 // this.get('/BottomPane').el.set_current_page(0);
331 var buf = (Gtk.SourceBuffer)this.el.get_buffer();
332 buf.set_text(str, str.length);
333 buf.set_undo_manager(null);
335 var lm = Gtk.SourceLanguageManager.get_default();
337 var lang = _this.file.language;
338 //?? is javascript going to work as js?
340 ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));
344 this.el.grab_focus();
345 _this.save_button.el.sensitive = false;
348 public class Xcls_buffer : Object
350 public Gtk.SourceBuffer el;
351 private Editor _this;
355 public bool check_queued;
356 public int error_line;
357 public bool check_running;
360 public Xcls_buffer(Editor _owner )
364 this.el = new Gtk.SourceBuffer( null );
367 this.check_queued = false;
368 this.error_line = -1;
369 this.check_running = false;
371 // set gobject values
374 this.el.changed.connect( () => {
377 _this.save_button.el.sensitive = true;
378 print("EDITOR CHANGED");
383 // this.get('/LeftPanel.model').changed( str , false);
388 // user defined functions
389 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
390 this.error_line = validate_res.size;
392 if (this.error_line < 1) {
395 var tlines = this.el.get_line_count ();
397 var valiter = validate_res.map_iterator();
398 while (valiter.next()) {
400 // print("get inter\n");
401 var eline = valiter.get_key();
402 if (eline > tlines) {
405 this.el.get_iter_at_line( out iter, eline);
406 //print("mark line\n");
407 this.el.create_source_mark(valiter.get_value(), "error", iter);
411 public string toString () {
415 this.el.get_start_iter(out s);
416 this.el.get_end_iter(out e);
417 var ret = this.el.get_text(s,e,true);
418 //print("TO STRING? " + ret);
421 public bool checkSyntax () {
423 if (this.check_running) {
424 print("Check is running\n");
425 if (this.check_queued) {
426 print("Check is already queued");
429 this.check_queued = true;
430 print("Adding queued Check ");
431 GLib.Timeout.add_seconds(1, () => {
432 this.check_queued = false;
443 var p = Palete.factory(_this.file.xtype);
445 var str = this.toString();
448 if (this.error_line > 0) {
451 this.el.get_bounds (out start, out end);
453 this.el.remove_source_marks (start, end, null);
456 if (str.length < 1) {
457 print("checkSyntax - empty string?\n");
460 this.check_running = true;
463 if (_this.file.language == "js") {
464 this.check_running = false;
465 print("calling validate javascript\n");
466 return this.highlightErrors(p.validateJavascript(
477 print("calling validate vala\n");
478 // clear the buttons.
482 _this.window.windowstate,
494 //print("done mark line\n");
496 return true; // at present allow saving - even if it's invalid..
498 public bool highlightErrorsJson (string type, Json.Object obj) {
501 this.el.get_bounds (out start, out end);
503 this.el.remove_source_marks (start, end, type);
506 // we should highlight other types of errors..
508 if (!obj.has_member(type)) {
509 print("Return has no errors\n");
512 if (_this.file == null) {
516 var err = obj.get_object_member(type);
521 var regex = new Regex("\\.bjs$");
524 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
525 } catch (GLib.RegexError e) {
529 if (!err.has_member(valafn)) {
530 print("File path has no errors\n");
534 var lines = err.get_object_member(valafn);
537 if (obj.has_member("line_offset")) {
538 offset = (int)obj.get_int_member("line_offset") + 1;
542 var tlines = this.el.get_line_count () +1;
544 lines.foreach_member((obj, line, node) => {
547 // print("get inter\n");
548 var eline = int.parse(line) - offset;
549 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
552 if (eline > tlines || eline < 0) {
555 this.el.get_iter_at_line( out iter, eline);
556 //print("mark line\n");
557 var msg = "Line: %d".printf(eline+1);
558 var ar = lines.get_array_member(line);
559 for (var i = 0 ; i < ar.get_length(); i++) {
560 msg += (msg.length > 0) ? "\n" : "";
561 msg += ar.get_string_element(i);
565 this.el.create_source_mark(msg, type, iter);