Fix lack of feedback for edit and delete

This commit is contained in:
Jon Tibble 2010-06-16 02:23:57 +01:00
parent 814a4f023d
commit 5e0ab4a7f6
6 changed files with 59 additions and 20 deletions

View File

@ -325,6 +325,19 @@ class MediaManagerItem(QtGui.QWidget):
"""
pass
def checkItemSelected(self, message):
"""
Check if a list item is selected so an action may be performed on it
``message``
The message to give the user if no item is selected
"""
if not self.ListView.selectedIndexes():
QtGui.QMessageBox.information(self,
self.trUtf8('No Items Selected'), message)
return False
return True
def onFileClick(self):
files = QtGui.QFileDialog.getOpenFileNames(
self, self.OnNewPrompt,
@ -392,7 +405,7 @@ class MediaManagerItem(QtGui.QWidget):
if not self.ListView.selectedIndexes() and not self.remoteTriggered:
QtGui.QMessageBox.information(self,
self.trUtf8('No Items Selected'),
self.trUtf8('You must select one or more items.'))
self.trUtf8('You must select one or more items to preview.'))
else:
log.debug(self.PluginNameShort + u' Preview requested')
service_item = self.buildServiceItem()
@ -404,7 +417,7 @@ class MediaManagerItem(QtGui.QWidget):
if not self.ListView.selectedIndexes():
QtGui.QMessageBox.information(self,
self.trUtf8('No Items Selected'),
self.trUtf8('You must select one or more items.'))
self.trUtf8('You must select one or more items to send live.'))
else:
log.debug(self.PluginNameShort + u' Live requested')
service_item = self.buildServiceItem()

View File

@ -115,16 +115,24 @@ class CustomMediaItem(MediaManagerItem):
self.parent.edit_custom_form.exec_()
def onEditClick(self):
item = self.ListView.currentItem()
if item:
"""
Edit a custom item
"""
if self.checkItemSelected(translate(u'CustomPlugin.MediaItem',
u'You must select an item to edit.')):
item = self.ListView.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.edit_custom_form.loadCustom(item_id, False)
self.parent.edit_custom_form.exec_()
self.initialise()
def onDeleteClick(self):
item = self.ListView.currentItem()
if item:
"""
Remove a custom item from the list and database
"""
if self.checkItemSelected(translate(u'CustomPlugin.MediaItem',
u'You must select an item to delete.')):
item = self.ListView.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.custommanager.delete_custom(item_id)
row = self.ListView.row(item)

View File

@ -116,14 +116,18 @@ class ImageMediaItem(MediaManagerItem):
self.PageLayout.addWidget(self.ImageWidget)
def onDeleteClick(self):
items = self.ListView.selectedIndexes()
if items:
"""
Remove an image item from the list
"""
if self.checkItemSelected(translate(u'ImagePlugin.MediaItem',
u'You must select an item to delete.')):
items = self.ListView.selectedIndexes()
for item in items:
text = self.ListView.item(item.row())
if text:
try:
os.remove(
os.path.join(self.servicePath, unicode(text.text())))
os.remove(os.path.join(self.servicePath,
unicode(text.text())))
except OSError:
#if not present do not worry
pass

View File

@ -137,8 +137,12 @@ class MediaMediaItem(MediaManagerItem):
self.settingsSection))
def onDeleteClick(self):
item = self.ListView.currentItem()
if item:
"""
Remove a media item from the list
"""
if self.checkItemSelected(translate(u'MediaPlugin.MediaItem',
u'You must select an item to delete.')):
item = self.ListView.currentItem()
row = self.ListView.row(item)
self.ListView.takeItem(row)
SettingsManager.set_list(self.settingsSection,
@ -152,4 +156,3 @@ class MediaMediaItem(MediaManagerItem):
item_name.setIcon(build_icon(img))
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
self.ListView.addItem(item_name)

View File

@ -174,8 +174,12 @@ class PresentationMediaItem(MediaManagerItem):
self.ListView.addItem(item_name)
def onDeleteClick(self):
item = self.ListView.currentItem()
if item:
"""
Remove a presentation item from the list
"""
if self.checkItemSelected(translate(u'PresentationPlugin.MediaItem',
u'You must select an item to delete.')):
item = self.ListView.currentItem()
row = self.ListView.row(item)
self.ListView.takeItem(row)
SettingsManager.set_list(self.settingsSection,

View File

@ -275,15 +275,23 @@ class SongMediaItem(MediaManagerItem):
self.edit_song_form.exec_()
def onEditClick(self):
item = self.ListView.currentItem()
if item:
"""
Edit a song
"""
if self.checkItemSelected(translate(u'SongsPlugin.MediaItem',
u'You must select an item to edit.')):
item = self.ListView.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.edit_song_form.loadSong(item_id, False)
self.edit_song_form.exec_()
def onDeleteClick(self):
items = self.ListView.selectedIndexes()
if items:
"""
Remove a song from the list and database
"""
if self.checkItemSelected(translate(u'SongsPlugin.MediaItem',
u'You must select an item to delete.')):
items = self.ListView.selectedIndexes()
if len(items) == 1:
del_message = translate(u'SongsPlugin.MediaItem',
u'Delete song?')
@ -371,4 +379,3 @@ class SongMediaItem(MediaManagerItem):
song.title, author_audit, song.copyright, song.ccli_number
]
return True