dbgenerate.js
[app.Builder.js] / Sample / Editor.js
index 35f6b62..38006d3 100644 (file)
@@ -7,18 +7,20 @@ GObject = imports.gi.GObject;
 GtkSource = imports.gi.GtkSource;
 WebKit = imports.gi.WebKit;
 Vte = imports.gi.Vte;
-GtkClutter = imports.gi.GtkClutter;
+////GtkClutter = imports.gi.GtkClutter;
+////Gdl = imports.gi.Gdl;
 console = imports.console;
 XObject = imports.XObject.XObject;
 Editor=new XObject({
     xtype: Gtk.Window,
     listeners : {
-        destroy_event : function (self, event) {
-            this.el.hide();
-            return true;
-        },
         delete_event : function (self, event) {
-              this.el.hide();
+            if (!this.get('/Editor.RightEditor').save()) {
+                // no hiding with errors.
+                return true;
+            }
+            this.el.hide();
+            this.get('/Editor').activePath = false;
             return true;
         },
         configure_event : function (self, object) {
@@ -37,6 +39,15 @@ Editor=new XObject({
     id : "EditorWindow",
     title : "Application Builder - Editor",
     width_request : 500,
+    save : function (self, event) {
+        if (!this.get('/Editor.RightEditor').save()) {
+            // no hiding with errors.
+            return true;
+        }
+        this.get('/Editor').activePath = false;
+        this.el.hide();
+        return true;
+    },
     init : function() {
         XObject.prototype.init.call(this);
        // this.show_all();
@@ -52,6 +63,13 @@ Editor=new XObject({
                     items : [
                         {
                             xtype: Gtk.Button,
+                            listeners : {
+                                clicked : function (self) {
+                                
+                                  this.get('/Editor.RightEditor').save();
+                                }
+                            },
+                            id : "save_button",
                             label : "Save"
                         }
                     ]
@@ -61,18 +79,35 @@ Editor=new XObject({
                     id : "RightEditor",
                     pack : "add",
                     save : function() {
+                        // make sure we have an active path..
+                         if (!this.get('/Editor').activePath) {
+                            return true;
+                         }
+                         
+                         var str = this.get('/Editor.buffer').toString();
+                         if (!this.get('/Editor.buffer').checkSyntax()) {
+                             this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
+                             return false;
+                         }
+                         
                          this.get('/LeftPanel.model').changed(  str , false);
+                         this.get('/Editor').dirty = false;
+                         this.get('/Editor.save_button').el.sensitive = false;
+                         return true;
                     },
                     items : [
                         {
                             xtype: GtkSource.View,
                             listeners : {
                                 key_release_event : function (self, event) {
-                                    if (event.key.keyval != 115 || !(Gdk.ModifierType.CONTROL_MASK & 4) ) {
-                                        return;
+                                    
+                                    if (event.key.keyval == 115 && (event.key.state & Gdk.ModifierType.CONTROL_MASK ) ) {
+                                        print("SAVE: ctrl-S  pressed");
+                                        this.save();
+                                        return false;
                                     }
-                                    print(event.key.keyval)
-                                    this.save();
+                                   // print(event.key.keyval)
+                                    
                                     return false;
                                 }
                             },
@@ -116,11 +151,11 @@ Editor=new XObject({
                                 buf.move_mark(cursor, iter);
                                 this.get('/Editor').dirty = false;
                                 this.el.grab_focus();
+                                 this.get('/Editor.save_button').el.sensitive = false;
                             },
                             save : function() {
-                                var str = this.get('buffer').toString();
-                                print("SAVE" + str);
-                                 this.get('/LeftPanel.model').changed(  str , false);
+                                
+                                return this.get('/Editor.RightEditor').save();
                             },
                             show_line_numbers : true,
                             items : [
@@ -129,9 +164,12 @@ Editor=new XObject({
                                     listeners : {
                                         changed : function (self) {
                                         
-                                            this.checkSyntax();
-                                            print("EDITOR CHANGED");
+                                            if(this.checkSyntax()) {
+                                                this.get('/Editor.save_button').el.sensitive = true;
+                                            }
+                                           // print("EDITOR CHANGED");
                                             this.get('/Editor').dirty = true;
+                                        
                                             // this.get('/LeftPanel.model').changed(  str , false);
                                             return false;
                                         }
@@ -142,8 +180,10 @@ Editor=new XObject({
                                         var str = this.toString();
                                         var res = '';
                                         try {
+                                          //  print('var res = ' + str);
                                             Seed.check_syntax('var res = ' + str);
-                                            return true;
+                                            
+                                           
                                         } catch (e) {
                                             
                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
@@ -151,18 +191,24 @@ Editor=new XObject({
                                                }));
                                             print("SYNTAX ERROR IN EDITOR");   
                                             print(e);
-                                             print(str);
+                                            // print(str);
                                             //console.dump(e);
                                             return false;
                                         }
+                                         this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
+                                            red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
+                                           }));
+                                        
+                                        return true;
                                     },
                                     toString : function() {
-                                          var s = new Gtk.TextIter();
+                                        
+                                        var s = new Gtk.TextIter();
                                         var e = new Gtk.TextIter();
                                         this.el.get_start_iter(s);
                                         this.el.get_end_iter(e);
                                         var ret = this.el.get_text(s,e,true);
-                                        print("TO STRING? " + ret);
+                                        //print("TO STRING? " + ret);
                                         return ret;
                                     }
                                 }