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/test.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 : Gtk.Window
23 {
24     public Xcls_save_button save_button;
25     public Xcls_RightEditor RightEditor;
26     public Xcls_view view;
27     public Xcls_buffer buffer;
28
29         // my vars
30     public string active_path;
31     public string activeEditor;
32     public bool dirty;
33     public bool pos;
34     public int pos_root_x;
35     public int pos_root_y;
36
37         // ctor 
38     public Xcls_Editor()
39     {
40         _this = this;
41         Editor = this;
42
43         // my vars
44         this.active_path = "";
45         this.activeEditor = "";
46         this.dirty = false;
47         this.pos = false;
48
49         // set gobject values
50         this.height_request = 300;
51         this.title = "Application Builder - Editor";
52         this.width_request = 500;
53         this.add (  new Xcls_VBox2() );
54
55         // listeners 
56         this.delete_event.connect( (event) => {
57             if (!Editor.RightEditor.save()) {
58                 // no hiding with errors.
59                 return true;
60             }
61             _this.hide();
62             _this.active_path = "";
63             return true;
64         } );
65         this.configure_event.connect(  (object) => {
66             _this.pos = true;
67             this.get_position(out _this.pos_root_x, out _this.pos_root_y);
68         
69         
70             return false;
71         } );
72         this.show.connect(  () => {
73             if (this.pos) {
74                 _this.set_uposition(this.pos_root_x,this.pos_root_y);
75             }
76         } );
77     }
78
79     // userdefined functions 
80     public bool save()  {
81         
82             if (!Editor.RightEditor.save()) {
83                 // no hiding with errors.
84                 return true;
85             }
86             _this.active_path = "";
87             _this.hide();
88             return true;
89         
90         }
91     public class Xcls_VBox2 : Gtk.VBox
92     {
93
94             // my vars
95
96             // ctor 
97         public Xcls_VBox2()
98         {
99
100             // my vars
101
102             // set gobject values
103             this.pack_start (  new Xcls_Toolbar3(), false,true );
104             this.add (  new Xcls_RightEditor() );
105         }
106
107         // userdefined functions 
108     }
109     public class Xcls_Toolbar3 : Gtk.Toolbar
110     {
111
112             // my vars
113
114             // ctor 
115         public Xcls_Toolbar3()
116         {
117
118             // my vars
119
120             // set gobject values
121             this.add (  new Xcls_save_button() );
122         }
123
124         // userdefined functions 
125     }
126     public class Xcls_save_button : Gtk.ToolButton
127     {
128
129             // my vars
130
131             // ctor 
132         public Xcls_save_button()
133         {
134             _this.save_button = this;
135
136             // my vars
137
138             // set gobject values
139             this.label = "Save";
140
141             // listeners 
142             this.clicked.connect( () => { 
143                 Editor.RightEditor.save();
144             } );
145         }
146
147         // userdefined functions 
148     }
149     public class Xcls_RightEditor : Gtk.ScrolledWindow
150     {
151
152             // my vars
153
154             // ctor 
155         public Xcls_RightEditor()
156         {
157             _this.RightEditor = this;
158
159             // my vars
160
161             // set gobject values
162             this.add (  new Xcls_view() );
163         }
164
165         // userdefined functions 
166         public bool save() {
167             
168                  if (_this.active_path.length  < 1 ) {
169                     return true;
170                  }
171                  
172                  var str = Editor.buffer.toString();
173                  
174                  if (!Editor.buffer.checkSyntax()) {
175                      print("check syntax failed");
176                      //this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
177                      return false;
178                  }
179                  
180                  // LeftPanel.model.changed(  str , false);
181                  _this.dirty = false;
182                  _this.save_button.sensitive = false;
183                  return true;
184             }
185     }
186     public class Xcls_view : Gtk.SourceView
187     {
188
189             // my vars
190
191             // ctor 
192         public Xcls_view()
193         {
194             _this.view = this;
195
196             // my vars
197
198             // set gobject values
199             this.auto_indent = true;
200             this.indent_width = 4;
201             this.insert_spaces_instead_of_tabs = true;
202             this.show_line_numbers = true;
203             this.set_buffer (  new Xcls_buffer() );
204
205             // init method 
206                 var description =   Pango.FontDescription.from_string("monospace");
207                 description.set_size(8000);
208                 this.override_font(description);
209
210             // listeners 
211             this.key_release_event.connect( (event) => {
212                 
213                 if (event.key.keyval == 115 && (event.key.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
214                     print("SAVE: ctrl-S  pressed");
215                     this.save();
216                     return false;
217                 }
218                // print(event.key.keyval)
219                 
220                 return false;
221             
222             } );
223         }
224
225         // userdefined functions 
226         public void save() {
227             
228                 Editor.RightEditor.save();
229             }
230     }
231     public class Xcls_buffer : Gtk.SourceBuffer
232     {
233
234             // my vars
235
236             // ctor 
237         public Xcls_buffer()
238         {
239             _this.buffer = this;
240
241             // my vars
242
243             // set gobject values
244
245             // listeners 
246         }
247
248         // userdefined functions 
249     }
250 }