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