diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2014-07-16 23:22:36 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2014-07-16 23:31:31 +0200 |
commit | 5aec5408950ed41fad203e749bda225bd3f86a8b (patch) | |
tree | 87e49708cb0ab6d8ca92484ac331cd6a42a166a6 /src/calcurse.c | |
parent | e93030befb2aebe94faf5c5455313d312611d7b3 (diff) | |
download | calcurse-5aec5408950ed41fad203e749bda225bd3f86a8b.zip |
Allow for merging data files when reloading
This allows for merging the (unsaved) items with the items from the data
files when invoking the reload operation. To this end, an external merge
tool (defaults to vimdiff) is used.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/calcurse.c')
-rw-r--r-- | src/calcurse.c | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/calcurse.c b/src/calcurse.c index 149d7bb..cfe8298 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -256,11 +256,54 @@ 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; + if (io_get_modified()) { + const char *msg_um_prefix = + _("There are unsaved modifications:"); + const char *msg_um_discard = _("(d)iscard"); + const char *msg_um_merge = _("(m)erge"); + const char *msg_um_keep = _("(k)eep and cancel"); + const char *msg_um_choice = _("[dmk]"); + + char msg_um_asktype[BUFSIZ]; + snprintf(msg_um_asktype, BUFSIZ, "%s %s, %s, %s", + msg_um_prefix, msg_um_discard, msg_um_merge, + msg_um_keep); + + char *path_apts_backup, *path_todo_backup; + const char *backup_ext = ".sav"; + + switch (status_ask_choice(msg_um_asktype, msg_um_choice, 3)) { + case 1: + break; + case 2: + path_apts_backup = xmalloc(strlen(path_apts) + + strlen(backup_ext) + 1); + path_todo_backup = xmalloc(strlen(path_todo) + + strlen(backup_ext) + 1); + sprintf(path_apts_backup, "%s%s", path_apts, + backup_ext); + sprintf(path_todo_backup, "%s%s", path_todo, + backup_ext); + + io_save_mutex_lock(); + io_save_apts(path_apts_backup); + io_save_todo(path_todo_backup); + io_save_mutex_unlock(); + + wins_launch_external2(path_apts, path_apts_backup, + conf.mergetool); + wins_launch_external2(path_todo, path_todo_backup, + conf.mergetool); + + xfree(path_apts_backup); + xfree(path_todo_backup); + break; + case 3: + /* FALLTHROUGH */ + default: + wins_update(FLAG_STA); + return; + } } /* Reinitialize data structures. */ |