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