Test.GtkWriter.vala.c
[app.Builder.js] / Builder4 / 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 : (self, event) => {
16             this.el.hide();
17             return true;
18         },
19         response : (self, response_id) => {
20         
21             if (response_id < 1) {
22                 this.el.hide();
23                  return;
24             }
25             var name = _this.name.el.get_text();
26             if (name.length < 1) {
27                 StandardErrorDialog.show(
28                     "You must give the template a name. "
29                 );
30                 return;
31             }
32             if (!Regex.match_simple ("^[A-Za-z]+$", name) || 
33                 !Regex.match_simple ("^[A-Za-z ]+$", name) )
34             {
35                 StandardErrorDialog.show(
36                     "Template Nane must contain only letters and spaces. "
37                 );
38                  return;
39             }
40             _this.palete.saveTemplate(name, _this.data);
41             // now we save it..
42             this.el.hide();
43             
44         }
45     },
46     default_height : 200,
47     default_width : 400,
48     modal : true,
49     'void:show' : (Palete.Palete palete, JsRender.Node data) {
50         _this.data = data;
51         _this.palete = palete;
52         _this.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;