Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Hello Experts!!
Ditto what Steve says Paulette.
The get_selection_oids() function below can return selected oids if you know the parent and target search tag names (or target regex of oid_find_children()).
function ancestor_oid(o, tag, highest=0, doc=current_doc()) {
local saveo;
while (oid_name(o)!=tag) {
if (o == oid_first_tag(doc)) {
# no such animal
return 0;
}
o = oid_parent(o);
}
if (highest) {
saveo=o;
while (o!=oid_first_tag(doc)) {
if (oid_name(o)==tag) {
saveo=o;
}
o=oid_parent(o);
}
o=saveo;
}
return o;
}
function get_selection_oids(par,chld_tag,rgx=0) {
# returns colon delimited list of found chld_tag oids in selection, excluding atict:del deletions
local o1, o2, p1, p2, arr[], selarr, i;
o1=selection_start(p1)
o2=selection_end(p2)
if (!oid_find_children(par,arr,chld_tag,rgx)) { return 0; }
for (i=1;i<=high_bound(arr);i++) {
if (ancestor_oid(arr[i], 'atict:del')) { continue; }
if (oid_offset(o1,p1,arr[i],-1)>=0&&oid_offset(o2,p2,arr[i],0)<=0) {
selarr.=":$arr[$i]"
}
}
sub('^:','',selarr)
return selarr
}
Oops, make that "... if you know theparent oid and target search tag name ..."
Hello Brian J. and everybody.
I'm sorry to respond until now. I think my best solution will be to get the content selected from the Arbortext Editor using some of the acl commands and then manage that information in Java. I tested a little with the "selection_markup()" command and I could see that I'm receiving a String representation of the selection, I wasn't sure about doing that since the content will be modified, this means I'll add some extra elements and maybe I'll remove some others, also because I'm doubting about what's the largest text I could pass as a String to my Java object, my best idea for the moment is to remove the selected content and insert the modified content which will correspond to my modified String in Java, I am not sure about how to identify the exact position of the extraction in the document, the whole process is quite complicated because I don't want to insert the modified content in a different position; I haven't had time to test all the code you kindly provide me, but as soon as I have a chance to test it I'll let you know what's the best solution, at least for me 😄
Again thank you so much for your ideas, suggestions and time. I really appreciate a lot your support.
Paulette.
Hello everyone!
At the end I dediced to use the selection_markup() ACL command, once I have the corresponding String with my selection, I pass it as a parameter to my Java Object and I make all changes in Java according to what I need, finally I'll get the new String with its corresponding changes and I'll insert it using the delete_mark and insert("modified_string") ACL commands; now, what I would like to add is a new "fancy" feature, once I put back the new content into the book I would like to select this new "modified" content. All the previously selected section is continuous and I was thinking that maybe using marking I could mark the begin and the end of my selection; however I don't know quite well how to manage marking with ACL, I'm not sure neither if I could have a way to identify my previously selected chunk of sections.
Does anybody of you knows a way to achieve my objective? I mean, is there any command which could help me to select again a previously selected, modified, removed and re-inserted chunk of sections?
I hope anybody could give me a clue or any information of managing selections in Arbortext using ACL; as always I appreciate a lot your time and responses.
Paulette
Also look at the "insert_string" command also which has some options you might find useful such as -sgml (w/markup)
local o1, p1, o2, p2;
o2=selection_end(p2);
goto_oid(o1,p1);
goto_oid(o2,p2);
re-selects it. After inserting a new string/markup insert you probably have a different end so you'd want to save a new selection end (cursor position after insert) with
o3=selection_end(p3);
goto_oid(o1,p1);
goto_oid(o3,p3);
Where this breaks down unfortunately is when the selection was made backwards (right to left); use oid_offset to test for that.
This function returns the character offset between the two document locations specified by oid1,pos1 and oid2,pos2 respectively. Each non-text object (that is, markup, equations, graphics) counts as one character. The offset returned will be negative if the location specified by oid2,pos2 comes before the position specified by oid1,pos1."
In Reply to Paulette Zorrilla:
Hello everyone!
At the end I dediced to use the selection_markup() ACL command, once I have the corresponding String with my selection, I pass it as a parameter to my Java Object and I make all changes in Java according to what I need, finally I'll get the new String with its corresponding changes and I'll insert it using the delete_mark and insert("modified_string") ACL commands; now, what I would like to add is a new "fancy" feature, once I put back the new content into the book I would like to select this new "modified" content. All the previously selected section is continuous and I was thinking that maybe using marking I could mark the begin and the end of my selection; however I don't know quite well how to manage marking with ACL, I'm not sure neither if I could have a way to identify my previously selected chunk of sections.
Does anybody of you knows a way to achieve my objective? I mean, is there any command which could help me to select again a previously selected, modified, removed and re-inserted chunk of sections?
I hope anybody could give me a clue or any information of managing selections in Arbortext using ACL; as always I appreciate a lot your time and responses.
Paulette
Lou!
Tahnk you so much for your response, I have been working those days testing with different commands, however I think I was using them in a wrong way, I didn't know that using only mark command Arbortext would select the content, I was using the oid_select() command but at the end I wasn't receiving the complete selection.
I tested the commands you sent me and at the end I need to use the o3, p3 option after I insert the new content, this way my plugin is getting the correct bunch of sections, in my case, which I selected, modified, removed and re-inserted. I tested also with selections from right to left and it seems don't have any problem. I'll continue testing with other documents and other selections, but for the moment my code is working only with mark and goto_oid acl commands.
Again, thank you so much and I'll let my code in case anybody could find it useful.
local $markup = java_instance($obj,"navigateThroughSelection", $selection, $main::EPIC_CODE_HOME); #Modify the wrapped content, returns $markup which corresponds to selected and modified content.
java_delete($obj); #Delete Java Object
if($markup != "-1") {
insert(markup);
goto_oid(o1,p1);
mark begin;
goto_oid(o3,p3);
mark end;