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