Sample/Editor.js
[app.Builder.js] / Sample / Editor.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 GtkClutter = imports.gi.GtkClutter;
11 console = imports.console;
12 XObject = imports.XObject.XObject;
13 Editor=new XObject({
14     xtype: Gtk.Window,
15     listeners : {
16         delete_event : function (self, event) {
17             return false;
18         },
19         destroy_event : function (self, event) {
20             return false;
21         }
22     },
23     height_request : 300,
24     id : "EditorWindow",
25     title : "Application Builder - Editor",
26     width_request : 500,
27     init : function() {
28         XObject.prototype.init.call(this);
29        // this.show_all();
30     },
31     items : [
32         {
33             xtype: Gtk.VBox,
34             pack : "add",
35             items : [
36                 {
37                     xtype: Gtk.Toolbar,
38                     pack : "pack_start,false,true",
39                     items : [
40                         {
41                             xtype: Gtk.Button,
42                             label : "Save"
43                         }
44                     ]
45                 },
46                 {
47                     xtype: Gtk.ScrolledWindow,
48                     id : "RightEditor",
49                     pack : "add",
50                     items : [
51                         {
52                             xtype: GtkSource.View,
53                             id : "view",
54                             indent_width : 4,
55                             pack : "add",
56                             auto_indent : true,
57                             init : function() {
58                                 XObject.prototype.init.call(this);
59                                  var description = Pango.Font.description_from_string("monospace")
60                                 description.set_size(8000);
61                                 this.el.modify_font(description);
62                             
63                             },
64                             insert_spaces_instead_of_tabs : true,
65                             load : function(str) {
66                             
67                             // show the help page for the active node..
68                                //this.get('/Help').show();
69                             
70                             
71                               // this.get('/BottomPane').el.set_current_page(0);
72                                 this.el.get_buffer().set_text(str, str.length);
73                                 var lm = GtkSource.LanguageManager.get_default();
74                                 
75                                 this.el.get_buffer().set_language(lm.get_language('js'));
76                                 var buf = this.el.get_buffer();
77                                 var cursor = buf.get_mark("insert");
78                                 var iter= new Gtk.TextIter;
79                                 buf.get_iter_at_mark(iter, cursor);
80                                 iter.set_line(1);
81                                 iter.set_line_offset(4);
82                                 buf.move_mark(cursor, iter);
83                                 
84                                 
85                                 cursor = buf.get_mark("selection_bound");
86                                 iter= new Gtk.TextIter;
87                                 buf.get_iter_at_mark(iter, cursor);
88                                 iter.set_line(1);
89                                 iter.set_line_offset(4);
90                                 buf.move_mark(cursor, iter);
91                                  
92                                 this.el.grab_focus();
93                             },
94                             show_line_numbers : true,
95                             items : [
96                                 {
97                                     xtype: GtkSource.Buffer,
98                                     listeners : {
99                                         changed : function (self) {
100                                             var s = new Gtk.TextIter();
101                                             var e = new Gtk.TextIter();
102                                             this.el.get_start_iter(s);
103                                             this.el.get_end_iter(e);
104                                             var str = this.el.get_text(s,e,true);
105                                             try {
106                                                 Seed.check_syntax('var e = ' + str);
107                                             } catch (e) {
108                                                 this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
109                                                     red: 0xFFFF, green: 0xCCCC , blue : 0xCCCC
110                                                    }));
111                                                 //print("SYNTAX ERROR IN EDITOR");   
112                                                 //print(e);
113                                                 //console.dump(e);
114                                                 return;
115                                             }
116                                             this.get('/RightEditor.view').el.modify_base(Gtk.StateType.NORMAL, new Gdk.Color({
117                                                     red: 0xFFFF, green: 0xFFFF , blue : 0xFFFF
118                                                    }));
119                                             
120                                              this.get('/LeftPanel.model').changed(  str , false);
121                                         }
122                                     },
123                                     pack : "set_buffer"
124                                 }
125                             ]
126                         }
127                     ]
128                 }
129             ]
130         }
131     ]
132 });
133 Editor.init();
134 XObject.cache['/Editor'] = Editor;