forked from openlp/openlp
- 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:
parent
0099cb402a
commit
607a0d1155
@ -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():
|
||||||
self.verseTextEdit.setFocus()
|
if QtGui.QMessageBox.critical(self,
|
||||||
return False, translate('CustomPlugin.EditCustomForm',
|
translate('CustomPlugin.EditCustomForm', 'Error'),
|
||||||
'You have one or more unsaved slides, please either save your '
|
translate('CustomPlugin.EditCustomForm', 'You have one or more '
|
||||||
'slide(s) or clear your changes.')
|
'unsaved slides. Do you want to save them and continue?'),
|
||||||
return True, u''
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
|
||||||
|
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
|
||||||
|
self.onSaveButtonPressed()
|
||||||
|
else:
|
||||||
|
self.verseTextEdit.setFocus()
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user