Warn when reloading with unsaved modifications

Since the reload operation overwrites all changes, warn before reloading
if there are unsaved modifications.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
day.c: Fix typo in error message

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Add a cleanup handler for the notify main thread

Make sure we do not leave behind unusable mutexes when calling
pthread_cancel().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
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>
Avoid cancelling the save thread during saving

Ensure that we never cancel the periodic save thread when it currently
saves the configuration and data files.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Refactor wins_launch_external()

Allow for passing an arbitrary number of arguments. This also allows us
to remove wins_launch_external2() and use wins_launch_external() at all
call sites instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
wins.c: Drop NB_*_CMDS

Store the current number of commands in a static variable and drop the
NB_*_CMDS variables which we outdated anyway.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Split out code to set bindings

Split wins_status_bar() into wins_set_bindings(), wins_update_bindings()
and wins_status_bar(). This allows for using wins_set_bindings() to set
custom key bindings to be displayed.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Reintroduce key bindings in configuration menus

The key bindings display in the status bar was removed from the general
options menu in bd182fb (Use generic list box for general options,
2014-05-13) and from the notification options menu in 5eea05a (Use
generic list box for notification options, 2014-05-13). Display the new
key bindings to use for navigation.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Only run the merge tool on files with differences

If the backup file and the data file are equal, there is no need to run
the merge tool.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Pause notification thread when reloading items

Prevent the notification thread from accessing data structures for
appointments and todo items while we are recreating them.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Rework key binding context switching

Store key binding contexts using another data structure to optimize
space usage and execution time.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
keys.c: Merge keydef and binding_labels

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Fix selection in listbox_load_items()

Call listbox_fix_sel() after setting an initial selection in
listbox_load_items() to make sure we do not pick a caption row.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Initialize prompt buffers in the configuration menus

malloc() does not make sure that the buffer is initialized to contain
all zeros. Initialize the buffer with the empty string.

Reported-by: Håkan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Do not display dialog on periodic save

When periodic save is enabled, do not print the "The data files were
successfully saved" dialog every time io_save_cal() is called.

Reported-by: Håkan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Do not use malloc() or xmalloc()

Use mem_malloc() instead which automatically picks the right
implementation depending on whether memory debugging is enabled or not.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Always fix selection in listbox_load_items()

Since commit 80a7267 (Fix selection in listbox_load_items(),
2014-07-18), listbox_fix_sel() is called if the selection is out of
range after loading the new set of items. However, we should *always*
fix the selection to make sure the selection doesn't move to a caption
row when reloading items.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Make bindings always fill the whole status bar

Compute padding for key bindings in the status bar such that they use
all available space (without exceeding the given page size).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Use wins_set_bindings() for the configuration menu

Make use of the general key binding context switching implementation for
the configuration main menu.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>