fix deleting hopefully
[app.Builder.js] / Sample / Window.js
index f998bb5..7d66a12 100644 (file)
@@ -25,7 +25,7 @@ Window=new XObject({
                this.get('/MidPropTree').hideWin();
             this.get('/RightPalete').hide();
             this.get('/BottomPane').el.hide();
-            this.get('/Editor').el.show_all();
+            //this.get('/Editor').el.show_all();
         
         }
     },
@@ -343,6 +343,10 @@ Window=new XObject({
                                                             // that is done by GTK..
                                                             
                                                             
+                                                               if (!this.get('/Editor').save()) {
+                                                                   // popup!! - click handled.. 
+                                                                   return true;
+                                                                }
                                                         
                                                             if (!this.el.expanded) {
                                                                 this.onExpand();
@@ -364,15 +368,15 @@ Window=new XObject({
                                                     id : "expander",
                                                     label : "Select Project or File",
                                                     pack : "pack_start,false,true",
+                                                    init : function() {
+                                                        XObject.prototype.init.call(this);
+                                                       this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
+                                                    },
                                                     onCollapse : function() {
                                                         
                                                         var nb = this.get('/LeftTopPanel.notebook');
                                                         nb.el.set_current_page(0);
                                                     },
-                                                    init : function() {
-                                                        XObject.prototype.init.call(this);
-                                                       this.el.add_events (Gdk.EventMask.BUTTON_MOTION_MASK );
-                                                    },
                                                     onExpand : function() {
                                                         var nb = this.get('/LeftTopPanel.notebook');            
                                                         var pm  = imports.Builder.Provider.ProjectManager.ProjectManager;
@@ -471,6 +475,12 @@ Window=new XObject({
                                                                     listeners : {
                                                                         button_press_event : function (self, ev) {
                                                                                console.log("button press?");
+                                                                               
+                                                                               if (!this.get('/Editor').save()) {
+                                                                                   // popup!! - click handled.. 
+                                                                                   return true;
+                                                                                }
+                                                                               
                                                                                 if (ev.type != Gdk.EventType.BUTTON_PRESS  || ev.button.button != 3) {
                                                                                     print("click" + ev.type);
                                                                                     return false;
@@ -480,7 +490,7 @@ Window=new XObject({
                                                                                 var res = {}; 
                                                                                 this.get('/LeftTree.view').el.get_path_at_pos(ev.button.x,ev.button.y, res);
                                                                                 
-                                                                                if (!this.get('/LeftTreeMenu').el)  this.get('/LeftTreeMenu').init();
+                                                                                if (!this.get('/LeftTreeMenu').el)  { this.get('/LeftTreeMenu').init(); }
                                                                                 
                                                                                 this.get('/LeftTreeMenu').el.set_screen(Gdk.Screen.get_default());
                                                                                 this.get('/LeftTreeMenu').el.show_all();
@@ -1136,8 +1146,8 @@ Window=new XObject({
                                                                                         
                                                                                         if (f.items.length && typeof(f.items[0]) == 'string') {
                                                                                         
-                                                                                            this.get('/RightEditor').el.show();
-                                                                                            this.get('/RightEditor.view').load( f.items[0]);
+                                                                                            //this.get('/RightEditor').el.show();
+                                                                                            //this.get('/RightEditor.view').load( f.items[0]);
                                                                                             return;
                                                                                         }
                                                                                         print("LOAD");
@@ -1161,7 +1171,8 @@ Window=new XObject({
                                                                                         
                                                                                         
                                                                                         //print("hide right editior");
-                                                                                        this.get('/RightEditor').el.hide();
+                                                                                        //this.get('/RightEditor').el.hide();
+                                                                                        this.get('/Editor').el.hide();
                                                                                         //print("set current tree");
                                                                                         this.currentTree = this.toJS(false, false)[0];
                                                                                         //console.dump(this.currentTree);
@@ -1717,13 +1728,18 @@ Window=new XObject({
                                                         },
                                                         {
                                                             xtype: Gtk.Button,
-                                                            pack : "add",
                                                             listeners : {
                                                                 button_press_event : function (self, event) {
-                                                                    this.get('/MidPropTree.model').showData('events');
+                                                                    
+                                                                       if (!this.get('/Editor').save()) {
+                                                                           // popup!! - click handled.. 
+                                                                           return true;
+                                                                        }
+                                                                        this.get('/MidPropTree.model').showData('events');
                                                                     return false;
                                                                 }
                                                             },
+                                                            pack : "add",
                                                             items : [
                                                                 {
                                                                     xtype: Gtk.HBox,
@@ -1746,9 +1762,14 @@ Window=new XObject({
                                                         },
                                                         {
                                                             xtype: Gtk.Button,
-                                                            pack : "add",
                                                             listeners : {
                                                                 button_press_event : function (self, ev) {
+                                                                
+                                                                       if (!this.get('/Editor').save()) {
+                                                                           // popup!! - click handled.. 
+                                                                           return true;
+                                                                        }
+                                                                        
                                                                        var p = this.get('/AddPropertyPopup');
                                                                        if (!p.el) {
                                                                                p.init();
@@ -1759,6 +1780,7 @@ Window=new XObject({
                                                                     return true;
                                                                 }
                                                             },
+                                                            pack : "add",
                                                             items : [
                                                                 {
                                                                     xtype: Gtk.HBox,
@@ -1933,6 +1955,10 @@ Window=new XObject({
                                                                 button_press_event : function (self, ev) {
                                                                 
                                                                     
+                                                                    if (!this.get('/Editor').save()) {
+                                                                        // popup!! - click handled.. 
+                                                                        return true;
+                                                                    }
                                                                     var res = { }; 
                                                                     
                                                                     if (!this.el.get_path_at_pos(ev.button.x,ev.button.y, res)) {
@@ -1971,6 +1997,16 @@ Window=new XObject({
                                                                         
                                                                      //   this.activePath = false;
                                                                        // stop editing!!!!
+                                                                        if (this.get('/Editor').dirty) {
+                                                                            //if (!this.get('/Editor.buffer').checkSyntax()) {
+                                                                            //   this.get('/StandardErrorDialog').show("Fix errors in code and save.."); 
+                                                                            //   return true;
+                                                                            //    // error Dialog
+                                                                            //}
+                                                                            if (!this.get('/Editor.view').save()) {
+                                                                                return true;
+                                                                            }
+                                                                        }   
                                                                         this.get('/LeftPanel').editableColumn.items[0].el.stop_editing();
                                                                         this.get('/LeftPanel').editing = false;
                                                                     
@@ -2186,9 +2222,16 @@ Window=new XObject({
                                                                                                 ]);
                                                                     },
                                                                     load : function(ar) {
+                                                                    // might casue problesm..
+                                                                        // this.get('/Editor.RightEditor').save();
+                                                                    
+                                                                           this.get('/Editor').el.hide();
+                                                                         this.get('/Editor').activePath = false;
+                                                                    
+                                                                    
                                                                       this.el.clear();
-                                                                                            
-                                                                        this.get('/RightEditor').el.hide();
+                                                                                  
+                                                                        //this.get('/RightEditor').el.hide();
                                                                         if (ar === false) {
                                                                             return ;
                                                                         }
@@ -2240,7 +2283,8 @@ Window=new XObject({
                                                                         return ret;
                                                                     },
                                                                     startEditing : function(path,col) {
-                                                                    // alled by menu 'edit' currently..
+                                                                        
+                                                                        // alled by menu 'edit' currently..
                                                                         /**
                                                                         * start editing path (or selected if not set..)
                                                                         * @param {String|false} path  (optional) treepath to edit - selected tree gets
@@ -2277,7 +2321,9 @@ Window=new XObject({
                                                                         // make sure the pulldown is set correctly..
                                                                         // not really needed for second col...
                                                                         var showEditor = false;
-                                                                        
+                                                                        this.get('/Editor').activePath = false;
+                                                                        this.get('/Editor').el.hide();
+                                                                         
                                                                         if (col) {
                                                                             var provider = this.get('/LeftTree').getPaleteProvider();
                                                                             var type = this.get('/LeftPanel.model').getType(path);
@@ -2307,28 +2353,30 @@ Window=new XObject({
                                                                         }
                                                                         var _this = this;    
                                                                         // end editing..
-                                                                        this.get('/BottomPane').el.hide();
-                                                                        this.get('/RightEditor').el.hide();
-                                                                        
+                                                                       // this.get('/BottomPane').el.hide();
+                                                                        //this.get('/RightEditor').el.hide();
+                                                                         
                                                                         
                                                                         if (showEditor) {
                                                                     
                                                                             this.activePath = false;
+                                                                            
+                                                                            _this.get('/Editor').el.show_all();
                                                                             GLib.timeout_add(0, 1, function() {
                                                                     
-                                                                                _this.get('/BottomPane').el.show();
-                                                                                _this.get('/RightEditor').el.show();
-                                                                                _this.get('/RightEditor.view').load( _this.getValue(path, 1) );
+                                                                                //_this.get('/BottomPane').el.show();
+                                                                                 //_this.get('/RightEditor').el.show();
                                                                                 
-                                                                                //e.editing_done();
-                                                                                //e.remove_widget();
-                                                                                _this.activePath = path ;
+                                                                                _this.get('/Editor.RightEditor.view').load( _this.getValue(path, 1) );
                                                                                 
+                                                                                _this.get('/Editor').activePath = path;
+                                                                                _this.activePath = path ;
+                                                                              
                                                                                 return false;
                                                                             });
                                                                             return;
                                                                         }
-                                                                        
+                                                                          
                                                                         
                                                                         
                                                                     
@@ -2459,9 +2507,9 @@ Window=new XObject({
                                                                                    
                                                                                 }
                                                                             },
+                                                                            editable : false,
                                                                             pack : "pack_start",
                                                                             text_column : 0,
-                                                                            editable : true,
                                                                             has_entry : true,
                                                                             init : function() {
                                                                                 XObject.prototype.init.call(this);
@@ -2778,6 +2826,17 @@ Window=new XObject({
                                                                                     id : "AutoRedraw",
                                                                                     label : "Auto Redraw On",
                                                                                     pack : "pack_start,false,false,0"
+                                                                                },
+                                                                                {
+                                                                                    xtype: Gtk.Button,
+                                                                                    listeners : {
+                                                                                        clicked : function (self) {
+                                                                                          this.get('/RightBrowser.view').redraws = 99;
+                                                                                          this.get('/RightBrowser.view').renderJS(null,true);
+                                                                                        }
+                                                                                    },
+                                                                                    label : "Full Redraw",
+                                                                                    pack : "pack_start,false,false,0"
                                                                                 }
                                                                             ]
                                                                         },
@@ -2824,11 +2883,26 @@ Window=new XObject({
                                                                                         console_message : function (self, object, p0, p1) {
                                                                                             print(object);
                                                                                            //  console.log(object);
+                                                                                           
+                                                                                        
+                                                                                            if (object.match(/variable/) && object.match(/Builder/)) {
+                                                                                                print("got builder missing message");
+                                                                                                this.refreshRequired = true;
+                                                                                                this.lastRedraw = 0;
+                                                                                                this.runRefresh();
+                                                                                                return true;
+                                                                                            }
+                                                                                            
+                                                                                           
                                                                                                 if (!object.match(/^\{/)) {
                                                                                                 
                                                                                                     //this.get('/Terminal').feed(object);
                                                                                                     return true; // do not handle!!! -> later maybe in console..
                                                                                                 }
+                                                                                                
+                                                                                                
+                                                                                                
+                                                                                                
                                                                                                // console.log(object);
                                                                                                 var val =  JSON.parse(object);
                                                                                         
@@ -2965,9 +3039,9 @@ Window=new XObject({
                                                                                            return null; //new WebKit.WebView();
                                                                                         }
                                                                                     },
-                                                                                    redraws : 0,
                                                                                     id : "view",
                                                                                     pack : "add",
+                                                                                    redraws : 0,
                                                                                     init : function() {
                                                                                         XObject.prototype.init.call(this);
                                                                                         // this may not work!?
@@ -3720,94 +3794,11 @@ Window=new XObject({
                                             pack : "add",
                                             init : function() {
                                                 XObject.prototype.init.call(this);
-                                               this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
-                                                       this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Console" }));
-                                                       this.el.set_tab_label(this.items[2].el, new Gtk.Label({ label : "Inspector" }));
+                                               //this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Code Editor" }));
+                                                       this.el.set_tab_label(this.items[0].el, new Gtk.Label({ label : "Console" }));
+                                                       this.el.set_tab_label(this.items[1].el, new Gtk.Label({ label : "Inspector" }));
                                             },
                                             items : [
-                                                {
-                                                    xtype: Gtk.ScrolledWindow,
-                                                    pack : "add",
-                                                    id : "RightEditor",
-                                                    items : [
-                                                        {
-                                                            xtype: GtkSource.View,
-                                                            pack : "add",
-                                                            id : "view",
-                                                            init : function() {
-                                                                XObject.prototype.init.call(this);
-                                                                 var description = Pango.Font.description_from_string("monospace")
-                                                                description.set_size(8000);
-                                                                this.el.modify_font(description);
-                                                            
-                                                            },
-                                                            load : function(str) {
-                                                            
-                                                            // show the help page for the active node..
-                                                               this.get('/Help').show();
-                                                            
-                                                            
-                                                               this.get('/BottomPane').el.set_current_page(0);
-                                                                this.el.get_buffer().set_text(str, str.length);
-                                                                var lm = GtkSource.LanguageManager.get_default();
-                                                                
-                                                                this.el.get_buffer().set_language(lm.get_language('js'));
-                                                                var buf = this.el.get_buffer();
-                                                                var cursor = buf.get_mark("insert");
-                                                                var iter= new Gtk.TextIter;
-                                                                buf.get_iter_at_mark(iter, cursor);
-                                                                iter.set_line(1);
-                                                                iter.set_line_offset(4);
-                                                                buf.move_mark(cursor, iter);
-                                                                
-                                                                
-                                                                cursor = buf.get_mark("selection_bound");
-                                                                iter= new Gtk.TextIter;
-                                                                buf.get_iter_at_mark(iter, cursor);
-                                                                iter.set_line(1);
-                                                                iter.set_line_offset(4);
-                                                                buf.move_mark(cursor, iter);
-                                                                 
-                                                                this.el.grab_focus();
-                                                            },
-                                                            insert_spaces_instead_of_tabs : true,
-                                                            indent_width : 4,
-                                                            auto_indent : true,
-                                                            show_line_numbers : true,
-                                                            items : [
-                                                                {
-                                                                    xtype: GtkSource.Buffer,
-                                                                    listeners : {
-                                                                        changed : function (self) {
-                                                                            var s = new Gtk.TextIter();
-                                                                            var e = new Gtk.TextIter();
-                                                                            this.el.get_start_iter(s);
-                                                                            this.el.get_end_iter(e);
-                                                                            var str = this.el.get_text(s,e,true);
-                                                                            try {
-                                                                                Seed.check_syntax('var e = ' + str);
-                                                                            } catch (e) {
-                                                                                this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
-                                                                                    red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
-                                                                                   }));
-                                                                                //print("SYNTAX ERROR IN EDITOR");   
-                                                                                //print(e);
-                                                                                //console.dump(e);
-                                                                                return;
-                                                                            }
-                                                                            this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
-                                                                                    red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
-                                                                                   }));
-                                                                            
-                                                                             this.get('/LeftPanel.model').changed(  str , false);
-                                                                        }
-                                                                    },
-                                                                    pack : "set_buffer"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                },
                                                 {
                                                     xtype: Gtk.ScrolledWindow,
                                                     pack : "add",
@@ -3951,48 +3942,6 @@ Window=new XObject({
                                                     items : [
                                                         {
                                                             xtype: Gtk.TreeView,
-                                                            pack : "add",
-                                                            init : function() {
-                                                                XObject.prototype.init.call(this);
-                                                              this.el.set_size_request(150,-1);
-                                                                                      //  set_reorderable: [1]
-                                                                                              
-                                                                        var description = new Pango.FontDescription.c_new();
-                                                                description.set_size(8000);
-                                                                this.el.modify_font(description);
-                                                                
-                                                                this.selection = this.el.get_selection();
-                                                                this.selection.set_mode( Gtk.SelectionMode.SINGLE);
-                                                               // this.selection.signal['changed'].connect(function() {
-                                                                //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
-                                                                //});
-                                                                // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
-                                                                 
-                                                                Gtk.drag_source_set (
-                                                                        this.el,            /* widget will be drag-able */
-                                                                        Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
-                                                                        null,            /* lists of target to support */
-                                                                        0,              /* size of list */
-                                                                        Gdk.DragAction.COPY         /* what to do with data after dropped */
-                                                                );
-                                                                //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
-                                                               
-                                                                Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
-                                                                Gtk.drag_source_add_text_targets(this.el); 
-                                                                /*
-                                                                print("RP: TARGET:" + LeftTree.atoms["STRING"]);
-                                                                targets = new Gtk.TargetList();
-                                                                targets.add( LeftTree.atoms["STRING"], 0, 0);
-                                                                targets.add_text_targets( 1 );
-                                                                Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
-                                                                
-                                                                //if you want to allow text to be output elsewhere..
-                                                                //Gtk.drag_source_add_text_targets(this.el);
-                                                                */
-                                                                return true; 
-                                                            },
-                                                            headers_visible : false,
-                                                            enable_tree_lines : true,
                                                             listeners : {
                                                                 drag_begin : function (self, ctx) {
                                                                     // we could fill this in now...
@@ -4045,8 +3994,58 @@ Window=new XObject({
                                                                        this.el.dropList = false;
                                                                        this.get('/LeftTree.view').highlight(false);
                                                                        return true;
+                                                                },
+                                                                button_press_event : function (self, event) {
+                                                                
+                                                                       if (!this.get('/Editor').save()) {
+                                                                           // popup!! - click handled.. 
+                                                                           return true;
+                                                                        }
+                                                                    return false;
                                                                 }
                                                             },
+                                                            pack : "add",
+                                                            enable_tree_lines : true,
+                                                            headers_visible : false,
+                                                            init : function() {
+                                                                XObject.prototype.init.call(this);
+                                                              this.el.set_size_request(150,-1);
+                                                                                      //  set_reorderable: [1]
+                                                                                              
+                                                                        var description = new Pango.FontDescription.c_new();
+                                                                description.set_size(8000);
+                                                                this.el.modify_font(description);
+                                                                
+                                                                this.selection = this.el.get_selection();
+                                                                this.selection.set_mode( Gtk.SelectionMode.SINGLE);
+                                                               // this.selection.signal['changed'].connect(function() {
+                                                                //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
+                                                                //});
+                                                                // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
+                                                                 
+                                                                Gtk.drag_source_set (
+                                                                        this.el,            /* widget will be drag-able */
+                                                                        Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
+                                                                        null,            /* lists of target to support */
+                                                                        0,              /* size of list */
+                                                                        Gdk.DragAction.COPY         /* what to do with data after dropped */
+                                                                );
+                                                                //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
+                                                               
+                                                                Gtk.drag_source_set_target_list(this.el, this.get('/Window').targetList);
+                                                                Gtk.drag_source_add_text_targets(this.el); 
+                                                                /*
+                                                                print("RP: TARGET:" + LeftTree.atoms["STRING"]);
+                                                                targets = new Gtk.TargetList();
+                                                                targets.add( LeftTree.atoms["STRING"], 0, 0);
+                                                                targets.add_text_targets( 1 );
+                                                                Gtk.drag_dest_set_target_list(this.el, LeftTree.targetList);
+                                                                
+                                                                //if you want to allow text to be output elsewhere..
+                                                                //Gtk.drag_source_add_text_targets(this.el);
+                                                                */
+                                                                return true; 
+                                                            },
                                                             items : [
                                                                 {
                                                                     xtype: Gtk.ListStore,