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            print(response_id)
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            if (!name.match(/^[A-Z ]$/i) || name.match(/^[A-Z]/i)) {
33                 this.get('/StandardErrorDialog').show(
34                     "Template Nane must contain only letters and spaces. "
35                 );
36                  return;
37             }
38             this.get('/LeftTree').getPaletteProvider().saveTemplate(name, this.data);
39             // now we save it..
40                 this.el.hide();
41             
42         }
43     },
44     default_height : 200,
45     default_width : 400,
46     modal : true,
47     show : function(data) {
48         this.data = data;
49         this.get('name').el.set_text('');
50         this.el.show_all();
51     },
52     items : [
53         {
54             xtype: Gtk.HBox,
55             pack : function(p,e) {
56                                 p.el.get_content_area().add(e.el)
57                             },
58             items : [
59                 {
60                     xtype: Gtk.Label,
61                     label : "Name",
62                     pack : "add",
63                     listeners : {
64                         
65                     }
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;