Sample/DialogSaveTemplate.js
[app.Builder.js] / Sample / DialogSaveTemplate.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 DialogSaveTemplate=new XObject({
13     xtype: Gtk.Dialog,
14     listeners : {
15         delete_event : function (self, event) {
16             this.el.hide();
17             return true;
18         },
19         response : function (self, response_id) {
20             if (!response_id) {
21                 this.el.hide();
22                  return;
23             }
24             var name = this.get('name').el.get_text();
25             if (!name.length) {
26                 this.get('/StandardErrorDialog').show(
27                     "You must give the template a name. "
28                 );
29                 return;
30             }
31            if (!name.match(/^[A-Z ]$/i) || name.match(/^[A-Z]/i)) {
32                 this.get('/StandardErrorDialog').show(
33                     "Template Nane must contain only letters and spaces. "
34                 );
35                  return;
36             }
37             this.get('/LeftTree').getPaletteProvider().saveTemplate(name, this.data);
38             // now we save it..
39                 this.el.hide();
40             
41         }
42     },
43     default_height : 200,
44     default_width : 400,
45     modal : true,
46     show : function(data) {
47         this.data = data;
48         this.get('name').el.set_text('');
49         this.el.show_all();
50     },
51     items : [
52         {
53             xtype: Gtk.HBox,
54             pack : function(p,e) {
55                                 p.el.get_content_area().add(e.el)
56                             },
57             items : [
58                 {
59                     xtype: Gtk.Label,
60                     id : "name",
61                     label : "Name",
62                     pack : "add"
63                 },
64                 {
65                     xtype: Gtk.Entry,
66                     pack : "add"
67                 }
68             ]
69         },
70         {
71             xtype: Gtk.Button,
72             label : "Cancel",
73             pack : "add_action_widget,0"
74         },
75         {
76             xtype: Gtk.Button,
77             label : "OK",
78             pack : "add_action_widget,0"
79         }
80     ]
81 });
82 DialogSaveTemplate.init();
83 XObject.cache['/DialogSaveTemplate'] = DialogSaveTemplate;