From 058a283290eef4d57dacf716f6a82b1fbb4a0496 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Sun, 14 Jan 2024 22:26:16 -0600 Subject: [PATCH] Improve limits on nudging Do not enable the nudging action unless exactly one clip is selected Allow nudging forward when there is not a blank before it As reported here: https://forum.shotcut.org/t/beta-version-24-01-now-available-to-test/42498/2 https://forum.shotcut.org/t/beta-version-24-01-now-available-to-test/42498/24 --- src/docks/timelinedock.cpp | 41 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/docks/timelinedock.cpp b/src/docks/timelinedock.cpp index 5979b804bc..6da54ea2ff 100644 --- a/src/docks/timelinedock.cpp +++ b/src/docks/timelinedock.cpp @@ -638,18 +638,13 @@ void TimelineDock::setupActions() action->setEnabled(false); connect(action, &QAction::triggered, this, [&]() { auto selectedClips = selection(); - if (!selectedClips.isEmpty()) { - if (selection().size() > 1) - setSelection({selection().first()}); - int trackIndex = selection().first().y(); - int clipIndex = selection().first().x(); + if (selectedClips.size() == 1) { + int trackIndex = selectedClips.first().y(); + int clipIndex = selectedClips.first().x(); bool valid = clipIndex > 0 && !isTransition(trackIndex, clipIndex) && !isBlank(trackIndex, clipIndex); if (valid && !Settings.timelineRipple()) { - valid = isBlank(trackIndex, clipIndex - 1) && ((clipIndex == clipCount(trackIndex) - 1) - || isBlank(trackIndex, clipIndex + 1)); - } else if (valid) { - valid = clipIndex < clipCount(trackIndex) - 1; + valid = (clipIndex == clipCount(trackIndex) - 1) || isBlank(trackIndex, clipIndex + 1); } if (!valid) { emit showStatusMessage(tr("Nudge Forward is not available")); @@ -661,11 +656,11 @@ void TimelineDock::setupActions() } }); connect(this, &TimelineDock::selectionChanged, action, [ = ]() { - bool enabled = m_selection.selectedClips.length() > 0; - if (enabled && !selection().isEmpty()) { - int trackIndex = selection().first().y(); - int clipIndex = selection().first().x(); - enabled = !isBlank(trackIndex, clipIndex); + auto selectedClips = selection(); + bool enabled = selectedClips.size() == 1; + if (enabled) { + enabled = !isBlank(selectedClips.first().y(), selectedClips.first().x()) + && !isTransition(selectedClips.first().y(), selectedClips.first().x()); } action->setEnabled(enabled); }); @@ -676,11 +671,9 @@ void TimelineDock::setupActions() action->setEnabled(false); connect(action, &QAction::triggered, this, [&]() { auto selectedClips = selection(); - if (!selectedClips.isEmpty()) { - if (selection().size() > 1) - setSelection({selection().first()}); - int trackIndex = selection().first().y(); - int clipIndex = selection().first().x(); + if (selectedClips.size() == 1) { + int trackIndex = selectedClips.first().y(); + int clipIndex = selectedClips.first().x(); if (clipIndex <= 0 || isTransition(trackIndex, clipIndex) || isBlank(trackIndex, clipIndex) || !isBlank(trackIndex, clipIndex - 1)) { emit showStatusMessage(tr("Nudge Backward is not available")); @@ -692,11 +685,11 @@ void TimelineDock::setupActions() } }); connect(this, &TimelineDock::selectionChanged, action, [ = ]() { - bool enabled = m_selection.selectedClips.length() > 0; - if (enabled && !selection().isEmpty()) { - int trackIndex = selection().first().y(); - int clipIndex = selection().first().x(); - enabled = !isBlank(trackIndex, clipIndex); + auto selectedClips = selection(); + bool enabled = selectedClips.size() == 1; + if (enabled) { + enabled = !isBlank(selectedClips.first().y(), selectedClips.first().x()) + && !isTransition(selectedClips.first().y(), selectedClips.first().x()); } action->setEnabled(enabled); });