diff --git a/src/core.cpp b/src/core.cpp index 4a76aedfe575eb0a70c5ad0f5a057544f0dc143b..95fa9dd9ab7f568141acd6feaf3196fbce3af2d0 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -283,10 +283,15 @@ void Core::selectTimelineItem(int id) } } -std::shared_ptr Core::getSubtitleModel() +std::shared_ptr Core::getSubtitleModel(bool enforce) { if (m_guiConstructed && m_mainWindow->getCurrentTimeline()->controller()->getModel()) { - return m_mainWindow->getCurrentTimeline()->controller()->getModel()->getSubtitleModel(); + auto subModel = m_mainWindow->getCurrentTimeline()->controller()->getModel()->getSubtitleModel(); + if (enforce && subModel == nullptr) { + m_mainWindow->slotEditSubtitle(); + subModel = m_mainWindow->getCurrentTimeline()->controller()->getModel()->getSubtitleModel(); + } + return subModel; } return nullptr; } diff --git a/src/core.h b/src/core.h index 7969cdeadcb18c49c5529275ce7ebc78458ca07a..621babd8d387731b0981161143d85e78f40d3de4 100644 --- a/src/core.h +++ b/src/core.h @@ -238,7 +238,7 @@ public: /** @brief Temporarily un/plug a list of clips in timeline. */ void temporaryUnplug(QList clipIds, bool hide); /** @brief Returns the current doc's subtitle model. */ - std::shared_ptr getSubtitleModel(); + std::shared_ptr getSubtitleModel(bool enforce = false); KSharedDataCache audioThumbCache; diff --git a/src/timeline2/view/timelinecontroller.cpp b/src/timeline2/view/timelinecontroller.cpp index b5b6a903814d4e263bcac2f9f3a092738039d2a5..139c40ab517c1822a10d22dc1b1ad02134c00684 100644 --- a/src/timeline2/view/timelinecontroller.cpp +++ b/src/timeline2/view/timelinecontroller.cpp @@ -3794,8 +3794,8 @@ void TimelineController::addSubtitle(int startframe) startframe = pCore->getTimelinePosition(); } int endframe = startframe + pCore->getDurationFromString(KdenliveSettings::subtitle_duration()); + auto subtitleModel = pCore->getSubtitleModel(true); int id = TimelineModel::getNextId(); - auto subtitleModel = pCore->getSubtitleModel(); Fun local_undo = [subtitleModel, id, startframe, endframe]() { subtitleModel->removeSubtitle(id); pCore->refreshProjectRange({startframe, endframe});