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); }
221 // user defined functions
223 public class Xcls_view : Object
225 public Gtk.SourceView el;
226 private Editor _this;
232 public Xcls_view(Editor _owner )
236 this.el = new Gtk.SourceView();
240 // set gobject values
241 this.el.auto_indent = true;
242 this.el.indent_width = 4;
243 this.el.show_line_marks = true;
244 this.el.insert_spaces_instead_of_tabs = true;
245 this.el.show_line_numbers = true;
246 this.el.highlight_current_line = true;
247 var child_0 = new Xcls_buffer( _this );
249 this.el.set_buffer ( child_0.el );
253 var description = Pango.FontDescription.from_string("monospace");
254 description.set_size(8000);
255 this.el.override_font(description);
257 var attrs = new Gtk.SourceMarkAttributes();
258 var pink = new Gdk.RGBA();
259 pink.parse ( "pink");
260 attrs.set_background ( pink);
261 attrs.set_icon_name ( "process-stop");
262 attrs.query_tooltip_text.connect(( mark) => {
263 print("tooltip query? %s\n", mark.name);
267 this.el.set_mark_attributes ("error", attrs, 1);
269 this.el.key_release_event.connect( (event) => {
271 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
272 print("SAVE: ctrl-S pressed");
273 _this.saveContents();
276 // print(event.key.keyval)
283 // user defined functions
284 public void load (string str) {
286 // show the help page for the active node..
287 //this.get('/Help').show();
290 // this.get('/BottomPane').el.set_current_page(0);
291 this.el.get_buffer().set_text(str, str.length);
292 var lm = Gtk.SourceLanguageManager.get_default();
294 var lang = _this.file.language;
295 //?? is javascript going to work as js?
297 ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));
298 var buf = this.el.get_buffer();
300 /* -- what does all this do? */
302 var cursor = buf.get_mark("insert");
304 buf.get_iter_at_mark(out iter, cursor);
306 iter.set_line_offset(4);
307 buf.move_mark(cursor, iter);
310 cursor = buf.get_mark("selection_bound");
311 //iter= new Gtk.TextIter;
312 buf.get_iter_at_mark(out iter, cursor);
314 iter.set_line_offset(4);
315 buf.move_mark(cursor, iter);
320 this.el.grab_focus();
321 _this.save_button.el.sensitive = false;
324 public class Xcls_buffer : Object
326 public Gtk.SourceBuffer el;
327 private Editor _this;
331 public int error_line;
334 public Xcls_buffer(Editor _owner )
338 this.el = new Gtk.SourceBuffer( null );
341 this.error_line = -1;
343 // set gobject values
346 this.el.changed.connect( () => {
348 if(this.checkSyntax()) {
349 _this.save_button.el.sensitive = true;
351 // print("EDITOR CHANGED");
354 // this.get('/LeftPanel.model').changed( str , false);
359 // user defined functions
360 public string toString () {
364 this.el.get_start_iter(out s);
365 this.el.get_end_iter(out e);
366 var ret = this.el.get_text(s,e,true);
367 //print("TO STRING? " + ret);
370 public bool checkSyntax () {
372 var p = Palete.factory(_this.file.xtype);
374 var str = this.toString();
378 if (this.error_line > 0) {
381 this.el.get_bounds (out start, out end);
383 this.el.remove_source_marks (start, end, null);
387 var validate_res = p.validateCode(
396 this.error_line = validate_res.size;
398 if (this.error_line < 1) {
401 var tlines = this.el.get_line_count ();
403 var valiter = validate_res.map_iterator();
404 while (valiter.next()) {
406 // print("get inter\n");
407 var eline = valiter.get_key();
408 if (eline > tlines) {
411 this.el.get_iter_at_line( out iter, eline);
412 //print("mark line\n");
413 this.el.create_source_mark(valiter.get_value(), "error", iter);
416 //print("done mark line\n");
418 return true; // at present allow saving - even if it's invalid..