diff --git a/include/core/editcommands.h b/include/core/editcommands.h index 9b96ea3c..142636cc 100644 --- a/include/core/editcommands.h +++ b/include/core/editcommands.h @@ -30,6 +30,7 @@ enum CommandId { ID_EventCreate, ID_EventDelete, ID_EventDuplicate, + ID_EventPaste, }; #define IDMask_EventType_Object (1 << 8) @@ -322,7 +323,7 @@ public: bool mergeWith(const QUndoCommand *) override { return false; } int id() const override; -private: +protected: Map *map; QList selectedEvents; // allow multiple deletion of events Editor *editor; @@ -330,6 +331,17 @@ private: +/// Implements a command to commit Event pastes from clipboard. +class EventPaste : public EventDuplicate { +public: + EventPaste(Editor *editor, Map *map, QList pastedEvents, + QUndoCommand *parent = nullptr); + + int id() const override; +}; + + + /// Implements a command to commit map edits from the scripting API. /// The scripting api can edit metatiles and map dimensions. class ScriptEditMap : public QUndoCommand { diff --git a/src/core/editcommands.cpp b/src/core/editcommands.cpp index e7a3d300..0d012b3a 100644 --- a/src/core/editcommands.cpp +++ b/src/core/editcommands.cpp @@ -414,7 +414,11 @@ int EventDelete::id() const { EventDuplicate::EventDuplicate(Editor *editor, Map *map, QList selectedEvents, QUndoCommand *parent) : QUndoCommand(parent) { - setText("Duplicate Event"); + if (selectedEvents.size() > 1) { + setText("Duplicate Events"); + } else { + setText("Duplicate Event"); + } this->editor = editor; @@ -462,6 +466,24 @@ int EventDuplicate::id() const { return CommandId::ID_EventDuplicate | getEventTypeMask(this->selectedEvents); } +/****************************************************************************** + ************************************************************************ + ******************************************************************************/ + +EventPaste::EventPaste(Editor *editor, Map *map, + QList pastedEvents, + QUndoCommand *parent) : EventDuplicate(editor, map, pastedEvents) { + if (pastedEvents.size() > 1) { + setText("Paste Events"); + } else { + setText("Paste Event"); + } +} + +int EventPaste::id() const { + return CommandId::ID_EventPaste | getEventTypeMask(this->selectedEvents); +} + /****************************************************************************** ************************************************************************ ******************************************************************************/ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3c9dac47..5b7d781f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -156,9 +156,11 @@ void MainWindow::initExtraShortcuts() { auto *shortcut_Copy = new Shortcut(QKeySequence("Ctrl+C"), this, SLOT(copy())); shortcut_Copy->setObjectName("shortcut_Copy"); + shortcut_Copy->setWhatsThis("Copy"); auto *shortcut_Paste = new Shortcut(QKeySequence("Ctrl+V"), this, SLOT(paste())); shortcut_Paste->setObjectName("shortcut_Paste"); + shortcut_Copy->setWhatsThis("Paste"); } QObjectList MainWindow::shortcutableObjects() const { @@ -1583,18 +1585,8 @@ void MainWindow::paste() { newEvents.append(pasteEvent); } - editor->project->loadEventPixmaps(editor->map->getAllEvents()); + editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents)); - for (Event *event : newEvents) { - editor->addMapEvent(event); - } - - // select these events - editor->selected_events->clear(); - for (Event *event : newEvents) { - editor->selected_events->append(event->pixmapItem); - } - editor->shouldReselectEvents(); break; } }