- make sure the 'edit all' button is disabled when creating a new custom

- ask if unsaved data should be saved when clicking on the save button
This commit is contained in:
Andreas Preikschat 2010-10-09 13:00:28 +02:00
parent 0099cb402a
commit 607a0d1155

View File

@ -81,7 +81,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.onVerseListViewPressed) self.onVerseListViewPressed)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_update_list'), self.loadThemes) QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
# Create other objects and forms # Create other objects and forms.
self.custommanager = custommanager self.custommanager = custommanager
self.initialise() self.initialise()
@ -104,7 +104,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.creditEdit.setText(u'') self.creditEdit.setText(u'')
self.verseTextEdit.clear() self.verseTextEdit.clear()
self.verseListView.clear() self.verseListView.clear()
#make sure we have a new item # Make sure we have a new item.
self.customSlide = CustomSlide() self.customSlide = CustomSlide()
self.themeComboBox.addItem(u'') self.themeComboBox.addItem(u'')
@ -115,6 +115,16 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.themeComboBox.addItem(themename) self.themeComboBox.addItem(themename)
def loadCustom(self, id, preview=False): def loadCustom(self, id, preview=False):
"""
Called when editing or creating a new custom.
``id``
The cutom's id. If zero, then a new custom is created.
``preview``
States whether the custom is edited while being previewed in the
preview panel.
"""
self.customSlide = CustomSlide() self.customSlide = CustomSlide()
self.initialise() self.initialise()
if id != 0: if id != 0:
@ -132,7 +142,8 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.themeComboBox.setCurrentIndex(id) self.themeComboBox.setCurrentIndex(id)
else: else:
self.themeComboBox.setCurrentIndex(0) self.themeComboBox.setCurrentIndex(0)
#if not preview hide the preview button self.editAllButton.setEnabled(False)
# If not preview hide the preview button.
self.previewButton.setVisible(False) self.previewButton.setVisible(False)
if preview: if preview:
self.previewButton.setVisible(True) self.previewButton.setVisible(True)
@ -148,10 +159,10 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.close() self.close()
def saveCustom(self): def saveCustom(self):
valid, message = self._validate() """
if not valid: Saves the custom.
QtGui.QMessageBox.critical(self, """
translate('CustomPlugin.EditCustomForm', 'Error'), message) if not self._validate():
return False return False
sxml = CustomXMLBuilder() sxml = CustomXMLBuilder()
sxml.new_document() sxml.new_document()
@ -237,7 +248,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
else: else:
self.verseListView.currentItem().setText( self.verseListView.currentItem().setText(
self.verseTextEdit.toPlainText()) self.verseTextEdit.toPlainText())
#number of lines has change # The number of lines has changed.
if len(self.beforeText.split(u'\n')) != \ if len(self.beforeText.split(u'\n')) != \
len(self.verseTextEdit.toPlainText().split(u'\n')): len(self.verseTextEdit.toPlainText().split(u'\n')):
tempList = {} tempList = {}
@ -266,18 +277,35 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.editAllButton.setEnabled(True) self.editAllButton.setEnabled(True)
def _validate(self): def _validate(self):
"""
Checks whether a custom is valid or not.
"""
# We must have a title.
if len(self.titleEdit.displayText()) == 0: if len(self.titleEdit.displayText()) == 0:
self.titleEdit.setFocus() self.titleEdit.setFocus()
return False, translate('CustomPlugin.EditCustomForm', QtGui.QMessageBox.critical(self,
'You need to type in a title.') translate('CustomPlugin.EditCustomForm', 'Error'),
# must have 1 slide translate('CustomPlugin.EditCustomForm',
'You need to type in a title.'))
return False
# We must have one slide.
if self.verseListView.count() == 0: if self.verseListView.count() == 0:
self.verseTextEdit.setFocus() self.verseTextEdit.setFocus()
return False, translate('CustomPlugin.EditCustomForm', QtGui.QMessageBox.critical(self,
'You need to add at least one slide') translate('CustomPlugin.EditCustomForm', 'Error'),
translate('CustomPlugin.EditCustomForm',
'You need to add at least one slide.'))
return False
# We must not have unsaved data.
if self.verseTextEdit.toPlainText(): if self.verseTextEdit.toPlainText():
if QtGui.QMessageBox.critical(self,
translate('CustomPlugin.EditCustomForm', 'Error'),
translate('CustomPlugin.EditCustomForm', 'You have one or more '
'unsaved slides. Do you want to save them and continue?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
self.onSaveButtonPressed()
else:
self.verseTextEdit.setFocus() self.verseTextEdit.setFocus()
return False, translate('CustomPlugin.EditCustomForm', return False
'You have one or more unsaved slides, please either save your ' return True
'slide(s) or clear your changes.')
return True, u''