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 - 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.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             var child_0 = new Xcls_Toolbar3();
145             this.el.pack_start (  child_0.el , false,true );
146             var child_1 = new Xcls_RightEditor();
147             this.el.add (  child_1.el  );
148         }
149
150         // userdefined functions 
151
152         // skip pack - not pipe 
153
154         // skip xtype - not pipe 
155
156         // skip |xns - could not find seperator
157
158         // skip items - not pipe 
159
160         // skip xvala_cls - not pipe 
161
162         // skip xvala_xcls - not pipe 
163
164         // skip xvala_id - not pipe 
165     }
166     public class Xcls_Toolbar3
167     {
168         public Gtk.Toolbar el;
169
170             // my vars
171
172             // ctor 
173         public Xcls_Toolbar3()
174         {
175             this.el = new Gtk.Toolbar();
176
177             // my vars
178
179             // set gobject values
180             var child_0 = new Xcls_save_button();
181             this.el.add (  child_0.el  );
182         }
183
184         // userdefined functions 
185
186         // skip pack - not pipe 
187
188         // skip xtype - not pipe 
189
190         // skip |xns - could not find seperator
191
192         // skip items - not pipe 
193
194         // skip xvala_cls - not pipe 
195
196         // skip xvala_xcls - not pipe 
197
198         // skip xvala_id - not pipe 
199     }
200     public class Xcls_save_button
201     {
202         public Gtk.ToolButton el;
203
204             // my vars
205
206             // ctor 
207         public Xcls_save_button()
208         {
209             this.el = new Gtk.ToolButton();
210             _this.save_button = this;
211
212             // my vars
213
214             // set gobject values
215             this.el.label = "Save";
216
217             // listeners 
218             this.el.clicked.connect( () => { 
219                 Editor.RightEditor.save();
220             } );
221         }
222
223         // userdefined functions 
224
225         // skip listeners - not pipe 
226
227         // skip id - not pipe 
228
229         // skip label - already used 
230
231         // skip xtype - not pipe 
232
233         // skip |xns - could not find seperator
234
235         // skip xvala_cls - not pipe 
236
237         // skip xvala_xcls - not pipe 
238
239         // skip xvala_id - not pipe 
240     }
241     public class Xcls_RightEditor
242     {
243         public Gtk.ScrolledWindow el;
244
245             // my vars
246
247             // ctor 
248         public Xcls_RightEditor()
249         {
250             this.el = new Gtk.ScrolledWindow();
251             _this.RightEditor = this;
252
253             // my vars
254
255             // set gobject values
256             var child_0 = new Xcls_view();
257             this.el.add (  child_0.el  );
258         }
259
260         // userdefined functions 
261
262         // skip id - not pipe 
263
264         // skip pack - not pipe 
265
266         // skip xtype - not pipe 
267         public bool save() {
268                  print("editor.rightbutton.save");
269                  if (_this.active_path.length  < 1 ) {
270                       print("skip - no active path");
271                     return true;
272                  }
273                  
274                  var str = Editor.buffer.toString();
275                  
276                  if (!Editor.buffer.checkSyntax()) {
277                      print("check syntax failed");
278                      //this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
279                      return false;
280                  }
281                  
282                  // LeftPanel.model.changed(  str , false);
283                  _this.dirty = false;
284                  _this.save_button.sensitive = false;
285                  print("set save button grey");
286                  return true;
287             }
288
289         // skip |xns - could not find seperator
290
291         // skip items - not pipe 
292
293         // skip xvala_cls - not pipe 
294
295         // skip xvala_xcls - not pipe 
296
297         // skip xvala_id - not pipe 
298     }
299     public class Xcls_view
300     {
301         public Gtk.SourceView el;
302
303             // my vars
304
305             // ctor 
306         public Xcls_view()
307         {
308             this.el = new Gtk.SourceView();
309             _this.view = this;
310
311             // my vars
312
313             // set gobject values
314             this.el.auto_indent = true;
315             this.el.indent_width = 4;
316             this.el.insert_spaces_instead_of_tabs = true;
317             this.el.show_line_numbers = true;
318             var child_0 = new Xcls_buffer();
319             this.el.set_buffer (  child_0.el  );
320
321             // init method 
322                 var description =   Pango.FontDescription.from_string("monospace");
323                 description.set_size(8000);
324                 this.override_font(description);
325
326             // listeners 
327             this.el.key_release_event.connect( (event) => {
328                 
329                 if (event.key.keyval == 115 && (event.key.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         // userdefined functions 
342
343         // skip listeners - not pipe 
344
345         // skip id - not pipe 
346
347         // skip indent_width - already used 
348
349         // skip pack - not pipe 
350
351         // skip xtype - not pipe 
352
353         // skip |auto_indent - already used 
354
355         // skip |init - already used 
356
357         // skip |insert_spaces_instead_of_tabs - already used 
358
359         // skip |load - could not find seperator
360         public void save() {
361             
362                 Editor.RightEditor.save();
363             }
364
365         // skip |show_line_numbers - already used 
366
367         // skip |xns - could not find seperator
368
369         // skip items - not pipe 
370
371         // skip xvala_cls - not pipe 
372
373         // skip xvala_xcls - not pipe 
374
375         // skip xvala_id - not pipe 
376     }
377     public class Xcls_buffer
378     {
379         public Gtk.SourceBuffer el;
380
381             // my vars
382
383             // ctor 
384         public Xcls_buffer()
385         {
386             this.el = new Gtk.SourceBuffer();
387             _this.buffer = this;
388
389             // my vars
390
391             // set gobject values
392
393             // listeners 
394             this.el.changed.connect( () => {
395                 // check syntax??
396                     if(this.checkSyntax()) {
397                     Editor.save_button.sensitive = true;
398                 }
399                // print("EDITOR CHANGED");
400                 Editor.dirty = true;
401             
402                 // this.get('/LeftPanel.model').changed(  str , false);
403                 return ;
404             } );
405         }
406
407         // userdefined functions 
408
409         // skip listeners - not pipe 
410
411         // skip id - not pipe 
412
413         // skip pack - not pipe 
414
415         // skip xtype - not pipe 
416         public bool checkSyntax() { 
417                 // we could try running valac... ?? but it's a bit confusing..
418                 return true;
419             
420             }
421         public string toString() {
422                 
423                 Gtk.TextIter s;
424                 Gtk.TextIter e;
425                 this.get_start_iter(out s);
426                 this.get_end_iter(out e);
427                 var ret = this.get_text(s,e,true);
428                 //print("TO STRING? " + ret);
429                 return ret;
430             }
431
432         // skip |xns - could not find seperator
433
434         // skip xvala_cls - not pipe 
435
436         // skip xvala_xcls - not pipe 
437
438         // skip xvala_id - not pipe 
439     }
440 }