1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : MG_configs.cxx // |
---|
4 | // Purpose : Merge editor configurations // |
---|
5 | // // |
---|
6 | // // |
---|
7 | // Coded by Ralf Westram (coder@reallysoft.de) in July 2003 // |
---|
8 | // Copyright Department of Microbiology (Technical University Munich) // |
---|
9 | // // |
---|
10 | // Visit our web site at: http://www.arb-home.de/ // |
---|
11 | // // |
---|
12 | // // |
---|
13 | // ==================================================================== // |
---|
14 | |
---|
15 | #include "merge.hxx" |
---|
16 | |
---|
17 | #include <ad_config.h> |
---|
18 | #include <arbdb.h> |
---|
19 | #include <awt_sel_boxes.hxx> |
---|
20 | #include <aw_root.hxx> |
---|
21 | #include <aw_awar.hxx> |
---|
22 | #include <aw_msg.hxx> |
---|
23 | |
---|
24 | #define AWAR_CONFIG_NAME_SRC AWAR_MERGE_TMP_SRC "name" |
---|
25 | #define AWAR_CONFIG_NAME_DST AWAR_MERGE_TMP_DST "name" |
---|
26 | #define AWAR_CONFIG_NEWNAME AWAR_MERGE_TMP "newname" |
---|
27 | |
---|
28 | void MG_create_config_awar(AW_root *aw_root, AW_default aw_def) |
---|
29 | { |
---|
30 | aw_root->awar_string(AWAR_CONFIG_NAME_SRC, "", aw_def); |
---|
31 | aw_root->awar_string(AWAR_CONFIG_NAME_DST, "", aw_def); |
---|
32 | aw_root->awar_string(AWAR_CONFIG_NEWNAME, "", aw_def); |
---|
33 | } |
---|
34 | |
---|
35 | static void MG_config_rename_cb(AW_window *aww, GBDATA *gbd, int db_nr) { |
---|
36 | const char *tsource = db_nr == 1 ? AWAR_CONFIG_NAME_SRC : AWAR_CONFIG_NAME_DST; |
---|
37 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
38 | char *dest = aww->get_root()->awar(AWAR_CONFIG_NEWNAME)->read_string(); |
---|
39 | |
---|
40 | GB_ERROR error = GB_check_key(dest); |
---|
41 | if (!error) { |
---|
42 | error = GB_begin_transaction(gbd); |
---|
43 | if (!error) { |
---|
44 | GBDATA *gb_config_data = GB_search(gbd, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
45 | if (!gb_config_data) error = GB_await_error(); |
---|
46 | else { |
---|
47 | GBDATA *gb_dest_name = GB_find_string(gb_config_data, "name", dest, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
48 | if (gb_dest_name) error = GBS_global_string("Configuration '%s' already exists", dest); |
---|
49 | else { |
---|
50 | GBDATA *gb_source_name = GB_find_string(gb_config_data, "name", source, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
51 | if (gb_source_name) error = GB_write_string(gb_source_name, dest); |
---|
52 | else error = "Please select a configuration"; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | error = GB_end_transaction(gbd, error); |
---|
57 | } |
---|
58 | |
---|
59 | aww->hide_or_notify(error); |
---|
60 | |
---|
61 | free(source); |
---|
62 | free(dest); |
---|
63 | } |
---|
64 | |
---|
65 | static AW_window *MG_create_config_rename_window(AW_root *root, int db_nr) { |
---|
66 | AW_window_simple *aws = new AW_window_simple; |
---|
67 | if (db_nr == 1) { |
---|
68 | aws->init(root, "MERGE_RENAME_CONFIG_1", "CONFIGURATION RENAME 1"); |
---|
69 | } |
---|
70 | else { |
---|
71 | aws->init(root, "MERGE_RENAME_CONFIG_2", "CONFIGURATION RENAME 2"); |
---|
72 | } |
---|
73 | aws->load_xfig("ad_al_si.fig"); |
---|
74 | |
---|
75 | aws->at("close"); |
---|
76 | aws->callback(AW_POPDOWN); |
---|
77 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
78 | |
---|
79 | aws->at("label"); |
---|
80 | aws->create_autosize_button(0, "Please enter the new name\nof the configuration"); |
---|
81 | |
---|
82 | aws->at("input"); |
---|
83 | aws->create_input_field(AWAR_CONFIG_NEWNAME, 15); |
---|
84 | |
---|
85 | aws->at("ok"); |
---|
86 | aws->callback(makeWindowCallback(MG_config_rename_cb, GLOBAL_gb_dst, db_nr)); |
---|
87 | aws->create_button("GO", "GO", "G"); |
---|
88 | |
---|
89 | return aws; |
---|
90 | } |
---|
91 | |
---|
92 | static void MG_config_delete_cb(AW_window *aww, int db_nr) { |
---|
93 | const char *config_name_awar = db_nr == 1 ? AWAR_CONFIG_NAME_SRC : AWAR_CONFIG_NAME_DST; |
---|
94 | char *config_name = aww->get_root()->awar(config_name_awar)->read_string(); |
---|
95 | |
---|
96 | GBDATA *gb_main = get_gb_main(db_nr); |
---|
97 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
98 | |
---|
99 | if (!error) { |
---|
100 | GBDATA *gb_config_data = GB_search(gb_main, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
101 | GBDATA *gb_config_name = GB_find_string(gb_config_data, "name", config_name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
102 | |
---|
103 | if (gb_config_name) { |
---|
104 | GBDATA *gb_config = GB_get_father(gb_config_name); |
---|
105 | error = GB_delete(gb_config); |
---|
106 | } |
---|
107 | else { |
---|
108 | error = "Select a config to delete"; |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | GB_end_transaction_show_error(gb_main, error, aw_message); |
---|
113 | |
---|
114 | free(config_name); |
---|
115 | } |
---|
116 | |
---|
117 | static void MG_transfer_config(AW_window *aww) { |
---|
118 | AW_root *awr = aww->get_root(); |
---|
119 | char *source = awr->awar(AWAR_CONFIG_NAME_SRC)->read_string(); |
---|
120 | char *dest = awr->awar(AWAR_CONFIG_NAME_SRC)->read_string(); |
---|
121 | |
---|
122 | GB_ERROR error = GB_begin_transaction(GLOBAL_gb_dst); |
---|
123 | if (!error) { |
---|
124 | error = GB_begin_transaction(GLOBAL_gb_src); |
---|
125 | if (!error) { |
---|
126 | GBDATA *gb_src_config_data = GB_search(GLOBAL_gb_src, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
127 | GBDATA *gb_dst_config_data = GB_search(GLOBAL_gb_dst, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
128 | GBDATA *gb_src_cfgname = GB_find_string(gb_src_config_data, "name", source, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
129 | GBDATA *gb_dst_cfgname = GB_find_string(gb_dst_config_data, "name", dest, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
130 | |
---|
131 | if (!gb_src_cfgname) { |
---|
132 | error = "Please select the configuration you want to transfer"; |
---|
133 | } |
---|
134 | else if (gb_dst_cfgname) { |
---|
135 | error = "To overwrite a configuration, delete it first!"; |
---|
136 | } |
---|
137 | else { |
---|
138 | GBDATA *gb_src_cfg = GB_get_father(gb_src_cfgname); |
---|
139 | GBDATA *gb_dst_cfg = GB_create_container(gb_dst_config_data, "configuration"); |
---|
140 | error = GB_copy(gb_dst_cfg, gb_src_cfg); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | error = GB_end_transaction(GLOBAL_gb_src, error); |
---|
145 | error = GB_end_transaction(GLOBAL_gb_dst, error); |
---|
146 | |
---|
147 | if (error) aw_message(error); |
---|
148 | |
---|
149 | free(source); |
---|
150 | free(dest); |
---|
151 | } |
---|
152 | |
---|
153 | AW_window *MG_create_merge_configs_window(AW_root *awr) { |
---|
154 | GB_ERROR error = MG_expect_renamed(); |
---|
155 | if (error) { |
---|
156 | aw_message(error); |
---|
157 | return NULL; // deny to open window before user has renamed species |
---|
158 | } |
---|
159 | |
---|
160 | AW_window_simple *aws = new AW_window_simple; |
---|
161 | |
---|
162 | aws->init(awr, "MERGE_CONFIGS", "Merge species selections (=editor configs)"); |
---|
163 | aws->load_xfig("merge/configs.fig"); |
---|
164 | |
---|
165 | aws->button_length(20); |
---|
166 | |
---|
167 | aws->at("close"); |
---|
168 | aws->callback(AW_POPDOWN); |
---|
169 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
170 | |
---|
171 | aws->at("help"); |
---|
172 | aws->callback(makeHelpCallback("mg_species_configs.hlp")); |
---|
173 | aws->create_button("HELP", "HELP", "H"); |
---|
174 | |
---|
175 | aws->at("configs1"); |
---|
176 | awt_create_CONFIG_selection_list(GLOBAL_gb_src, aws, AWAR_CONFIG_NAME_SRC, true); |
---|
177 | |
---|
178 | aws->at("configs2"); |
---|
179 | awt_create_CONFIG_selection_list(GLOBAL_gb_dst, aws, AWAR_CONFIG_NAME_DST, true); |
---|
180 | |
---|
181 | aws->at("delete1"); |
---|
182 | aws->callback(makeWindowCallback(MG_config_delete_cb, 1)); |
---|
183 | aws->create_button("DELETE CONFIG_DB1", "Delete Config"); |
---|
184 | |
---|
185 | aws->at("delete2"); |
---|
186 | aws->callback(makeWindowCallback(MG_config_delete_cb, 2)); |
---|
187 | aws->create_button("DELETE_CONFIG_DB2", "Delete Config"); |
---|
188 | |
---|
189 | aws->at("rename1"); |
---|
190 | aws->callback(makeCreateWindowCallback(MG_create_config_rename_window, 1)); |
---|
191 | aws->create_button("RENAME_CONFIG_DB1", "Rename Config"); |
---|
192 | |
---|
193 | aws->at("rename2"); |
---|
194 | aws->callback(makeCreateWindowCallback(MG_create_config_rename_window, 2)); |
---|
195 | aws->create_button("RENAME_CONFIG_DB2", "Rename Config"); |
---|
196 | |
---|
197 | aws->at("transfer"); |
---|
198 | aws->callback(MG_transfer_config); |
---|
199 | aws->create_button("TRANSFER_CONFIG", "Transfer Config"); |
---|
200 | |
---|
201 | aws->button_length(0); |
---|
202 | aws->shadow_width(1); |
---|
203 | aws->at("icon"); |
---|
204 | aws->callback(makeHelpCallback("mg_species_configs.hlp")); |
---|
205 | aws->create_button("HELP_MERGE", "#merge/icon.xpm"); |
---|
206 | |
---|
207 | return aws; |
---|
208 | } |
---|
209 | |
---|
210 | |
---|