Redesign the item deletion menu
Instead of the previous inconsistent and potentially nested menus, the following message is now displayed when deleting an item: Delete (s)elected occurrence, (a)ll occurrences, or only the (n)ote? Options that are not available (e.g. because the item is not recurrent or does not have a note) are omitted. For a non-recurrent item without a note the message becomes Delete (s)elected occurrence? and is skipped if general.confirmdelete is disabled. Implements GitHub feature request #308. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
95151e3f0c
commit
47fb9b740f
120
src/ui-day.c
120
src/ui-day.c
@ -1229,77 +1229,85 @@ void ui_day_item_add(void)
|
|||||||
/* Delete an item from the appointment list. */
|
/* Delete an item from the appointment list. */
|
||||||
void ui_day_item_delete(unsigned reg)
|
void ui_day_item_delete(unsigned reg)
|
||||||
{
|
{
|
||||||
const char *del_app_str =
|
const char *msg, *choices;
|
||||||
_("Do you really want to delete this item?");
|
int nb_choices;
|
||||||
|
|
||||||
const char *erase_warning =
|
|
||||||
_("This item is recurrent. "
|
|
||||||
"Delete (a)ll occurences or just this (o)ne?");
|
|
||||||
const char *erase_choices = _("[ao]");
|
|
||||||
const int nb_erase_choices = 2;
|
|
||||||
|
|
||||||
const char *note_warning =
|
|
||||||
_("This item has a note attached to it. "
|
|
||||||
"Delete (i)tem or just its (n)ote?");
|
|
||||||
const char *note_choices = _("[in]");
|
|
||||||
const int nb_note_choices = 2;
|
|
||||||
time_t occurrence;
|
time_t occurrence;
|
||||||
|
|
||||||
if (day_item_count(0) <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *p = ui_day_get_sel();
|
struct day_item *p = ui_day_get_sel();
|
||||||
|
int has_note = (day_item_get_note(p) != NULL);
|
||||||
|
int is_recur = (p->type == RECUR_EVNT || p->type == RECUR_APPT);
|
||||||
|
|
||||||
if (conf.confirm_delete) {
|
if (has_note && is_recur) {
|
||||||
if (status_ask_bool(del_app_str) != 1) {
|
msg = _("This item is recurrent and has a note attached to it. "
|
||||||
wins_erase_status_bar();
|
"Delete (s)elected occurrence, (a)ll occurrences, "
|
||||||
return;
|
"or just its (n)ote?");
|
||||||
}
|
choices = _("[san]");
|
||||||
|
nb_choices = 3;
|
||||||
|
} else if (has_note) {
|
||||||
|
msg = _("This item has a note attached to it. "
|
||||||
|
"Delete (s)elected occurrence or just its (n)ote?");
|
||||||
|
choices = _("[sn]");
|
||||||
|
nb_choices = 2;
|
||||||
|
} else if (is_recur) {
|
||||||
|
msg = _("This item is recurrent. "
|
||||||
|
"Delete (s)elected occurrence or (a)ll occurrences?");
|
||||||
|
choices = _("[sa]");
|
||||||
|
nb_choices = 2;
|
||||||
|
} else {
|
||||||
|
msg = _("Confirm deletion. "
|
||||||
|
"Delete (s)elected occurrence? Press (s) to confirm.");
|
||||||
|
choices = _("[s]");
|
||||||
|
nb_choices = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (day_item_get_note(p)) {
|
int answer = 1;
|
||||||
switch (status_ask_choice
|
if (nb_choices > 1 || conf.confirm_delete) {
|
||||||
(note_warning, note_choices, nb_note_choices)) {
|
answer = status_ask_choice(msg, choices, nb_choices);
|
||||||
case 1:
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
day_item_erase_note(p);
|
|
||||||
io_set_modified();
|
|
||||||
return;
|
|
||||||
default: /* User escaped */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->type == RECUR_EVNT || p->type == RECUR_APPT) {
|
/* Always map "all occurrences" to 2 and "note" to 3. */
|
||||||
switch (status_ask_choice
|
if (has_note && !is_recur && answer == 2)
|
||||||
(erase_warning, erase_choices, nb_erase_choices)) {
|
answer = 3;
|
||||||
case 1:
|
/*
|
||||||
break;
|
* The option "selected occurrence" should be treated like "all
|
||||||
case 2:
|
* occurrences" for a non-recurrent item (delete the whole item).
|
||||||
if (p->type == RECUR_EVNT) {
|
*/
|
||||||
day_item_add_exc(p, ui_day_sel_date());
|
if (!is_recur && answer == 1)
|
||||||
} else {
|
answer = 2;
|
||||||
recur_apoint_find_occurrence(p->item.rapt,
|
|
||||||
ui_day_sel_date(),
|
|
||||||
&occurrence);
|
|
||||||
day_item_add_exc(p, occurrence);
|
|
||||||
}
|
|
||||||
|
|
||||||
io_set_modified();
|
switch (answer) {
|
||||||
ui_calendar_monthly_view_cache_set_invalid();
|
case 1:
|
||||||
/* Keep the selection on the same day. */
|
/* Delete selected occurrence (of a recurrent item) only. */
|
||||||
day_set_sel_data(
|
if (p->type == RECUR_EVNT) {
|
||||||
day_get_item(listbox_get_sel(&lb_apt) - 1)
|
day_item_add_exc(p, ui_day_sel_date());
|
||||||
);
|
} else {
|
||||||
return;
|
recur_apoint_find_occurrence(p->item.rapt,
|
||||||
default:
|
ui_day_sel_date(),
|
||||||
return;
|
&occurrence);
|
||||||
|
day_item_add_exc(p, occurrence);
|
||||||
}
|
}
|
||||||
|
/* Keep the selection on the same day. */
|
||||||
|
day_set_sel_data(day_get_item(listbox_get_sel(&lb_apt) - 1));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
/* Delete all occurrences (or a non-recurrent item). */
|
||||||
|
ui_day_item_cut(reg);
|
||||||
|
/* Keep the selection on the same day. */
|
||||||
|
day_set_sel_data(day_get_item(listbox_get_sel(&lb_apt) - 1));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
/* Delete note. */
|
||||||
|
day_item_erase_note(p);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* User escaped, do nothing. */
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ui_day_item_cut(reg);
|
|
||||||
/* Keep the selection on the same day. */
|
|
||||||
day_set_sel_data(day_get_item(listbox_get_sel(&lb_apt) - 1));
|
|
||||||
io_set_modified();
|
io_set_modified();
|
||||||
ui_calendar_monthly_view_cache_set_invalid();
|
ui_calendar_monthly_view_cache_set_invalid();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user