ARB
MG_configs.cxx
Go to the documentation of this file.
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 
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);
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 
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 
92  if (!error) {
94  if (!error) {
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 
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");
146 
147  aws->at("configs2");
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 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2516
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2144
#define AWAR_CONFIG_NAME(db)
Definition: MG_configs.cxx:29
const char * GB_ERROR
Definition: arb_core.h:25
static void MG_config_delete_cb(AW_window *aww, DbSel db)
Definition: MG_configs.cxx:64
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1385
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2549
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
Definition: arbdb.cxx:2572
void MG_create_config_awar(AW_root *aw_root, AW_default aw_def)
Definition: MG_configs.cxx:31
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
Definition: merge.hxx:35
GB_ERROR MG_expect_renamed()
Definition: MG_names.cxx:119
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
AW_DB_selection * awt_create_CONFIG_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, bool fallback2default)
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1720
GBDATA * GLOBAL_gb_dst
Definition: MG_main.cxx:32
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1904
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
static AW_root * SINGLETON
Definition: aw_root.hxx:102
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1827
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
static GB_ERROR config_rename_handler(const char *dest, DbSel db)
Definition: MG_configs.cxx:36
#define AWAR_CONFIG_NAME_SRC
Definition: MG_configs.cxx:27
#define AWAR_CONFIG_NAME_DST
Definition: MG_configs.cxx:28
#define CONFIG_DATA_PATH
Definition: ad_config.h:24
static void error(const char *msg)
Definition: mkptypes.cxx:96
static void MG_transfer_config(AW_window *aww)
Definition: MG_configs.cxx:87
DbSel
Definition: merge.hxx:35
char * read_string() const
Definition: AW_awar.cxx:201
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GBDATA * GLOBAL_gb_src
Definition: MG_main.cxx:31
AW_window * MG_create_merge_configs_window(AW_root *awr)
Definition: MG_configs.cxx:122
Definition: merge.hxx:35
void aw_message(const char *msg)
Definition: AW_status.cxx:932
GBDATA * GB_find_string(GBDATA *gbd, const char *key, const char *str, GB_CASE case_sens, GB_SEARCH_TYPE gbs)
Definition: adquery.cxx:302
AW_root * get_root()
Definition: aw_window.hxx:348
#define NULp
Definition: cxxforward.h:97
GBDATA * gb_main
Definition: adname.cxx:33
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GBDATA * get_gb_main(DbSel db)
Definition: merge.hxx:88
static void config_rename_cb(AW_window *aww, DbSel db)
Definition: MG_configs.cxx:58
void AWT_activate_prompt(const char *title, const char *prompt, const char *defaultResult, const char *button, const ResultHandler &handle_result, const char *helpfile, const char *srt)
Definition: AWT_prompt.cxx:62