HTML: use Right/Left arrows to switch between dives

Use arrows to switch between dives in dive detailed view.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: use a global variable to hold the dive we show / edit

There is massive confusion about what we display when and where and which
dive structure (or pointer to a dive structure) contains which information
at which stage. This is the first step towards restructuring all of this.

This creates a global variable displayed_dive which at any point in time
should be what is displayed on screen (both in the profile and in the
maintab). It removes the editedDive concept from MainTab.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: plotDive should just take one dive

We don't have a concept of what to do when plotting multiple dives, so
let's not pretend and remove all the messing around with lists.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: fix get_divenr to do the right thing on a copy of a dive

We should not care if the dive has the same address in memory. We care if
it is the same dive (by using the unique ID).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: add helper function to copy and clear a dive

This way we can safely copy around dives (specifically, copy the dive to
be displayed / edited into the displayed_dive).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: plotDive: plot current dive by default & use displayed_dive

No longer use the dive structure that is passed in but instead always use
the displayed_dive to display things.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: updateDiveInfo shows the selected dive by default

So don't be redundant.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: always display pictures for displayed dive

The only time this is ever wrong is in print mode, so let's never show
pictures in print mode.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: updateDiveInfo displays displayed_dive

Instead of passing in a divenr of -1 to make it clear things this changes
things to use an options "clear" flag.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add a "smart strdup" helper named copy_string()

If the string is non-NULL, copy it, otherwise return NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: improve memory handling in maintab

Free strings before overwriting them. Use copy_dive() instead of just
copying the dive structure.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: track if any data was modified

Instead of comparing the dive structures (which doesn't work since the
strings are actually copies), track if the user made changes.

Cylinders and weights still need to be compared as they are handled in
different widgets.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: only switch to edit mode if user made change

With this patch a simple click into the main tab does not start editing
mode. Only once a value is modified do we show the message box and disable
the other widgets.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: get rid of "current" pointer in cylinders and weights

Instead always display the display_dive.

Now the only thing left to slay is the stagingDive...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: add clone_dive helper

This is kind of the inverse to copy_dive(). Instead of duplicating all the
data that the dive points to, it moves it to a new struct dive and zeroes
out the old one so there are no two sets of pointers to these data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: make planner act on displayed_dive

Instead of constantly creating and deleting dives and messing with the
dive list.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: don't use random dives from the divelist for data

Everything should come from the displayed_dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
UI restructure: use displayed_dive for add dive and plan dive

This gets rid of the stagingDive and stops the constant adding and
removing of dives from the divelist (that was an INSANE design,
seriously).

When adding or planning a dive all work is now done in the dedicated
displayed_dive.

Add dive mostly works - when the user clicks save the dive is added to the
dive list and selected.

Plan dive is mostly untested. It passed trivial "start planner, save"
testing so it's not entirely broken, but I'm sure there's more work to be
done there.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>