Test.GtkWriter.vala.c
[app.Builder.js] / Builder4 / Editor.vala
1 /* -- to compile
2 valac  --pkg gio-2.0  --pkg posix  --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0  --pkg  libwnck-3.0 \
3     /tmp/Editor.vala  -o /tmp/Editor
4 */
5
6
7 /* -- to test class
8 static int main (string[] args) {
9     Gtk.init (ref args);
10     new Xcls_Editor();
11     Editor.show_all();
12      Gtk.main ();
13     return 0;
14 }
15 */
16
17
18 public static Xcls_Editor  Editor;
19
20 public class Xcls_Editor
21 {
22     public Gtk.Window el;
23     private static Xcls_Editor  _this;
24
25     public Xcls_save_button save_button;
26     public Xcls_RightEditor RightEditor;
27     public Xcls_view view;
28     public Xcls_buffer buffer;
29
30         // my vars
31     public bool dirty;
32     public bool pos;
33     public int pos_root_x;
34     public int pos_root_y;
35     public string activeEditor;
36     public string active_path;
37
38         // ctor 
39     public Xcls_Editor()
40     {
41         this.el = new Gtk.Window();
42         _this = this;
43         Editor = this;
44
45         // my vars
46         this.dirty = false;
47         this.pos = false;
48         this.activeEditor = "";
49         this.active_path = "";
50
51         // set gobject values
52         this.el.height_request = 300;
53         this.el.title = "Application Builder -  Code  Editor";
54         this.el.width_request = 500;
55         var child_0 = new Xcls_VBox2();
56         this.el.add (  child_0.el  );
57
58         // listeners 
59         this.el.configure_event.connect(  (object) => {
60             _this.pos = true;
61             this.el.get_position(out _this.pos_root_x, out _this.pos_root_y);
62         
63         
64             return false;
65         }
66          
67          );
68         this.el.show.connect(   () => {
69             if (this.pos) {
70                 _this.el.move(this.pos_root_x,this.pos_root_y);
71             }
72         }
73           );
74     }
75
76     // userdefined functions 
77
78     // skip listeners - not pipe 
79
80     // skip .bool:dirty - already used 
81
82     // skip .bool:pos - already used 
83
84     // skip .int:pos_root_x - already used 
85
86     // skip .int:pos_root_y - already used 
87
88     // skip .string:activeEditor - already used 
89
90     // skip .string:active_path - already used 
91
92     // skip height_request - already used 
93
94     // skip id - not pipe 
95
96     // skip title - already used 
97
98     // skip width_request - already used 
99
100     // skip xtype - not pipe 
101     public bool save  ()  {
102         
103             if (!Editor.RightEditor.save()) {
104                 // no hiding with errors.
105                 return true;
106             }
107             _this.active_path = "";
108             _this.el.hide();
109             return true;
110         
111         } 
112
113     // skip |init - already used 
114
115     // skip |show_all - no return type
116     public void show_all  () {
117             this.el.show_all();
118         
119         }
120          
121
122     // skip |xns - no return type
123
124     // skip items - not pipe 
125
126     // skip xvala_cls - not pipe 
127
128     // skip xvala_xcls - not pipe 
129
130     // skip xvala_id - not pipe 
131     public class Xcls_VBox2
132     {
133         public Gtk.VBox el;
134
135             // my vars
136
137             // ctor 
138         public Xcls_VBox2()
139         {
140             this.el = new Gtk.VBox( true, 0 );
141
142             // my vars
143
144             // set gobject values
145             var child_0 = new Xcls_Toolbar3();
146             this.el.pack_start (  child_0.el , false,true );
147             var child_1 = new Xcls_RightEditor();
148             this.el.add (  child_1.el  );
149         }
150
151         // userdefined functions 
152
153         // skip |homogeneous - already used 
154
155         // skip pack - not pipe 
156
157         // skip xtype - not pipe 
158
159         // skip |xns - no return type
160
161         // skip items - not pipe 
162
163         // skip xvala_cls - not pipe 
164
165         // skip xvala_xcls - not pipe 
166
167         // skip xvala_id - not pipe 
168     }
169     public class Xcls_Toolbar3
170     {
171         public Gtk.Toolbar el;
172
173             // my vars
174
175             // ctor 
176         public Xcls_Toolbar3()
177         {
178             this.el = new Gtk.Toolbar();
179
180             // my vars
181
182             // set gobject values
183             var child_0 = new Xcls_save_button();
184             this.el.add (  child_0.el  );
185         }
186
187         // userdefined functions 
188
189         // skip pack - not pipe 
190
191         // skip xtype - not pipe 
192
193         // skip |xns - no return type
194
195         // skip items - not pipe 
196
197         // skip xvala_cls - not pipe 
198
199         // skip xvala_xcls - not pipe 
200
201         // skip xvala_id - not pipe 
202     }
203     public class Xcls_save_button
204     {
205         public Gtk.ToolButton el;
206
207             // my vars
208
209             // ctor 
210         public Xcls_save_button()
211         {
212             this.el = new Gtk.ToolButton( null, "Save" );
213             _this.save_button = this;
214
215             // my vars
216
217             // set gobject values
218
219             // listeners 
220             this.el.clicked.connect(  () => { 
221                 Editor.RightEditor.save();
222             }
223              
224              );
225         }
226
227         // userdefined functions 
228
229         // skip listeners - not pipe 
230
231         // skip id - not pipe 
232
233         // skip label - already used 
234
235         // skip xtype - not pipe 
236
237         // skip |xns - no return type
238
239         // skip xvala_cls - not pipe 
240
241         // skip xvala_xcls - not pipe 
242
243         // skip xvala_id - not pipe 
244     }
245     public class Xcls_RightEditor
246     {
247         public Gtk.ScrolledWindow el;
248
249             // my vars
250
251             // ctor 
252         public Xcls_RightEditor()
253         {
254             this.el = new Gtk.ScrolledWindow( null, null );
255             _this.RightEditor = this;
256
257             // my vars
258
259             // set gobject values
260             var child_0 = new Xcls_view();
261             this.el.add (  child_0.el  );
262         }
263
264         // userdefined functions 
265
266         // skip id - not pipe 
267
268         // skip pack - not pipe 
269
270         // skip xtype - not pipe 
271         public bool save  () {
272                  print("editor.rightbutton.save");
273                  if (_this.active_path.length  < 1 ) {
274                       print("skip - no active path");
275                     return true;
276                  }
277                  
278                  var str = Editor.buffer.toString();
279                  
280                  if (!Editor.buffer.checkSyntax()) {
281                      print("check syntax failed");
282                      //this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
283                      return false;
284                  }
285                  
286                  // LeftPanel.model.changed(  str , false);
287                  _this.dirty = false;
288                  _this.save_button.el.sensitive = false;
289                  print("set save button grey");
290                  return true;
291             }
292              
293
294         // skip |xns - no return type
295
296         // skip items - not pipe 
297
298         // skip xvala_cls - not pipe 
299
300         // skip xvala_xcls - not pipe 
301
302         // skip xvala_id - not pipe 
303     }
304     public class Xcls_view
305     {
306         public Gtk.SourceView el;
307
308             // my vars
309
310             // ctor 
311         public Xcls_view()
312         {
313             this.el = new Gtk.SourceView();
314             _this.view = this;
315
316             // my vars
317
318             // set gobject values
319             this.el.auto_indent = true;
320             this.el.indent_width = 4;
321             this.el.insert_spaces_instead_of_tabs = true;
322             this.el.show_line_numbers = true;
323             var child_0 = new Xcls_buffer();
324             this.el.set_buffer (  child_0.el  );
325
326             // listeners 
327             this.el.key_release_event.connect(  (event) => {
328                 
329                 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
330                     print("SAVE: ctrl-S  pressed");
331                     this.save();
332                     return false;
333                 }
334                // print(event.key.keyval)
335                 
336                 return false;
337             
338             } 
339             
340              );
341         }
342
343         // userdefined functions 
344
345         // skip listeners - not pipe 
346
347         // skip id - not pipe 
348
349         // skip indent_width - already used 
350
351         // skip pack - not pipe 
352
353         // skip xtype - not pipe 
354
355         // skip |auto_indent - already used 
356
357         // skip |init - already used 
358
359         // skip |insert_spaces_instead_of_tabs - already used 
360
361         // skip |show_line_numbers - already used 
362         public void load (string str) {
363             
364             // show the help page for the active node..
365                //this.get('/Help').show();
366             
367             
368               // this.get('/BottomPane').el.set_current_page(0);
369                 this.el.get_buffer().set_text(str, str.length);
370                 var lm = Gtk.SourceLanguageManager.get_default();
371                 
372                 ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language("js"));
373                 var buf = this.el.get_buffer();
374                 var cursor = buf.get_mark("insert");
375                 Gtk.TextIter iter;
376                 buf.get_iter_at_mark(out iter, cursor);
377                 iter.set_line(1);
378                 iter.set_line_offset(4);
379                 buf.move_mark(cursor, iter);
380                 
381                 
382                 cursor = buf.get_mark("selection_bound");
383                 //iter= new Gtk.TextIter;
384                 buf.get_iter_at_mark(out iter, cursor);
385                 iter.set_line(1);
386                 iter.set_line_offset(4);
387                 buf.move_mark(cursor, iter);
388                 Editor.dirty = false;
389                 this.el.grab_focus();
390                 _this.save_button.el.sensitive = false;
391             }
392         public void save () {
393             
394                 Editor.RightEditor.save();
395             }
396              
397
398         // skip |xns - no return type
399
400         // skip items - not pipe 
401
402         // skip xvala_cls - not pipe 
403
404         // skip xvala_xcls - not pipe 
405
406         // skip xvala_id - not pipe 
407     }
408     public class Xcls_buffer
409     {
410         public Gtk.SourceBuffer el;
411
412             // my vars
413
414             // ctor 
415         public Xcls_buffer()
416         {
417             this.el = new Gtk.SourceBuffer( null );
418             _this.buffer = this;
419
420             // my vars
421
422             // set gobject values
423
424             // listeners 
425             this.el.changed.connect(  () => {
426                 // check syntax??
427                     if(this.checkSyntax()) {
428                     Editor.save_button.el.sensitive = true;
429                 }
430                // print("EDITOR CHANGED");
431                 Editor.dirty = true;
432             
433                 // this.get('/LeftPanel.model').changed(  str , false);
434                 return ;
435             }
436             
437              
438              );
439         }
440
441         // userdefined functions 
442
443         // skip listeners - not pipe 
444
445         // skip id - not pipe 
446
447         // skip pack - not pipe 
448
449         // skip xtype - not pipe 
450         public bool checkSyntax () {
451              /*
452                 var str = this.toString();
453                 var res = "";
454                 /*
455                 try {
456                   //  print('var res = ' + str);
457                     Seed.check_syntax('var res = ' + str);
458                     
459                    
460                 } catch (e) {
461                     
462                     this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
463                         red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
464                        }));
465                     print("SYNTAX ERROR IN EDITOR");   
466                     print(e);
467                     // print(str);
468                     //console.dump(e);
469                     return false;
470                 }
471                  this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
472                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
473                    }));
474                 */
475                 return true;
476             }
477         public string toString  () {
478                 
479                 Gtk.TextIter s;
480                 Gtk.TextIter e;
481                 this.el.get_start_iter(out s);
482                 this.el.get_end_iter(out e);
483                 var ret = this.el.get_text(s,e,true);
484                 //print("TO STRING? " + ret);
485                 return ret;
486             }
487              
488
489         // skip |xns - no return type
490
491         // skip xvala_cls - not pipe 
492
493         // skip xvala_xcls - not pipe 
494
495         // skip xvala_id - not pipe 
496     }
497 }