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