[author mode][content completion] insert element with attribute value from controlled list

<oXygen/> general issues.
c-alpha
Posts: 2
Joined: Tue Feb 28, 2017 8:57 pm

[author mode][content completion] insert element with attribute value from controlled list

Post by c-alpha » Tue Dec 10, 2019 8:58 pm

Hello folks,

I'm having my first go at customizing the content completion, so apologies up front for probably missing out on the obvious. I have read the content completion part of the online help, created a cc_config.xml file, and added its folder to the classpath. Messages in the info log show that the file is loaded ("start scanning file ... No problems found" on startup).

I'm working with a DTD which defines an integer element, and which has an attribute named base. @base can take a value from a controlled list (coincidentally "2", "8", "10", and "16"), or be absent (defaults to "10"). What I'd like to achieve minimally is that the content completion in author mode offers me to insert an integer element with @base set to one of the four controlled values, but without going to the attributes editor or pop-up. I.e. when pressing enter in author mode, I want to be presented with four options for inserting an integer element. Ideally, content completion would offer me four integer options: no attribute, @base=2, @base=8, and @base=16.

Is either the minimal or the ideal solution possible at all with the content completion system?

Also, there may be another disconnect relating to namespaces? As I'm working with a DTD, I would assume that everything happens in no namespace. As an experiment, I put the following in my cc_config.xml as the only content:

Code: Select all

<elementProposals insertElements="integer">
     <insertAttribute name="base" value="2"/>
</elementProposals>
My hope was that whenever I insert an integer element, it would have @base=2. But nothing happens, i.e. an integer element with no attributes gets inserted by content completion.

Any hints appreciated.

alex_jitianu
Posts: 742
Joined: Wed Nov 16, 2005 11:11 am

Re: [author mode][content completion] insert element with attribute value from controlled list

Post by alex_jitianu » Wed Dec 11, 2019 4:51 pm

Hello,

Content completion can be configured to specify the possible values, like this:

Code: Select all

    <match elementName="integer" attributeName="base">
        <items>
            <item value=""></item>
            <item value="2"></item>
            <item value="4"></item>
            <item value="6"></item>
        </items>
    </match>
And you can control what fragment gets inserted whenever an "integer" element is inserted like this:

Code: Select all

    
    <elementProposals path="integer" >
        <insertAttribute name="base" value="4"/>
    </elementProposals>
    
I want to be presented with four options for inserting an integer element. Ideally, content completion would offer me four integer options: no attribute, @base=2, @base=8, and @base=16.
But from what I understand, a scenario like the one described above can't be solved through content completion configuration alone. You need to configure 4 author actions, each one using the InsertFragmentOperation to insert a specific fragment, each fragment having a different @base value:

Code: Select all

<integer/>

Code: Select all

<integer base="2"/>

Code: Select all

<integer base="8"/>

Code: Select all

<integer base="16"/>
My hope was that whenever I insert an integer element, it would have @base=2. But nothing happens, i.e. an integer element with no attributes gets inserted by content completion.
As you can see above, the fragment required "elementProposals" you need to insert is a bit different than what you've tried. Also, after you make changes in the configuration file, you need to reload the target XML file to make sure the new configuration is loaded.

Best regards,
Alex

c-alpha
Posts: 2
Joined: Tue Feb 28, 2017 8:57 pm

Re: [author mode][content completion] insert element with attribute value from controlled list

Post by c-alpha » Wed Dec 11, 2019 6:35 pm

Hello alex_jitianu, and thanks for your prompt reply!
alex_jitianu wrote:
Wed Dec 11, 2019 4:51 pm
Hello,

Content completion can be configured to specify the possible values, like this:

Code: Select all

    <match elementName="integer" attributeName="base">
        <items>
            <item value=""></item>
            <item value="2"></item>
            <item value="4"></item>
            <item value="6"></item>
        </items>
    </match>
The DTD already defines a controlled list of values, so when I open the attributes editor it offers me a drop-down for @base with these values.
alex_jitianu wrote:
Wed Dec 11, 2019 4:51 pm
And you can control what fragment gets inserted whenever an "integer" element is inserted like this:

Code: Select all

    
    <elementProposals path="integer" >
        <insertAttribute name="base" value="4"/>
    </elementProposals>
    
I tried this in cc_config.xml, both with and without your match rule, reloaded the target XML, restarted the app, but somehow it is not triggered. I only get offered the completion for an integer element without @base (which I presume is generated from the DTD). Somehow the stuff in cc_config.xml doesn't seem to get triggered? Is there a way to get logging/debug info about the content completion process?
alex_jitianu wrote:
Wed Dec 11, 2019 4:51 pm
I want to be presented with four options for inserting an integer element. Ideally, content completion would offer me four integer options: no attribute, @base=2, @base=8, and @base=16.
But from what I understand, a scenario like the one described above can't be solved through content completion configuration alone. You need to configure 4 author actions, each one using the InsertFragmentOperation to insert a specific fragment, each fragment having a different @base value:
[...]
I couldn't get that to work either. Here is what I configured (inspired by how the action for the b element(bold) is done):
Screenshot 2019-12-11 at 16.32.52 .png
Screenshot 2019-12-11 at 16.32.52 .png (201.49 KiB) Viewed 166 times
It seems that what is inferred from the DTD hides/overrides whatever I configure in the framework?

alex_jitianu
Posts: 742
Joined: Wed Nov 16, 2005 11:11 am

Re: [author mode][content completion] insert element with attribute value from controlled list

Post by alex_jitianu » Thu Dec 12, 2019 4:47 pm

Hi,
I tried this in cc_config.xml, both with and without your match rule, reloaded the target XML, restarted the app, but somehow it is not triggered. I only get offered the completion for an integer element without @base (which I presume is generated from the DTD). Somehow the stuff in cc_config.xml doesn't seem to get triggered? Is there a way to get logging/debug info about the content completion process?
Please write me an email at support@oxygenxml.com and I will give you the required configuration file for generating log. Also, please send me the cc_config.xml file so I can test it myself with a small DTD.
It seems that what is inferred from the DTD hides/overrides whatever I configure in the framework?
After you create these actions you need to put them somewhere where the user can find them, like:
1. On the toolbar
2. In the content completion

Post Reply