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 string activeEditor;
23 public int pos_root_x;
24 public int pos_root_y;
27 public JsRender.JsRender file;
30 public signal void save ();
31 public JsRender.Node node;
37 this.el = new Gtk.VBox( false, 0 );
40 this.activeEditor = "";
49 var child_0 = new Xcls_HBox2( _this );
51 this.el.pack_start ( child_0.el , false,true );
52 var child_1 = new Xcls_RightEditor( _this );
54 this.el.add ( child_1.el );
57 // user defined functions
58 public bool saveContents () {
68 var str = _this.buffer.toString();
70 if (!_this.buffer.checkSyntax()) {
71 print("check syntax failed");
72 //this.get('/StandardErrorDialog').show("Fix errors in code and save..");
76 // LeftPanel.model.changed( str , false);
78 _this.save_button.el.sensitive = false;
83 // find the text for the node..
84 if (ptype == "listener") {
85 this.node.listeners.set(key,str);
88 this.node.props.set(key,str);
99 public void show (JsRender.JsRender file, JsRender.Node node, string ptype, string key)
107 // find the text for the node..
108 if (ptype == "listener") {
109 val = node.listeners.get(key);
112 val = node.props.get(key);
115 this.key_edit.el.text = key;
118 public class Xcls_HBox2 : Object
121 private Editor _this;
127 public Xcls_HBox2(Editor _owner )
130 this.el = new Gtk.HBox( false, 0 );
134 // set gobject values
135 var child_0 = new Xcls_save_button( _this );
137 this.el.pack_start ( child_0.el , false,false );
138 var child_1 = new Xcls_key_edit( _this );
140 this.el.pack_end ( child_1.el , true,true );
143 // user defined functions
145 public class Xcls_save_button : Object
147 public Gtk.Button el;
148 private Editor _this;
154 public Xcls_save_button(Editor _owner )
157 _this.save_button = this;
158 this.el = new Gtk.Button();
162 // set gobject values
163 this.el.label = "Save";
166 this.el.clicked.connect( () => {
167 _this.saveContents();
171 // user defined functions
173 public class Xcls_key_edit : Object
176 private Editor _this;
182 public Xcls_key_edit(Editor _owner )
185 _this.key_edit = this;
186 this.el = new Gtk.Entry();
190 // set gobject values
193 // user defined functions
195 public class Xcls_RightEditor : Object
197 public Gtk.ScrolledWindow el;
198 private Editor _this;
204 public Xcls_RightEditor(Editor _owner )
207 _this.RightEditor = this;
208 this.el = new Gtk.ScrolledWindow( null, null );
212 // set gobject values
213 var child_0 = new Xcls_view( _this );
215 this.el.add ( child_0.el );
219 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
222 // user defined functions
224 public class Xcls_view : Object
226 public Gtk.SourceView el;
227 private Editor _this;
233 public Xcls_view(Editor _owner )
237 this.el = new Gtk.SourceView();
241 // set gobject values
242 this.el.auto_indent = true;
243 this.el.indent_width = 4;
244 this.el.show_line_marks = true;
245 this.el.insert_spaces_instead_of_tabs = true;
246 this.el.show_line_numbers = true;
247 this.el.highlight_current_line = true;
248 var child_0 = new Xcls_buffer( _this );
250 this.el.set_buffer ( child_0.el );
254 var description = Pango.FontDescription.from_string("monospace");
255 description.set_size(8000);
256 this.el.override_font(description);
258 var attrs = new Gtk.SourceMarkAttributes();
259 var pink = new Gdk.RGBA();
260 pink.parse ( "pink");
261 attrs.set_background ( pink);
262 attrs.set_icon_name ( "process-stop");
263 attrs.query_tooltip_text.connect(( mark) => {
264 print("tooltip query? %s\n", mark.name);
268 this.el.set_mark_attributes ("error", attrs, 1);
271 this.el.key_release_event.connect( (event) => {
273 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
274 print("SAVE: ctrl-S pressed");
275 _this.saveContents();
278 // print(event.key.keyval)
285 // user defined functions
286 public void load (string str) {
288 // show the help page for the active node..
289 //this.get('/Help').show();
292 // this.get('/BottomPane').el.set_current_page(0);
293 this.el.get_buffer().set_text(str, str.length);
294 var lm = Gtk.SourceLanguageManager.get_default();
296 var lang = _this.file.language;
297 //?? is javascript going to work as js?
299 ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));
300 var buf = this.el.get_buffer();
302 /* -- what does all this do? */
304 var cursor = buf.get_mark("insert");
306 buf.get_iter_at_mark(out iter, cursor);
308 iter.set_line_offset(4);
309 buf.move_mark(cursor, iter);
312 cursor = buf.get_mark("selection_bound");
313 //iter= new Gtk.TextIter;
314 buf.get_iter_at_mark(out iter, cursor);
316 iter.set_line_offset(4);
317 buf.move_mark(cursor, iter);
322 this.el.grab_focus();
323 _this.save_button.el.sensitive = false;
326 public class Xcls_buffer : Object
328 public Gtk.SourceBuffer el;
329 private Editor _this;
333 public int error_line;
336 public Xcls_buffer(Editor _owner )
340 this.el = new Gtk.SourceBuffer( null );
343 this.error_line = -1;
345 // set gobject values
348 this.el.changed.connect( () => {
350 if(this.checkSyntax()) {
351 _this.save_button.el.sensitive = true;
353 // print("EDITOR CHANGED");
356 // this.get('/LeftPanel.model').changed( str , false);
361 // user defined functions
362 public string toString () {
366 this.el.get_start_iter(out s);
367 this.el.get_end_iter(out e);
368 var ret = this.el.get_text(s,e,true);
369 //print("TO STRING? " + ret);
372 public bool checkSyntax () {
374 var p = Palete.factory(_this.file.xtype);
376 var str = this.toString();
380 if (this.error_line > 0) {
383 this.el.get_bounds (out start, out end);
385 this.el.remove_source_marks (start, end, null);
389 var validate_res = p.validateCode(
398 this.error_line = validate_res.size;
400 if (this.error_line < 1) {
403 var tlines = this.el.get_line_count ();
405 var valiter = validate_res.map_iterator();
406 while (valiter.next()) {
408 // print("get inter\n");
409 var eline = valiter.get_key();
410 if (eline > tlines) {
413 this.el.get_iter_at_line( out iter, eline);
414 //print("mark line\n");
415 this.el.create_source_mark(valiter.get_value(), "error", iter);
418 //print("done mark line\n");
420 return true; // at present allow saving - even if it's invalid..