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             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( null, "Save" );
210             _this.save_button = this;
211
212             // my vars
213
214             // set gobject values
215
216             // listeners 
217             this.el.clicked.connect( () => { 
218                 Editor.RightEditor.save();
219             } );
220         }
221
222         // userdefined functions 
223
224         // skip listeners - not pipe 
225
226         // skip id - not pipe 
227
228         // skip label - already used 
229
230         // skip xtype - not pipe 
231
232         // skip |xns - could not find seperator
233
234         // skip xvala_cls - not pipe 
235
236         // skip xvala_xcls - not pipe 
237
238         // skip xvala_id - not pipe 
239     }
240     public class Xcls_RightEditor
241     {
242         public Gtk.ScrolledWindow el;
243
244             // my vars
245
246             // ctor 
247         public Xcls_RightEditor()
248         {
249             this.el = new Gtk.ScrolledWindow( null, null );
250             _this.RightEditor = this;
251
252             // my vars
253
254             // set gobject values
255             var child_0 = new Xcls_view();
256             this.el.add (  child_0.el  );
257         }
258
259         // userdefined functions 
260
261         // skip id - not pipe 
262
263         // skip pack - not pipe 
264
265         // skip xtype - not pipe 
266         public bool save() {
267                  print("editor.rightbutton.save");
268                  if (_this.active_path.length  < 1 ) {
269                       print("skip - no active path");
270                     return true;
271                  }
272                  
273                  var str = Editor.buffer.toString();
274                  
275                  if (!Editor.buffer.checkSyntax()) {
276                      print("check syntax failed");
277                      //this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
278                      return false;
279                  }
280                  
281                  // LeftPanel.model.changed(  str , false);
282                  _this.dirty = false;
283                  _this.save_button.el.sensitive = false;
284                  print("set save button grey");
285                  return true;
286             }
287
288         // skip |xns - could not find seperator
289
290         // skip items - not pipe 
291
292         // skip xvala_cls - not pipe 
293
294         // skip xvala_xcls - not pipe 
295
296         // skip xvala_id - not pipe 
297     }
298     public class Xcls_view
299     {
300         public Gtk.SourceView el;
301
302             // my vars
303
304             // ctor 
305         public Xcls_view()
306         {
307             this.el = new Gtk.SourceView();
308             _this.view = this;
309
310             // my vars
311
312             // set gobject values
313             this.el.auto_indent = true;
314             this.el.indent_width = 4;
315             this.el.insert_spaces_instead_of_tabs = true;
316             this.el.show_line_numbers = true;
317             var child_0 = new Xcls_buffer();
318             this.el.set_buffer (  child_0.el  );
319
320             // init method 
321                 var description =   Pango.FontDescription.from_string("monospace");
322                 description.set_size(8000);
323                 this.el.override_font(description);
324
325             // listeners 
326             this.el.key_release_event.connect( (event) => {
327                 
328                 if (event.key.keyval == 115 && (event.key.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
329                     print("SAVE: ctrl-S  pressed");
330                     this.save();
331                     return false;
332                 }
333                // print(event.key.keyval)
334                 
335                 return false;
336             
337             } );
338         }
339
340         // userdefined functions 
341
342         // skip listeners - not pipe 
343
344         // skip id - not pipe 
345
346         // skip indent_width - already used 
347
348         // skip pack - not pipe 
349
350         // skip xtype - not pipe 
351
352         // skip |auto_indent - already used 
353
354         // skip |init - already used 
355
356         // skip |insert_spaces_instead_of_tabs - already used 
357
358         // skip |load - could not find seperator
359         public void save() {
360             
361                 Editor.RightEditor.save();
362             }
363
364         // skip |show_line_numbers - already used 
365
366         // skip |xns - could not find seperator
367
368         // skip items - not pipe 
369
370         // skip xvala_cls - not pipe 
371
372         // skip xvala_xcls - not pipe 
373
374         // skip xvala_id - not pipe 
375     }
376     public class Xcls_buffer
377     {
378         public Gtk.SourceBuffer el;
379
380             // my vars
381
382             // ctor 
383         public Xcls_buffer()
384         {
385             this.el = new Gtk.SourceBuffer( null );
386             _this.buffer = this;
387
388             // my vars
389
390             // set gobject values
391
392             // listeners 
393             this.el.changed.connect( () => {
394                 // check syntax??
395                     if(this.checkSyntax()) {
396                     Editor.save_button.sensitive = true;
397                 }
398                // print("EDITOR CHANGED");
399                 Editor.dirty = true;
400             
401                 // this.get('/LeftPanel.model').changed(  str , false);
402                 return ;
403             } );
404         }
405
406         // userdefined functions 
407
408         // skip listeners - not pipe 
409
410         // skip id - not pipe 
411
412         // skip pack - not pipe 
413
414         // skip xtype - not pipe 
415         public bool checkSyntax() { 
416                 // we could try running valac... ?? but it's a bit confusing..
417                 return true;
418             
419             }
420         public string toString() {
421                 
422                 Gtk.TextIter s;
423                 Gtk.TextIter e;
424                 this.el.get_start_iter(out s);
425                 this.el.get_end_iter(out e);
426                 var ret = this.el.get_text(s,e,true);
427                 //print("TO STRING? " + ret);
428                 return ret;
429             }
430
431         // skip |xns - could not find seperator
432
433         // skip xvala_cls - not pipe 
434
435         // skip xvala_xcls - not pipe 
436
437         // skip xvala_id - not pipe 
438     }
439 }