From a196e5607866ea140f7aef418979e2aafe3095a6 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:08:55 +0200 Subject: [PATCH] Fix macro action paste happening in the wrong section Instead of checking the cursor position at the time of the paste, it needed to be checked at the time of the context menu creation to ensure the segment gets pasted into the correct section --- lib/macro/macro-segment-copy-paste.cpp | 28 ++++++++++++++------------ lib/macro/macro-segment-copy-paste.hpp | 1 + lib/macro/macro-tab.cpp | 10 +++++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/macro/macro-segment-copy-paste.cpp b/lib/macro/macro-segment-copy-paste.cpp index d0105eaf..b86ead13 100644 --- a/lib/macro/macro-segment-copy-paste.cpp +++ b/lib/macro/macro-segment-copy-paste.cpp @@ -1,7 +1,6 @@ #include "macro-segment-copy-paste.hpp" #include "advanced-scene-switcher.hpp" #include "macro.hpp" -#include "ui-helpers.hpp" #include @@ -76,22 +75,10 @@ void AdvSceneSwitcher::PasteMacroSegment() break; } case MacroSegmentCopyInfo::Type::ACTION: - if (IsCursorInWidgetArea(ui->macroElseActions)) { - AddMacroElseAction(macro.get(), - macro->ElseActions().size(), - copyInfo.segment->GetId(), - data.Get()); - break; - } AddMacroAction(macro.get(), macro->Actions().size(), copyInfo.segment->GetId(), data.Get()); break; case MacroSegmentCopyInfo::Type::ELSE: - if (IsCursorInWidgetArea(ui->macroActions)) { - AddMacroAction(macro.get(), macro->Actions().size(), - copyInfo.segment->GetId(), data.Get()); - break; - } AddMacroElseAction(macro.get(), macro->ElseActions().size(), copyInfo.segment->GetId(), data.Get()); break; @@ -111,6 +98,21 @@ bool MacroActionIsInClipboard() copyInfo.type == MacroSegmentCopyInfo::Type::ELSE; } +void SetCopySegmentTargetActionType(bool setToElseAction) +{ + if (copyInfo.type == MacroSegmentCopyInfo::Type::ACTION && + setToElseAction) { + copyInfo.type = MacroSegmentCopyInfo::Type::ELSE; + return; + } + + if (copyInfo.type == MacroSegmentCopyInfo::Type::ELSE && + !setToElseAction) { + copyInfo.type = MacroSegmentCopyInfo::Type::ACTION; + return; + } +} + void SetupSegmentCopyPasteShortcutHandlers(AdvSceneSwitcher *window) { auto copyShortcut = new QShortcut(QKeySequence("Ctrl+C"), window); diff --git a/lib/macro/macro-segment-copy-paste.hpp b/lib/macro/macro-segment-copy-paste.hpp index d71ab857..4af31d4a 100644 --- a/lib/macro/macro-segment-copy-paste.hpp +++ b/lib/macro/macro-segment-copy-paste.hpp @@ -4,6 +4,7 @@ class AdvSceneSwitcher; bool MacroSegmentIsInClipboard(); bool MacroActionIsInClipboard(); +void SetCopySegmentTargetActionType(bool setToElseAction); void SetupSegmentCopyPasteShortcutHandlers(AdvSceneSwitcher *window); } // namespace advss diff --git a/lib/macro/macro-tab.cpp b/lib/macro/macro-tab.cpp index a0d2b2cb..6cf79076 100644 --- a/lib/macro/macro-tab.cpp +++ b/lib/macro/macro-tab.cpp @@ -1180,18 +1180,24 @@ static void setupCopyPasteContextMenuEnry(AdvSceneSwitcher *ss, [ss]() { ss->CopyMacroSegment(); }); copy->setEnabled(!!segmentEdit); + bool pasteAsElseAction = true; const char *pasteText = "AdvSceneSwitcher.macroTab.segment.paste"; if (MacroActionIsInClipboard()) { if (IsCursorInWidgetArea(ss->ui->macroActions)) { + pasteAsElseAction = false; pasteText = "AdvSceneSwitcher.macroTab.segment.pasteAction"; } else if (IsCursorInWidgetArea(ss->ui->macroElseActions)) { + pasteAsElseAction = true; pasteText = "AdvSceneSwitcher.macroTab.segment.pasteElseAction"; } } - auto paste = menu.addAction(obs_module_text(pasteText), ss, - [ss]() { ss->PasteMacroSegment(); }); + auto paste = menu.addAction( + obs_module_text(pasteText), ss, [ss, pasteAsElseAction]() { + SetCopySegmentTargetActionType(pasteAsElseAction); + ss->PasteMacroSegment(); + }); paste->setEnabled(MacroSegmentIsInClipboard()); }