Skip to content

Commit a288e27

Browse files
committed
Merge branch 'fix_multiple_insertion'
2 parents 60a3cf5 + 8f0dc9a commit a288e27

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

extension/OOoLilyPond/OOoLilyPond.xba

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Sub OOoLilyPond()
3636
Dim oDoc As Object
3737
Dim oDocCtrl As Object
3838
Dim bWrongDocumentType As Boolean
39-
Dim oShape As Object
4039

4140
oMessages = CreateUnoService ("com.sun.star.beans.PropertyBag")
4241

@@ -123,6 +122,26 @@ Sub OOoLilyPond()
123122
bUseDefaultCustom1 = True
124123
bUseDefaultCustom2 = True
125124

125+
If Not ReadSelectionObject () Then Exit Sub ' create Cursor and read Attributes if Object is selected
126+
127+
' Now we know which template to use
128+
ReadTemplate()
129+
130+
' Open the dialog box
131+
EditorDialog()
132+
End Sub
133+
134+
135+
Function ReadSelectionObject () As Boolean
136+
137+
Dim oDoc As Object
138+
Dim oDocCtrl As Object
139+
Dim oShape As Object
140+
141+
' Get the current document and controller
142+
oDoc = ThisComponent
143+
oDocCtrl = oDoc.getCurrentController()
144+
126145
' create Cursor and read Attributes if Object is selected
127146
If Not IsEmpty(oDocCtrl.getSelection) Then ' Is only empty in Impress or Draw when nothing is selected
128147
oSelection=oDocCtrl.getSelection
@@ -134,16 +153,25 @@ Sub OOoLilyPond()
134153
oShape = oSelection.getByIndex(0)
135154
If bInWriter Then ' OLy < 0.4 in Writer
136155
' oCursor = oDoc.Text.createTextCursorByRange(oSelection(0).getAnchor())
137-
If Not ReadAttributes(oShape) Then Exit Sub 'Read the OLy fields from the Object Attributes
156+
If Not ReadAttributes(oShape) Then 'Read the OLy fields from the Object Attributes
157+
ReadSelectionObject = False
158+
Exit Function
159+
End If
138160
' oSelection(0).getParent().remove(oSelection(0)) ' Delete old OLyObject
139161
Else ' OLy object in Draw / Impress
140-
If Not ReadAttributes(oShape) Then Exit Sub 'Read the OLy fields from the Object Attributes
162+
If Not ReadAttributes(oShape) Then 'Read the OLy fields from the Object Attributes
163+
ReadSelectionObject = False
164+
Exit Function
165+
End If
141166
End If
142167
oShapePosition = oShape.position()
143168
bShapeIsSelected = True
144169

145170
Case "SwXTextGraphicObject" ' Graphic is selected in Writer
146-
If Not ReadAttributes(oSelection) Then Exit Sub ' Read the OLy fields from the Object Attributes
171+
If Not ReadAttributes(oSelection) Then ' Read the OLy fields from the Object Attributes
172+
ReadSelectionObject = False
173+
Exit Function
174+
End If
147175
bShapeIsSelected = True
148176

149177
Case "SwXTextRanges" ' Nothing or normal text selection in Writer
@@ -152,18 +180,13 @@ Sub OOoLilyPond()
152180
Case Else
153181
' Msgbox ("The selected object is not an OLy object ...", 0, "Error")
154182
Msgbox (oMessages.getPropertyValue ("sMsgNoOlyObject"), iMsgBox_E, oMessages.getPropertyValue ("sCaptionError"))
155-
Exit Sub
183+
ReadSelectionObject = False
184+
Exit Function
156185

157186
End Select
158187
End If
159-
160-
161-
' Now we know which template to use
162-
ReadTemplate()
163-
164-
' Open the dialog box
165-
EditorDialog()
166-
End Sub
188+
ReadSelectionObject = True
189+
End Function
167190

168191

169192
sub Make()
@@ -242,6 +265,7 @@ sub Make()
242265

243266
'If there were errors or warnings
244267
If iNErr >= 1 And Not bIgnoreWarnings Then
268+
ReadSelectionObject ()
245269
iErrNum = 1
246270
DisplayError()
247271
Exit Sub

0 commit comments

Comments
 (0)