We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question
0

Unordered numbering for tags

asked 2021-04-12 20:45:52 +0200

JGL gravatar image

updated 2021-04-12 20:46:11 +0200

Hello everyone !

I am looking for a way to automatically insert numbered tags in my writer documents (e.g. "TAG 1", "TAG 2", "TAG 3", ... "TAG 49", "TAG 50", ...).

The tricky part is I don't want this number to change with the insertion of new tags before as the usual behavior with numbered headings. I want the tag to be inserted and to remain the same whatever happens elsewhere in the document. So that when I have tags 1, 2, 3 ,4 already in the document and insert a fifth just after the first, I get 1, 5, 2, 3, 4 (not 1, 2, 3, 4, 5).

The reason is I am going to reference this number in another system (e.g. "See TAG 3") , and I don't want to update both the document and the ticket in the other system when I edit the document.

And I want LO to manage this number by itself so that I don't have to look up in long documents for "the last number I used" to avoid re-using the same twice.

What do you think ? Macro with a counter ? (I definitely have a hard time with LO macros... :/).

Thanks for your help ! :)

edit retag flag offensive close merge delete

Comments

Apart from using "unique" timestamps formatted as YYMMDDHHMMSS, I don't see simple solution. With such a tag, you can't guess how many tickets you have but it could solve nicely your problem.

Tell if you are interested and I'll develop in an answer.

ajlittoz gravatar imageajlittoz ( 2021-04-12 20:53:49 +0200 )edit

Thanks a lot for your input, I appreciate. It would indeed solve the problem, but it would make the tag IDs very long and hard to memorize for my colleagues who will basically be doing a ctrl-f before typing the IDs and looking them up.

JGL gravatar imageJGL ( 2021-04-12 21:07:51 +0200 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2021-04-16 00:44:51 +0200

Lupp gravatar image

updated 2021-04-16 00:46:15 +0200

If there aren't too many of these tags (for the navigator) you may insert the as bookmarks creating the shown text at the same time.

You may use a find tool or the navigator then alternatively.

This solution comes with a disadvantage: If you delete the bookmarks in the navigator, the text pieces will remain, but the code to find the next number can't work then correctly.
Of course, you might combine it with your own solution of writing the last used number to the document properties.

See example: C:\fakepath\ask303787insertTags.odt

edit flag offensive delete link more
1

answered 2021-04-15 16:57:25 +0200

JGL gravatar image

Just to put a cap on this post, I ended up facing my fears (XD) and wrote a macro that inserts a numbered tag [(1), (2), (3), ...] at the current cursor position and stores the last used value in a custom document property, so that when I run the macro again it never reuses the same tag, keeping them unique.

SUB TAG

dim oUserProps as object    'Custom properties
dim varNextTag as integer   'Next tag value
dim strTag as string        'Tag text
dim range as object         'Position where to insert the tag in the document

oUserProps = ThisComponent.getDocumentProperties().UserDefinedProperties

'--- Create custom property if it doesn't exist
If NOT oUserProps.getPropertySetInfo().hasPropertyByName("LastUsedTag") Then
    oUserProps.addProperty("LastUsedTag",, "0")
    oUserProps = ThisComponent.getDocumentProperties().UserDefinedProperties 'Reload properties with the newly added property
End If

varNextTag = CInt(oUserProps.[LastUsedTag])+1

strTag = "("&CStr(varNextTag)&")   "

range = ThisComponent.CurrentSelection.getByIndex(0)

range.String = strTag

oUserProps.[LastUsedTag] = varNextTag

End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-04-12 20:45:52 +0200

Seen: 47 times

Last updated: Apr 16