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 this.el.expand = true;
53 var child_0 = new Xcls_Box2( _this );
55 this.el.pack_start ( child_0.el , false,true );
56 var child_1 = new Xcls_RightEditor( _this );
58 this.el.pack_end ( child_1.el , true,true );
61 // user defined functions
62 public bool saveContents () {
72 var str = _this.buffer.toString();
77 if (!_this.buffer.checkSyntax()) {
78 print("check syntax failed");
79 //this.get('/StandardErrorDialog').show("Fix errors in code and save..");
83 // LeftPanel.model.changed( str , false);
85 _this.save_button.el.sensitive = false;
90 // find the text for the node..
91 if (ptype == "listener") {
92 this.node.listeners.set(key,str);
95 this.node.props.set(key,str);
106 public void showPlainFile (string fname)
113 GLib.FileUtils.get_contents(fname, out str);
116 this.key_edit.el.text = "";
119 public void show (JsRender.JsRender file, JsRender.Node node, string ptype, string key)
127 // find the text for the node..
128 if (ptype == "listener") {
129 val = node.listeners.get(key);
132 val = node.props.get(key);
135 this.key_edit.el.text = key;
138 public class Xcls_Box2 : Object
141 private Editor _this;
147 public Xcls_Box2(Editor _owner )
150 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
154 // set gobject values
155 this.el.homogeneous = false;
156 var child_0 = new Xcls_save_button( _this );
158 this.el.pack_start ( child_0.el , false,false );
159 var child_1 = new Xcls_key_edit( _this );
161 this.el.pack_end ( child_1.el , true,true );
164 // user defined functions
166 public class Xcls_save_button : Object
168 public Gtk.Button el;
169 private Editor _this;
175 public Xcls_save_button(Editor _owner )
178 _this.save_button = this;
179 this.el = new Gtk.Button();
183 // set gobject values
184 this.el.label = "Save";
187 this.el.clicked.connect( () => {
188 _this.saveContents();
192 // user defined functions
195 public class Xcls_key_edit : Object
198 private Editor _this;
204 public Xcls_key_edit(Editor _owner )
207 _this.key_edit = this;
208 this.el = new Gtk.Entry();
212 // set gobject values
215 // user defined functions
219 public class Xcls_RightEditor : Object
221 public Gtk.ScrolledWindow el;
222 private Editor _this;
228 public Xcls_RightEditor(Editor _owner )
231 _this.RightEditor = this;
232 this.el = new Gtk.ScrolledWindow( null, null );
236 // set gobject values
237 var child_0 = new Xcls_view( _this );
239 this.el.add ( child_0.el );
243 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
246 // user defined functions
248 public class Xcls_view : Object
250 public Gtk.SourceView el;
251 private Editor _this;
257 public Xcls_view(Editor _owner )
261 this.el = new Gtk.SourceView();
265 // set gobject values
266 this.el.auto_indent = true;
267 this.el.indent_width = 4;
268 this.el.show_line_marks = true;
269 this.el.insert_spaces_instead_of_tabs = true;
270 this.el.show_line_numbers = true;
271 this.el.highlight_current_line = true;
272 var child_0 = new Xcls_buffer( _this );
274 this.el.set_buffer ( child_0.el );
278 var description = Pango.FontDescription.from_string("monospace");
279 description.set_size(8000);
280 this.el.override_font(description);
284 var attrs = new Gtk.SourceMarkAttributes();
285 var pink = Gdk.RGBA();
286 pink.parse ( "pink");
287 attrs.set_background ( pink);
288 attrs.set_icon_name ( "process-stop");
289 attrs.query_tooltip_text.connect(( mark) => {
290 //print("tooltip query? %s\n", mark.name);
294 this.el.set_mark_attributes ("ERR", attrs, 1);
296 var wattrs = new Gtk.SourceMarkAttributes();
297 var blue = Gdk.RGBA();
298 blue.parse ( "#ABF4EB");
299 wattrs.set_background ( blue);
300 wattrs.set_icon_name ( "process-stop");
301 wattrs.query_tooltip_text.connect(( mark) => {
302 //print("tooltip query? %s\n", mark.name);
306 this.el.set_mark_attributes ("WARN", wattrs, 1);
310 var dattrs = new Gtk.SourceMarkAttributes();
311 var purple = Gdk.RGBA();
312 purple.parse ( "#EEA9FF");
313 dattrs.set_background ( purple);
314 dattrs.set_icon_name ( "process-stop");
315 dattrs.query_tooltip_text.connect(( mark) => {
316 //print("tooltip query? %s\n", mark.name);
320 this.el.set_mark_attributes ("DEPR", dattrs, 1);
323 this.el.key_release_event.connect( (event) => {
325 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
326 print("SAVE: ctrl-S pressed");
327 _this.saveContents();
330 // print(event.key.keyval)
337 // user defined functions
338 public void load (string str) {
340 // show the help page for the active node..
341 //this.get('/Help').show();
344 // this.get('/BottomPane').el.set_current_page(0);
345 var buf = (Gtk.SourceBuffer)this.el.get_buffer();
346 buf.set_text(str, str.length);
347 buf.set_undo_manager(null);
349 var lm = Gtk.SourceLanguageManager.get_default();
351 var lang = _this.file.language;
352 //?? is javascript going to work as js?
354 ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));
358 this.el.grab_focus();
359 _this.save_button.el.sensitive = false;
362 public class Xcls_buffer : Object
364 public Gtk.SourceBuffer el;
365 private Editor _this;
369 public bool check_queued;
370 public int error_line;
371 public bool check_running;
374 public Xcls_buffer(Editor _owner )
378 this.el = new Gtk.SourceBuffer( null );
381 this.check_queued = false;
382 this.error_line = -1;
383 this.check_running = false;
385 // set gobject values
388 this.el.changed.connect( () => {
391 _this.save_button.el.sensitive = true;
392 print("EDITOR CHANGED");
397 // this.get('/LeftPanel.model').changed( str , false);
402 // user defined functions
403 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
404 this.error_line = validate_res.size;
406 if (this.error_line < 1) {
409 var tlines = this.el.get_line_count ();
411 var valiter = validate_res.map_iterator();
412 while (valiter.next()) {
414 // print("get inter\n");
415 var eline = valiter.get_key();
416 if (eline > tlines) {
419 this.el.get_iter_at_line( out iter, eline);
420 //print("mark line\n");
421 this.el.create_source_mark(valiter.get_value(), "error", iter);
425 public string toString () {
429 this.el.get_start_iter(out s);
430 this.el.get_end_iter(out e);
431 var ret = this.el.get_text(s,e,true);
432 //print("TO STRING? " + ret);
435 public bool checkSyntax () {
437 if (this.check_running) {
438 print("Check is running\n");
439 if (this.check_queued) {
440 print("Check is already queued");
443 this.check_queued = true;
444 print("Adding queued Check ");
445 GLib.Timeout.add_seconds(1, () => {
446 this.check_queued = false;
457 var p = Palete.factory(_this.file.xtype);
459 var str = this.toString();
462 if (this.error_line > 0) {
465 this.el.get_bounds (out start, out end);
467 this.el.remove_source_marks (start, end, null);
470 if (str.length < 1) {
471 print("checkSyntax - empty string?\n");
474 this.check_running = true;
477 if (_this.file.language == "js") {
478 this.check_running = false;
479 print("calling validate javascript\n");
480 return this.highlightErrors(p.validateJavascript(
491 print("calling validate vala\n");
492 // clear the buttons.
496 _this.window.windowstate,
508 //print("done mark line\n");
510 return true; // at present allow saving - even if it's invalid..
512 public bool highlightErrorsJson (string type, Json.Object obj) {
515 this.el.get_bounds (out start, out end);
517 this.el.remove_source_marks (start, end, type);
520 // we should highlight other types of errors..
522 if (!obj.has_member(type)) {
523 print("Return has no errors\n");
527 if (_this.window.windowstate.state != WindowState.State.CODEONLY &&
528 _this.window.windowstate.state != WindowState.State.CODE
533 if (_this.file == null) {
537 var err = obj.get_object_member(type);
542 var regex = new Regex("\\.bjs$");
545 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
546 } catch (GLib.RegexError e) {
550 if (!err.has_member(valafn)) {
551 print("File path has no errors\n");
555 var lines = err.get_object_member(valafn);
558 if (obj.has_member("line_offset")) {
559 offset = (int)obj.get_int_member("line_offset") + 1;
563 var tlines = this.el.get_line_count () +1;
565 lines.foreach_member((obj, line, node) => {
568 // print("get inter\n");
569 var eline = int.parse(line) - offset;
570 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
573 if (eline > tlines || eline < 0) {
576 this.el.get_iter_at_line( out iter, eline);
577 //print("mark line\n");
578 var msg = "Line: %d".printf(eline+1);
579 var ar = lines.get_array_member(line);
580 for (var i = 0 ; i < ar.get_length(); i++) {
581 msg += (msg.length > 0) ? "\n" : "";
582 msg += ar.get_string_element(i);
586 this.el.create_source_mark(msg, type, iter);