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