From c3c2bf91ae68d7f4b92c28ce61640193b84f09ca Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 23 Feb 2018 13:24:37 +0000 Subject: [PATCH] Clone Custom item --- openlp/plugins/custom/lib/mediaitem.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index d4e7f8cfd..d6abd2714 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -30,6 +30,7 @@ from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings from openlp.core.lib import MediaManagerItem, ItemCapabilities, ServiceItemContext, PluginStatus, \ check_item_selected +from openlp.core.lib.ui import create_widget_action from openlp.plugins.custom.forms.editcustomform import EditCustomForm from openlp.plugins.custom.lib import CustomXMLParser, CustomXMLBuilder from openlp.plugins.custom.lib.db import CustomSlide @@ -84,6 +85,12 @@ class CustomMediaItem(MediaManagerItem): Registry().register_function('custom_preview', self.on_preview_click) Registry().register_function('custom_create_from_service', self.create_from_service_item) + def add_custom_context_actions(self): + create_widget_action(self.list_view, separator=True) + create_widget_action( + self.list_view, text=translate('OpenLP.MediaManagerItem', '&Clone'), icon=':/general/general_clone.png', + triggers=self.on_clone_click) + def config_update(self): """ Config has been updated so reload values @@ -243,6 +250,23 @@ class CustomMediaItem(MediaManagerItem): service_item.raw_footer.append('') return True + def on_clone_click(self): + """ + Clone the selected Custom item + """ + item = self.list_view.currentItem() + item_id = item.data(QtCore.Qt.UserRole) + old_custom_slide = self.plugin.db_manager.get_object(CustomSlide, item_id) + new_custom_slide = CustomSlide() + new_custom_slide.title = '{title} <{text}>'.format(title=old_custom_slide.title, + text=translate('SongsPlugin.MediaItem', + 'copy', 'For song cloning')) + new_custom_slide.text = old_custom_slide.text + new_custom_slide.credits = old_custom_slide.credits + new_custom_slide.theme_name = old_custom_slide.theme_name + self.plugin.db_manager.save_object(new_custom_slide) + self.on_search_text_button_clicked() + def on_search_text_button_clicked(self): """ Search the plugin database