Added ability to rename items in ServiceManager.

bzr-revno: 2352
This commit is contained in:
Dmitriy Marmyshev 2014-04-12 23:26:09 +02:00 committed by Raoul Snyman
commit 3cf9094e5f
7 changed files with 33 additions and 1 deletions

View File

@ -108,6 +108,9 @@ class ItemCapabilities(object):
``CanAutoStartForLive``
The capability to ignore the do not play if display blank flag.
``CanEditTitle``
The capability to edit the title of the item
"""
CanPreview = 1
CanEdit = 2
@ -125,6 +128,7 @@ class ItemCapabilities(object):
CanWordSplit = 14
HasBackgroundAudio = 15
CanAutoStartForLive = 16
CanEditTitle = 17
class ServiceItem(RegistryProperties):
@ -423,7 +427,7 @@ class ServiceItem(RegistryProperties):
"""
Returns the title of the service item.
"""
if self.is_text():
if self.is_text() or ItemCapabilities.CanEditTitle in self.capabilities:
return self.title
else:
if len(self._raw_frames) > 1:

View File

@ -234,6 +234,8 @@ class Ui_ServiceManager(object):
self.menu = QtGui.QMenu()
self.edit_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Edit Item'),
icon=':/general/general_edit.png', triggers=self.remote_edit)
self.rename_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Rename...'),
icon=':/general/general_edit.png', triggers=self.on_service_item_rename)
self.maintain_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Reorder Item'),
icon=':/general/general_edit.png',
triggers=self.on_service_item_edit_form)
@ -848,6 +850,7 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
pos = item.data(0, QtCore.Qt.UserRole)
service_item = self.service_items[pos - 1]
self.edit_action.setVisible(False)
self.rename_action.setVisible(False)
self.create_custom_action.setVisible(False)
self.maintain_action.setVisible(False)
self.notes_action.setVisible(False)
@ -855,6 +858,8 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
self.auto_start_action.setVisible(False)
if service_item['service_item'].is_capable(ItemCapabilities.CanEdit) and service_item['service_item'].edit_id:
self.edit_action.setVisible(True)
if service_item['service_item'].is_capable(ItemCapabilities.CanEditTitle):
self.rename_action.setVisible(True)
if service_item['service_item'].is_capable(ItemCapabilities.CanMaintain):
self.maintain_action.setVisible(True)
if item.parent() is None:
@ -1482,6 +1487,22 @@ class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManage
if new_item:
self.add_service_item(new_item, replace=True)
def on_service_item_rename(self):
"""
Opens a dialog to rename the service item.
"""
item = self.find_service_item()[0]
if not self.service_items[item]['service_item'].is_capable(ItemCapabilities.CanEditTitle):
return
title = self.service_items[item]['service_item'].title
title, ok = QtGui.QInputDialog.getText(self, translate('OpenLP.ServiceManager', 'Rename item title'),
translate('OpenLP.ServiceManager', 'Title:'),
QtGui.QLineEdit.Normal, self.trUtf8(title))
if ok:
self.service_items[item]['service_item'].title = title
self.repaint_service_list(item, -1)
self.set_modified()
def create_custom(self, field=None):
"""
Saves the current text item as a custom slide

View File

@ -840,6 +840,7 @@ class BibleMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop)
service_item.add_capability(ItemCapabilities.CanWordSplit)
service_item.add_capability(ItemCapabilities.CanEditTitle)
# Service Item: Title
service_item.title = create_separated_list(raw_title)
# Service Item: Theme

View File

@ -550,6 +550,7 @@ class ImageMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.CanPreview)
service_item.add_capability(ItemCapabilities.CanLoop)
service_item.add_capability(ItemCapabilities.CanAppend)
service_item.add_capability(ItemCapabilities.CanEditTitle)
# force a nonexistent theme
service_item.theme = -1
missing_items_file_names = []

View File

@ -216,6 +216,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
if not self.media_controller.media_length(service_item):
return False
service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
service_item.add_capability(ItemCapabilities.CanEditTitle)
service_item.add_capability(ItemCapabilities.RequiresMedia)
if Settings().value(self.settings_section + '/media auto start') == QtCore.Qt.Checked:
service_item.will_auto_start = True

View File

@ -263,6 +263,7 @@ class PresentationMediaItem(MediaManagerItem):
file_type = os.path.splitext(filename)[1][1:]
if not self.display_type_combo_box.currentText():
return False
service_item.add_capability(ItemCapabilities.CanEditTitle)
if (file_type == 'pdf' or file_type == 'xps') and context != ServiceItemContext.Service:
service_item.add_capability(ItemCapabilities.CanMaintain)
service_item.add_capability(ItemCapabilities.CanPreview)

View File

@ -313,6 +313,7 @@ class TestServiceManager(TestCase, TestMixin):
self.service_manager.notes_action.setVisible = MagicMock()
self.service_manager.time_action.setVisible = MagicMock()
self.service_manager.auto_start_action.setVisible = MagicMock()
self.service_manager.rename_action.setVisible = MagicMock()
# WHEN: Show the context menu.
self.service_manager.context_menu(q_point)
@ -329,6 +330,8 @@ class TestServiceManager(TestCase, TestMixin):
'The action should be set invisible.'
self.service_manager.auto_start_action.setVisible.assert_called_with(True), \
'The action should be set visible.'
self.service_manager.rename_action.setVisible.assert_called_once_with(False), \
'The action should be set invisible.'
def click_on_new_service_test(self):
"""