summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.c9
-rw-r--r--src/calcurse.h3
-rw-r--r--src/io.c19
-rw-r--r--src/ui-day.c20
-rw-r--r--src/ui-todo.c7
5 files changed, 58 insertions, 0 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index ce64b1f..149d7bb 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -256,6 +256,13 @@ static inline void key_generic_save(void)
static inline void key_generic_reload(void)
{
+ if (io_get_modified() && status_ask_bool(_("By reloading items, you "
+ "will lose any unsaved modifications. "
+ "Continue?")) != 1) {
+ wins_update(FLAG_STA);
+ return;
+ }
+
/* Reinitialize data structures. */
apoint_llist_free();
event_llist_free();
@@ -271,6 +278,7 @@ static inline void key_generic_reload(void)
io_load_todo();
io_load_app();
+ io_unset_modified();
ui_todo_load_items();
ui_todo_sel_reset();
@@ -616,6 +624,7 @@ int main(int argc, char **argv)
io_load_keys(conf.pager);
io_load_todo();
io_load_app();
+ io_unset_modified();
wins_resize();
/*
* Refresh the hidden key handler window here to prevent wgetch() from
diff --git a/src/calcurse.h b/src/calcurse.h
index e87f6b1..ca85690 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -779,6 +779,9 @@ unsigned io_dump_pid(char *);
unsigned io_get_pid(char *);
int io_file_is_empty(char *);
int io_file_cp(const char *, const char *);
+void io_unset_modified(void);
+void io_set_modified(void);
+int io_get_modified(void);
/* keys.c */
void keys_init(void);
diff --git a/src/io.c b/src/io.c
index 4ff31e3..acf624b 100644
--- a/src/io.c
+++ b/src/io.c
@@ -83,6 +83,8 @@ HTABLE_PROTOTYPE(ht_keybindings, ht_keybindings_s)
HTABLE_GENERATE(ht_keybindings, ht_keybindings_s, load_keys_ht_getkey,
load_keys_ht_compare)
+static int modified = 0;
+
/* Draw a progress bar while saving, loading or exporting data. */
static void progress_bar(progress_bar_t type, int progress)
{
@@ -430,6 +432,8 @@ void io_save_cal(enum save_display display)
if (!io_save_keys())
ERROR_MSG("%s", access_pb);
+ io_unset_modified();
+
/* Print a message telling data were saved */
if (ui_mode == UI_CURSES && conf.system_dialogs) {
status_mesg(save_success, enter);
@@ -1342,3 +1346,18 @@ int io_file_cp(const char *src, const char *dst)
return 1;
}
+
+void io_unset_modified(void)
+{
+ modified = 0;
+}
+
+void io_set_modified(void)
+{
+ modified = 1;
+}
+
+int io_get_modified(void)
+{
+ return modified;
+}
diff --git a/src/ui-day.c b/src/ui-day.c
index a39b88b..269d818 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -314,9 +314,11 @@ void ui_day_item_edit(void)
(_("Edit: "), choice_recur_evnt, 2)) {
case 1:
update_desc(&re->mesg);
+ io_set_modified();
break;
case 2:
update_rept(&re->rpt, re->day);
+ io_set_modified();
break;
default:
return;
@@ -325,6 +327,7 @@ void ui_day_item_edit(void)
case EVNT:
e = p->item.ev;
update_desc(&e->mesg);
+ io_set_modified();
break;
case RECUR_APPT:
ra = p->item.rapt;
@@ -340,23 +343,28 @@ void ui_day_item_edit(void)
case 1:
need_check_notify = 1;
update_start_time(&ra->start, &ra->dur, 1);
+ io_set_modified();
break;
case 2:
update_duration(&ra->start, &ra->dur);
+ io_set_modified();
break;
case 3:
if (notify_bar())
need_check_notify =
notify_same_recur_item(ra);
update_desc(&ra->mesg);
+ io_set_modified();
break;
case 4:
need_check_notify = 1;
update_rept(&ra->rpt, ra->start);
+ io_set_modified();
break;
case 5:
need_check_notify = 1;
update_start_time(&ra->start, &ra->dur, 0);
+ io_set_modified();
break;
default:
return;
@@ -375,19 +383,23 @@ void ui_day_item_edit(void)
case 1:
need_check_notify = 1;
update_start_time(&a->start, &a->dur, 1);
+ io_set_modified();
break;
case 2:
update_duration(&a->start, &a->dur);
+ io_set_modified();
break;
case 3:
if (notify_bar())
need_check_notify =
notify_same_item(a->start);
update_desc(&a->mesg);
+ io_set_modified();
break;
case 4:
need_check_notify = 1;
update_start_time(&a->start, &a->dur, 0);
+ io_set_modified();
break;
default:
return;
@@ -549,6 +561,7 @@ void ui_day_item_add(void)
date2sec(*ui_calendar_get_slctd_day(), 0,
0), 1);
}
+ io_set_modified();
}
ui_calendar_monthly_view_cache_set_invalid();
@@ -594,6 +607,7 @@ void ui_day_item_delete(unsigned reg)
break;
case 2:
day_item_erase_note(p);
+ io_set_modified();
return;
default: /* User escaped */
return;
@@ -607,6 +621,7 @@ void ui_day_item_delete(unsigned reg)
break;
case 2:
day_item_add_exc(p, date);
+ io_set_modified();
return;
default:
return;
@@ -617,6 +632,7 @@ void ui_day_item_delete(unsigned reg)
p = day_cut_item(date, listbox_get_sel(&lb_apt));
day_cut[reg].type = p->type;
day_cut[reg].item = p->item;
+ io_set_modified();
ui_calendar_monthly_view_cache_set_invalid();
}
@@ -764,6 +780,7 @@ void ui_day_item_repeat(void)
p = day_cut_item(date, item_nb);
day_cut[REG_BLACK_HOLE].type = p->type;
day_cut[REG_BLACK_HOLE].item = p->item;
+ io_set_modified();
ui_calendar_monthly_view_cache_set_invalid();
}
@@ -815,6 +832,7 @@ void ui_day_item_paste(unsigned reg)
day_item_fork(&day_cut[reg], &day);
day_paste_item(&day, ui_calendar_get_slctd_day_sec());
+ io_set_modified();
ui_calendar_monthly_view_cache_set_invalid();
}
@@ -905,6 +923,7 @@ void ui_day_flag(void)
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
day_item_switch_notify(item);
+ io_set_modified();
}
void ui_day_view_note(void)
@@ -923,4 +942,5 @@ void ui_day_edit_note(void)
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
day_edit_note(item, conf.editor);
+ io_set_modified();
}
diff --git a/src/ui-todo.c b/src/ui-todo.c
index 900bbfe..858596d 100644
--- a/src/ui-todo.c
+++ b/src/ui-todo.c
@@ -54,6 +54,7 @@ void ui_todo_add(void)
}
todo_add(todo_input, ch - '0', NULL);
ui_todo_load_items();
+ io_set_modified();
}
}
@@ -88,9 +89,11 @@ void ui_todo_delete(void)
case 1:
todo_delete(item);
ui_todo_load_items();
+ io_set_modified();
break;
case 2:
todo_delete_note(item);
+ io_set_modified();
break;
default:
wins_erase_status_bar();
@@ -109,6 +112,7 @@ void ui_todo_edit(void)
status_mesg(mesg, "");
updatestring(win[STA].p, &item->mesg, 0, 1);
+ io_set_modified();
}
/* Pipe a todo item to an external program. */
@@ -241,6 +245,7 @@ void ui_todo_chg_priority(int diff)
item_new = todo_add(item->mesg, id, item->note);
todo_delete(item);
+ io_set_modified();
listbox_set_sel(&lb_todo, todo_get_position(item_new));
}
@@ -260,6 +265,7 @@ void ui_todo_flag(void)
struct todo *item = todo_get_item(listbox_get_sel(&lb_todo));
todo_flag(item);
+ io_set_modified();
}
void ui_todo_view_note(void)
@@ -278,4 +284,5 @@ void ui_todo_edit_note(void)
struct todo *item = todo_get_item(listbox_get_sel(&lb_todo));
todo_edit_note(item, conf.editor);
+ io_set_modified();
}