Sample/RooProjectProperties.js
[app.Builder.js] / Sample / RooProjectProperties.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 console = imports.console;
11 XObject = imports.XObject.XObject;
12 RooProjectProperties=new XObject({
13     xtype: Gtk.Dialog,
14     modal : true,
15     show : function() {
16         // get the active project.
17         var file = this.get('/Window.LeftTree').getActiveFile();
18         if (!file) {
19             this.get('/StandardErrorDialog').show("No file is currently active");
20             return;
21         }
22         var project = this.get('/Window.LeftTree').getActiveFile().project;
23         //print (project.fn);
24         project.runjs = project.runjs || '';
25         this.get('view').el.get_buffer().set_text(project.runjs, project.runjs.length);
26         
27         this.el.show_all();
28     },
29     default_width : 500,
30     listeners : {
31         "delete_event":function (self, event) {
32             this.el.hide()
33             return true;
34         },
35         "response":function (self, response_id) {
36            print(response_id);
37            if (!response_id) {
38               this.el.hide();
39             
40               return;
41            }
42            var buf =    this.get('view').el.get_buffer()
43            var s = new Gtk.TextIter();
44             var e = new Gtk.TextIter();
45             buf.get_start_iter(s);
46             buf.get_end_iter(e);
47             var str = buf.get_text(s,e,true)
48          try {
49             Seed.check_syntax(str); 
50              } catch (e) {
51                  this.get('/StandardErrorDialog').show("There is a syntax error in the javascript");
52                 return;
53              }
54            var project = this.get('/Window.LeftTree').getActiveFile().project;
55            
56            
57            project.runjs = str;
58         //   print (str);
59            //    this.get('view').el.get_buffer().get_text(project.runjs, project.runjs.length);
60            // ok pressed..
61            this.el.hide();
62         }
63     },
64     items : [
65         {
66             xtype: Gtk.VBox,
67             pack : function(p,e) {
68                         p.el.get_content_area().add(e.el);
69                         e.border_width  =5;
70                     },
71             items : [
72                 {
73                     xtype: Gtk.Label,
74                     pack : "pack_start,false,false,0",
75                     label : "Javascript to run on before loading code"
76                 },
77                 {
78                     xtype: Gtk.ScrolledWindow,
79                     pack : "pack_end,true,true,0",
80                     items : [
81                         {
82                             xtype: GtkSource.View,
83                             pack : "add",
84                             id : "view"
85                         }
86                     ]
87                 }
88             ]
89         },
90         {
91             xtype: Gtk.Button,
92             pack : "add_action_widget,1",
93             label : "OK"
94         },
95         {
96             xtype: Gtk.Button,
97             pack : "add_action_widget,0",
98             label : "Cancel"
99         }
100     ]
101 });
102 RooProjectProperties.init();
103 XObject.cache['/RooProjectProperties'] = RooProjectProperties;