1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <arbdb.h> |
---|
4 | #include <arbdbt.h> |
---|
5 | #include <aw_root.hxx> |
---|
6 | #include <aw_device.hxx> |
---|
7 | #include <aw_window.hxx> |
---|
8 | #include <awt.hxx> |
---|
9 | #include "merge.hxx" |
---|
10 | |
---|
11 | #define AWAR_EX_NAME1 "tmp/merge1/extended_name" |
---|
12 | #define AWAR_EX_DEST1 "tmp/merge1/extended_dest" |
---|
13 | #define AWAR_EX_NAME2 "tmp/merge2/extended_name" |
---|
14 | #define AWAR_EX_DEST2 "tmp/merge2/extended_dest" |
---|
15 | |
---|
16 | void MG_create_extendeds_var(AW_root *aw_root, AW_default aw_def) |
---|
17 | { |
---|
18 | aw_root->awar_string( AWAR_EX_NAME1, "" , aw_def); |
---|
19 | aw_root->awar_string( AWAR_EX_DEST1, "" , aw_def); |
---|
20 | aw_root->awar_string( AWAR_EX_NAME2, "" , aw_def); |
---|
21 | aw_root->awar_string( AWAR_EX_DEST2, "" , aw_def); |
---|
22 | } |
---|
23 | |
---|
24 | void MG_extended_rename_cb(AW_window *aww,GBDATA *gbmain, int ex_nr){ |
---|
25 | GB_ERROR error = 0; |
---|
26 | char tsource[256]; |
---|
27 | char tdest[256]; |
---|
28 | sprintf(tsource,"tmp/merge%i/extended_name",ex_nr); |
---|
29 | sprintf(tdest,"tmp/merge%i/extended_dest",ex_nr); |
---|
30 | |
---|
31 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
32 | char *dest = aww->get_root()->awar(tdest)->read_string(); |
---|
33 | GB_begin_transaction(gbmain); |
---|
34 | GBDATA *gb_extended_data =GB_search(gbmain,"extended_data",GB_CREATE_CONTAINER); |
---|
35 | GBDATA *gb_extended =GBT_find_SAI_rel_exdata(gb_extended_data,source); |
---|
36 | GBDATA *gb_dest_sai =GBT_find_SAI_rel_exdata(gb_extended_data,dest); |
---|
37 | if (gb_dest_sai) { |
---|
38 | error = "Sorry: SAI already exists"; |
---|
39 | }else if (gb_extended) { |
---|
40 | GBDATA *gb_name = |
---|
41 | GB_search(gb_extended,"name",GB_STRING); |
---|
42 | error = GB_write_string(gb_name,dest); |
---|
43 | }else{ |
---|
44 | error = "Please select a SAI first"; |
---|
45 | } |
---|
46 | if (!error) GB_commit_transaction(gbmain); |
---|
47 | else GB_abort_transaction(gbmain); |
---|
48 | if (error) aw_message(error); |
---|
49 | else aww->hide(); |
---|
50 | delete source; |
---|
51 | delete dest; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | AW_window *MG_create_extended_rename_window1(AW_root *root) |
---|
56 | { |
---|
57 | AW_window_simple *aws = new AW_window_simple; |
---|
58 | aws->init( root, "MERGE_RENAME_SAI_1", "SAI RENAME 1", 100, 100 ); |
---|
59 | aws->load_xfig("ad_al_si.fig"); |
---|
60 | |
---|
61 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
62 | aws->at("close"); |
---|
63 | aws->create_button("CLOSE","CLOSE","C"); |
---|
64 | |
---|
65 | aws->at("label"); |
---|
66 | aws->create_button(0,"Please enter the new name\nof the SAI"); |
---|
67 | |
---|
68 | aws->at("input"); |
---|
69 | aws->create_input_field(AWAR_EX_DEST1,15); |
---|
70 | |
---|
71 | aws->at("ok"); |
---|
72 | aws->callback((AW_CB)MG_extended_rename_cb,(AW_CL)gb_merge,1); |
---|
73 | aws->create_button("GO","GO","G"); |
---|
74 | |
---|
75 | return (AW_window *)aws; |
---|
76 | } |
---|
77 | |
---|
78 | AW_window *MG_create_extended_rename_window2(AW_root *root) |
---|
79 | { |
---|
80 | AW_window_simple *aws = new AW_window_simple; |
---|
81 | aws->init( root, "MERGE_RENAME_SAI_2", "SAI RENAME 2", 100, 100 ); |
---|
82 | aws->load_xfig("ad_al_si.fig"); |
---|
83 | |
---|
84 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
85 | aws->at("close"); |
---|
86 | aws->create_button("CLOSE","CLOSE","C"); |
---|
87 | |
---|
88 | aws->at("label"); |
---|
89 | aws->create_button(0,"Please enter the new name\nof the SAI"); |
---|
90 | |
---|
91 | aws->at("input"); |
---|
92 | aws->create_input_field(AWAR_EX_DEST2,15); |
---|
93 | |
---|
94 | aws->at("ok"); |
---|
95 | aws->callback((AW_CB)MG_extended_rename_cb,(AW_CL)gb_dest,2); |
---|
96 | aws->create_button("GO","GO","G"); |
---|
97 | |
---|
98 | return (AW_window *)aws; |
---|
99 | } |
---|
100 | |
---|
101 | void MG_extended_delete_cb(AW_window *aww, GBDATA *gbmain, int ex_nr){ |
---|
102 | GB_ERROR error = 0; |
---|
103 | char tsource[256]; |
---|
104 | sprintf(tsource,"tmp/merge%i/extended_name",ex_nr); |
---|
105 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
106 | GB_begin_transaction(gbmain); |
---|
107 | GBDATA *gb_extended = GBT_find_SAI(gbmain,source); |
---|
108 | |
---|
109 | if (gb_extended) { |
---|
110 | error = GB_delete(gb_extended); |
---|
111 | }else{ |
---|
112 | error = "Please select a SAI first"; |
---|
113 | } |
---|
114 | |
---|
115 | if (!error) GB_commit_transaction(gbmain); |
---|
116 | else GB_abort_transaction(gbmain); |
---|
117 | |
---|
118 | if (error) aw_message(error); |
---|
119 | delete source; |
---|
120 | } |
---|
121 | |
---|
122 | void MG_transfer_extended(AW_window *aww, AW_CL force){ |
---|
123 | AW_root *awr = aww->get_root(); |
---|
124 | char *source = awr->awar(AWAR_EX_NAME1)->read_string(); |
---|
125 | char *dest = awr->awar(AWAR_EX_NAME1)->read_string(); |
---|
126 | GB_ERROR error = 0; |
---|
127 | GB_begin_transaction(gb_dest); |
---|
128 | GB_begin_transaction(gb_merge); |
---|
129 | |
---|
130 | GBDATA *gb_source = GBT_find_SAI(gb_merge,dest); |
---|
131 | GBDATA *gb_extended_data2 = GB_search(gb_dest,"extended_data",GB_CREATE_CONTAINER); |
---|
132 | GBDATA *gb_dest_sai = GBT_find_SAI_rel_exdata(gb_extended_data2,dest); |
---|
133 | |
---|
134 | if (!gb_source) error = "Please select an SAI you want to transfer !!!"; |
---|
135 | else if(gb_dest_sai) { |
---|
136 | if (force) { |
---|
137 | error = GB_delete(gb_dest_sai); |
---|
138 | }else{ |
---|
139 | error = "Sorry, You cannot destroy an old SAI, delete it first"; |
---|
140 | } |
---|
141 | } |
---|
142 | if (!error) { |
---|
143 | gb_dest_sai = GB_create_container(gb_extended_data2,"extended"); |
---|
144 | error = GB_copy(gb_dest_sai,gb_source); |
---|
145 | } |
---|
146 | |
---|
147 | if (!error) { |
---|
148 | GB_commit_transaction(gb_dest); |
---|
149 | GB_commit_transaction(gb_merge); |
---|
150 | }else{ |
---|
151 | GB_abort_transaction(gb_dest); |
---|
152 | GB_abort_transaction(gb_merge); |
---|
153 | } |
---|
154 | if (error) aw_message(error); |
---|
155 | delete source; |
---|
156 | delete dest; |
---|
157 | } |
---|
158 | |
---|
159 | void MG_map_extended1(AW_root *aw_root, AW_CL scannerid) |
---|
160 | { |
---|
161 | char *source = aw_root->awar(AWAR_EX_NAME1)->read_string(); |
---|
162 | GB_push_transaction(gb_merge); |
---|
163 | GBDATA *gb_extended = GBT_find_SAI(gb_merge,source); |
---|
164 | awt_map_arbdb_scanner(scannerid,gb_extended,0); |
---|
165 | GB_pop_transaction(gb_merge); |
---|
166 | delete source; |
---|
167 | } |
---|
168 | void MG_map_extended2(AW_root *aw_root, AW_CL scannerid) |
---|
169 | { |
---|
170 | char *source = aw_root->awar(AWAR_EX_NAME2)->read_string(); |
---|
171 | GB_push_transaction(gb_dest); |
---|
172 | GBDATA *gb_extended = GBT_find_SAI(gb_dest,source); |
---|
173 | awt_map_arbdb_scanner(scannerid,gb_extended,0); |
---|
174 | GB_pop_transaction(gb_dest); |
---|
175 | delete source; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | AW_window *MG_merge_extendeds_cb(AW_root *awr){ |
---|
180 | static AW_window_simple *aws = 0; |
---|
181 | if (aws) return (AW_window *)aws; |
---|
182 | |
---|
183 | aws = new AW_window_simple; |
---|
184 | aws->init( awr, "MERGE_SAI", "MERGE SAI", 10, 10 ); |
---|
185 | aws->load_xfig("merge/extended.fig"); |
---|
186 | |
---|
187 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
188 | aws->create_button("CLOSE","CLOSE","C"); |
---|
189 | |
---|
190 | aws->at("help"); |
---|
191 | aws->callback(AW_POPUP_HELP,(AW_CL)"mg_extendeds.hlp"); |
---|
192 | aws->create_button("HELP","HELP","H"); |
---|
193 | |
---|
194 | aws->at("ex1"); |
---|
195 | awt_create_selection_list_on_extendeds(gb_merge,(AW_window *)aws,AWAR_EX_NAME1); |
---|
196 | AW_CL scannerid=awt_create_arbdb_scanner(gb_merge, aws, |
---|
197 | "info1",0,0,0,AWT_SCANNER,0,0,0); |
---|
198 | aws->get_root()->awar(AWAR_EX_NAME1)->add_callback( |
---|
199 | MG_map_extended1,scannerid); |
---|
200 | |
---|
201 | aws->at("ex2"); |
---|
202 | awt_create_selection_list_on_extendeds(gb_dest,(AW_window *)aws,AWAR_EX_NAME2); |
---|
203 | scannerid=awt_create_arbdb_scanner(gb_dest, aws, |
---|
204 | "info2",0,0,0,AWT_SCANNER,0,0,0); |
---|
205 | aws->get_root()->awar(AWAR_EX_NAME2)->add_callback( |
---|
206 | MG_map_extended2,scannerid); |
---|
207 | |
---|
208 | |
---|
209 | aws->button_length(20); |
---|
210 | |
---|
211 | aws->at("delete1"); |
---|
212 | aws->callback((AW_CB)MG_extended_delete_cb,(AW_CL)gb_merge,1); |
---|
213 | aws->create_button("DELETE_SAI_DB1", "Delete SAI"); |
---|
214 | |
---|
215 | aws->at("delete2"); |
---|
216 | aws->callback((AW_CB)MG_extended_delete_cb,(AW_CL)gb_dest,2); |
---|
217 | aws->create_button("DELETE_SAI_DB2", "Delete SAI"); |
---|
218 | |
---|
219 | aws->at("rename1"); |
---|
220 | aws->callback((AW_CB1)AW_POPUP,(AW_CL)MG_create_extended_rename_window1); |
---|
221 | aws->create_button("RENAME_SAI_DB1", "Rename SAI"); |
---|
222 | |
---|
223 | aws->at("rename2"); |
---|
224 | aws->callback((AW_CB1)AW_POPUP,(AW_CL)MG_create_extended_rename_window2); |
---|
225 | aws->create_button("RENAME_SAI_DB2", "Rename SAI"); |
---|
226 | |
---|
227 | aws->at("transfer"); |
---|
228 | aws->callback(MG_transfer_extended,0); |
---|
229 | aws->create_button("TRANSFER_SAI", "Transfer SAI"); |
---|
230 | |
---|
231 | aws->button_length(0); |
---|
232 | aws->shadow_width(1); |
---|
233 | aws->at("icon"); |
---|
234 | aws->callback(AW_POPUP_HELP,(AW_CL)"mg_extendeds.hlp"); |
---|
235 | aws->create_button("HELP_MERGE", "#merge/icon.bitmap"); |
---|
236 | |
---|
237 | return (AW_window *)aws; |
---|
238 | } |
---|