source: tags/svn.1.5.4/MERGE/MG_configs.cxx

Last change on this file was 8309, checked in by westram, 14 years ago
  • moved much code into static scope

(partly reverted by [8310])

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
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 <awt_sel_boxes.hxx>
19#include <aw_root.hxx>
20#include <aw_awar.hxx>
21#include <aw_msg.hxx>
22#include <arbdb.h>
23
24#define AWAR_CONFIG_NAME1 "tmp/merge1/config_name"
25#define AWAR_CONFIG_DEST1 "tmp/merge1/config_dest"
26#define AWAR_CONFIG_NAME2 "tmp/merge2/config_name"
27#define AWAR_CONFIG_DEST2 "tmp/merge2/config_dest"
28
29void MG_create_config_awar(AW_root *aw_root, AW_default aw_def)
30{
31    aw_root->awar_string(AWAR_CONFIG_NAME1, "",   aw_def);
32    aw_root->awar_string(AWAR_CONFIG_DEST1, "",   aw_def);
33    aw_root->awar_string(AWAR_CONFIG_NAME2, "",   aw_def);
34    aw_root->awar_string(AWAR_CONFIG_DEST2, "",   aw_def);
35}
36
37static void MG_config_rename_cb(AW_window *aww, GBDATA *gbd, int config_nr) {
38    const char *tsource = config_nr == 1 ? AWAR_CONFIG_NAME1 : AWAR_CONFIG_NAME2;
39    const char *tdest   = config_nr == 1 ? AWAR_CONFIG_DEST1 : AWAR_CONFIG_DEST2;
40    char       *source  = aww->get_root()->awar(tsource)->read_string();
41    char       *dest    = aww->get_root()->awar(tdest)->read_string();
42
43    GB_ERROR error = GB_check_key(dest);
44    if (!error) {
45        error = GB_begin_transaction(gbd);
46        if (!error) {
47            GBDATA *gb_config_data     = GB_search(gbd, CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
48            if (!gb_config_data) error = GB_await_error();
49            else {
50                GBDATA *gb_dest_name    = GB_find_string(gb_config_data, "name", dest, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
51                if (gb_dest_name) error = GBS_global_string("Configuration '%s' already exists", dest);
52                else {
53                    GBDATA *gb_source_name    = GB_find_string(gb_config_data, "name", source, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
54                    if (gb_source_name) error = GB_write_string(gb_source_name, dest);
55                    else    error             = "Please select a configuration";
56                }
57            }
58        }
59        error = GB_end_transaction(gbd, error);
60    }
61
62    aww->hide_or_notify(error);
63
64    free(source);
65    free(dest);
66}
67
68static AW_window *MG_create_config_rename_window1(AW_root *root) {
69    AW_window_simple *aws = new AW_window_simple;
70    aws->init(root, "MERGE_RENAME_CONFIG_1", "CONFIGURATION RENAME 1");
71    aws->load_xfig("ad_al_si.fig");
72
73    aws->callback((AW_CB0)AW_POPDOWN);
74    aws->at("close");
75    aws->create_button("CLOSE", "CLOSE", "C");
76
77    aws->at("label");
78    aws->create_autosize_button(0, "Please enter the new name\nof the configuration");
79
80    aws->at("input");
81    aws->create_input_field(AWAR_CONFIG_DEST1, 15);
82
83    aws->at("ok");
84    aws->callback((AW_CB)MG_config_rename_cb, (AW_CL)GLOBAL_gb_merge, 1);
85    aws->create_button("GO", "GO", "G");
86
87    return (AW_window *)aws;
88}
89
90static AW_window *MG_create_config_rename_window2(AW_root *root) {
91    AW_window_simple *aws = new AW_window_simple;
92    aws->init(root, "MERGE_RENAME_CONFIG_2", "CONFIGURATION RENAME 2");
93    aws->load_xfig("ad_al_si.fig");
94
95    aws->callback((AW_CB0)AW_POPDOWN);
96    aws->at("close");
97    aws->create_button("CLOSE", "CLOSE", "C");
98
99    aws->at("label");
100    aws->create_autosize_button(0, "Please enter the new name\nof the configuration");
101
102    aws->at("input");
103    aws->create_input_field(AWAR_CONFIG_DEST2, 15);
104
105    aws->at("ok");
106    aws->callback((AW_CB)MG_config_rename_cb, (AW_CL)GLOBAL_gb_dest, 2);
107    aws->create_button("GO", "GO", "G");
108
109    return (AW_window *)aws;
110}
111
112static void MG_config_delete_cb(AW_window *aww, GBDATA *gbd, long config_nr) {
113
114    const char *config_name_awar = config_nr == 1 ? AWAR_CONFIG_NAME1 : AWAR_CONFIG_NAME2;
115    char       *config_name      = aww->get_root()->awar(config_name_awar)->read_string();
116
117    GB_ERROR    error = GB_begin_transaction(gbd);
118
119    if (!error) {
120        GBDATA *gb_config_data = GB_search(gbd, CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
121        GBDATA *gb_config_name = GB_find_string(gb_config_data, "name", config_name, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
122
123        if (gb_config_name) {
124            GBDATA *gb_config = GB_get_father(gb_config_name);
125            error             = GB_delete(gb_config);
126        }
127        else {
128            error = "Select a config to delete";
129        }
130    }
131
132    GB_end_transaction_show_error(gbd, error, aw_message);
133
134    free(config_name);
135}
136
137static void MG_transfer_config(AW_window *aww) {
138    AW_root *awr    = aww->get_root();
139    char    *source = awr->awar(AWAR_CONFIG_NAME1)->read_string();
140    char    *dest   = awr->awar(AWAR_CONFIG_NAME1)->read_string();
141
142    GB_ERROR error = GB_begin_transaction(GLOBAL_gb_dest);
143    if (!error) {
144        error = GB_begin_transaction(GLOBAL_gb_merge);
145        if (!error) {
146            GBDATA *gb_config_data1 = GB_search(GLOBAL_gb_merge, CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
147            GBDATA *gb_config_data2 = GB_search(GLOBAL_gb_dest,  CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
148            GBDATA *gb_cfgname_1    = GB_find_string(gb_config_data1, "name", source, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
149            GBDATA *gb_cfgname_2    = GB_find_string(gb_config_data2, "name", dest,   GB_IGNORE_CASE, SEARCH_GRANDCHILD);
150
151            if (!gb_cfgname_1) {
152                error = "Please select the configuration you want to transfer";
153            }
154            else if (gb_cfgname_2) {
155                error = "To overwrite a configuration, delete it first!";
156            }
157            else {
158                GBDATA *gb_cfg_1 = GB_get_father(gb_cfgname_1);
159                GBDATA *gb_cfg_2 = GB_create_container(gb_config_data2, "configuration");
160                error            = GB_copy(gb_cfg_2, gb_cfg_1);
161            }
162        }
163    }
164    error = GB_end_transaction(GLOBAL_gb_merge, error);
165    error = GB_end_transaction(GLOBAL_gb_dest, error);
166
167    if (error) aw_message(error);
168
169    free(source);
170    free(dest);
171}
172
173AW_window *MG_merge_configs_cb(AW_root *awr) {
174    static AW_window_simple *aws = 0;
175    if (aws) return (AW_window *)aws;
176
177    aws = new AW_window_simple;
178    aws->init(awr, "MERGE_CONFIGS", "MERGE CONFIGS");
179    aws->load_xfig("merge/configs.fig");
180
181    aws->button_length(20);
182
183    aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN);
184    aws->create_button("CLOSE", "CLOSE", "C");
185
186    aws->at("help");
187    aws->callback(AW_POPUP_HELP, (AW_CL)"mg_configs.hlp");
188    aws->create_button("HELP", "HELP", "H");
189
190    aws->at("configs1");
191    awt_create_selection_list_on_configurations(GLOBAL_gb_merge, (AW_window *)aws, AWAR_CONFIG_NAME1);
192
193    aws->at("configs2");
194    awt_create_selection_list_on_configurations(GLOBAL_gb_dest, (AW_window *)aws, AWAR_CONFIG_NAME2);
195
196    aws->at("delete1");
197    aws->callback((AW_CB)MG_config_delete_cb, (AW_CL)GLOBAL_gb_merge, 1);
198    aws->create_button("DELETE CONFIG_DB1", "Delete Config");
199
200    aws->at("delete2");
201    aws->callback((AW_CB)MG_config_delete_cb, (AW_CL)GLOBAL_gb_dest, 2);
202    aws->create_button("DELETE_CONFIG_DB2", "Delete Config");
203
204    aws->at("rename1");
205    aws->callback((AW_CB1)AW_POPUP, (AW_CL)MG_create_config_rename_window1);
206    aws->create_button("RENAME_CONFIG_DB1", "Rename Config");
207
208    aws->at("rename2");
209    aws->callback((AW_CB1)AW_POPUP, (AW_CL)MG_create_config_rename_window2);
210    aws->create_button("RENAME_CONFIG_DB2", "Rename Config");
211
212    aws->at("transfer");
213    aws->callback(MG_transfer_config);
214    aws->create_button("TRANSFER_CONFIG", "Transfer Config");
215
216    aws->button_length(0);
217    aws->shadow_width(1);
218    aws->at("icon");
219    aws->callback(AW_POPUP_HELP, (AW_CL)"mg_configs.hlp");
220    aws->create_button("HELP_MERGE", "#merge/icon.bitmap");
221
222    return (AW_window *)aws;
223}
224
225
Note: See TracBrowser for help on using the repository browser.