24 #define AWAR_QUESTION "tmp/question"
26 int aw_question(
const char *unique_id,
const char *question,
const char *buttons,
bool sameSizeButtons,
const char *helpfile) {
53 int result = awar_neverAskAgain ? awar_neverAskAgain->
read_int() : 0;
58 if (!question) question =
"No question?! Please report this as a bug.";
60 char *button_list = strdup(buttons ? buttons :
"OK");
61 if (button_list[0] == 0) {
62 freedup(button_list,
"Maybe ok,EXIT");
65 "(Program error - Unsure what happens when you click ok\n"
66 " Check console for backtrace and report error)",
74 size_t question_length, question_lines;
79 button_list, unique_id ? unique_id :
"<NOID>",
80 question_length, question_lines,
int(sameSizeButtons),
81 null2empty(helpfile));
88 printf(
"hindex='%s'\n", hindex);
96 aw_msg->init(root, wid,
"ARB prompt",
false);
101 aw_msg->label_length(10);
104 aw_msg->auto_space(10, 10);
106 aw_msg->button_length(question_length+3);
107 aw_msg->button_height(question_lines+1);
111 aw_msg->button_height(0);
113 aw_msg->at_newline();
115 if (sameSizeButtons) {
116 size_t max_button_length = helpfile ? 4 : 0;
117 char *pos = button_list;
120 char *comma = strchr(pos,
',');
121 if (!comma) comma = strchr(pos, 0);
123 size_t len = comma-pos;
124 if (len>max_button_length) max_button_length = len;
126 if (!comma[0])
break;
130 aw_msg->button_length(max_button_length+2);
133 aw_msg->button_length(0);
137 char *ret = strtok(button_list,
",");
138 bool help_button_done =
false;
143 if (helpfile && !help_button_done) {
145 aw_msg->create_button(
"HELP",
"HELP",
"H");
146 help_button_done =
true;
148 aw_msg->at_newline();
151 if (strcmp(ret,
"EXIT") == 0) {
152 aw_msg->callback(makeWindowCallback(
message_cb, -1));
155 aw_msg->callback(makeWindowCallback(
message_cb, counter++));
158 if (sameSizeButtons) {
159 aw_msg->create_button(
NULp, ret);
162 aw_msg->create_autosize_button(
NULp, ret);
164 ret = strtok(
NULp,
",");
167 if (helpfile && !help_button_done) {
169 aw_msg->create_button(
"HELP",
"HELP",
"H");
170 help_button_done =
true;
174 if (awar_neverAskAgain) {
175 aw_msg->at_newline();
176 const char *
label = counter>1 ?
"Never ask again" :
"Never notify me again";
177 aw_msg->label_length(strlen(label));
178 aw_msg->label(label);
179 aw_msg->create_toggle(awar_neverAskAgain->
awar_name);
182 aw_msg->window_fit();
186 printf(
"[Reusing existing aw_question-window]\n");
195 #if defined(TRACE_STATUS_MORE)
197 #endif // TRACE_STATUS_MORE
210 if (awar_neverAskAgain && awar_neverAskAgain->
read_int()) {
212 awar_neverAskAgain->
write_int(answerCode);
217 (
"You will not be asked that question again in this session.\n"
218 "%s will always assume the answer you just gave.\n"
220 "After restarting %s that question will be asked again.\n"
221 "To disable that question permanently for future sessions,\n"
222 "you need to save properties.\n"
224 "Depending on the type of question, disabling it might be\n"
225 "helpful or obstructive.\n"
226 "Disabled questions can be reactivated from the properties menu.\n",
239 fprintf(stderr,
"Core dump requested\n");
281 const char *msg =
"No questions were disabled yet.";
283 if (gb_neverAskedAgain) {
293 "To reactivate them for future sessions, save properties.",
301 void AW_repeated_question::add_help(
const char *help_file) {
302 freedup(helpfile, help_file);
305 int AW_repeated_question::get_answer(
const char *unique_id,
const char *question,
const char *buttons,
const char *to_all,
bool add_abort) {
307 buttons_used = strdup(buttons);
314 if (answer == -1 || !dont_ask_again) {
317 int all_len = strlen(all);
318 size_t but_len = strlen(buttons);
319 size_t new_buttons_len = but_len*3+1+(add_abort ? 6 : 0)+all_len*3;
320 char *new_buttons = ARB_alloc<char>(new_buttons_len);
321 int button_count = 0;
324 char *w = new_buttons;
325 const char *r = buttons;
328 const char *comma = strchr(r,
',');
329 if (!comma) comma = strchr(r, 0);
332 if (!dont_ask_again) {
333 if (w>new_buttons) *w++ =
'^';
334 memcpy(w, r, len); w += len;
337 memcpy(w, r, len); w += len;
338 memcpy(w, all, all_len); w += all_len;
343 if (!comma[0])
break;
347 const char *abort =
"^ABORT";
348 strcpy(w, abort); w += strlen(abort);
355 aw_assert(
size_t(w-new_buttons) < new_buttons_len);
360 int user_answer =
aw_question(unique_id, question, new_buttons,
true, helpfile);
362 if (dont_ask_again) {
363 answer = user_answer;
366 answer = user_answer/2;
367 dont_ask_again = (user_answer%2) || (user_answer == (button_count*2));
372 aw_assert(answer<(button_count+(add_abort ? 1 : 0)));
GB_ERROR GB_check_key(const char *key) __ATTR__USERESULT
#define AW_MESSAGE_LISTEN_DELAY
long GB_read_int(GBDATA *gbd)
GBDATA * GB_child(GBDATA *father)
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
const char * GBS_global_string(const char *templat,...)
void AW_advice(const char *message, AW_Advice_Type type, const char *title, const char *corresponding_help)
Show a message box with an advice for the user.
void add_timed_callback_never_disabled(int ms, const TimedCallback &tcb)
char * GBS_string_2_key(const char *str)
#define ARB_SIGSEGV(backtrace)
unsigned aw_message_timer_listen_event(AW_root *, AW_window *aww)
static AW_root * SINGLETON
WindowCallback makeHelpCallback(const char *helpfile)
void message_cb(AW_window *, int result)
void aw_popup_ok(const char *msg)
static void error(const char *msg)
void AW_reactivate_all_questions(AW_window *)
GB_ERROR GB_write_int(GBDATA *gbd, long i)
bool aw_ask_sure(const char *unique_id, const char *msg)
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
#define assert_or_exit(cond)
void GBK_dump_backtrace(FILE *out, const char *message)
void aw_message(const char *msg)
__ATTR__NORETURN void aw_popup_exit(const char *msg)
GB_ERROR write_string(const char *aw_string)
GBDATA * GB_nextChild(GBDATA *child)
GB_transaction ta(gb_var)
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_ERROR write_int(long aw_int)
long GBS_read_hash(const GB_HASH *hs, const char *key)
char * GBS_global_string_copy(const char *templat,...)
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)