Builder4/Editor.bjs
[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 private static Xcls_Editor  _this;
21
22 public class Xcls_Editor
23 {
24     public Gtk.Window el;
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 string activeEditor;
32     public string active_path;
33     public bool dirty;
34     public bool pos;
35     public int pos_root_x;
36     public int pos_root_y;
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.activeEditor = "";
47         this.active_path = "";
48         this.dirty = false;
49         this.pos = false;
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.delete_event.connect( (event) => {
60             if (!Editor.RightEditor.save()) {
61                 // no hiding with errors.
62                 return true;
63             }
64             _this.el.hide();
65             _this.active_path = "";
66             return true;
67         } );
68         this.el.configure_event.connect(  (object) => {
69             _this.pos = true;
70             this.el.get_position(out _this.pos_root_x, out _this.pos_root_y);
71         
72         
73             return false;
74         } );
75         this.el.show.connect(  () => {
76             if (this.pos) {
77                 _this.el.move(this.pos_root_x,this.pos_root_y);
78             }
79         } );
80     }
81
82     // userdefined functions 
83
84     // skip listeners - not pipe 
85
86     // skip .activeEditor - already used 
87
88     // skip .active_path - already used 
89
90     // skip .dirty - already used 
91
92     // skip .pos - already used 
93
94     // skip .pos_root_x - already used 
95
96     // skip .pos_root_y - already used 
97
98     // skip height_request - already used 
99
100     // skip id - not pipe 
101
102     // skip title - already used 
103
104     // skip width_request - already used 
105
106     // skip xtype - not pipe 
107
108     // skip |init - already used 
109     public bool save()  {
110         
111             if (!Editor.RightEditor.save()) {
112                 // no hiding with errors.
113                 return true;
114             }
115             _this.active_path = "";
116             _this.el.hide();
117             return true;
118         
119         }
120
121     // skip |xns - could not find seperator
122
123     // skip items - not pipe 
124
125     // skip xvala_cls - not pipe 
126
127     // skip xvala_xcls - not pipe 
128
129     // skip xvala_id - not pipe 
130     public class Xcls_VBox2
131     {
132         public Gtk.VBox el;
133
134             // my vars
135
136             // ctor 
137         public Xcls_VBox2()
138         {
139             this.el = new Gtk.VBox();
140
141             // my vars
142
143             // set gobject values
144             this.el.homogeneous = "true";
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 - could not find seperator
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 - could not find seperator
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         // userdefined functions 
226
227         // skip listeners - not pipe 
228
229         // skip id - not pipe 
230
231         // skip label - already used 
232
233         // skip xtype - not pipe 
234
235         // skip |xns - could not find seperator
236
237         // skip xvala_cls - not pipe 
238
239         // skip xvala_xcls - not pipe 
240
241         // skip xvala_id - not pipe 
242     }
243     public class Xcls_RightEditor
244     {
245         public Gtk.ScrolledWindow el;
246
247             // my vars
248
249             // ctor 
250         public Xcls_RightEditor()
251         {
252             this.el = new Gtk.ScrolledWindow( null, null );
253             _this.RightEditor = this;
254
255             // my vars
256
257             // set gobject values
258             var child_0 = new Xcls_view();
259             this.el.add (  child_0.el  );
260         }
261
262         // userdefined functions 
263
264         // skip id - not pipe 
265
266         // skip pack - not pipe 
267
268         // skip xtype - not pipe 
269         public bool save() {
270                  print("editor.rightbutton.save");
271                  if (_this.active_path.length  < 1 ) {
272                       print("skip - no active path");
273                     return true;
274                  }
275                  
276                  var str = Editor.buffer.toString();
277                  
278                  if (!Editor.buffer.checkSyntax()) {
279                      print("check syntax failed");
280                      //this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
281                      return false;
282                  }
283                  
284                  // LeftPanel.model.changed(  str , false);
285                  _this.dirty = false;
286                  _this.save_button.el.sensitive = false;
287                  print("set save button grey");
288                  return true;
289             }
290
291         // skip |xns - could not find seperator
292
293         // skip items - not pipe 
294
295         // skip xvala_cls - not pipe 
296
297         // skip xvala_xcls - not pipe 
298
299         // skip xvala_id - not pipe 
300     }
301     public class Xcls_view
302     {
303         public Gtk.SourceView el;
304
305             // my vars
306
307             // ctor 
308         public Xcls_view()
309         {
310             this.el = new Gtk.SourceView();
311             _this.view = this;
312
313             // my vars
314
315             // set gobject values
316             this.el.auto_indent = true;
317             this.el.indent_width = 4;
318             this.el.insert_spaces_instead_of_tabs = true;
319             this.el.show_line_numbers = true;
320             var child_0 = new Xcls_buffer();
321             this.el.set_buffer (  child_0.el  );
322
323             // init method 
324                 var description =   Pango.FontDescription.from_string("monospace");
325                 description.set_size(8000);
326                 this.el.override_font(description);
327
328             // listeners 
329             this.el.key_release_event.connect( (event) => {
330                 
331                 if (event.key.keyval == 115 && (event.key.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
332                     print("SAVE: ctrl-S  pressed");
333                     this.save();
334                     return false;
335                 }
336                // print(event.key.keyval)
337                 
338                 return false;
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 |load - could not find seperator
362         public void save() {
363             
364                 Editor.RightEditor.save();
365             }
366
367         // skip |show_line_numbers - already used 
368
369         // skip |xns - could not find seperator
370
371         // skip items - not pipe 
372
373         // skip xvala_cls - not pipe 
374
375         // skip xvala_xcls - not pipe 
376
377         // skip xvala_id - not pipe 
378     }
379     public class Xcls_buffer
380     {
381         public Gtk.SourceBuffer el;
382
383             // my vars
384
385             // ctor 
386         public Xcls_buffer()
387         {
388             this.el = new Gtk.SourceBuffer( null );
389             _this.buffer = this;
390
391             // my vars
392
393             // set gobject values
394
395             // listeners 
396             this.el.changed.connect( () => {
397                 // check syntax??
398                     if(this.checkSyntax()) {
399                     Editor.save_button.el.sensitive = true;
400                 }
401                // print("EDITOR CHANGED");
402                 Editor.dirty = true;
403             
404                 // this.get('/LeftPanel.model').changed(  str , false);
405                 return ;
406             } );
407         }
408
409         // userdefined functions 
410
411         // skip listeners - not pipe 
412
413         // skip id - not pipe 
414
415         // skip pack - not pipe 
416
417         // skip xtype - not pipe 
418         public bool checkSyntax() { 
419                 // we could try running valac... ?? but it's a bit confusing..
420                 return true;
421             
422             }
423         public string toString() {
424                 
425                 Gtk.TextIter s;
426                 Gtk.TextIter e;
427                 this.el.get_start_iter(out s);
428                 this.el.get_end_iter(out e);
429                 var ret = this.el.get_text(s,e,true);
430                 //print("TO STRING? " + ret);
431                 return ret;
432             }
433
434         // skip |xns - could not find seperator
435
436         // skip xvala_cls - not pipe 
437
438         // skip xvala_xcls - not pipe 
439
440         // skip xvala_id - not pipe 
441     }
442 }