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
7 static int main (string[] args) {
16 public static Xcls_Editor Editor;
18 private static Xcls_Editor _this;
20 public class Xcls_Editor : Gtk.Window
22 public Xcls_save_button save_button;
23 public Xcls_RightEditor RightEditor;
24 public Xcls_view view;
25 public Xcls_buffer buffer;
28 public string activeEditor;
29 public string active_path;
32 public int pos_root_x;
33 public int pos_root_y;
42 this.activeEditor = "";
43 this.active_path = "";
48 this.height_request = 300;
49 this.title = "Application Builder - Editor";
50 this.width_request = 500;
51 this.add ( new Xcls_VBox2() );
54 this.delete_event.connect( (event) => {
55 if (!Editor.RightEditor.save()) {
56 // no hiding with errors.
60 _this.active_path = "";
63 this.configure_event.connect( (object) => {
65 this.get_position(out _this.pos_root_x, out _this.pos_root_y);
70 this.show.connect( () => {
72 _this.move(this.pos_root_x,this.pos_root_y);
77 // userdefined functions
80 if (!Editor.RightEditor.save()) {
81 // no hiding with errors.
84 _this.active_path = "";
89 public class Xcls_VBox2 : Gtk.VBox
100 // set gobject values
101 this.pack_start ( new Xcls_Toolbar3(), false,true );
102 this.add ( new Xcls_RightEditor() );
105 // userdefined functions
107 public class Xcls_Toolbar3 : Gtk.Toolbar
113 public Xcls_Toolbar3()
118 // set gobject values
119 this.add ( new Xcls_save_button() );
122 // userdefined functions
124 public class Xcls_save_button : Gtk.ToolButton
130 public Xcls_save_button()
132 _this.save_button = this;
136 // set gobject values
140 this.clicked.connect( () => {
141 Editor.RightEditor.save();
145 // userdefined functions
147 public class Xcls_RightEditor : Gtk.ScrolledWindow
153 public Xcls_RightEditor()
155 _this.RightEditor = this;
159 // set gobject values
160 this.add ( new Xcls_view() );
163 // userdefined functions
166 if (_this.active_path.length < 1 ) {
170 var str = Editor.buffer.toString();
172 if (!Editor.buffer.checkSyntax()) {
173 print("check syntax failed");
174 //this.get('/StandardErrorDialog').show("Fix errors in code and save..");
178 // LeftPanel.model.changed( str , false);
180 _this.save_button.sensitive = false;
184 public class Xcls_view : Gtk.SourceView
196 // set gobject values
197 this.auto_indent = true;
198 this.indent_width = 4;
199 this.insert_spaces_instead_of_tabs = true;
200 this.show_line_numbers = true;
201 this.set_buffer ( new Xcls_buffer() );
204 var description = Pango.FontDescription.from_string("monospace");
205 description.set_size(8000);
206 this.override_font(description);
209 this.key_release_event.connect( (event) => {
211 if (event.key.keyval == 115 && (event.key.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
212 print("SAVE: ctrl-S pressed");
216 // print(event.key.keyval)
223 // userdefined functions
226 Editor.RightEditor.save();
229 public class Xcls_buffer : Gtk.SourceBuffer
241 // set gobject values
244 this.changed.connect( () => {
246 if(this.checkSyntax()) {
247 Editor.save_button.sensitive = true;
249 // print("EDITOR CHANGED");
252 // this.get('/LeftPanel.model').changed( str , false);
257 // userdefined functions
258 public bool checkSyntax() {
259 // we could try running valac... ?? but it's a bit confusing..
263 public string toString() {
267 this.get_start_iter(out s);
268 this.get_end_iter(out e);
269 var ret = this.get_text(s,e,true);
270 //print("TO STRING? " + ret);