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 | const char *AWAR_TREE_NAME1 = "tmp/merge1/tree_name"; |
---|
12 | const char *AWAR_TREE_DEST1 = "tmp/merge1/tree_dest"; |
---|
13 | const char *AWAR_TREE_NAME2 = "tmp/merge2/tree_name"; |
---|
14 | const char *AWAR_TREE_DEST2 = "tmp/merge2/tree_dest"; |
---|
15 | |
---|
16 | void MG_create_trees_awar(AW_root *aw_root, AW_default aw_def) |
---|
17 | { |
---|
18 | aw_root->awar_string( AWAR_TREE_NAME1, "" , aw_def); |
---|
19 | aw_root->awar_string( AWAR_TREE_DEST1, "" , aw_def); |
---|
20 | aw_root->awar_string( AWAR_TREE_NAME2, "" , aw_def); |
---|
21 | aw_root->awar_string( AWAR_TREE_DEST2, "" , aw_def); |
---|
22 | } |
---|
23 | |
---|
24 | void MG_tree_rename_cb(AW_window *aww,GBDATA *gbd, int tree_nr){ |
---|
25 | |
---|
26 | GB_ERROR error = 0; |
---|
27 | char tsource[256]; |
---|
28 | char tdest[256]; |
---|
29 | sprintf(tsource,"tmp/merge%i/tree_name",tree_nr); |
---|
30 | sprintf(tdest,"tmp/merge%i/tree_dest",tree_nr); |
---|
31 | |
---|
32 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
33 | char *dest = aww->get_root()->awar(tdest)->read_string(); |
---|
34 | error = GBT_check_tree_name(dest); |
---|
35 | if (!error) { |
---|
36 | GB_begin_transaction(gbd); |
---|
37 | GBDATA *gb_tree_data = |
---|
38 | GB_search(gbd,"tree_data",GB_CREATE_CONTAINER); |
---|
39 | GBDATA *gb_tree_name = |
---|
40 | GB_find(gb_tree_data,source,0,down_level); |
---|
41 | GBDATA *gb_dest_tree = |
---|
42 | GB_find(gb_tree_data,dest,0,down_level); |
---|
43 | if (gb_dest_tree) { |
---|
44 | error = "Sorry: Tree already exists"; |
---|
45 | }else if (gb_tree_name) { |
---|
46 | GBDATA *gb_new_tree = GB_create_container(gb_tree_data,dest); |
---|
47 | GB_copy(gb_new_tree, gb_tree_name); |
---|
48 | error = GB_delete(gb_tree_name); |
---|
49 | }else{ |
---|
50 | error = "Please select a tree first"; |
---|
51 | } |
---|
52 | if (!error) GB_commit_transaction(gbd); |
---|
53 | else GB_abort_transaction(gbd); |
---|
54 | } |
---|
55 | if (error) aw_message(error); |
---|
56 | else aww->hide(); |
---|
57 | delete source; |
---|
58 | delete dest; |
---|
59 | } |
---|
60 | |
---|
61 | AW_window *MG_create_tree_rename_window1(AW_root *root) |
---|
62 | { |
---|
63 | AW_window_simple *aws = new AW_window_simple; |
---|
64 | aws->init( root, "MERGE_RENAME_TREE_1", "TREE RENAME 1", 100, 100 ); |
---|
65 | aws->load_xfig("ad_al_si.fig"); |
---|
66 | |
---|
67 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
68 | aws->at("close"); |
---|
69 | aws->create_button("CLOSE","CLOSE","C"); |
---|
70 | |
---|
71 | aws->at("label"); |
---|
72 | aws->create_button(0,"Please enter the new name\nof the tree"); |
---|
73 | |
---|
74 | aws->at("input"); |
---|
75 | aws->create_input_field(AWAR_TREE_DEST1,15); |
---|
76 | |
---|
77 | aws->at("ok"); |
---|
78 | aws->callback((AW_CB)MG_tree_rename_cb,(AW_CL)gb_merge,1); |
---|
79 | aws->create_button("GO","GO","G"); |
---|
80 | |
---|
81 | return (AW_window *)aws; |
---|
82 | } |
---|
83 | |
---|
84 | AW_window *MG_create_tree_rename_window2(AW_root *root) |
---|
85 | { |
---|
86 | AW_window_simple *aws = new AW_window_simple; |
---|
87 | aws->init( root, "MERGE_RENAME_TREE_2", "TREE RENAME 2", 100, 100 ); |
---|
88 | aws->load_xfig("ad_al_si.fig"); |
---|
89 | |
---|
90 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
91 | aws->at("close"); |
---|
92 | aws->create_button("CLOSE","CLOSE","C"); |
---|
93 | |
---|
94 | aws->at("label"); |
---|
95 | aws->create_button(0,"Please enter the new name\nof the tree"); |
---|
96 | |
---|
97 | aws->at("input"); |
---|
98 | aws->create_input_field(AWAR_TREE_DEST2,15); |
---|
99 | |
---|
100 | aws->at("ok"); |
---|
101 | aws->callback((AW_CB)MG_tree_rename_cb,(AW_CL)gb_dest,2); |
---|
102 | aws->create_button("GO","GO","G"); |
---|
103 | |
---|
104 | return (AW_window *)aws; |
---|
105 | } |
---|
106 | void MG_tr_delete_cb(AW_window *aww,GBDATA *gbd, long tree_nr){ |
---|
107 | GB_ERROR error = 0; |
---|
108 | char tsource[256]; |
---|
109 | sprintf(tsource,"tmp/merge%li/tree_name",tree_nr); |
---|
110 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
111 | GB_begin_transaction(gbd); |
---|
112 | GBDATA *gb_tree_data = |
---|
113 | GB_search(gbd,"tree_data",GB_CREATE_CONTAINER); |
---|
114 | GBDATA *gb_tree_name = |
---|
115 | GB_find(gb_tree_data,source,0,down_level); |
---|
116 | if (gb_tree_name) { |
---|
117 | error = GB_delete(gb_tree_name); |
---|
118 | }else{ |
---|
119 | error = "Please select a tree first"; |
---|
120 | } |
---|
121 | |
---|
122 | if (!error) GB_commit_transaction(gbd); |
---|
123 | else GB_abort_transaction(gbd); |
---|
124 | |
---|
125 | if (error) aw_message(error); |
---|
126 | delete source; |
---|
127 | } |
---|
128 | void MG_transfer_tree(AW_window *aww){ |
---|
129 | AW_root *awr = aww->get_root(); |
---|
130 | char *source = awr->awar(AWAR_TREE_NAME1)->read_string(); |
---|
131 | char *dest = awr->awar(AWAR_TREE_NAME1)->read_string(); |
---|
132 | GB_ERROR error = 0; |
---|
133 | GB_begin_transaction(gb_dest); |
---|
134 | GB_begin_transaction(gb_merge); |
---|
135 | |
---|
136 | GBDATA *gb_tree_data1 = |
---|
137 | GB_search(gb_merge,"tree_data",GB_CREATE_CONTAINER); |
---|
138 | GBDATA *gb_tree_data2 = |
---|
139 | GB_search(gb_dest,"tree_data",GB_CREATE_CONTAINER); |
---|
140 | GBDATA *gb_source = |
---|
141 | GB_find(gb_tree_data1,dest,0,down_level); |
---|
142 | GBDATA *gb_dest_tree = |
---|
143 | GB_find(gb_tree_data2,dest,0,down_level); |
---|
144 | |
---|
145 | if (!gb_source) error = "Please select a tree you want to transfer !!!"; |
---|
146 | else if(gb_dest_tree) { |
---|
147 | error = "Sorry, You cannot destroy an old tree, delete it first"; |
---|
148 | }else{ |
---|
149 | gb_dest_tree = GB_create_container(gb_tree_data2,dest); |
---|
150 | error = GB_copy(gb_dest_tree,gb_source); |
---|
151 | } |
---|
152 | |
---|
153 | if (!error) { |
---|
154 | GB_commit_transaction(gb_dest); |
---|
155 | GB_commit_transaction(gb_merge); |
---|
156 | }else{ |
---|
157 | GB_abort_transaction(gb_dest); |
---|
158 | GB_abort_transaction(gb_merge); |
---|
159 | } |
---|
160 | if (error) aw_message(error); |
---|
161 | delete source; |
---|
162 | delete dest; |
---|
163 | } |
---|
164 | |
---|
165 | AW_window *MG_merge_trees_cb(AW_root *awr){ |
---|
166 | static AW_window_simple *aws = 0; |
---|
167 | if (aws) return (AW_window *)aws; |
---|
168 | |
---|
169 | aws = new AW_window_simple; |
---|
170 | aws->init( awr, "MERGE_TREES", "MERGE TREES", 10, 10 ); |
---|
171 | aws->load_xfig("merge/trees.fig"); |
---|
172 | |
---|
173 | aws->button_length(20); |
---|
174 | |
---|
175 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
176 | aws->create_button("CLOSE","CLOSE","C"); |
---|
177 | |
---|
178 | aws->at("help"); |
---|
179 | aws->callback(AW_POPUP_HELP,(AW_CL)"mg_trees.hlp"); |
---|
180 | aws->create_button("HELP","HELP","H"); |
---|
181 | |
---|
182 | aws->at("trees1"); |
---|
183 | awt_create_selection_list_on_trees(gb_merge,(AW_window *)aws,AWAR_TREE_NAME1); |
---|
184 | |
---|
185 | aws->at("trees2"); |
---|
186 | awt_create_selection_list_on_trees(gb_dest,(AW_window *)aws,AWAR_TREE_NAME2); |
---|
187 | |
---|
188 | aws->at("delete1"); |
---|
189 | aws->callback((AW_CB)MG_tr_delete_cb,(AW_CL)gb_merge,1); |
---|
190 | aws->create_button("DELETE TREE_DB1", "Delete Tree"); |
---|
191 | |
---|
192 | aws->at("delete2"); |
---|
193 | aws->callback((AW_CB)MG_tr_delete_cb,(AW_CL)gb_dest,2); |
---|
194 | aws->create_button("DELETE_TREE_DB2", "Delete Tree"); |
---|
195 | |
---|
196 | aws->at("rename1"); |
---|
197 | aws->callback((AW_CB1)AW_POPUP,(AW_CL)MG_create_tree_rename_window1); |
---|
198 | aws->create_button("RENAME_TREE_DB1", "Rename Tree"); |
---|
199 | |
---|
200 | aws->at("rename2"); |
---|
201 | aws->callback((AW_CB1)AW_POPUP,(AW_CL)MG_create_tree_rename_window2); |
---|
202 | aws->create_button("RENAME_TREE_DB2", "Rename Tree"); |
---|
203 | |
---|
204 | aws->at("transfer"); |
---|
205 | aws->callback(MG_transfer_tree); |
---|
206 | aws->create_button("TRANSFER_TREE", "Transfer Tree"); |
---|
207 | |
---|
208 | aws->button_length(0); |
---|
209 | aws->shadow_width(1); |
---|
210 | aws->at("icon"); |
---|
211 | aws->callback(AW_POPUP_HELP,(AW_CL)"mg_trees.hlp"); |
---|
212 | aws->create_button("HELP_MERGE", "#merge/icon.bitmap"); |
---|
213 | |
---|
214 | return (AW_window *)aws; |
---|
215 | } |
---|
216 | |
---|