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