mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Undo: be smarter about dive computer shown after deletion
When deleting a dive computer, don't just show the first dive computer, but the next one in the list (if it exists). Moreover, on undo jump to the previously shown dive computer. Do this by keeping track of the before and after dive computer number in the undo command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4fe9b39cdb
commit
a124198275
2 changed files with 8 additions and 5 deletions
|
@ -802,7 +802,8 @@ SplitDiveComputer::SplitDiveComputer(dive *d, int dc_num) : SplitDivesBase(d, sp
|
||||||
setText(tr("split dive computer"));
|
setText(tr("split dive computer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DiveComputerBase::DiveComputerBase(dive *old_dive, dive *new_dive)
|
DiveComputerBase::DiveComputerBase(dive *old_dive, dive *new_dive, int dc_nr_after_in) : dc_nr_before(dc_number),
|
||||||
|
dc_nr_after(dc_nr_after_in)
|
||||||
{
|
{
|
||||||
if (!new_dive)
|
if (!new_dive)
|
||||||
return;
|
return;
|
||||||
|
@ -840,7 +841,8 @@ void DiveComputerBase::redoit()
|
||||||
restoreSelection(diveToRemove.dives, diveToRemove.dives[0]);
|
restoreSelection(diveToRemove.dives, diveToRemove.dives[0]);
|
||||||
|
|
||||||
// Update the profile to show the first dive computer
|
// Update the profile to show the first dive computer
|
||||||
dc_number = 0;
|
dc_number = dc_nr_after;
|
||||||
|
std::swap(dc_nr_before, dc_nr_after);
|
||||||
MainWindow::instance()->graphics->replot(current_dive);
|
MainWindow::instance()->graphics->replot(current_dive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,13 +853,13 @@ void DiveComputerBase::undoit()
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveDiveComputerToFront::MoveDiveComputerToFront(dive *d, int dc_num)
|
MoveDiveComputerToFront::MoveDiveComputerToFront(dive *d, int dc_num)
|
||||||
: DiveComputerBase(d, make_first_dc(d, dc_num))
|
: DiveComputerBase(d, make_first_dc(d, dc_num), 0)
|
||||||
{
|
{
|
||||||
setText(tr("move dive computer to front"));
|
setText(tr("move dive computer to front"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteDiveComputer::DeleteDiveComputer(dive *d, int dc_num)
|
DeleteDiveComputer::DeleteDiveComputer(dive *d, int dc_num)
|
||||||
: DiveComputerBase(d, clone_delete_divecomputer(d, dc_num))
|
: DiveComputerBase(d, clone_delete_divecomputer(d, dc_num), std::min(count_divecomputers(d) - 1, dc_num))
|
||||||
{
|
{
|
||||||
setText(tr("delete dive computer"));
|
setText(tr("delete dive computer"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ class DiveComputerBase : public DiveListBase {
|
||||||
protected:
|
protected:
|
||||||
// old_dive must be a dive known to the core.
|
// old_dive must be a dive known to the core.
|
||||||
// new_dive must be new dive whose ownership is taken.
|
// new_dive must be new dive whose ownership is taken.
|
||||||
DiveComputerBase(dive *old_dive, dive *new_dive);
|
DiveComputerBase(dive *old_dive, dive *new_dive, int dc_nr_after);
|
||||||
private:
|
private:
|
||||||
void undoit() override;
|
void undoit() override;
|
||||||
void redoit() override;
|
void redoit() override;
|
||||||
|
@ -254,6 +254,7 @@ protected:
|
||||||
// For redo and undo
|
// For redo and undo
|
||||||
DivesAndTripsToAdd diveToAdd;
|
DivesAndTripsToAdd diveToAdd;
|
||||||
DivesAndSitesToRemove diveToRemove;
|
DivesAndSitesToRemove diveToRemove;
|
||||||
|
int dc_nr_before, dc_nr_after;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MoveDiveComputerToFront : public DiveComputerBase {
|
class MoveDiveComputerToFront : public DiveComputerBase {
|
||||||
|
|
Loading…
Add table
Reference in a new issue