1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: prj 17.10.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 include
17 {
18 // $"..\gt2\gt.g"
19 "gtsave.g"
20 }
21
22 /*-----------------------------------------------------------------------------
23 *
24 * ID: prj 12.10.06 1.1.A.
25 *
26 * Summary: Project type
27 *
28 -----------------------------------------------------------------------------*/
29
30 type prj <inherit = gt index = str>
31 {
32 uint opened // 1 if there is an open project
33 uint changed // 1 if the project was changed
34 uint nfy // id of the notify function
35 str filename // The current file name or an empty string
36 str program // The unique program name
37 uint version // The unique version
38 str update // Update data for adding missing values
39 }
40
41 /*-----------------------------------------------------------------------------
42 *
43 * ID: prjnfy 12.10.06 1.1.A.
44 *
45 * Summary: Project notify codes
46 *
47 -----------------------------------------------------------------------------*/
48
49 define <export>
50 {
51 PRJNFY_OPEN = 0 // The project was opened
52 PRJNFY_CLOSE // The project was closed
53 PRJNFY_CANCLOSE // Send when the user tries to close the project
54 PRJNFY_CHANGE // The project was chaged. Send one time (after the
55 // first changing )
56 PRJNFY_NEW // Request the new project pattern
57 PRJNFY_NAME // Change the file name
58 }
59
60 global
61 {
62 str prjempty
63 }
64
65 method gt.clear()
66 {
67 this.names.clear()
68 this.items.clear()
69 this.files.clear()
70 this.procval.clear()
71 }
72
73 /*-----------------------------------------------------------------------------
74 *
75 * ID: prj_setnotify 12.10.06 1.1.A.
76 *
77 * Summary: Specify notify function. func uint name( prj iprj, uint code )
78 where code can be PRJNFY_*
79 *
80 -----------------------------------------------------------------------------*/
81
82 method prj.settings( uint nfyfunc, str program, uint version )
83 {
84 this.nfy = nfyfunc
85 this.program = program
86 this.version = version
87 }
88
89 /*-----------------------------------------------------------------------------
90 *
91 * ID: prj_notify 12.10.06 1.1.A.
92 *
93 * Summary: Send notify message PRJNFY_*
94 *
95 -----------------------------------------------------------------------------*/
96
97 method uint prj.notify( uint nfy )
98 {
99 if this.nfy : return this.nfy->func( this, nfy )
100 return 0
101 }
102
103 /*-----------------------------------------------------------------------------
104 *
105 * ID: prj_close 12.10.06 1.1.A.
106 *
107 * Summary: Close the project
108 *
109 -----------------------------------------------------------------------------*/
110
111 method uint prj.close
112 {
113 if !this.opened : return 1
114
115 this.notify( $PRJNFY_CANCLOSE )
116
117 this.clear()
118 this.opened = 0
119 this.changed = 0
120 // this.filename.clear()
121
122 this.notify( $PRJNFY_CLOSE )
123 return 1
124 }
125
126 /*-----------------------------------------------------------------------------
127 *
128 * ID: prj_new 12.10.06 1.1.A.
129 *
130 * Summary: Specify notify function. func uint name( prj iprj, uint code )
131 where code can be PRJNFY_*
132 *
133 -----------------------------------------------------------------------------*/
134
135 method uint prj.new
136 {
137 if this.opened : this.close()
138 if *this.update : this += this.update
139 this.notify( $PRJNFY_NEW )
140 this.filename.clear()
141 this.opened = 1
142 this.changed = 1
143 this.notify( $PRJNFY_OPEN )
144 return 1
145 }
146
147 /*-----------------------------------------------------------------------------
148 *
149 * ID: prj_open 12.10.06 1.1.A.
150 *
151 * Summary: Load a project from the file
152 *
153 -----------------------------------------------------------------------------*/
154
155 method uint prj.open( str filename )
156 {
157 if this.opened : this.close()
158 if *this.update : this += this.update
159 this.read( filename )
160 this.filename = filename
161 this.opened = 1
162 this.notify( $PRJNFY_OPEN )
163 return 1
164 }
165
166 /*-----------------------------------------------------------------------------
167 *
168 * ID: prj_save 12.10.06 1.1.A.
169 *
170 * Summary: Save a project
171 *
172 -----------------------------------------------------------------------------*/
173
174
175 method uint prj.save()
176 {
177 str data script
178 /* subfunc str getedit( str name )
179 {
180 name = this[ name ]
181 if name[0] == '<' || name[0] == '"' || name[0] == '''
182 {
183 name.insert( 0, "*" )
184 }
185 return name
186 }*/
187 // gt2save gt2s
188
189 if !this.opened || !*this.filename : return 0
190
191 // gt2s.offstep = 3
192 // gt2s.inside = 0
193 // gt2s.endname = 0
194
195 // this.write( this.filename, gt2s )
196 /*
197 data = "<project version = 1 program = Scriptius >
198 <name>\( getedit( "name" ))</>
199 <runshell>\( getedit( "runshell" ))</>
200 <recompile>\( getedit( "recompile" ))</>
201 <exe>\( getedit( "exe" ))</>
202 <icon>\( getedit( "icon" ))</>
203 <autoexe>\( getedit( "autoexe" ))</>
204 <savelog>\( getedit( "savelog" ))</>
205 <check1>\( getedit( "check1" ))</>
206 <check2>\( getedit( "check2" ))</>
207 <script>\( prjrw_getlist( script ))</>
208 </>"
209
210 data.write( this.filename )
211 */
212 if this.changed
213 {
214 this.changed = 0
215 this.notify( $PRJNFY_CHANGE )
216 }
217 return 1
218 }
219
220 /*-----------------------------------------------------------------------------
221 *
222 * ID: prj_save 12.10.06 1.1.A.
223 *
224 * Summary: Save a project to the filename
225 *
226 -----------------------------------------------------------------------------*/
227
228 method uint prj.save( str filename )
229 {
230 uint ret
231
232 this.filename = filename
233 ret = this.save()
234 this.notify( $PRJNFY_NAME )
235 return ret
236 }
237
238 /*-----------------------------------------------------------------------------
239 *
240 * ID: prj_index 12.10.06 1.1.A.
241 *
242 * Summary:
243 *
244 -----------------------------------------------------------------------------*/
245
246 method uint prj.index( str name )
247 {
248 uint gti
249
250 gti as this.find( "project/\(name)" )
251 if >i : return >i.val[ 0 ].value
252 prjempty.clear()
253 return &prjempty
254 }
255
256 /*-----------------------------------------------------------------------------
257 *
258 * ID: prj_set 12.10.06 1.1.A.
259 *
260 * Summary: Set a project value
261 *
262 -----------------------------------------------------------------------------*/
263
264 method prj.set( str name value )
265 {
266 uint sti
267
268 sti as this[ name ]
269 if &sti
270 {
271 sti = value
272 if !this.changed
273 {
274 this.changed = 1
275 this.notify( $PRJNFY_CHANGE )
276 }
277 }
278 }
279
280 /*-----------------------------------------------------------------------------
281 *
282 * ID: prj_set 12.10.06 1.1.A.
283 *
284 * Summary: Set a project value
285 *
286 -----------------------------------------------------------------------------*/
287
288 method prj.set( gtitem gti, str value )
289 {
290 gti.value() = value
291 if !this.changed
292 {
293 this.changed = 1
294 this.notify( $PRJNFY_CHANGE )
295 }
296 }
297
298 /*-----------------------------------------------------------------------------
299 *
300 * ID: prj_insert 12.10.06 1.1.A.
301 *
302 * Summary: Insert project items
303 *
304 -----------------------------------------------------------------------------*/
305
306 method gtitem prj.insert( str data, gtitem parent after )
307 {
308 uint ret
309
310 // ret as parent.load( data, after )
311 if !this.changed
312 {
313 this.changed = 1
314 this.notify( $PRJNFY_CHANGE )
315 }
316
317 return ret->gtitem
318 }
319
320 /*-----------------------------------------------------------------------------
321 *
322 * ID: prj_moveup 12.10.06 1.1.A.
323 *
324 * Summary: Move the project item up
325 *
326 -----------------------------------------------------------------------------*/
327
328 method gtitem prj.moveup( gtitem cur )
329 {
330 /* if cur.moveup() && !this.changed
331 {
332 this.changed = 1
333 this.notify( $PRJNFY_CHANGE )
334 }*/
335 return cur
336 }
337
338 /*-----------------------------------------------------------------------------
339 *
340 * ID: prj_movedown 12.10.06 1.1.A.
341 *
342 * Summary: Move the project item down
343 *
344 -----------------------------------------------------------------------------*/
345
346 method gtitem prj.movedown( gtitem cur )
347 {
348 /* if cur.movedown() && !this.changed
349 {
350 this.changed = 1
351 this.notify( $PRJNFY_CHANGE )
352 }*/
353 return cur
354 }
355
356 /*-----------------------------------------------------------------------------
357 *
358 * ID: prj_disable 12.10.06 1.1.A.
359 *
360 * Summary: Move the project item down
361 *
362 -----------------------------------------------------------------------------*/
363
364 method uint prj.disable( gtitem gti, uint state )
365 {
366 // if state : gti.setattrib( "disable" )
367 // else : gti.delattrib( "disable" )
368
369 if !this.changed
370 {
371 this.changed = 1
372 this.notify( $PRJNFY_CHANGE )
373 }
374 return 1
375 }
376
377 /*-----------------------------------------------------------------------------
378 *
379 * ID: prj_disable 12.10.06 1.1.A.
380 *
381 * Summary: Move the project item down
382 *
383 -----------------------------------------------------------------------------*/
384
385 method uint prj.del( gtitem gti )
386 {
387 gti.del()
388
389 if !this.changed
390 {
391 this.changed = 1
392 this.notify( $PRJNFY_CHANGE )
393 }
394 return 1
395 }
Редактировать