Copy link to clipboard
Copied
SDK: My keywords are organized in a hierarchy. Now I want to create a table with the names of all leaf keywords, i.e. keywords without children, end nodes. I understand that I need to call catalog:getKeywords() to get all top-level keywords and then use lrKeyword:getChildren() recursively to get my leaf keywords. However, for some reason recursivity turns my brain to jelly. The recursive function I'm looking for is probably no more than 4 or 5 lines long, but I just can't get it right. Is there a kind soul out there who can help me out?
Also, I'm a bit worried about how to do this once I have that function. The function will have to use startAsyncTask in order to use catalog:getKeywords() and lrKeyword:getChildren(), so how can I be sure that the list of leaf keywords returned by the recursive function is actually available when I want to use if in the calling script?
Here's a function that returns an array of all the lef keywords:
local function findLeafKeywords ()
local leafKeywords = {}
local function find (keyword)
if #keyword:getChildren () == 0 then
table.insert (leafKeywords, keyword)
else
for _, child in ipairs (keyword:getChildren ()) do
find (child)
end
end
end
for _, keyword in ipairs (catalog:getKeywords ()) do find (keyword) end
return le
...
"Is there a way to set the focus to the edit control of my choice? I can't find any mention of this in the API docs."
Unfortunately note.
Copy link to clipboard
Copied
Here's a function that returns an array of all the lef keywords:
local function findLeafKeywords ()
local leafKeywords = {}
local function find (keyword)
if #keyword:getChildren () == 0 then
table.insert (leafKeywords, keyword)
else
for _, child in ipairs (keyword:getChildren ()) do
find (child)
end
end
end
for _, keyword in ipairs (catalog:getKeywords ()) do find (keyword) end
return leafKeywords
end
Copy link to clipboard
Copied
You are the best!
Recursivity really messes with my mind. Even with your code right in front of me I have difficulty in wrapping my mind around it 😉
Anyway, it all works and i'm happy.
Thank you!
By the way, I have a dialog box with 9 edit controls (the leaf keyword names actually serve as the edit controls' "completion" property for autocompletion). Is there a way to set the focus to the edit control of my choice? I can't find any mention of this in the API docs.
Copy link to clipboard
Copied
"The function will have to use startAsyncTask in order to use catalog:getKeywords() and lrKeyword:getChildren(), so how can I be sure that the list of leaf keywords returned by the recursive function is actually available when I want to use if in the calling script?"
Invoke the main function of the script from startAsyncTask() -- then everything it does will be done serially in that separate task, and you won't have to worry about multiple tasks trying to synchronize.
Copy link to clipboard
Copied
"Is there a way to set the focus to the edit control of my choice? I can't find any mention of this in the API docs."
Unfortunately note.
Copy link to clipboard
Copied
Thanks again. I'm beginning to see what's possible and whar's not in this API. O hope you don't mind all the questions.