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