tools
[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                 },
65                 {
66                     xtype: Gtk.Entry,
67                     id : "name",
68                     pack : "add"
69                 }
70             ]
71         },
72         {
73             xtype: Gtk.Button,
74             label : "Cancel",
75             pack : "add_action_widget,0"
76         },
77         {
78             xtype: Gtk.Button,
79             label : "OK",
80             pack : "add_action_widget,1"
81         }
82     ]
83 });
84 DialogSaveTemplate.init();
85 XObject.cache['/DialogSaveTemplate'] = DialogSaveTemplate;