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 <sel_boxes.hxx>
18 #include <selection_admin.h>
19 #include <prompt.hxx>
20 
21 #include <aw_root.hxx>
22 #include <aw_awar.hxx>
23 #include <aw_awar_defs.hxx>
24 #include <aw_msg.hxx>
25 
26 #include <ad_config.h>
27 #include <arbdb.h>
28 
29 // @@@ change term "config" to "species selection" here (in interface + messages)
30 
31 #define AWAR_CONFIG_NAME(db) awar_name_tmp(db, "specsel_name")
32 #define AWAR_SPECSEL_COMMENT_NAME(db) awar_name_tmp(db, "specsel_comment")
33 
34 inline void create_config_awars_for_db(AW_root *aw_root, AW_default aw_def, DbSel db) {
35  aw_root->awar_string(AWAR_CONFIG_NAME(db), "", aw_def);
36  aw_root->awar_string(AWAR_SPECSEL_COMMENT_NAME(db), "", aw_def);
37 }
38 void MG_create_config_awar(AW_root *aw_root, AW_default aw_def) {
39  create_config_awars_for_db(aw_root, aw_def, SRC_DB);
40  create_config_awars_for_db(aw_root, aw_def, DST_DB);
41 
42  aw_root->awar_int(AWAR_TREE_REFRESH, 0, aw_def); // dummy used by extract_species_selection()
43 }
44 
46  DbSel db;
47 
48 public:
49  MgSelectionAdmin(DbSel db_) : db(db_) {}
50 
51  const char *get_macro_suffix() const { return db == SRC_DB ? "src" : "tgt"; }
53 
54  const char *get_selection_awarname() const { return AWAR_CONFIG_NAME(db); }
55  const char *get_selectionComment_awarname() const { return AWAR_SPECSEL_COMMENT_NAME(db); }
56 
57  const char *get_window_title() const { return GBS_global_string("Species selections (%s DB)", dbSide(db)); }
58 
59  const char *get_name_of_tree() const { arb_assert(0); return NULp; }
60  class TreeNode *get_tree_root() const { return NULp; } // means: store species selection w/o groups
61 
62  const char *get_toparea_SAIs() const { return ""; } // do not add SAI info to species selection
63 
64  // rename/delete selections => no special action required in mergetool:
65  void speciesSelection_renamed_cb(const char *, const char *) const {}
66  void speciesSelection_deleted_cb(const char *) const {}
67 };
68 
69 
71  static AW_window *existing_aws[2] = { NULp, NULp };
72 
73  int db_idx = int(db)-1;
74  if (!existing_aws[db_idx]) {
75  AW_root *root = aw_parent->get_root();
76  MgSelectionAdmin * const admin = new MgSelectionAdmin(db);
77  AW_window *aws = create_species_selection_window(root, admin);
78  existing_aws[db_idx] = aws;
79  }
80  existing_aws[db_idx]->activate();
81 }
82 
83 static void MG_transfer_selection(AW_window *aww, DbSel from_db) {
84  AW_root *awr = aww->get_root();
85  char *config = awr->awar(AWAR_CONFIG_NAME(from_db))->read_string();
86  DbSel to_db = otherDb(from_db);
87 
88  GBDATA *gb_main_from = get_gb_main(from_db);
89  GBDATA *gb_main_to = get_gb_main(to_db);
90 
91  GB_ERROR error = GB_begin_transaction(gb_main_to);
92  if (!error) {
93  error = GB_begin_transaction(gb_main_from);
94  if (!error) {
95  GBDATA *gb_config_data_from = GB_search(gb_main_from, CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
96  GBDATA *gb_config_data_to = GB_search(gb_main_to, CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
97 
98  GBDATA *gb_exist_name_from = GB_find_string(gb_config_data_from, "name", config, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
99  GBDATA *gb_exist_name_to = GB_find_string(gb_config_data_to, "name", config, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
100 
101  if (!gb_exist_name_from) {
102  error = GBS_global_string("First select a species selection in the %s list.", dbSide(from_db));
103  }
104  else if (gb_exist_name_to) {
105  error = GBS_global_string("The %s database already has a selection '%s'.\n"
106  "Use 'Edit selection' to delete or rename.",
107  dbSide(to_db), config);
108  }
109  else {
110  GBDATA *gb_cfg_from = GB_get_father(gb_exist_name_from);
111  GBDATA *gb_cfg_to = GB_create_container(gb_config_data_to, "configuration");
112  error = GB_copy_dropProtectMarksAndTempstate(gb_cfg_to, gb_cfg_from);
113  }
114  }
115  error = GB_end_transaction(gb_main_from, error);
116  }
117  error = GB_end_transaction(gb_main_to, error);
118 
119  if (error) aw_message(error);
120  else awr->awar(AWAR_CONFIG_NAME(to_db))->write_string(config);
121 
122  free(config);
123 }
124 
127  if (error) {
128  aw_message(error);
129  return NULp; // deny to open window before user has renamed species
130  }
131 
132  AW_window_simple *aws = new AW_window_simple;
133 
134  aws->init(awr, "MERGE_CONFIGS", "Transfer species selections (=editor configs)");
135  aws->load_xfig("merge/configs.fig");
136 
137  aws->button_length(10);
138 
139  aws->at("close");
140  aws->callback(AW_POPDOWN);
141  aws->create_button("CLOSE", "CLOSE", "C");
142 
143  aws->at("help");
144  aws->callback(makeHelpCallback("mg_species_configs.hlp"));
145  aws->create_button("HELP", "HELP", "H");
146 
147  aws->at("configs1");
149 
150  aws->at("configs2");
152 
153  aws->button_length(20);
154 
155  aws->at("edit1");
156  aws->callback(makeWindowCallback(MG_popup_selection_admin, SRC_DB));
157  aws->create_button("EDIT_SELECTION_DB1", "Edit selection");
158 
159  aws->at("edit2");
160  aws->callback(makeWindowCallback(MG_popup_selection_admin, DST_DB));
161  aws->create_button("EDIT_SELECTION_DB2", "Edit selection");
162 
163  aws->at("xfer1");
164  aws->callback(makeWindowCallback(MG_transfer_selection, SRC_DB));
165  aws->create_button("TRANSFER_SELECTION_DB1", "Transfer selection");
166  aws->alias_remote_command("TRANSFER_CONFIG", "TRANSFER_SELECTION_DB1"); // macro backward compatibility
167 
168  aws->at("xfer2");
169  aws->callback(makeWindowCallback(MG_transfer_selection, DST_DB));
170  aws->create_button("TRANSFER_SELECTION_DB2", "Transfer selection");
171 
172  aws->button_length(0);
173  aws->shadow_width(1);
174  aws->at("icon");
175  aws->callback(makeHelpCallback("mg_species_configs.hlp"));
176  aws->create_button("HELP_MERGE", "#merge/icon.xpm");
177 
178  return aws;
179 }
180 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2152
#define arb_assert(cond)
Definition: arb_assert.h:245
#define AWAR_CONFIG_NAME(db)
Definition: MG_configs.cxx:31
GBDATA * get_gb_main() const
Definition: MG_configs.cxx:52
const char * GB_ERROR
Definition: arb_core.h:25
MgSelectionAdmin(DbSel db_)
Definition: MG_configs.cxx:49
const char * get_window_title() const
Definition: MG_configs.cxx:57
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
AW_window * MG_create_merge_selections_window(AW_root *awr)
Definition: MG_configs.cxx:125
void MG_create_config_awar(AW_root *aw_root, AW_default aw_def)
Definition: MG_configs.cxx:38
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
Definition: merge.hxx:35
class TreeNode * get_tree_root() const
Definition: MG_configs.cxx:60
GB_ERROR MG_expect_renamed()
Definition: MG_names.cxx:119
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
void create_config_awars_for_db(AW_root *aw_root, AW_default aw_def, DbSel db)
Definition: MG_configs.cxx:34
const char * get_toparea_SAIs() const
Definition: MG_configs.cxx:62
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1722
void activate()
Definition: aw_window.hxx:368
GBDATA * GLOBAL_gb_dst
Definition: MG_main.cxx:31
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1829
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define CONFIG_DATA_PATH
Definition: ad_config.h:27
static void error(const char *msg)
Definition: mkptypes.cxx:96
const char * get_name_of_tree() const
Definition: MG_configs.cxx:59
#define AWAR_TREE_REFRESH
AW_DB_selection * awt_create_CONFIG_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname)
Definition: sel_boxes.cxx:459
DbSel
Definition: merge.hxx:35
void speciesSelection_deleted_cb(const char *) const
Definition: MG_configs.cxx:66
char * read_string() const
Definition: AW_awar.cxx:198
AW_window * create_species_selection_window(AW_root *root, const SelectionAdmin *selection)
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:606
static void MG_transfer_selection(AW_window *aww, DbSel from_db)
Definition: MG_configs.cxx:83
GBDATA * GLOBAL_gb_src
Definition: MG_main.cxx:30
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:632
void MG_popup_selection_admin(AW_window *aw_parent, DbSel db)
Definition: MG_configs.cxx:70
Definition: merge.hxx:35
void speciesSelection_renamed_cb(const char *, const char *) const
Definition: MG_configs.cxx:65
const char * dbSide(DbSel db)
Definition: merge.hxx:39
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
const char * get_macro_suffix() const
Definition: MG_configs.cxx:51
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:362
#define NULp
Definition: cxxforward.h:116
DbSel otherDb(DbSel db)
Definition: merge.hxx:38
GB_ERROR write_string(const char *aw_string)
const char * get_selection_awarname() const
Definition: MG_configs.cxx:54
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:622
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GBDATA * get_gb_main(DbSel db)
Definition: merge.hxx:91
const char * get_selectionComment_awarname() const
Definition: MG_configs.cxx:55
#define AWAR_SPECSEL_COMMENT_NAME(db)
Definition: MG_configs.cxx:32