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;
29 public JsRender.JsRender file;
32 public signal void save ();
33 public JsRender.Node node;
39 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
43 this.activeEditor = "";
53 this.el.homogeneous = false;
54 var child_0 = new Xcls_Box2( _this );
56 this.el.pack_start ( child_0.el , false,true );
57 var child_1 = new Xcls_RightEditor( _this );
59 this.el.pack_end ( child_1.el , true,true );
62 // user defined functions
63 public bool saveContents () {
66 if (_this.file == null) {
75 var str = _this.buffer.toString();
77 _this.buffer.checkSyntax();
81 // LeftPanel.model.changed( str , false);
83 _this.save_button.el.sensitive = false;
85 // find the text for the node..
86 if (_this.file.xtype != "PlainFile") {
87 if (ptype == "listener") {
88 this.node.listeners.set(key,str);
91 this.node.props.set(key,str);
94 _this.file.setSource( str );
103 public void show (JsRender.JsRender file, JsRender.Node node, string ptype, string key)
111 if (file.xtype != "PlainFile") {
117 // find the text for the node..
118 if (ptype == "listener") {
119 val = node.listeners.get(key);
122 val = node.props.get(key);
128 this.view.load( file.toSource() );
131 this.key_edit.el.text = key;
136 public class Xcls_Box2 : Object
139 private Editor _this;
145 public Xcls_Box2(Editor _owner )
148 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
152 // set gobject values
153 this.el.homogeneous = false;
154 var child_0 = new Xcls_save_button( _this );
156 this.el.pack_start ( child_0.el , false,false );
157 var child_1 = new Xcls_key_edit( _this );
159 this.el.pack_end ( child_1.el , true,true );
162 // user defined functions
164 public class Xcls_save_button : Object
166 public Gtk.Button el;
167 private Editor _this;
173 public Xcls_save_button(Editor _owner )
176 _this.save_button = this;
177 this.el = new Gtk.Button();
181 // set gobject values
182 this.el.label = "Save";
185 this.el.clicked.connect( () => {
186 _this.saveContents();
190 // user defined functions
193 public class Xcls_key_edit : Object
196 private Editor _this;
202 public Xcls_key_edit(Editor _owner )
205 _this.key_edit = this;
206 this.el = new Gtk.Entry();
210 // set gobject values
213 // user defined functions
217 public class Xcls_RightEditor : Object
219 public Gtk.ScrolledWindow el;
220 private Editor _this;
226 public Xcls_RightEditor(Editor _owner )
229 _this.RightEditor = this;
230 this.el = new Gtk.ScrolledWindow( null, null );
234 // set gobject values
235 var child_0 = new Xcls_view( _this );
237 this.el.add ( child_0.el );
241 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
244 // user defined functions
246 public class Xcls_view : Object
248 public Gtk.SourceView el;
249 private Editor _this;
255 public Xcls_view(Editor _owner )
259 this.el = new Gtk.SourceView();
263 // set gobject values
264 this.el.auto_indent = true;
265 this.el.indent_width = 4;
266 this.el.show_line_marks = true;
267 this.el.insert_spaces_instead_of_tabs = true;
268 this.el.show_line_numbers = true;
269 this.el.highlight_current_line = true;
270 var child_0 = new Xcls_buffer( _this );
272 this.el.set_buffer ( child_0.el );
276 var description = Pango.FontDescription.from_string("monospace");
277 description.set_size(8000);
278 this.el.override_font(description);
282 var attrs = new Gtk.SourceMarkAttributes();
283 var pink = Gdk.RGBA();
284 pink.parse ( "pink");
285 attrs.set_background ( pink);
286 attrs.set_icon_name ( "process-stop");
287 attrs.query_tooltip_text.connect(( mark) => {
288 //print("tooltip query? %s\n", mark.name);
292 this.el.set_mark_attributes ("ERR", attrs, 1);
294 var wattrs = new Gtk.SourceMarkAttributes();
295 var blue = Gdk.RGBA();
296 blue.parse ( "#ABF4EB");
297 wattrs.set_background ( blue);
298 wattrs.set_icon_name ( "process-stop");
299 wattrs.query_tooltip_text.connect(( mark) => {
300 //print("tooltip query? %s\n", mark.name);
304 this.el.set_mark_attributes ("WARN", wattrs, 1);
308 var dattrs = new Gtk.SourceMarkAttributes();
309 var purple = Gdk.RGBA();
310 purple.parse ( "#EEA9FF");
311 dattrs.set_background ( purple);
312 dattrs.set_icon_name ( "process-stop");
313 dattrs.query_tooltip_text.connect(( mark) => {
314 //print("tooltip query? %s\n", mark.name);
318 this.el.set_mark_attributes ("DEPR", dattrs, 1);
321 this.el.key_release_event.connect( (event) => {
323 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
324 print("SAVE: ctrl-S pressed");
325 _this.saveContents();
328 // print(event.key.keyval)
335 // user defined functions
336 public void load (string str) {
338 // show the help page for the active node..
339 //this.get('/Help').show();
342 // this.get('/BottomPane').el.set_current_page(0);
343 var buf = (Gtk.SourceBuffer)this.el.get_buffer();
344 buf.set_text(str, str.length);
345 buf.set_undo_manager(null);
347 var lm = Gtk.SourceLanguageManager.get_default();
349 if (_this.file != null) {
350 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) {
405 this.error_line = validate_res.size;
407 if (this.error_line < 1) {
410 var tlines = this.el.get_line_count ();
412 var valiter = validate_res.map_iterator();
413 while (valiter.next()) {
415 // print("get inter\n");
416 var eline = valiter.get_key();
417 if (eline > tlines) {
420 this.el.get_iter_at_line( out iter, eline);
421 //print("mark line\n");
422 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
426 public string toString () {
430 this.el.get_start_iter(out s);
431 this.el.get_end_iter(out e);
432 var ret = this.el.get_text(s,e,true);
433 //print("TO STRING? " + ret);
436 public bool checkSyntax () {
438 if (this.check_running) {
439 print("Check is running\n");
440 if (this.check_queued) {
441 print("Check is already queued");
444 this.check_queued = true;
445 print("Adding queued Check ");
446 GLib.Timeout.add_seconds(1, () => {
447 this.check_queued = false;
456 var str = this.toString();
459 if (this.error_line > 0) {
462 this.el.get_bounds (out start, out end);
464 this.el.remove_source_marks (start, end, null);
466 if (str.length < 1) {
467 print("checkSyntax - empty string?\n");
471 if (_this.file == null && _this.fname.length > 0) {
473 // assume it's gtk...
474 this.check_running = true;
476 _this.window.windowstate.valasource.checkPlainFileSpawn(
477 _this.window.project,
484 if (_this.file == null) {
487 var p = Palete.factory(_this.file.xtype);
491 this.check_running = true;
494 if (_this.file.language == "js") {
495 this.check_running = false;
496 print("calling validate javascript\n");
497 return this.highlightErrors(p.validateJavascript(
508 print("calling validate vala\n");
509 // clear the buttons.
513 _this.window.windowstate,
525 //print("done mark line\n");
527 return true; // at present allow saving - even if it's invalid..
529 public bool highlightErrorsJson (string type, Json.Object obj) {
532 this.el.get_bounds (out start, out end);
534 this.el.remove_source_marks (start, end, type);
537 // we should highlight other types of errors..
539 if (!obj.has_member(type)) {
540 print("Return has no errors\n");
544 if (_this.window.windowstate.state != WindowState.State.CODEONLY &&
545 _this.window.windowstate.state != WindowState.State.CODE
551 var err = obj.get_object_member(type);
552 var valafn = _this.fname;
553 if (_this.file != null) {
560 var regex = new Regex("\\.bjs$");
563 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
564 } catch (GLib.RegexError e) {
571 if (!err.has_member(valafn)) {
572 print("File path has no errors\n");
576 var lines = err.get_object_member(valafn);
579 if (obj.has_member("line_offset")) {
580 offset = (int)obj.get_int_member("line_offset") + 1;
586 var tlines = this.el.get_line_count () +1;
588 lines.foreach_member((obj, line, node) => {
591 // print("get inter\n");
592 var eline = int.parse(line) - offset;
593 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
596 if (eline > tlines || eline < 0) {
599 this.el.get_iter_at_line( out iter, eline);
600 //print("mark line\n");
601 var msg = "Line: %d".printf(eline+1);
602 var ar = lines.get_array_member(line);
603 for (var i = 0 ; i < ar.get_length(); i++) {
604 msg += (msg.length > 0) ? "\n" : "";
605 msg += ar.get_string_element(i);
609 this.el.create_source_mark(msg, type, iter);