validate all verses before showing a message box and list all verses with misplaced tags at once

This commit is contained in:
Oliver Wieland 2013-10-10 18:20:59 +02:00
parent 3896d2845e
commit 684538214c

View File

@ -721,17 +721,27 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.manager.save_object(book) self.manager.save_object(book)
else: else:
return False return False
cnt_errors = 0
error_list = ''
verse_tag = []
verse_num = []
for i in range(self.verseListWidget.rowCount()): for i in range(self.verseListWidget.rowCount()):
item = self.verseListWidget.item(i, 0) item = self.verseListWidget.item(i, 0)
tags = self.find_tags.findall(item.text()) tags = self.find_tags.findall(item.text())
if self._validate_tags(tags) == False: if self._validate_tags(tags) == False:
field = unicode(item.data(QtCore.Qt.UserRole).toString()) field = unicode(item.data(QtCore.Qt.UserRole).toString())
verse_tag = VerseType.translated_name(field[0]) verse_tag.append(VerseType.translated_name(field[0]))
verse_num = field[1:] verse_num.append(field[1:])
cnt_errors += 1;
if cnt_errors > 0:
for i in range(cnt_errors):
error_list += '%s %s' % (verse_tag[i], verse_num[i])
if i < cnt_errors-1:
error_list += ', '
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.EditSongForm', message=translate('SongsPlugin.EditSongForm',
'There are misplaced tags in %s %s. ' 'There are misplaced formatting tags in the following verses:\n\n%s\n\n'
'You need to fix this problem first.' % (verse_tag, verse_num))) 'Please correct these tags before continuing.' % error_list))
return False return False
return True return True