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
This commit is contained in:
WarmUpTill 2024-09-23 21:08:55 +02:00 committed by WarmUpTill
parent 0536e4a60b
commit a196e56078
3 changed files with 24 additions and 15 deletions

View File

@ -1,7 +1,6 @@
#include "macro-segment-copy-paste.hpp"
#include "advanced-scene-switcher.hpp"
#include "macro.hpp"
#include "ui-helpers.hpp"
#include <QShortcut>
@ -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);

View File

@ -4,6 +4,7 @@ class AdvSceneSwitcher;
bool MacroSegmentIsInClipboard();
bool MacroActionIsInClipboard();
void SetCopySegmentTargetActionType(bool setToElseAction);
void SetupSegmentCopyPasteShortcutHandlers(AdvSceneSwitcher *window);
} // namespace advss

View File

@ -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());
}