3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
15 delete_event : function (self, event) {
16 if (!this.get('/Editor.RightEditor').save()) {
17 // no hiding with errors.
21 this.get('/Editor').activePath = false;
27 if (!Editor.RightEditor.save()) {
28 // no hiding with errors.
32 _this.active_path = "";
37 configure_event : function (self, object) {
38 this.pos = this.el.get_position();
45 this.el.get_position(out _this.pos_root_x, out _this.pos_root_y);
51 show : function (self) {
53 this.el.set_uposition(this.pos.root_x,this.pos.root_y);
59 _this.el.move(this.pos_root_x,this.pos_root_y);
67 title : "Application Builder - Code Editor",
70 XObject.prototype.init.call(this);
73 save : function (self, event) {
74 if (!this.get('/Editor.RightEditor').save()) {
75 // no hiding with errors.
78 this.get('/Editor').activePath = false;
86 if (!Editor.RightEditor.save()) {
87 // no hiding with errors.
90 _this.active_path = "";
96 show_all : function() {
113 pack : "pack_start,false,true",
116 xtype: Gtk.ToolButton,
118 clicked : function (self) {
120 this.get('/Editor.RightEditor').save();
124 Editor.RightEditor.save();
135 xtype: Gtk.ScrolledWindow,
139 // make sure we have an active path..
140 if (!this.get('/Editor').activePath) {
144 var str = this.get('/Editor.buffer').toString();
145 if (!this.get('/Editor.buffer').checkSyntax()) {
146 this.get('/StandardErrorDialog').show("Fix errors in code and save..");
150 this.get('/LeftPanel.model').changed( str , false);
151 this.get('/Editor').dirty = false;
152 this.get('/Editor.save_button').el.sensitive = false;
157 print("editor.rightbutton.save");
158 if (_this.active_path.length < 1 ) {
159 print("skip - no active path");
163 var str = Editor.buffer.toString();
165 if (!Editor.buffer.checkSyntax()) {
166 print("check syntax failed");
167 //this.get('/StandardErrorDialog').show("Fix errors in code and save..");
171 // LeftPanel.model.changed( str , false);
173 _this.save_button.el.sensitive = false;
174 print("set save button grey");
181 xtype: GtkSource.View,
183 key_release_event : function (self, event) {
185 if (event.key.keyval == 115 && (event.key.state & Gdk.ModifierType.CONTROL_MASK ) ) {
186 print("SAVE: ctrl-S pressed");
190 // print(event.key.keyval)
197 if (event.keyval == 115 && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
198 print("SAVE: ctrl-S pressed");
202 // print(event.key.keyval)
214 XObject.prototype.init.call(this);
215 var description = Pango.Font.description_from_string("monospace")
216 description.set_size(8000);
217 this.el.modify_font(description);
222 var description = Pango.FontDescription.from_string("monospace");
223 description.set_size(8000);
224 this.el.override_font(description);
228 insert_spaces_instead_of_tabs : true,
229 load : function(str) {
231 // show the help page for the active node..
232 //this.get('/Help').show();
235 // this.get('/BottomPane').el.set_current_page(0);
236 this.el.get_buffer().set_text(str, str.length);
237 var lm = GtkSource.LanguageManager.get_default();
239 this.el.get_buffer().set_language(lm.get_language('js'));
240 var buf = this.el.get_buffer();
241 var cursor = buf.get_mark("insert");
242 var iter= new Gtk.TextIter;
243 buf.get_iter_at_mark(iter, cursor);
245 iter.set_line_offset(4);
246 buf.move_mark(cursor, iter);
249 cursor = buf.get_mark("selection_bound");
250 iter= new Gtk.TextIter;
251 buf.get_iter_at_mark(iter, cursor);
253 iter.set_line_offset(4);
254 buf.move_mark(cursor, iter);
255 this.get('/Editor').dirty = false;
256 this.el.grab_focus();
257 this.get('/Editor.save_button').el.sensitive = false;
261 return this.get('/Editor.RightEditor').save();
267 Editor.RightEditor.save();
270 show_line_numbers : true,
273 xtype: GtkSource.Buffer,
275 changed : function (self) {
277 if(this.checkSyntax()) {
278 this.get('/Editor.save_button').el.sensitive = true;
280 // print("EDITOR CHANGED");
281 this.get('/Editor').dirty = true;
283 // this.get('/LeftPanel.model').changed( str , false);
291 if(this.checkSyntax()) {
292 Editor.save_button.el.sensitive = true;
294 // print("EDITOR CHANGED");
297 // this.get('/LeftPanel.model').changed( str , false);
306 checkSyntax : function() {
307 var str = this.toString();
310 // print('var res = ' + str);
311 Seed.check_syntax('var res = ' + str);
316 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
317 red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
319 print("SYNTAX ERROR IN EDITOR");
325 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
326 red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
333 // we could try running valac... ?? but it's a bit confusing..
340 toString : function() {
342 var s = new Gtk.TextIter();
343 var e = new Gtk.TextIter();
344 this.el.get_start_iter(s);
345 this.el.get_end_iter(e);
346 var ret = this.el.get_text(s,e,true);
347 //print("TO STRING? " + ret);
355 this.el.get_start_iter(out s);
356 this.el.get_end_iter(out e);
357 var ret = this.el.get_text(s,e,true);
358 //print("TO STRING? " + ret);
373 XObject.cache['/Editor'] = Editor;