typo
[roobuilder] / src / Builder4 / DialogSaveModule.vala
1     static DialogSaveModule  _DialogSaveModule;
2
3     public class DialogSaveModule : Object
4     {
5         public Gtk.Dialog el;
6         private DialogSaveModule  _this;
7
8         public static DialogSaveModule singleton()
9         {
10             if (_DialogSaveModule == null) {
11                 _DialogSaveModule= new DialogSaveModule();
12             }
13             return _DialogSaveModule;
14         }
15         public Xcls_name name;
16
17             // my vars (def)
18         public signal void complete (string result);
19         public JsRender.Node data;
20         public Project.Project project;
21
22         // ctor
23         public DialogSaveModule()
24         {
25             _this = this;
26             this.el = new Gtk.Dialog();
27
28             // my vars (dec)
29
30             // set gobject values
31             this.el.default_height = 200;
32             this.el.default_width = 400;
33             this.el.modal = true;
34             var child_1 = new Xcls_Box2( _this );
35             child_1.ref();
36             this.el.get_content_area().append ( child_1.el  );
37             var child_2 = new Xcls_Button5( _this );
38             child_2.ref();
39             this.el.add_action_widget ( child_2.el , 0 );
40             var child_3 = new Xcls_Button6( _this );
41             child_3.ref();
42             this.el.add_action_widget ( child_3.el , 1 );
43
44             //listeners
45             this.el.response.connect( (response_id) => {
46                 if (response_id < 1) {
47                     this.el.hide();
48                      this.complete("");
49                 }
50                     
51                var  name = _this.name.el.get_text();
52                 if (name.length < 1) {
53                     Xcls_StandardErrorDialog.singleton().show(
54                          _this.el,
55                         "You must give the template a name. "
56                     );
57                      return;
58                 }
59                 if (!Regex.match_simple ("^[A-Za-z][A-Za-z0-9.]+$", name) )
60                 {
61                     Xcls_StandardErrorDialog.singleton().show(
62                          _this.el.transient_for,
63                         "Template Name must contain only letters dots"
64                     );
65                     return;;
66                 }
67                 
68                 var targetfile = project.path + "/templates/" + name + ".bjs";
69                 
70                 
71                 if (GLib.FileUtils.test(targetfile, GLib.FileTest.EXISTS)) {
72                     Xcls_StandardErrorDialog.singleton().show(
73                         _this.el.transient_for,
74                         "That file already exists"
75                     ); 
76                     return;
77                 }
78                 JsRender.JsRender f;
79                  try {
80                    f =  JsRender.JsRender.factory(
81                                   project.xtype ,  
82                                 project, 
83                                 targetfile);
84                 } catch (JsRender.Error e) {
85                         Xcls_StandardErrorDialog.singleton().show(
86                         _this.el.transient_for,
87                         "Error creating file"
88                     ); 
89                         return;
90                 }
91                 
92             
93                 f.tree =  _this.data.deepClone();
94                 f.save();
95                  project.addFile(f);
96                 // now we save it..
97                 this.el.hide();
98                 this.complete(name);
99                
100             
101             });
102         }
103
104         // user defined functions
105         public void showIt (Gtk.Window parent, Project.Project project, JsRender.Node data) {
106          
107              
108             this.el.set_transient_for(parent);
109             this.el.modal = true;
110             
111             this.data = data;
112             this.project = project;
113             this.name.el.set_text("");
114             this.el.show();
115         
116              
117             
118         }
119         public class Xcls_Box2 : Object
120         {
121             public Gtk.Box el;
122             private DialogSaveModule  _this;
123
124
125                 // my vars (def)
126
127             // ctor
128             public Xcls_Box2(DialogSaveModule _owner )
129             {
130                 _this = _owner;
131                 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
132
133                 // my vars (dec)
134
135                 // set gobject values
136                 var child_1 = new Xcls_Label3( _this );
137                 child_1.ref();
138                 this.el.append ( child_1.el  );
139                 new Xcls_name( _this );
140                 this.el.append ( _this.name.el  );
141             }
142
143             // user defined functions
144         }
145         public class Xcls_Label3 : Object
146         {
147             public Gtk.Label el;
148             private DialogSaveModule  _this;
149
150
151                 // my vars (def)
152
153             // ctor
154             public Xcls_Label3(DialogSaveModule _owner )
155             {
156                 _this = _owner;
157                 this.el = new Gtk.Label( "Name" );
158
159                 // my vars (dec)
160
161                 // set gobject values
162             }
163
164             // user defined functions
165         }
166
167         public class Xcls_name : Object
168         {
169             public Gtk.Entry el;
170             private DialogSaveModule  _this;
171
172
173                 // my vars (def)
174
175             // ctor
176             public Xcls_name(DialogSaveModule _owner )
177             {
178                 _this = _owner;
179                 _this.name = this;
180                 this.el = new Gtk.Entry();
181
182                 // my vars (dec)
183
184                 // set gobject values
185             }
186
187             // user defined functions
188         }
189
190
191         public class Xcls_Button5 : Object
192         {
193             public Gtk.Button el;
194             private DialogSaveModule  _this;
195
196
197                 // my vars (def)
198
199             // ctor
200             public Xcls_Button5(DialogSaveModule _owner )
201             {
202                 _this = _owner;
203                 this.el = new Gtk.Button();
204
205                 // my vars (dec)
206
207                 // set gobject values
208                 this.el.label = "Cancel";
209             }
210
211             // user defined functions
212         }
213
214         public class Xcls_Button6 : Object
215         {
216             public Gtk.Button el;
217             private DialogSaveModule  _this;
218
219
220                 // my vars (def)
221
222             // ctor
223             public Xcls_Button6(DialogSaveModule _owner )
224             {
225                 _this = _owner;
226                 this.el = new Gtk.Button();
227
228                 // my vars (dec)
229
230                 // set gobject values
231                 this.el.label = "OK";
232             }
233
234             // user defined functions
235         }
236
237     }