diff --git a/CHANGELOG.md b/CHANGELOG.md index 33378f9db..3702b88ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -252,6 +252,7 @@ Feature #5146: Safe Dispose corpse Feature #5147: Show spell magicka cost in spell buying window Feature #5170: Editor: Land shape editing, land selection + Feature #5172: Editor: Delete instances/references with keypress in scene window Feature #5193: Weapon sheathing Feature #5219: Impelement TestCells console command Feature #5224: Handle NiKeyframeController for NiTriShape diff --git a/CHANGELOG_PR.md b/CHANGELOG_PR.md index 526e09f14..f462da32c 100644 --- a/CHANGELOG_PR.md +++ b/CHANGELOG_PR.md @@ -42,6 +42,7 @@ New Editor Features: - "Faction Ranks" table for "Faction" records (#4209) - Changes to height editing can be cancelled without changes to data (press esc to cancel) (#4840) - Land heightmap/shape editing and vertex selection (#5170) +- Deleting instances with a keypress (#5172) Bug Fixes: - The Mouse Wheel can now be used for key bindings (#2679) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 1bf5752f0..442e707bf 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -355,6 +355,7 @@ void CSMPrefs::State::declare() declareShortcut ("scene-select-secondary", "Secondary Select", QKeySequence(Qt::ControlModifier | (int)Qt::MiddleButton)); declareModifier ("scene-speed-modifier", "Speed Modifier", Qt::Key_Shift); + declareShortcut ("scene-delete", "Delete Instance", QKeySequence(Qt::Key_Delete)); declareShortcut ("scene-load-cam-cell", "Load Camera Cell", QKeySequence(Qt::KeypadModifier | Qt::Key_5)); declareShortcut ("scene-load-cam-eastcell", "Load East Cell", QKeySequence(Qt::KeypadModifier | Qt::Key_6)); declareShortcut ("scene-load-cam-northcell", "Load North Cell", QKeySequence(Qt::KeypadModifier | Qt::Key_8)); diff --git a/apps/opencs/view/render/instancemode.cpp b/apps/opencs/view/render/instancemode.cpp index dd5dc3bac..92f5cbb2d 100644 --- a/apps/opencs/view/render/instancemode.cpp +++ b/apps/opencs/view/render/instancemode.cpp @@ -10,6 +10,7 @@ #include "../../model/world/idtree.hpp" #include "../../model/world/commands.hpp" #include "../../model/world/commandmacro.hpp" +#include "../../model/prefs/shortcut.hpp" #include "../widget/scenetoolbar.hpp" #include "../widget/scenetoolmode.hpp" @@ -96,6 +97,9 @@ CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidg { connect(this, SIGNAL(requestFocus(const std::string&)), worldspaceWidget, SIGNAL(requestFocus(const std::string&))); + + CSMPrefs::Shortcut* deleteShortcut = new CSMPrefs::Shortcut("scene-delete", worldspaceWidget); + connect(deleteShortcut, SIGNAL(activated(bool)), this, SLOT(deleteSelectedInstances(bool))); } void CSVRender::InstanceMode::activate (CSVWidget::SceneToolbar *toolbar) @@ -659,3 +663,21 @@ void CSVRender::InstanceMode::subModeChanged (const std::string& id) getWorldspaceWidget().abortDrag(); getWorldspaceWidget().setSubMode (getSubModeFromId (id), SceneUtil::Mask_EditorReference); } + +void CSVRender::InstanceMode::deleteSelectedInstances(bool active) +{ + std::vector > selection = getWorldspaceWidget().getSelection (SceneUtil::Mask_EditorReference); + if (selection.empty()) return; + + CSMDoc::Document& document = getWorldspaceWidget().getDocument(); + CSMWorld::IdTable& referencesTable = dynamic_cast ( + *document.getData().getTableModel (CSMWorld::UniversalId::Type_References)); + QUndoStack& undoStack = document.getUndoStack(); + + CSMWorld::CommandMacro macro (undoStack, "Delete Instances"); + for(osg::ref_ptr tag: selection) + if (CSVRender::ObjectTag *objectTag = dynamic_cast (tag.get())) + macro.push(new CSMWorld::DeleteCommand(referencesTable, objectTag->mObject->getReferenceId())); + + getWorldspaceWidget().clearSelection (SceneUtil::Mask_EditorReference); +} diff --git a/apps/opencs/view/render/instancemode.hpp b/apps/opencs/view/render/instancemode.hpp index 6ddaa254f..23df3f37d 100644 --- a/apps/opencs/view/render/instancemode.hpp +++ b/apps/opencs/view/render/instancemode.hpp @@ -92,6 +92,7 @@ namespace CSVRender private slots: void subModeChanged (const std::string& id); + void deleteSelectedInstances(bool active); }; }