~suutari-olli/openlp/force-split

« back to all changes in this revision

Viewing changes to openlp/plugins/songs/forms/editverseform.py

  • Committer: suutari-olli
  • Date: 2016-06-16 19:50:15 UTC
  • Revision ID: suutari.olli@gmail.com-20160616195015-mujusanz5l48q64m
Reverted the perfectly functioning Verse split technigue and replaced it with insert [--]. 
This still needs to be turned into force split in renderer.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
        Find the last used verse tag by using given position and regex.
84
84
        Then insert the tag and create a new line if required.
85
85
        """
 
86
        text = self.verse_text_edit.toPlainText()
86
87
        position = self.verse_text_edit.textCursor().position()
87
 
        text = self.verse_text_edit.toPlainText()
88
 
        position = text.rfind('---[', 0, position)
89
 
        # If  editing single verse or ---[ not found, get value of the current verse and insert it.
90
 
        # This will insert the verse tag if editing a single verse or all  verses and no verse tag is present.
91
 
        if self.has_single_verse or position == -1:
92
 
            verse_type_index = self.verse_type_combo_box.currentIndex()
93
 
            self.insert_verse(VerseType.tags[verse_type_index], self.verse_number_box.value())
94
 
        # Find & Duplicate the currently selected verses tag and insert it.
95
 
        else:
96
 
            text = text[position:]
97
 
            position = text.find(']---')
98
 
            if position == -1:
99
 
                return
100
 
            text = text[:position + 4]
101
 
            match = re.match(('---\[.*\]---'), text)
102
 
            insert_string = match.group()
103
 
            # Reset text & position data for checking the proper inserting place & is newline required.
104
 
            text = self.verse_text_edit.toPlainText()
105
 
            position = self.verse_text_edit.textCursor().position()
106
 
            if position and text[position - 1] != '\n':
107
 
                insert_string = '\n' + insert_string
108
 
            if position == len(text) or text[position] != '\n':
109
 
                insert_string += '\n'
110
 
            self.verse_text_edit.insertPlainText(insert_string)
111
 
            self.verse_text_edit.setFocus()
 
88
        insert_string = '[--]'
 
89
        if position and text[position - 1] != '\n':
 
90
            insert_string = '\n' + insert_string
 
91
        if position == len(text) or text[position] != '\n':
 
92
            insert_string += '\n'
 
93
        self.verse_text_edit.insertPlainText(insert_string)
 
94
        self.verse_text_edit.setFocus()
112
95
 
113
96
    def on_insert_button_clicked(self):
114
97
        """
133
116
        """
134
117
        Adjusts the verse number SpinBox in regard to the selected verse type and the cursor's position.
135
118
        """
 
119
        if self.has_single_verse:
 
120
            return
136
121
        position = self.verse_text_edit.textCursor().position()
137
122
        text = self.verse_text_edit.toPlainText()
138
123
        verse_name = VerseType.translated_names[
139
124
            self.verse_type_combo_box.currentIndex()]
140
 
        if not text or self.has_single_verse:
 
125
        if not text:
141
126
            return
142
127
        position = text.rfind('---[{verse}'.format(verse=verse_name), 0, position)
143
128
        if position == -1:
147
132
        position = text.find(']---')
148
133
        if position == -1:
149
134
            return
150
 
        # If editing a Single verse, set the text to match current verse, otherwise increase the suggested verse.
151
 
        # This seems to only take effect when adding a split in middle of the sentence.
152
 
        if self.has_single_verse:
153
 
            text = text[:position]
154
 
        else:
155
 
            text = text[:position + 4]
 
135
        text = text[:position + 4]
156
136
        match = VERSE_REGEX.match(text)
157
137
        if match:
158
138
            try: