Skip to content

Commit

Permalink
Small tweaks to object context menu
Browse files Browse the repository at this point in the history
* Always display "Save As Template", but disable with tool tip when it
  can't be used.

* Added some separators.
  • Loading branch information
bjorn committed Jul 14, 2020
1 parent 0058cc7 commit 11f882c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/tiled/abstractobjecttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ void AbstractObjectTool::showContextMenu(MapObject *clickedObject,
return;

QMenu menu;
menu.setToolTipsVisible(true);

QAction *duplicateAction = menu.addAction(tr("Duplicate %n Object(s)", "", selectedObjects.size()),
this, &AbstractObjectTool::duplicateObjects);
QAction *removeAction = menu.addAction(tr("Remove %n Object(s)", "", selectedObjects.size()),
Expand All @@ -469,6 +471,8 @@ void AbstractObjectTool::showContextMenu(MapObject *clickedObject,
isTileObject);

if (anyTileObjectSelected) {
menu.addSeparator();

auto resetTileSizeAction = menu.addAction(tr("Reset Tile Size"), this, &AbstractObjectTool::resetTileSize);
resetTileSizeAction->setEnabled(std::any_of(selectedObjects.begin(),
selectedObjects.end(),
Expand All @@ -479,6 +483,8 @@ void AbstractObjectTool::showContextMenu(MapObject *clickedObject,
tile()->tileset()->isExternal()));
}

menu.addSeparator();

// Create action for replacing an object with a template
auto replaceTemplateAction = menu.addAction(tr("Replace With Template"), this, &AbstractObjectTool::replaceObjectsWithTemplate);
auto selectedTemplate = objectTemplate();
Expand All @@ -495,9 +501,12 @@ void AbstractObjectTool::showContextMenu(MapObject *clickedObject,

if (!(currentObject->isTemplateBase() || currentObject->isTemplateInstance())) {
const Cell cell = selectedObjects.first()->cell();
// Saving objects with embedded tilesets is disabled
if (cell.isEmpty() || cell.tileset()->isExternal())
menu.addAction(tr("Save As Template"), this, &AbstractObjectTool::saveSelectedObject);
auto action = menu.addAction(tr("Save As Template"), this, &AbstractObjectTool::saveSelectedObject);

if (!cell.isEmpty() && !cell.tileset()->isExternal()) {
action->setEnabled(false);
action->setToolTip(tr("Can't create template with embedded tileset"));
}
}

if (currentObject->isTemplateBase()) { // Hide this operations for template base
Expand Down

0 comments on commit 11f882c

Please sign in to comment.