1
// ================================================================ //
3
// File : AWT_sel_boxes.cxx //
6
// Institute of Microbiology (Technical University Munich) //
7
// http://www.arb-home.de/ //
9
// ================================================================ //
12
#include <ad_config.h>
13
#include <aw_root.hxx>
14
#include <aw_device.hxx>
15
#include <aw_window.hxx>
16
#include <aw_awars.hxx>
17
#include <aw_global.hxx>
19
#include "awtlocal.hxx"
20
12
#include "awt_sel_boxes.hxx"
21
#include "awt_item_sel_list.hxx"
23
// ******************** selection boxes on alignments ********************
25
static void awt_create_selection_list_on_ad_cb(GBDATA *, struct adawcbstruct *cbs) {
26
cbs->aws->clear_selection_list(cbs->id);
28
for (GBDATA * gb_alignment = GB_search(cbs->gb_main, "presets/alignment", GB_FIND);
30
gb_alignment = GB_nextEntry(gb_alignment))
32
char *alignment_type = GBT_read_string(gb_alignment, "alignment_type");
33
char *alignment_name = GBT_read_string(gb_alignment, "alignment_name");
34
char *str = GBS_string_eval(alignment_type, cbs->comm, 0);
37
cbs->aws->insert_selection(cbs->id, alignment_name, alignment_name);
43
cbs->aws->insert_default_selection(cbs->id, "????", "????");
44
cbs->aws->update_selection_list(cbs->id);
48
void awt_create_selection_list_on_ad(GBDATA *gb_main,AW_window *aws, const char *varname,const char *comm)
49
// if comm is set then only those alignments are taken
50
// which can be parsed by comm
52
AW_selection_list *id;
55
GB_push_transaction(gb_main);
57
id = aws->create_selection_list(varname,0,"",20,3);
58
struct adawcbstruct *cbs = new adawcbstruct;
59
memset(cbs, 0, sizeof(*cbs));
62
cbs->awr = aws->get_root();
63
cbs->gb_main = gb_main;
65
cbs->comm = 0; if (comm) cbs->comm = strdup(comm);
67
awt_create_selection_list_on_ad_cb(0,cbs);
69
gb_presets = GB_search(gb_main,"presets",GB_CREATE_CONTAINER);
70
GB_add_callback(gb_presets,GB_CB_CHANGED, (GB_CB)awt_create_selection_list_on_ad_cb, (int *)cbs);
72
GB_pop_transaction(gb_main);
76
// ******************** selection boxes on trees ********************
78
void awt_create_selection_list_on_trees_cb(GBDATA *dummy, struct adawcbstruct *cbs) {
81
cbs->aws->clear_selection_list(cbs->id);
82
char **tree_names = GBT_get_tree_names(cbs->gb_main);
84
int maxTreeNameLen = 0;
85
for (char **tree= tree_names ; *tree; tree++){
86
int len = strlen(*tree);
87
if (len>maxTreeNameLen) maxTreeNameLen = len;
89
for (char **tree= tree_names ; *tree; tree++){
90
const char *info = GBT_tree_info_string(cbs->gb_main, *tree, maxTreeNameLen);
92
cbs->aws->insert_selection( cbs->id, info, *tree );
94
cbs->aws->insert_selection( cbs->id, *tree, *tree );
97
GBT_free_names(tree_names);
99
cbs->aws->insert_default_selection( cbs->id, "????", "????" );
100
cbs->aws->update_selection_list( cbs->id );
103
void awt_create_selection_list_on_trees(GBDATA *gb_main,AW_window *aws,const char *varname) {
104
AW_selection_list *id;
105
GBDATA *gb_tree_data;
107
GB_push_transaction(gb_main);
109
id = aws->create_selection_list(varname,0,"",40,4);
110
struct adawcbstruct *cbs = new adawcbstruct;
111
memset(cbs, 0, sizeof(*cbs));
114
cbs->awr = aws->get_root();
115
cbs->gb_main = gb_main;
118
awt_create_selection_list_on_trees_cb(0,cbs);
120
gb_tree_data = GB_search(gb_main,"tree_data",GB_CREATE_CONTAINER);
121
GB_add_callback(gb_tree_data,GB_CB_CHANGED, (GB_CB)awt_create_selection_list_on_trees_cb, (int *)cbs);
123
GB_pop_transaction(gb_main);
126
// ******************** selection boxes on pt-servers ********************
128
#define PT_SERVERNAME_LENGTH 23 // that's for buttons
129
#define PT_SERVERNAME_SELLIST_WIDTH 30 // this for lists
130
#define PT_SERVER_TRACKLOG_TIMER 10000 // every 10 seconds
132
struct selection_list_handle {
134
AW_selection_list *sellst;
135
struct selection_list_handle *next;
138
static selection_list_handle *allPTserverSellists = 0; // all pt server selection lists
140
static void fill_pt_server_selection_list(AW_window *aws, AW_selection_list *id) {
141
aws->clear_selection_list(id);
14
#include <item_sel_list.h>
16
#include <aw_awars.hxx>
17
#include <aw_file.hxx>
19
#include <aw_root.hxx>
20
#include <aw_edit.hxx>
22
#include <ad_config.h>
26
#include <arb_strbuf.h>
27
#include <arb_strarray.h>
29
#include <arb_global_defs.h>
32
#include "awt_modules.hxx"
33
#include <BufferedFileReader.h>
39
// --------------------------------------
40
// selection boxes on alignments
42
class AWT_alignment_selection : public AW_DB_selection { // derived from a Noncopyable
43
char *ali_type_match; // filter for wanted alignments (GBS_string_eval command)
45
AWT_alignment_selection(AW_selection_list *sellist_, GBDATA *gb_presets, const char *ali_type_match_)
46
: AW_DB_selection(sellist_, gb_presets)
47
, ali_type_match(nulldup(ali_type_match_))
50
void fill() OVERRIDE {
51
GBDATA *gb_presets = get_gbd();
52
GB_transaction ta(gb_presets);
54
for (GBDATA *gb_alignment = GB_entry(gb_presets, "alignment");
56
gb_alignment = GB_nextEntry(gb_alignment))
58
char *alignment_type = GBT_read_string(gb_alignment, "alignment_type");
59
char *alignment_name = GBT_read_string(gb_alignment, "alignment_name");
60
char *str = GBS_string_eval(alignment_type, ali_type_match, 0);
62
if (!*str) insert(alignment_name, alignment_name);
67
insert_default(DISPLAY_NONE, NO_ALI_SELECTED);
70
void reconfigure(const char *new_ali_type_match) {
71
freedup(ali_type_match, new_ali_type_match);
76
AW_DB_selection *awt_create_selection_list_on_alignments(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match) {
77
// Create selection lists on alignments
79
// if 'ali_type_match' is set, then only insert alignments,
80
// where 'ali_type_match' GBS_string_eval's the alignment type
84
GB_transaction ta(gb_main);
85
gb_presets = GBT_get_presets(gb_main);
87
AW_selection_list *sellist = aws->create_selection_list(varname, 20, 3, true);
88
AWT_alignment_selection *alisel = new AWT_alignment_selection(sellist, gb_presets, ali_type_match);
89
alisel->refresh(); // belongs to window now
93
void awt_reconfigure_selection_list_on_alignments(AW_DB_selection *dbsel, const char *ali_type_match) {
94
AWT_alignment_selection *alisel = dynamic_cast<AWT_alignment_selection*>(dbsel);
95
alisel->reconfigure(ali_type_match);
98
// ---------------------------------
99
// selection boxes on trees
101
struct AWT_tree_selection: public AW_DB_selection {
102
AWT_tree_selection(AW_selection_list *sellist_, GBDATA *gb_tree_data)
103
: AW_DB_selection(sellist_, gb_tree_data)
106
void fill() OVERRIDE {
107
GBDATA *gb_main = get_gb_main();
108
GB_transaction ta(gb_main);
110
ConstStrArray tree_names;
111
GBT_get_tree_names(tree_names, gb_main, true);
113
if (!tree_names.empty()) {
114
int maxTreeNameLen = 0;
115
for (int i = 0; tree_names[i]; ++i) {
116
const char *tree = tree_names[i];
117
int len = strlen(tree);
118
if (len>maxTreeNameLen) maxTreeNameLen = len;
120
for (int i = 0; tree_names[i]; ++i) {
121
const char *tree = tree_names[i];
122
const char *info = GBT_tree_info_string(gb_main, tree, maxTreeNameLen);
127
aw_message(GB_await_error());
132
insert_default(DISPLAY_NONE, NO_TREE_SELECTED);
136
AW_DB_selection *awt_create_selection_list_on_trees(GBDATA *gb_main, AW_window *aws, const char *varname, bool fallback2default) {
137
GBDATA *gb_tree_data;
139
GB_transaction ta(gb_main);
140
gb_tree_data = GBT_get_tree_data(gb_main);
142
AW_selection_list *sellist = aws->create_selection_list(varname, 40, 4, fallback2default);
143
AWT_tree_selection *treesel = new AWT_tree_selection(sellist, gb_tree_data); // owned by nobody
149
// --------------------------------------
150
// selection boxes on pt-servers
152
#define PT_SERVERNAME_LENGTH 23 // that's for buttons
153
#define PT_SERVERNAME_SELLIST_WIDTH 30 // this for lists
154
#define PT_SERVER_TRACKLOG_TIMER 10000 // every 10 seconds
156
class AWT_ptserver_selection : public AW_selection {
157
typedef list<AWT_ptserver_selection*> PTserverSelections;
159
static PTserverSelections ptserver_selections;
161
AWT_ptserver_selection(AW_selection_list *sellist_);
163
void fill() OVERRIDE;
165
static void refresh_all();
168
AWT_ptserver_selection::PTserverSelections AWT_ptserver_selection::ptserver_selections;
170
void AWT_ptserver_selection::fill() {
143
171
const char * const *pt_servers = GBS_get_arb_tcp_entries("ARB_PT_SERVER*");
277
311
aw_root->awar(varname)->write_int(ptserver_index);
280
char *readable_name = readable_pt_servername(ptserver_index, PT_SERVERNAME_LENGTH);
314
char *readable_name = readable_pt_servername(ptserver_index, PT_SERVERNAME_LENGTH);
315
char *const varnameDup = strdup(varname);
282
AW_CL cl_varname = (AW_CL)strdup(varname); // make copy of awar_name for callbacks
317
awt_assert(!GB_have_error());
284
319
aw_root->awar_string(awar_buttontext_name, readable_name, AW_ROOT_DEFAULT);
285
aw_root->awar(varname)->add_callback(update_ptserver_button, cl_varname);
320
aw_root->awar(varname)->add_callback(makeRootCallback(update_ptserver_button, varnameDup));
287
322
int old_button_length = aws->get_button_length();
289
324
aws->button_length(PT_SERVERNAME_LENGTH+1);
290
aws->callback(AW_POPUP, (AW_CL)awt_popup_selection_list_on_pt_servers, cl_varname);
325
aws->callback(makeCreateWindowCallback(create_selection_list_on_pt_servers_window, varnameDup));
291
326
aws->create_button("CURR_PT_SERVER", awar_buttontext_name);
293
328
aws->button_length(old_button_length);
295
330
free(readable_name);
296
331
free(awar_buttontext_name);
299
AW_selection_list *id = aws->create_selection_list(varname);
300
announce_pt_server_selection_list(aws, id);
301
fill_pt_server_selection_list(aws, id);
335
(new AWT_ptserver_selection(aws->create_selection_list(varname, true)))->refresh();
306
// ******************** selection boxes on tables ********************
308
void awt_create_selection_list_on_tables_cb(GBDATA *dummy, struct awt_sel_list_for_tables *cbs){
310
cbs->aws->clear_selection_list(cbs->id);
339
// ----------------------------------
340
// selection boxes on tables
343
#if defined(WARN_TODO)
344
#warning derive awt_sel_list_for_tables from AW_DB_selection
347
struct awt_sel_list_for_tables {
350
AW_selection_list *id;
351
const char *table_name;
354
static void awt_create_selection_list_on_tables_cb(GBDATA *, struct awt_sel_list_for_tables *cbs) {
311
356
GBDATA *gb_table;
312
357
for (gb_table = GBT_first_table(cbs->gb_main);
314
gb_table = GBT_next_table(gb_table)){
359
gb_table = GBT_next_table(gb_table)) {
316
GBDATA *gb_name = GB_entry(gb_table,"name");
317
GBDATA *gb_description = GB_search(gb_table,"description",GB_STRING);
361
GBDATA *gb_name = GB_entry(gb_table, "name");
362
GBDATA *gb_description = GB_search(gb_table, "description", GB_STRING);
318
363
if (!gb_name) continue;
319
364
char *table_name = GB_read_string(gb_name);
320
365
char *description = GB_read_string(gb_description);
321
const char *info_text = GBS_global_string("%s: %s",table_name,description);
322
cbs->aws->insert_selection(cbs->id,info_text,table_name);
366
const char *info_text = GBS_global_string("%s: %s", table_name, description);
367
cbs->id->insert(info_text, table_name);
323
368
free(table_name);
324
369
free(description);
326
cbs->aws->insert_default_selection( cbs->id, "", "" );
327
cbs->aws->update_selection_list( cbs->id );
371
cbs->id->insert_default("", "");
330
void awt_create_selection_list_on_tables(GBDATA *gb_main,AW_window *aws,const char *varname)
375
void awt_create_selection_list_on_tables(GBDATA *gb_main, AW_window *aws, const char *varname)
332
377
AW_selection_list *id;
333
378
GBDATA *gb_table_data;
334
379
struct awt_sel_list_for_tables *cbs;
335
380
GB_push_transaction(gb_main);
337
id = aws->create_selection_list(varname,0,"",40,8);
382
id = aws->create_selection_list(varname, 40, 8, true);
338
383
cbs = new awt_sel_list_for_tables;
340
385
cbs->gb_main = gb_main;
343
awt_create_selection_list_on_tables_cb(0,cbs);
388
awt_create_selection_list_on_tables_cb(0, cbs);
345
gb_table_data = GB_search(gb_main,"table_data",GB_CREATE_CONTAINER);
346
GB_add_callback(gb_table_data,GB_CB_CHANGED,(GB_CB)awt_create_selection_list_on_tables_cb, (int *)cbs);
390
gb_table_data = GB_search(gb_main, "table_data", GB_CREATE_CONTAINER);
391
GB_add_callback(gb_table_data, GB_CB_CHANGED, makeDatabaseCallback(awt_create_selection_list_on_tables_cb, cbs));
348
393
GB_pop_transaction(gb_main);
350
// ******************** selection boxes on tables ********************
352
void awt_create_selection_list_on_table_fields_cb(GBDATA *dummy, struct awt_sel_list_for_tables *cbs){
354
cbs->aws->clear_selection_list(cbs->id);
355
GBDATA *gb_table = GBT_open_table(cbs->gb_main,cbs->table_name, GB_TRUE); // read only
396
static void awt_create_selection_list_on_table_fields_cb(GBDATA *, struct awt_sel_list_for_tables *cbs) {
398
GBDATA *gb_table = GBT_open_table(cbs->gb_main, cbs->table_name, true); // read only
356
399
GBDATA *gb_table_field;
357
400
for (gb_table_field = GBT_first_table_field(gb_table);
359
402
gb_table_field = GBT_next_table_field(gb_table_field))
361
GBDATA *gb_name = GB_entry(gb_table_field,"name");
362
GBDATA *gb_description = GB_search(gb_table_field,"description",GB_STRING);
404
GBDATA *gb_name = GB_entry(gb_table_field, "name");
405
GBDATA *gb_description = GB_search(gb_table_field, "description", GB_STRING);
363
406
if (!gb_name) continue;
364
407
char *table_name = GB_read_string(gb_name);
365
408
char *description = GB_read_string(gb_description);
366
const char *info_text = GBS_global_string("%s: %s",table_name,description);
367
cbs->aws->insert_selection(cbs->id,info_text,table_name);
409
const char *info_text = GBS_global_string("%s: %s", table_name, description);
410
cbs->id->insert(info_text, table_name);
368
411
free(table_name);
369
412
free(description);
371
cbs->aws->insert_default_selection( cbs->id, "", "" );
372
cbs->aws->update_selection_list( cbs->id );
414
cbs->id->insert_default("", "");
375
void awt_create_selection_list_on_table_fields(GBDATA *gb_main,AW_window *aws,const char *table_name, const char *varname)
377
AW_selection_list *id;
418
void awt_create_selection_list_on_table_fields(GBDATA *gb_main, AW_window *aws, const char *table_name, const char *varname) {
419
// if tablename == 0 -> take fields from species table
421
AW_selection_list *id;
378
422
struct awt_sel_list_for_tables *cbs;
379
423
GB_push_transaction(gb_main);
381
id = aws->create_selection_list(varname,0,"",40,8);
425
id = aws->create_selection_list(varname, 40, 8, true);
382
426
cbs = new awt_sel_list_for_tables;
384
428
cbs->gb_main = gb_main;
386
430
cbs->table_name = strdup(table_name);
388
awt_create_selection_list_on_table_fields_cb(0,cbs);
432
awt_create_selection_list_on_table_fields_cb(0, cbs);
390
GBDATA *gb_table = GBT_open_table(gb_main,table_name, GB_TRUE); // read only
392
GB_add_callback(gb_table,GB_CB_CHANGED,(GB_CB)awt_create_selection_list_on_table_fields_cb, (int *)cbs);
434
GBDATA *gb_table = GBT_open_table(gb_main, table_name, true); // read only
436
GB_add_callback(gb_table, GB_CB_CHANGED, makeDatabaseCallback(awt_create_selection_list_on_table_fields_cb, cbs));
394
438
GB_pop_transaction(gb_main);
397
// ******************** selection boxes on editor configurations ********************
399
void awt_create_selection_list_on_configurations_cb(GBDATA*, struct adawcbstruct *cbs) {
400
cbs->aws->clear_selection_list(cbs->id);
403
char **config = GBT_get_configuration_names_and_count(cbs->gb_main, &config_count);
406
for (int c = 0; c<config_count; c++) {
407
cbs->aws->insert_selection(cbs->id, config[c], config[c]);
441
// -------------------------------------------------
442
// selection boxes on editor configurations
444
struct AWT_configuration_selection : public AW_DB_selection {
445
AWT_configuration_selection(AW_selection_list *sellist_, GBDATA *gb_configuration_data)
446
: AW_DB_selection(sellist_, gb_configuration_data)
449
void fill() OVERRIDE {
450
ConstStrArray config;
451
GBT_get_configuration_names(config, get_gb_main());
453
if (!config.empty()) {
454
for (int c = 0; config[c]; c++) insert(config[c], config[c]);
409
GBT_free_names(config);
412
cbs->aws->insert_default_selection(cbs->id, "????", "????");
413
cbs->aws->update_selection_list(cbs->id);
416
void awt_create_selection_list_on_configurations(GBDATA *gb_main,AW_window *aws,const char *varname)
418
AW_selection_list *id;
419
GBDATA *gb_configuration_data;
420
GB_push_transaction(gb_main);
422
id = aws->create_selection_list(varname,0,"",40,15);
424
struct adawcbstruct *cbs = new adawcbstruct;
425
memset(cbs, 0, sizeof(*cbs));
428
cbs->awr = aws->get_root();
429
cbs->gb_main = gb_main;
432
awt_create_selection_list_on_configurations_cb(0,cbs);
434
gb_configuration_data = GB_search(gb_main,AWAR_CONFIG_DATA,GB_CREATE_CONTAINER);
435
GB_add_callback(gb_configuration_data,GB_CB_CHANGED,
436
(GB_CB)awt_create_selection_list_on_configurations_cb, (int *)cbs);
438
GB_pop_transaction(gb_main);
456
insert_default(DISPLAY_NONE, NO_CONFIG_SELECTED);
460
void awt_create_selection_list_on_configurations(GBDATA *gb_main, AW_window *aws, const char *varname, bool fallback2default) {
461
GBDATA *gb_configuration_data;
463
GB_transaction ta(gb_main);
464
gb_configuration_data = GB_search(gb_main, CONFIG_DATA_PATH, GB_CREATE_CONTAINER);
466
AW_selection_list *sellist = aws->create_selection_list(varname, 40, 15, fallback2default);
467
(new AWT_configuration_selection(sellist, gb_configuration_data))->refresh();
441
470
char *awt_create_string_on_configurations(GBDATA *gb_main) {
442
471
// returns semicolon-separated string containing configuration names
443
472
// (or NULL if no configs exist)
445
474
GB_push_transaction(gb_main);
448
char **config = GBT_get_configuration_names_and_count(gb_main, &config_count);
476
ConstStrArray config;
477
GBT_get_configuration_names(config, gb_main);
481
if (!config.empty()) {
452
482
GBS_strstruct *out = GBS_stropen(1000);
453
for (int c = 0; c<config_count; c++) {
483
for (int c = 0; config[c]; c++) {
454
484
if (c>0) GBS_chrcat(out, ';');
455
485
GBS_strcat(out, config[c]);
494
536
const char *group = GB_read_char_pntr(gb_group);
495
537
char *group_and_name = GBS_global_string_copy("[%s] %s", group, name);
497
cbs->aws->insert_selection(cbs->id, group_and_name, name);
539
sel->insert(group_and_name, name);
498
540
free(group_and_name);
501
cbs->aws->insert_selection( cbs->id, name, name );
505
cbs->aws->sort_selection_list(cbs->id, 0, 0);
507
if (cbs->add_selected_species) {
508
GBDATA *gb_sel = GB_search(cbs->gb_main,AWAR_SPECIES_NAME,GB_STRING);
509
char *name = GB_read_string(gb_sel);
511
char *sname = (char *)calloc(1, strlen(name)+2);
512
sprintf(sname+1,"%s",name);
514
char *text = (char *)GBS_global_string("Selected Species: '%s'",name);
515
cbs->aws->insert_selection( cbs->id, text, sname );
520
cbs->aws->insert_default_selection( cbs->id, "- none -", "none" );
521
cbs->aws->update_selection_list( cbs->id );
523
#if defined(DEVEL_RALF)
524
printf("done awt_create_selection_list_on_extendeds_update\n"); // @@@
528
void *awt_create_selection_list_on_extendeds(GBDATA *gb_main,AW_window *aws, const char *varname,
529
char *(*filter_poc)(GBDATA *gb_ext, AW_CL), AW_CL filter_cd,
530
bool add_sel_species)
532
AW_selection_list *id;
533
struct awt_sel_list_for_sai *cbs;
535
GB_push_transaction(gb_main);
537
id = aws->create_selection_list(varname,0,"",40,4);
538
cbs = new awt_sel_list_for_sai;
541
cbs->gb_main = gb_main;
543
cbs->filter_poc = filter_poc;
544
cbs->filter_cd = filter_cd;
545
cbs->add_selected_species = add_sel_species;
547
awt_create_selection_list_on_extendeds_update(0,(void *)cbs);
549
GBDATA *gb_sai_data = GBT_get_SAI_data(gb_main);
550
GB_add_callback(gb_sai_data,GB_CB_CHANGED, (GB_CB)awt_create_selection_list_on_extendeds_update, (int *)cbs);
552
if (add_sel_species){ // update box if another species is selected
553
GBDATA *gb_sel = GB_search(gb_main,AWAR_SPECIES_NAME,GB_STRING);
554
GB_add_callback(gb_sel,GB_CB_CHANGED, (GB_CB)awt_create_selection_list_on_extendeds_update, (int *)cbs);
556
GB_pop_transaction(gb_main);
564
// ******************** selection boxes on saving selection lists ********************
566
void create_save_box_for_selection_lists_save(AW_window *aws,AW_CL selidcd,AW_CL basenamecd)
568
AW_selection_list *selid = (AW_selection_list *)selidcd;
569
char *awar_prefix = (char *)basenamecd;
571
char bline_anz[GB_PATH_MAX];
572
sprintf(bline_anz,"%s/line_anz",awar_prefix);
574
AW_root *aw_root = aws->get_root();
575
long lineanz = aw_root->awar(bline_anz)->read_int();
576
char *filename = awt_get_selected_fullname(aw_root, awar_prefix);
578
GB_ERROR error = aws->save_selection_list(selid,filename,lineanz);
580
if (!error) awt_refresh_selection_box(aw_root, awar_prefix);
581
aws->hide_or_notify(error);
585
AW_window *create_save_box_for_selection_lists(AW_root *aw_root,AW_CL selid)
587
AW_selection_list *selection_list = (AW_selection_list*)selid;
589
char *var_id = GBS_string_2_key(selection_list->variable_name);
590
char *awar_base_name = GBS_global_string_copy("tmp/save_box_sel_%s", var_id); // don't free (passed to callback)
591
char *awar_line_anz = GBS_global_string_copy("%s/line_anz", awar_base_name);
543
sel->insert(name, name);
547
sel->sort(false, false);
549
sel->insert_default(DISPLAY_NONE, "");
553
void awt_selection_list_on_sai_update_cb(UNFIXED, AWT_sai_selection *saisel) {
554
/* update the selection box defined by awt_create_selection_list_on_sai
556
* useful only when filterproc is defined
557
* (changes to SAIs will automatically callback this function)
563
AWT_sai_selection *SAI_selection_list_spec::create_list(AW_window *aws, bool fallback2default) const {
564
GB_transaction ta(gb_main);
566
AW_selection_list *sellist = aws->create_selection_list(awar_name, 40, 4, fallback2default);
567
GBDATA *gb_sai_data = GBT_get_SAI_data(gb_main);
568
AWT_sai_selection *saisel = new AWT_sai_selection(sellist, gb_sai_data, filter_poc, filter_cd);
570
awt_selection_list_on_sai_update_cb(0, saisel);
571
GB_add_callback(gb_sai_data, GB_CB_CHANGED, makeDatabaseCallback(awt_selection_list_on_sai_update_cb, saisel));
576
static void popup_filtered_sai_selection_list(AW_root *aw_root, const SAI_selection_list_spec *spec) {
577
const char *awar_name = spec->get_awar_name();
579
static GB_HASH *SAI_window_hash = 0;
580
if (!SAI_window_hash) SAI_window_hash = GBS_create_hash(10, GB_MIND_CASE);
582
AW_window_simple *aws = reinterpret_cast<AW_window_simple *>(GBS_read_hash(SAI_window_hash, awar_name));
585
aws = new AW_window_simple;
586
aws->init(aw_root, "SELECT_SAI", "SELECT SAI");
587
aws->load_xfig("select_simple.fig");
589
aws->at("selection");
590
aws->callback((AW_CB0)AW_POPDOWN);
591
spec->create_list(aws, true);
594
aws->callback(AW_POPDOWN);
595
aws->create_button("CLOSE", "CLOSE", "C");
599
GBS_write_hash(SAI_window_hash, awar_name, reinterpret_cast<long>(aws));
604
static void popup_filtered_sai_selection_list(AW_window *aww, const SAI_selection_list_spec *spec) {
605
popup_filtered_sai_selection_list(aww->get_root(), spec);
608
void awt_popup_sai_selection_list(AW_window *aww, const char *awar_name, GBDATA *gb_main) {
609
SAI_selection_list_spec spec(awar_name, gb_main);
610
popup_filtered_sai_selection_list(aww, &spec);
613
AWT_sai_selection *awt_create_selection_list_on_sai(GBDATA *gb_main, AW_window *aws, const char *varname, bool fallback2default, awt_sai_sellist_filter filter_poc, AW_CL filter_cd) {
614
/* Selection list for SAIs
616
* if filter_proc is set then show only those items on which
617
* filter_proc returns a string (string must be a heap copy)
619
SAI_selection_list_spec spec(varname, gb_main);
620
spec.define_filter(filter_poc, filter_cd);
621
return spec.create_list(aws, fallback2default);
624
void awt_create_SAI_selection_button(GBDATA *gb_main, AW_window *aws, const char *varname, awt_sai_sellist_filter filter_poc, AW_CL filter_cd) {
625
SAI_selection_list_spec *spec = new SAI_selection_list_spec(varname, gb_main);
626
spec->define_filter(filter_poc, filter_cd);
627
aws->callback(makeWindowCallback(popup_filtered_sai_selection_list, spec));
628
aws->create_button("SELECT_SAI", varname);
631
// --------------------------------------------------
632
// save/load selection content to/from file
634
static GB_ERROR standard_list2file(const CharPtrArray& display, const CharPtrArray& value, StrArray& line) {
635
GB_ERROR error = NULL;
636
for (size_t i = 0; i<display.size() && !error; ++i) {
637
const char *disp = display[i];
639
if (disp[0] == '#') { // would interpret as comment when loaded
640
error = "Invalid character '#' at start of displayed text (won't load)";
643
if (strchr(disp, ',')) {
644
// would be interpreted as separator between display and value on load
645
error = "Invalid character ',' in displayed text (won't load correctly)";
648
awt_assert(strchr(disp, '\n') == 0);
650
const char *val = value[i];
651
if (strcmp(disp, val) == 0) {
652
line.put(strdup(disp));
655
char *escaped = GBS_escape_string(val, "\n", '\\');
656
line.put(GBS_global_string_copy("%s,%s", disp, escaped));
667
static GB_ERROR standard_file2list(const CharPtrArray& line, StrArray& display, StrArray& value) {
668
for (size_t i = 0; i<line.size(); ++i) {
669
if (line[i][0] == '#') continue; // ignore comments
671
const char *comma = strchr(line[i], ',');
673
display.put(GB_strpartdup(line[i], comma-1));
676
const char *rest = comma+strspn(comma, " \t");
677
char *unescaped = GBS_unescape_string(rest, "\n", '\\');
678
value.put(unescaped);
681
display.put(strdup(line[i]));
682
value.put(strdup(line[i]));
689
StorableSelectionList::StorableSelectionList(const TypedSelectionList& tsl_)
691
list2file(standard_list2file),
692
file2list(standard_file2list)
695
inline char *get_shared_sellist_awar_base(const TypedSelectionList& typedsellst) {
696
return GBS_global_string_copy("tmp/sellist/%s", typedsellst.get_shared_id());
698
inline char *get_shared_sellist_awar_name(const TypedSelectionList& typedsellst, const char *name) {
699
char *base = get_shared_sellist_awar_base(typedsellst);
700
char *awar_name = GBS_global_string_copy("%s/%s", base, name);
705
GB_ERROR StorableSelectionList::save(const char *filename, long number_of_lines) const {
706
// number_of_lines == 0 -> save all lines (otherwise truncate after 'number_of_lines')
708
StrArray display, values;
709
AW_selection_list *sellist = tsl.get_sellist();
711
sellist->to_array(display, false);
712
sellist->to_array(values, true);
714
awt_assert(display.size() == values.size());
716
if (number_of_lines>0) { // limit number of lines?
717
display.resize(number_of_lines);
718
values.resize(number_of_lines);
721
GB_ERROR error = NULL;
722
if (display.size()<1) {
723
error = "List is empty (did not save)";
727
error = list2file(display, values, line);
730
error = "list>file conversion produced nothing (internal error)";
733
FILE *out = fopen(filename, "wt");
735
error = GB_IO_error("writing", filename);
738
const char *warning = NULL;
739
for (size_t i = 0; i<line.size(); ++i) {
740
if (!warning && strchr(line[i], '\n')) {
741
warning = "Warning: Saved content contains LFs (loading will be impossible)";
758
inline char *string2heapcopy(const string& s) {
759
char *copy = (char*)malloc(s.length()+1);
760
memcpy(copy, s.c_str(), s.length()+1);
764
GB_ERROR StorableSelectionList::load(const char *filemask, bool append) const {
765
GB_ERROR error = NULL;
768
if (GB_is_directory(filemask)) {
769
error = GBS_global_string("refusing to load all files from directory\n"
771
"(one possibility is to enter '*.%s')'",
772
filemask, get_filter());
775
GBS_read_dir(fnames, filemask, NULL);
776
if (fnames.empty() && GB_have_error()) {
777
error = GB_await_error();
782
for (int f = 0; fnames[f] && !error; ++f) {
783
FILE *in = fopen(fnames[f], "rb");
785
error = GB_IO_error("reading", fnames[f]);
788
BufferedFileReader file(fnames[f], in);
790
while (file.getLine(line)) {
791
if (!line.empty()) lines.put(string2heapcopy(line));
796
AW_selection_list *sellist = tsl.get_sellist();
797
if (!append) sellist->clear();
800
StrArray displayed, values;
801
error = file2list(lines, displayed, values);
803
int dsize = displayed.size();
804
int vsize = values.size();
806
if (dsize != vsize) {
807
error = GBS_global_string("Error in translation (value/display mismatch: %i!=%i)", vsize, dsize);
810
for (int i = 0; i<dsize; ++i) {
811
sellist->insert(displayed[i], values[i]);
813
sellist->insert_default("", "");
819
sellist->insert_default(GBS_global_string("Error: %s", error), "");
826
static void save_list_cb(AW_window *aww, const StorableSelectionList *storabsellist) {
827
const TypedSelectionList& typedsellist = storabsellist->get_typedsellist();
829
char *awar_prefix = get_shared_sellist_awar_base(typedsellist);
830
char *bline_anz = get_shared_sellist_awar_name(typedsellist, "line_anz");
831
AW_root *aw_root = aww->get_root();
832
char *filename = AW_get_selected_fullname(aw_root, awar_prefix);
834
long lineLimit = aw_root->awar(bline_anz)->read_int();
835
GB_ERROR error = storabsellist->save(filename, lineLimit);
837
if (!error) AW_refresh_fileselection(aw_root, awar_prefix);
838
aww->hide_or_notify(error);
845
static void load_list_cb(AW_window *aww, const StorableSelectionList *storabsellist) {
846
const TypedSelectionList& typedsellist = storabsellist->get_typedsellist();
848
AW_root *aw_root = aww->get_root();
849
char *awar_prefix = get_shared_sellist_awar_base(typedsellist);
850
char *awar_append = get_shared_sellist_awar_name(typedsellist, "append");
851
bool append = aw_root->awar(awar_append)->read_int();
852
char *filename = AW_get_selected_fullname(aw_root, awar_prefix);
853
GB_ERROR error = storabsellist->load(filename, append);
855
aww->hide_or_notify(error);
862
AW_window *create_save_box_for_selection_lists(AW_root *aw_root, const StorableSelectionList *storabsellist) {
863
const TypedSelectionList& typedsellist = storabsellist->get_typedsellist();
865
char *awar_base = get_shared_sellist_awar_base(typedsellist);
866
char *awar_line_anz = get_shared_sellist_awar_name(typedsellist, "line_anz");
593
aw_create_selection_box_awars(aw_root, awar_base_name, ".", GBS_global_string("noname.list"), "list");
868
char *def_name = GBS_string_2_key(typedsellist.whats_contained());
869
AW_create_fileselection_awars(aw_root, awar_base, ".", storabsellist->get_filter(), def_name);
594
871
aw_root->awar_int(awar_line_anz, 0, AW_ROOT_DEFAULT);
597
AW_window_simple *aws = new AW_window_simple;
598
char *window_id = GBS_global_string_copy("SAVE_SELECTION_BOX_%s", var_id);
600
aws->init(aw_root, window_id, "SAVE BOX");
874
AW_window_simple *aws = new AW_window_simple;
876
char *window_id = GBS_global_string_copy("SAVE_SELECTION_BOX_%s", typedsellist.get_unique_id());
877
char *window_title = GBS_global_string_copy("Save %s", typedsellist.whats_contained());
879
aws->init(aw_root, window_id, window_title);
601
880
aws->load_xfig("sl_s_box.fig");
603
aws->at("close");aws->callback((AW_CB0)AW_POPDOWN);
604
aws->create_button("CLOSE", "CLOSE","C");
882
aws->button_length(10);
885
aws->callback((AW_CB0)AW_POPDOWN);
886
aws->create_button("CANCEL", "CANCEL", "C");
607
889
aws->highlight();
608
aws->callback(create_save_box_for_selection_lists_save,selid,(AW_CL)awar_base_name); // loose ownership of awar_base_name!
609
aws->create_button("SAVE", "SAVE","S");
890
aws->callback(makeWindowCallback(save_list_cb, storabsellist));
891
aws->create_button("SAVE", "SAVE", "S");
611
893
aws->at("nlines");
612
aws->create_option_menu(awar_line_anz, 0, "");
613
aws->insert_default_option("all","a",0);
614
aws->insert_option( "50", "a", 50);
615
aws->insert_option( "100", "a", 100);
616
aws->insert_option( "500", "a", 500);
617
aws->insert_option( "1000", "a", 1000);
618
aws->insert_option( "5000", "a", 5000);
619
aws->insert_option("10000", "a", 10000);
894
aws->create_option_menu(awar_line_anz, true);
895
aws->insert_default_option("all", "a", 0);
896
aws->insert_option ("10", "", 10);
897
aws->insert_option ("50", "", 50);
898
aws->insert_option ("100", "", 100);
899
aws->insert_option ("500", "", 500);
900
aws->insert_option ("1000", "", 1000);
901
aws->insert_option ("5000", "", 5000);
902
aws->insert_option ("10000", "", 10000);
620
903
aws->update_option_menu();
622
awt_create_selection_box(aws,awar_base_name);
905
AW_create_standard_fileselection(aws, awar_base);
625
909
free(awar_line_anz);
912
aws->recalc_pos_atShow(AW_REPOS_TO_MOUSE);
631
void AWT_load_list(AW_window *aww, AW_CL sel_id, AW_CL ibase_name)
633
AW_selection_list * selid = (AW_selection_list *)sel_id;
634
char *basename = (char *)ibase_name;
636
AW_root *aw_root = aww->get_root();
639
// char bfile_name[GB_PATH_MAX];
640
// sprintf(bfile_name,"%s/file_name",basename);
641
// char *filename = aw_root->awar(bfile_name)->read_string();
643
char *filename = awt_get_selected_fullname(aw_root, basename);
644
error = aww->load_selection_list(selid,filename);
646
if (error) aw_message(error);
653
AW_window *create_load_box_for_selection_lists(AW_root *aw_root, AW_CL selid)
656
sprintf(base_name,"tmp/load_box_sel_%li",(long)selid);
658
aw_create_selection_box_awars(aw_root, base_name, ".", "list", "");
917
AW_window *create_load_box_for_selection_lists(AW_root *aw_root, const StorableSelectionList *storabsellist) {
918
const TypedSelectionList& typedsellist = storabsellist->get_typedsellist();
920
char *awar_base_name = get_shared_sellist_awar_base(typedsellist);
921
char *awar_append = get_shared_sellist_awar_name(typedsellist, "append");
923
AW_create_fileselection_awars(aw_root, awar_base_name, ".", storabsellist->get_filter(), "");
924
aw_root->awar_int(awar_append, 1); // append is default ( = old behavior)
660
926
AW_window_simple *aws = new AW_window_simple;
661
aws->init( aw_root, "LOAD_SELECTION_BOX", "Load box");
928
char *window_id = GBS_global_string_copy("LOAD_SELECTION_BOX_%s", typedsellist.get_unique_id());
929
char *window_title = GBS_global_string_copy("Load %s", typedsellist.whats_contained());
931
aws->init(aw_root, window_id, window_title);
662
932
aws->load_xfig("sl_l_box.fig");
665
935
aws->callback((AW_CB0)AW_POPDOWN);
666
aws->create_button("CLOSE", "CLOSE","C");
936
aws->create_button("CANCEL", "CANCEL", "C");
669
939
aws->highlight();
670
aws->callback(AWT_load_list,selid,(AW_CL)strdup(base_name));
671
aws->create_button("LOAD", "LOAD","L");
673
awt_create_selection_box((AW_window *)aws,base_name);
674
return (AW_window*) aws;
678
void create_print_box_for_selection_lists(AW_window *aw_window,AW_CL selid){
679
AW_root *aw_root = aw_window->get_root();
680
char *data = aw_window->get_selection_list_contents((AW_selection_list *)selid);
681
AWT_create_ascii_print_window(aw_root,data,"no title");
687
/* ************************************************** */
688
AW_window *awt_create_load_box(AW_root *aw_root, const char *load_what, const char *file_extension, char **set_file_name_awar,
689
void (*callback)(AW_window*),
690
AW_window* (*create_popup)(AW_root *, AW_default))
692
/* You can either provide a normal callback or a create_popup-callback
693
* (the not-used callback has to be 0)
940
aws->callback(makeWindowCallback(load_list_cb, storabsellist));
941
aws->create_button("LOAD", "LOAD", "L");
944
aws->label("Append?");
945
aws->create_toggle(awar_append);
947
AW_create_fileselection(aws, awar_base_name, "", "PWD", ANY_DIR, true);
949
aws->recalc_pos_atShow(AW_REPOS_TO_MOUSE);
954
free(awar_base_name);
959
void awt_clear_selection_list_cb(AW_window *, AW_selection_list *sellist) {
961
sellist->insert_default("", "");
965
void create_print_box_for_selection_lists(AW_window *aw_window, const TypedSelectionList *typedsellist) {
966
char *data = typedsellist->get_sellist()->get_content_as_string(0);
967
AWT_create_ascii_print_window(aw_window->get_root(), data, typedsellist->whats_contained());
971
AW_window *awt_create_load_box(AW_root *aw_root,
974
const char *default_directory,
975
const char *file_extension,
976
char **set_file_name_awar,
977
const WindowCallback& ok_cb,
978
const WindowCallback& close_cb,
979
const char *close_button_text)
981
/* general purpose file selection box
983
* 'action' describes what is intended to be done (e.g. "Load").
984
* used for window title and button.
986
* 'what' describes what is going to be loaded (e.g. "destination database")
987
* It is also used to create the awars for the filebox, i.e. same description for multiple
988
* fileboxes makes them share the awars.
990
* if 'set_file_name_awar' is non-NULL, it'll be set to a heap-copy of the awar-name
991
* containing the full selected filename.
993
* 'default_directory' specifies the directory opened in the filebox
995
* 'file_extension' specifies the filter to be used (which files are shown)
997
* You have to provide an 'ok_cb', which will be called when 'OK' is pressed.
998
* Optionally you may pass a 'close_cb' which will be called when 'CLOSE' is pressed.
999
* If not given, AW_POPDOWN will be called.
1001
* Both callbacks will be called as callbacks of the load-box-window.
1002
* The load-box does not popdown, the callback has to do that.
1004
* Optionally you may also pass the button text for the 'CLOSE'-button (e.g. 'EXIT' or 'Abort')
698
char *base_name = GBS_global_string_copy("tmp/load_box_%s",load_what);
1008
char *what_key = GBS_string_2_key(what);
1009
char *base_name = GBS_global_string_copy("tmp/load_box_%s", what_key);
700
aw_create_selection_box_awars(aw_root, base_name, ".", file_extension, "");
1011
AW_create_fileselection_awars(aw_root, base_name, default_directory, file_extension, "");
702
1013
if (set_file_name_awar) {
703
1014
*set_file_name_awar = GBS_global_string_copy("%s/file_name", base_name);
706
1017
AW_window_simple *aws = new AW_window_simple;
708
1019
char title[100];
709
sprintf(title, "Load %s", load_what);
710
aws->init( aw_root, title, title);
1020
sprintf(title, "%s %s", action, what);
1021
aws->init(aw_root, title, title);
711
1022
aws->load_xfig("load_box.fig");
714
1025
aws->at("close");
715
aws->callback((AW_CB0)AW_POPDOWN);
716
aws->create_button("CLOSE", "CLOSE","C");
1026
aws->callback(close_cb);
1027
if (close_button_text) {
1028
aws->create_button("CLOSE", close_button_text, "");
1031
aws->create_button("CLOSE", "CLOSE", "C");
1033
#if defined(ARB_GTK)
1034
aws->set_close_action("CLOSE");
1038
// @@@ allow to pass helpfile
718
1039
aws->at("help");
719
aws->callback(AW_POPUP_HELP,(AW_CL)"");
720
aws->create_button("HELP","HELP");
1040
aws->callback(makeHelpCallback(""));
1041
aws->create_button("HELP", "HELP");
726
awt_assert(!create_popup);
727
aws->callback((AW_CB0)callback);
730
awt_assert(create_popup);
731
aws->callback((AW_CB1)AW_POPUP, (AW_CL)create_popup);
734
aws->create_button("LOAD", "LOAD","L");
736
awt_create_selection_box((AW_window *)aws,base_name);
1045
aws->callback(ok_cb);
1046
aws->create_button("GO", action);
1048
AW_create_standard_fileselection(aws, base_name);
737
1049
free(base_name);
738
return (AW_window*) aws;
741
/* ************************************************** */
745
void awt_set_long(AW_window *aws, AW_CL varname, AW_CL value) // set an awar
747
aws->get_root()->awar((char *)varname)->write_int((long) value);
750
void awt_write_string( AW_window *aws, AW_CL varname, AW_CL value) // set an awar
752
aws->get_root()->awar((char *)varname)->write_string((char *)value);
755
struct fileChanged_cb_data {
756
char *fpath; // full name of edited file
757
int lastModtime; // last known modification time of 'fpath'
758
bool editorTerminated; // do not free before this has been set to 'true'
759
awt_fileChanged_cb callback;
761
fileChanged_cb_data(char **fpath_ptr, awt_fileChanged_cb cb) {
763
*fpath_ptr = 0; // take ownage
764
lastModtime = getModtime();
765
editorTerminated = false;
769
~fileChanged_cb_data() {
775
if (stat(fpath, &st) == 0) return st.st_mtime;
779
bool fileWasChanged() {
780
int modtime = getModtime();
781
bool changed = modtime != lastModtime;
782
lastModtime = modtime;
1051
aws->recalc_pos_atShow(AW_REPOS_TO_MOUSE);
1056
// --------------------------------------------------------------------------------
1058
#define SUBSET_NOELEM_DISPLAY "<none>"
1060
class AW_subset_selection : public AW_selection {
1061
AW_selection_list& parent_sellist;
1063
static void finish_fill_box(AW_selection_list *parent_sellist, AW_selection_list *sub_sellist) {
1064
sub_sellist->insert_default(parent_sellist->get_default_display(), parent_sellist->get_default_value());
1065
sub_sellist->update();
1068
static AW_selection_list *create_box(AW_window *aww, AW_selection_list& parent_sellist) {
1069
const char *parent_awar_name = parent_sellist.get_awar_name();
1070
awt_assert(parent_awar_name[0] != '/');
1071
awt_assert(parent_sellist.get_awar_type() == GB_STRING); // only impl for strings
1073
AW_root *aw_root = aww->get_root();
1074
char *awar_name = GBS_global_string_copy("tmp/subsel/%s", parent_awar_name);
1076
aw_root->awar_string(awar_name);
1078
AW_selection_list *sub_sellist = aww->create_selection_list(awar_name, true);
1079
finish_fill_box(&parent_sellist, sub_sellist);
1087
AW_subset_selection(AW_window *aww, AW_selection_list& parent_sellist_)
1088
: AW_selection(create_box(aww, parent_sellist_)),
1089
parent_sellist(parent_sellist_)
1092
AW_selection_list *get_parent_sellist() const { return &parent_sellist; }
1094
const char *default_select_value() const { return parent_sellist.get_default_value(); }
1095
const char *default_select_display() const { return parent_sellist.get_default_display(); }
1097
void get_subset(StrArray& subset) {
1098
get_sellist()->to_array(subset, true);
1101
void fill() OVERRIDE { awt_assert(0); } // unused
1103
void collect_subset_cb(awt_collect_mode what) {
1104
AW_selection_list *subset_list = get_sellist();
1105
AW_selection_list *whole_list = get_parent_sellist();
1109
for (AW_selection_list_iterator listEntry(whole_list); listEntry; ++listEntry) {
1110
if (subset_list->get_index_of(listEntry.get_value()) == -1) { // only add not already existing elements
1111
subset_list->insert(listEntry.get_displayed(), listEntry.get_value());
1114
finish_fill_box(whole_list, subset_list);
1118
if (!whole_list->default_is_selected()) {
1119
const char *selected = whole_list->get_awar_value();
1120
int src_index = whole_list->get_index_of(selected);
1122
if (subset_list->get_index_of(selected) == -1) { // not yet in subset_list
1123
AW_selection_list_iterator entry(whole_list, src_index);
1124
subset_list->insert(entry.get_displayed(), entry.get_value());
1125
subset_list->update();
1128
subset_list->set_awar_value(selected); // position right side to newly added or already existing alignment
1129
whole_list->select_element_at(src_index+1); // go down 1 position on left side
1135
if (!subset_list->default_is_selected()) {
1136
char *selected = strdup(subset_list->get_awar_value());
1137
int old_position = subset_list->get_index_of(selected);
1139
subset_list->delete_element_at(old_position);
1140
finish_fill_box(whole_list, subset_list);
1142
subset_list->select_element_at(old_position);
1143
whole_list->set_awar_value(selected); // set left selection to deleted alignment
1149
subset_list->clear();
1150
finish_fill_box(whole_list, subset_list);
1154
void reorder_subset_cb(awt_reorder_mode dest) {
1155
AW_selection_list *subset_list = get_sellist();
1157
if (!subset_list->default_is_selected()) {
1158
const char *selected = subset_list->get_awar_value();
1160
StrArray listContent;
1161
subset_list->to_array(listContent, true);
1163
int old_pos = GBT_names_index_of(listContent, selected);
1167
case ARM_TOP: new_pos= 0; break;
1168
case ARM_UP: new_pos= old_pos-1; break;
1169
case ARM_DOWN: new_pos= old_pos+1; break;
1170
case ARM_BOTTOM: new_pos= -1; break;
1172
if (old_pos != new_pos) {
1173
GBT_names_move(listContent, old_pos, new_pos);
1174
subset_list->init_from_array(listContent, subset_list->get_default_value());
787
static void editor_terminated_cb(const char *IF_DEBUG(message), void *cb_data) {
788
fileChanged_cb_data *data = (fileChanged_cb_data*)cb_data;
791
printf("editor_terminated_cb: message='%s' fpath='%s'\n", message, data->fpath);
794
data->callback(data->fpath, data->fileWasChanged(), true);
795
data->editorTerminated = true; // trigger removal of check_file_changed_cb
798
#define AWT_CHECK_FILE_TIMER 700 // in ms
800
static void check_file_changed_cb(AW_root *aw_root, AW_CL cl_cbdata) {
801
fileChanged_cb_data *data = (fileChanged_cb_data*)cl_cbdata;
803
if (data->editorTerminated) {
807
bool changed = data->fileWasChanged();
809
if (changed) data->callback(data->fpath, true, false);
810
aw_root->add_timed_callback(AWT_CHECK_FILE_TIMER, check_file_changed_cb, cl_cbdata);
814
void AWT_edit(const char *path, awt_fileChanged_cb callback, AW_window *aww, GBDATA *gb_main) {
815
// Start external editor on file 'path' (asynchronously)
816
// if 'callback' is specified, it is called everytime the file is changed
817
// [aww and gb_main may be 0 if callback is 0]
819
const char *editor = GB_getenvARB_TEXTEDIT();
820
char *fpath = GBS_eval_env(path);
822
fileChanged_cb_data *cb_data = 0;
829
cb_data = new fileChanged_cb_data(&fpath, callback); // fpath now is 0 and belongs to cb_data
831
char *arb_notify = GB_generate_notification(gb_main, editor_terminated_cb, "editor terminated", (void*)cb_data);
832
if (!arb_notify) error = GB_await_error();
834
char *arb_message = GBS_global_string_copy("arb_message \"Could not start editor '%s'\"", editor);
836
command = GBS_global_string_copy("((%s %s || %s); %s)&", editor, cb_data->fpath, arb_message, arb_notify);
842
command = GBS_global_string_copy("%s %s &", editor, fpath);
847
error = GB_system(command);
849
aw_message(error); error = NULL;
850
if (callback) error = GB_remove_last_notification(gb_main);
852
else { // successfully started editor
853
// Can't be sure editor really started when callback is used (see command above).
854
// But it doesn't matter, cause arb_notify is called anyway and removes all callbacks
856
// add timed callback tracking file change
857
AW_root *aw_root = aww->get_root();
858
aw_root->add_timed_callback(AWT_CHECK_FILE_TIMER, check_file_changed_cb, (AW_CL)cb_data);
859
cb_data = 0; // now belongs to check_file_changed_cb
864
if (error) aw_message(error);
872
void AWT_popup_select_species_field_window(AW_window *aww, AW_CL cl_awar_name, AW_CL cl_gb_main)
874
static AW_window_simple *aws = 0;
876
// everytime map selection awar to latest user awar:
877
AW_root *aw_root = aww->get_root();
878
const char *awar_name = (const char *)cl_awar_name;
879
aw_root->awar("tmp/viewkeys/key_text_select")->map(awar_name);
882
aws = new AW_window_simple;
884
aws->init( aw_root, "SELECT_SPECIES_FIELD", "Select species field");
885
aws->load_xfig("awt/nds_sel.fig");
886
aws->button_length(13);
888
aws->callback( AW_POPDOWN);
890
aws->create_button("CLOSE", "CLOSE","C");
892
awt_create_selection_list_on_scandb((GBDATA *)cl_gb_main,
894
"tmp/viewkeys/key_text_select",
896
"scandb","rescandb", &AWT_species_selector, 20, 10);
1181
static void collect_subset_cb(AW_window *, awt_collect_mode what, AW_CL cl_subsel) { ((AW_subset_selection*)cl_subsel)->collect_subset_cb(what); }
1182
static void reorder_subset_cb(AW_window *, awt_reorder_mode dest, AW_CL cl_subsel) { ((AW_subset_selection*)cl_subsel)->reorder_subset_cb(dest); }
1184
AW_selection *awt_create_subset_selection_list(AW_window *aww, AW_selection_list *parent_selection, const char *at_box, const char *at_add, const char *at_sort) {
1185
awt_assert(parent_selection);
1188
int x_list = aww->get_at_xposition();
1190
AW_subset_selection *subsel = new AW_subset_selection(aww, *parent_selection);
1192
aww->button_length(0);
1195
int x_buttons = aww->get_at_xposition();
1197
bool move_rightwards = x_list>x_buttons;
1198
awt_create_collect_buttons(aww, move_rightwards, collect_subset_cb, (AW_CL)subsel);
1201
awt_create_order_buttons(aww, reorder_subset_cb, (AW_CL)subsel);