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