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 <awt_sel_boxes.hxx> |
---|
18 | #include <awt_prompt.hxx> |
---|
19 | |
---|
20 | #include <aw_root.hxx> |
---|
21 | #include <aw_awar.hxx> |
---|
22 | #include <aw_msg.hxx> |
---|
23 | |
---|
24 | #include <ad_config.h> |
---|
25 | #include <arbdb.h> |
---|
26 | |
---|
27 | #define AWAR_CONFIG_NAME_SRC AWAR_MERGE_TMP_SRC "name" |
---|
28 | #define AWAR_CONFIG_NAME_DST AWAR_MERGE_TMP_DST "name" |
---|
29 | #define AWAR_CONFIG_NAME(db) awar_name_tmp(db, "name") |
---|
30 | |
---|
31 | void MG_create_config_awar(AW_root *aw_root, AW_default aw_def) { |
---|
32 | aw_root->awar_string(AWAR_CONFIG_NAME_SRC, "", aw_def); |
---|
33 | aw_root->awar_string(AWAR_CONFIG_NAME_DST, "", aw_def); |
---|
34 | } |
---|
35 | |
---|
36 | static GB_ERROR config_rename_handler(const char *dest, DbSel db) { |
---|
37 | GBDATA *gb_main = get_gb_main(db); |
---|
38 | const char *source = AW_root::SINGLETON->awar(AWAR_CONFIG_NAME(db))->read_char_pntr(); |
---|
39 | |
---|
40 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
41 | if (!error) { |
---|
42 | GBDATA *gb_config_data = GB_search(gb_main, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
43 | if (!gb_config_data) error = GB_await_error(); |
---|
44 | else { |
---|
45 | GBDATA *gb_dest_name = GB_find_string(gb_config_data, "name", dest, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
46 | if (gb_dest_name) error = GBS_global_string("Configuration '%s' already exists", dest); |
---|
47 | else { |
---|
48 | GBDATA *gb_source_name = GB_find_string(gb_config_data, "name", source, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
49 | if (gb_source_name) error = GB_write_string(gb_source_name, dest); |
---|
50 | else error = "Please select a configuration"; |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
54 | error = GB_end_transaction(gb_main, error); |
---|
55 | return error; |
---|
56 | } |
---|
57 | |
---|
58 | static void config_rename_cb(AW_window *aww, DbSel db) { |
---|
59 | const char *source = aww->get_root()->awar(AWAR_CONFIG_NAME(db))->read_char_pntr(); |
---|
60 | ResultHandler handler = makeResultHandler(config_rename_handler, db); |
---|
61 | AWT_activate_prompt("Rename configuration", "Enter new name of configuration:", source, "Rename", handler); |
---|
62 | } |
---|
63 | |
---|
64 | static void MG_config_delete_cb(AW_window *aww, DbSel db) { |
---|
65 | char *config_name = aww->get_root()->awar(AWAR_CONFIG_NAME(db))->read_string(); |
---|
66 | GBDATA *gb_main = get_gb_main(db); |
---|
67 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
68 | |
---|
69 | if (!error) { |
---|
70 | GBDATA *gb_config_data = GB_search(gb_main, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
71 | GBDATA *gb_config_name = GB_find_string(gb_config_data, "name", config_name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
72 | |
---|
73 | if (gb_config_name) { |
---|
74 | GBDATA *gb_config = GB_get_father(gb_config_name); |
---|
75 | error = GB_delete(gb_config); |
---|
76 | } |
---|
77 | else { |
---|
78 | error = "Select a config to delete"; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | GB_end_transaction_show_error(gb_main, error, aw_message); |
---|
83 | |
---|
84 | free(config_name); |
---|
85 | } |
---|
86 | |
---|
87 | static void MG_transfer_config(AW_window *aww) { |
---|
88 | AW_root *awr = aww->get_root(); |
---|
89 | char *config = awr->awar(AWAR_CONFIG_NAME_SRC)->read_string(); |
---|
90 | |
---|
91 | GB_ERROR error = GB_begin_transaction(GLOBAL_gb_dst); |
---|
92 | if (!error) { |
---|
93 | error = GB_begin_transaction(GLOBAL_gb_src); |
---|
94 | if (!error) { |
---|
95 | GBDATA *gb_src_config_data = GB_search(GLOBAL_gb_src, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
96 | GBDATA *gb_dst_config_data = GB_search(GLOBAL_gb_dst, CONFIG_DATA_PATH, GB_CREATE_CONTAINER); |
---|
97 | |
---|
98 | GBDATA *gb_src_cfgname = GB_find_string(gb_src_config_data, "name", config, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
99 | GBDATA *gb_dst_cfgname = GB_find_string(gb_dst_config_data, "name", config, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
100 | |
---|
101 | if (!gb_src_cfgname) { |
---|
102 | error = "Please select the configuration you want to transfer"; |
---|
103 | } |
---|
104 | else if (gb_dst_cfgname) { |
---|
105 | error = GBS_global_string("Configuration '%s' exists. Delete it first.", config); |
---|
106 | } |
---|
107 | else { |
---|
108 | GBDATA *gb_src_cfg = GB_get_father(gb_src_cfgname); |
---|
109 | GBDATA *gb_dst_cfg = GB_create_container(gb_dst_config_data, "configuration"); |
---|
110 | error = GB_copy_dropProtectMarksAndTempstate(gb_dst_cfg, gb_src_cfg); |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | error = GB_end_transaction(GLOBAL_gb_src, error); |
---|
115 | error = GB_end_transaction(GLOBAL_gb_dst, error); |
---|
116 | |
---|
117 | if (error) aw_message(error); |
---|
118 | |
---|
119 | free(config); |
---|
120 | } |
---|
121 | |
---|
122 | AW_window *MG_create_merge_configs_window(AW_root *awr) { |
---|
123 | GB_ERROR error = MG_expect_renamed(); |
---|
124 | if (error) { |
---|
125 | aw_message(error); |
---|
126 | return NULp; // deny to open window before user has renamed species |
---|
127 | } |
---|
128 | |
---|
129 | AW_window_simple *aws = new AW_window_simple; |
---|
130 | |
---|
131 | aws->init(awr, "MERGE_CONFIGS", "Merge species selections (=editor configs)"); |
---|
132 | aws->load_xfig("merge/configs.fig"); |
---|
133 | |
---|
134 | aws->button_length(20); |
---|
135 | |
---|
136 | aws->at("close"); |
---|
137 | aws->callback(AW_POPDOWN); |
---|
138 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
139 | |
---|
140 | aws->at("help"); |
---|
141 | aws->callback(makeHelpCallback("mg_species_configs.hlp")); |
---|
142 | aws->create_button("HELP", "HELP", "H"); |
---|
143 | |
---|
144 | aws->at("configs1"); |
---|
145 | awt_create_CONFIG_selection_list(GLOBAL_gb_src, aws, AWAR_CONFIG_NAME_SRC); |
---|
146 | |
---|
147 | aws->at("configs2"); |
---|
148 | awt_create_CONFIG_selection_list(GLOBAL_gb_dst, aws, AWAR_CONFIG_NAME_DST); |
---|
149 | |
---|
150 | aws->at("delete1"); |
---|
151 | aws->callback(makeWindowCallback(MG_config_delete_cb, SRC_DB)); |
---|
152 | aws->create_button("DELETE CONFIG_DB1", "Delete Config"); |
---|
153 | |
---|
154 | aws->at("delete2"); |
---|
155 | aws->callback(makeWindowCallback(MG_config_delete_cb, DST_DB)); |
---|
156 | aws->create_button("DELETE_CONFIG_DB2", "Delete Config"); |
---|
157 | |
---|
158 | aws->at("rename1"); |
---|
159 | aws->callback(makeWindowCallback(config_rename_cb, SRC_DB)); |
---|
160 | aws->create_button("RENAME_CONFIG_DB1", "Rename Config"); |
---|
161 | |
---|
162 | aws->at("rename2"); |
---|
163 | aws->callback(makeWindowCallback(config_rename_cb, DST_DB)); |
---|
164 | aws->create_button("RENAME_CONFIG_DB2", "Rename Config"); |
---|
165 | |
---|
166 | aws->at("transfer"); |
---|
167 | aws->callback(MG_transfer_config); |
---|
168 | aws->create_button("TRANSFER_CONFIG", "Transfer Config"); |
---|
169 | |
---|
170 | aws->button_length(0); |
---|
171 | aws->shadow_width(1); |
---|
172 | aws->at("icon"); |
---|
173 | aws->callback(makeHelpCallback("mg_species_configs.hlp")); |
---|
174 | aws->create_button("HELP_MERGE", "#merge/icon.xpm"); |
---|
175 | |
---|
176 | return aws; |
---|
177 | } |
---|
178 | |
---|
179 | |
---|