Skip to content

Commit

Permalink
MapEditorController: Remove Popup window for empty map parts
Browse files Browse the repository at this point in the history
If the map part to be removed or merged is empty, it's an option to
avoid asking the user before removing the empty map part as no objects
are affected.
This commit removes the popup window in case of empty map parts.
  • Loading branch information
dl3sdo committed Nov 19, 2022
1 parent 66a9f17 commit 9cd83d6
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions src/gui/map/map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3852,40 +3852,39 @@ void MapEditorController::removeMapPart()
auto* part = map->getCurrentPart();
auto i = part->getNumObjects();

QMessageBox::StandardButton button =
QMessageBox::question(
if (i > 0)
{
if (QMessageBox::question(
window,
tr("Remove current part"),
i ? tr("Do you want to remove map part \"%1\" and its %2 objects?").arg(part->getName()).arg(i) :
tr("Do you want to remove empty map part \"%1\"?").arg(part->getName()),
QMessageBox::Yes | QMessageBox::No );
tr("Do you want to remove map part \"%1\" and its %2 objects?").arg(part->getName()).arg(i),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No)
return;
}

if (button == QMessageBox::Yes)
auto index = map->getCurrentPartIndex();
UndoStep* undo_step = new MapPartUndoStep(map, MapPartUndoStep::AddMapPart, index);

if (i > 0)
{
auto index = map->getCurrentPartIndex();
UndoStep* undo_step = new MapPartUndoStep(map, MapPartUndoStep::AddMapPart, index);

if (i > 0)
auto* add_step = new AddObjectsUndoStep(map);
do
{
auto* add_step = new AddObjectsUndoStep(map);
do
{
--i;
auto* object = part->getObject(i);
add_step->addObject(i, object);
part->releaseObject(object);
}
while (i > 0);

auto* combined_step = new CombinedUndoStep(map);
combined_step->push(add_step);
combined_step->push(undo_step);
undo_step = combined_step;
--i;
auto* object = part->getObject(i);
add_step->addObject(i, object);
part->releaseObject(object);
}
while (i > 0);

map->push(undo_step);
map->removePart(index);
auto* combined_step = new CombinedUndoStep(map);
combined_step->push(add_step);
combined_step->push(undo_step);
undo_step = combined_step;
}

map->push(undo_step);
map->removePart(index);
}

void MapEditorController::renameMapPart()
Expand Down Expand Up @@ -3936,33 +3935,34 @@ void MapEditorController::mergeCurrentMapPartTo(int target)
{
MapPart* const source_part = map->getCurrentPart();
MapPart* const target_part = map->getPart(target);
const QMessageBox::StandardButton button =
QMessageBox::question(
window,
tr("Merge map parts"),
tr("Do you want to move all %1 objects from map part \"%2\" to \"%3\", "
"and to remove \"%2\"?")
.arg(source_part->getNumObjects()).arg(source_part->getName(), target_part->getName()),
QMessageBox::Yes | QMessageBox::No );
auto i = source_part->getNumObjects();

if (button == QMessageBox::Yes)
if (i > 0)
{
// Beware that the source part is removed, and
// the target part's index might change during merge.
auto source = map->getCurrentPartIndex();
UndoStep* add_part_step = new MapPartUndoStep(map, MapPartUndoStep::AddMapPart, source);

auto first = map->mergeParts(source, target);

auto* switch_part_undo = new SwitchPartUndoStep(map, target, source);
for (auto i = target_part->getNumObjects(); i > first; --i)
switch_part_undo->addObject(0);

auto* undo = new CombinedUndoStep(map);
undo->push(switch_part_undo);
undo->push(add_part_step);
map->push(undo);
if (QMessageBox::question(
window,
tr("Merge map parts"),
tr("Do you want to move all %1 objects from map part \"%2\" to \"%3\", and to remove \"%2\"?")
.arg(i).arg(source_part->getName(), target_part->getName()),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No)
return;
}

// Beware that the source part is removed, and
// the target part's index might change during merge.
auto source = map->getCurrentPartIndex();
UndoStep* add_part_step = new MapPartUndoStep(map, MapPartUndoStep::AddMapPart, source);

auto first = map->mergeParts(source, target);

auto* switch_part_undo = new SwitchPartUndoStep(map, target, source);
for (i = target_part->getNumObjects(); i > first; --i)
switch_part_undo->addObject(0);

auto* undo = new CombinedUndoStep(map);
undo->push(switch_part_undo);
undo->push(add_part_step);
map->push(undo);
}

void MapEditorController::mergeAllMapParts()
Expand Down

0 comments on commit 9cd83d6

Please sign in to comment.