| 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 | |
|---|
| 45 | class MgSelectionAdmin: public SelectionAdmin { |
|---|
| 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"; } |
|---|
| 52 | GBDATA *get_gb_main() const { return ::get_gb_main(db); } |
|---|
| 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 | |
|---|
| 70 | void MG_popup_selection_admin(AW_window *aw_parent, DbSel db) { |
|---|
| 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 | |
|---|
| 125 | AW_window *MG_create_merge_selections_window(AW_root *awr) { |
|---|
| 126 | GB_ERROR error = MG_expect_renamed(); |
|---|
| 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"); |
|---|
| 148 | awt_create_CONFIG_selection_list(GLOBAL_gb_src, aws, AWAR_CONFIG_NAME(SRC_DB)); |
|---|
| 149 | |
|---|
| 150 | aws->at("configs2"); |
|---|
| 151 | awt_create_CONFIG_selection_list(GLOBAL_gb_dst, aws, AWAR_CONFIG_NAME(DST_DB)); |
|---|
| 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 | |
|---|