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     },
50     items : [
51         {
52             xtype: Gtk.HBox,
53             pack : function(p,e) {
54                                 p.el.get_content_area().add(e.el)
55                             },
56             items : [
57                 {
58                     xtype: Gtk.Label,
59                     id : "name",
60                     label : "Name",
61                     pack : "add"
62                 },
63                 {
64                     xtype: Gtk.Entry,
65                     pack : "add"
66                 }
67             ]
68         },
69         {
70             xtype: Gtk.Button,
71             label : "Cancel",
72             pack : "add_action_widget,0"
73         },
74         {
75             xtype: Gtk.Button,
76             label : "OK",
77             pack : "add_action_widget,0"
78         }
79     ]
80 });
81 DialogSaveTemplate.init();
82 XObject.cache['/DialogSaveTemplate'] = DialogSaveTemplate;