31 void DbScanner::editfield_value_changed_cb() {
32 if (ignore_editfield_change)
return;
36 bool update_self =
false;
44 error =
"No item selected";
46 else if (!field_name[0]) {
47 error =
"No field selected";
49 else if (!awar_edit_enabled->
read_int()) {
51 error =
"Change ignored (edit is disabled!)";
55 int vlen = strlen(value);
57 while (vlen>0 && value[vlen-1] ==
'\n') vlen--;
60 GBDATA *gbd = search_selected_field();
72 if (strcmp(field_name,
"name") == 0) {
78 error =
"cannot rename unnamed item";
114 error =
"The 'name' field can't be empty.";
118 if (!error) update_self =
true;
126 error =
"Sorry, cannot perform a deletion.\n(The selected entry has child entries. Delete them first.)";
140 awar_selected_field->
touch();
151 void DbScanner::toggle_marked_cb() {
152 if (gb_item && !ignore_marktoggle_change) {
159 void DbScanner::remap_edit_box() {
163 if (awar_edit_enabled->
read_int()) {
164 gb_wanted_field = search_selected_field();
167 if (gb_wanted_field != gb_field) {
168 DatabaseCallback editbox_update_cb = makeDatabaseCallback(DbScanner::field_changed_cb,
this);
171 gb_field = gb_wanted_field;
180 inline const char *
awarname(
const char *scanner_id,
const char *entry) {
184 void DbScanner::create_awars(
const char *scanner_id,
bool have_edit_field,
bool have_edit_toggle,
bool have_mark_toggle) {
188 const char *list_awarname =
awarname(scanner_id,
"list");
189 if (get_root()->awar_no_error(list_awarname)) {
190 GBK_terminatef(
"multiple scanners bound to AWAR '%s'", list_awarname);
195 if (have_edit_field) {
197 if (have_edit_toggle) {
201 if (have_mark_toggle) {
206 void DbScanner::create_field_edit_widgets(
const char *edit_pos_fig,
const char *edit_enable_pos_fig) {
209 RootCallback remap_rcb = makeRootCallback(DbScanner::remap_edit_box,
this);
210 WindowCallback remap_wcb = makeWindowCallback(DbScanner::remap_edit_box,
this);
212 if (edit_enable_pos_fig) {
213 aws->
at(edit_enable_pos_fig);
214 aws->create_toggle(awar_edit_enabled->
awar_name);
219 if (edit_enable_pos_fig) awar_edit_enabled->
add_callback(remap_rcb);
220 awar_editfield->
add_callback(makeRootCallback(DbScanner::editfield_value_changed_cb,
this));
222 aws->
at(edit_pos_fig);
228 const char *scanner_id,
230 const char *box_pos_fig,
231 const char *edit_pos_fig,
232 const char *edit_enable_pos_fig,
234 const char *mark_pos_fig,
245 scanner->create_awars(scanner_id, edit_pos_fig, edit_enable_pos_fig, mark_pos_fig);
248 aws->
at(box_pos_fig);
249 scanner->create_field_selection_list();
251 aws->
at(mark_pos_fig);
252 scanner->create_mark_toggle();
255 scanner->create_field_edit_widgets(edit_pos_fig, edit_enable_pos_fig);
278 int ssize = strlen(data);
286 if (ssize>5) strcpy(data+rest-5,
"[...]");
291 buf.
ncat(data, ssize);
295 buf.
ncat(
"<unprintable>", 13);
308 int max_keyname_length = 0;
310 for (
int i = 0; i<depth; ++i) buf.
ncat(
": ", 2);
313 int keylen = strlen(key);
314 buf.
ncatPadded(key, keylen, previous_max_keyname_length);
316 max_keyname_length =
std::max(max_keyname_length, keylen);
319 if (isContainer) buf.
ncat(
"<CONTAINER>:", 12);
330 max_keyname_length =
std::max(max_keyname_length, fill_fields_recursive(gb2, depth+1, buf));
335 if (!depth) trackKeys.
clear();
337 return max_keyname_length;
341 int max_keyname_length = 0;
345 for (
int existing = 1; existing >= 0; --existing) {
348 if (gb_key_hidden &&
GB_read_int(gb_key_hidden))
continue;
351 if (!gb_key_name)
continue;
358 if ((!existing) == (!gbd)) {
361 int keylen = strlen(key);
362 buf.
ncatPadded(key, keylen, previous_max_keyname_length);
364 max_keyname_length =
std::max(max_keyname_length, keylen);
367 append_field_data(buf, type, gbd);
374 return max_keyname_length;
386 if (!data) data = strdup(
"<you cannot edit this datatype>");
396 bool adjusted =
false;
397 if (prevMaxLen != currMaxLen) {
398 prevMaxLen = currMaxLen;
404 void DbScanner::changed_cb(
GB_CB_TYPE cbtype) {
424 int max_keyname_length = 0;
425 switch (scannermode) {
426 case DB_SCANNER: max_keyname_length = fill_fields_recursive(gb_item, 0, buf);
break;
427 case DB_KEYVIEWER: max_keyname_length = fill_fields_by_keydata(buf);
break;
431 if (!
width_adjusted(previous_max_keyname_length, max_keyname_length))
break;
461 awar_selected_field->
touch();
464 void DbScanner::keydata_modified_cb(
GB_CB_TYPE cbtype) {
467 bool deselect =
false;
503 gb_item = gb_new_item;
515 void DbScanner::remap_item() {
529 bool skipThis =
false;
530 if (!skipThis && skipContainers) {
532 skipThis = type ==
GB_DB;
534 if (!skipThis && skipHidden) {
536 skipThis = gb_key_hidden &&
GB_read_int(gb_key_hidden);
541 fields.put(key_name);
545 gb_key = gb_next_key;
GB_ERROR GB_begin_transaction(GBDATA *gbd)
GB_ERROR GBT_rename_species(const char *oldname, const char *newname, bool ignore_protection)
long GB_read_int(GBDATA *gbd)
GBDATA * GB_child(GBDATA *father)
#define implicated(hypothesis, conclusion)
void insert_default(const char *displayed, const AW_scalar &value)
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
void set_popup_callback(const WindowCallback &wcb)
GBDATA * GB_nextEntry(GBDATA *entry)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
int ARB_stricmp(const char *s1, const char *s2)
char * ARB_strdup(const char *str)
char * GB_read_as_string(GBDATA *gbd)
bool width_adjusted(int &prevMaxLen, int currMaxLen)
size_t GBS_shorten_repeated_data(char *data)
const char * GBS_global_string(const char *templat,...)
void GBK_terminatef(const char *templat,...)
GBDATA * GB_get_father(GBDATA *gbd)
GB_ERROR GB_push_transaction(GBDATA *gbd)
char * get_mapped_item_id() const
static const size_t MAX_DISPLAY_LENGTH
bool speciesOrOrganism(QUERY_ITEM_TYPE type)
int ncatPadded(const char *from, size_t count, size_t paddedWidth)
AW_awar * add_callback(const RootCallback &cb)
GB_ERROR GB_delete(GBDATA *&source)
void insert(const char *displayed, const AW_scalar &value)
const char * read_char_pntr() const
GB_ERROR GB_await_error()
static AW_root * SINGLETON
NOT4PERL long * GBT_read_int(GBDATA *gb_container, const char *fieldpath)
char * GBT_read_string(GBDATA *gb_container, const char *fieldpath)
GB_TYPES GB_read_type(GBDATA *gbd)
GB_CSTR GB_read_key_pntr(GBDATA *gbd)
int GB_read_security_write(GBDATA *gbd)
const char * change_key_path
GB_ERROR GBT_begin_rename_session(GBDATA *gb_main, int all_flag)
GBDATA *(* get_selected_item)(GBDATA *gb_main, AW_root *aw_root)
static void error(const char *msg)
static DbScanner * create(GBDATA *gb_main, const char *scanner_id, AW_window *aws, const char *box_pos_fig, const char *edit_pos_fig, const char *edit_enable_pos_fig, DB_SCANNERMODE scannermode, const char *mark_pos_fig, ItemSelector &selector)
int GB_read_flag(GBDATA *gbd)
char *(* generate_item_id)(GBDATA *gb_main, GBDATA *gb_item)
char * read_string() const
GB_ERROR GB_pop_transaction(GBDATA *gbd)
GBDATA *(* get_first_item)(GBDATA *, QUERY_RANGE)
GB_ERROR GBT_abort_rename_session(void)
GB_ERROR GBT_commit_rename_session(void) __ATTR__USERESULT
GBDATA *(* get_next_item)(GBDATA *, QUERY_RANGE)
void(* update_item_awars)(GBDATA *gb_main, AW_root *aw_root, const char *item_name)
GB_ERROR AWTC_recreate_name(GBDATA *gb_species)
void ncat(const char *from, size_t count)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
void GB_write_flag(GBDATA *gbd, long flag)
GBDATA * GBT_get_changekey(GBDATA *gb_main, const char *key, const char *change_key_path)
const ItemSelector & get_selector() const
void GB_remove_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
void Map(GBDATA *gb_new_item, const char *key_path)
GB_ERROR write_string(const char *aw_string)
const char * get_data() const
const char * GBT_get_name(GBDATA *gb_item)
GBDATA * GB_nextChild(GBDATA *child)
const char * awarname(const char *scanner_id, const char *entry)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
const char * make_unique_key(const char *key)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
STATIC_ASSERT(INFO_WIDTH<=AW_selection_list_entry::MAX_DISPLAY_LENGTH)
char GB_type_2_char(GB_TYPES type)
GB_ERROR write_int(long aw_int)
GBDATA * GB_entry(GBDATA *father, const char *key)
void collectKeysRegisteredInDatabase(StrArray &fields, GBDATA *gb_main, ItemSelector &sel, bool skipContainers, bool skipHidden)
size_t get_position() const
void create_text_field(const char *awar_name, int columns=20, int rows=4)
void aw_message_if(GB_ERROR error)
GB_ERROR GB_write_autoconv_string(GBDATA *gbd, const char *val)