Intellisense: populating with multiple triggers

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by GavinK151
hi guys, looking for a bit of guidance on 2 things for intellsense, having a hard time understanding where to go...

The situation:

My application allows users to edit HTML. They can however insert tags that look something like:

<mytag:if condition="whatever" on="true">
    some more stuff here
Now, after the "mytag:" only a finite set of items are valid ("if", "when", "with") and I can get a list to popup with the options by defining a trigger inside the ActiproSoftware.HTML.xml file thus:

<KeyPressTrigger Key="MyTagTrigger" Character=":">
          <KeyPressTriggerValidState State="MyState" />
In the States section I have:

<State Key="MyState" TokenKey="MyState">
      <RegexPatternGroup Type="StartScope" TokenKey="MyStateStart" PatternValue="&lt;mytag" />
      <RegexPatternGroup Type="EndScope"   TokenKey="MyStateStop"  PatternValue="&gt;" />
I then added this new state as a ChildState to the "DefaultState" in the ActiproSoftware.HTML.xml file.
(do I need to do this?)

...and finally in SyntaxEditor_Trigger() I populate the list:

IntelliPromptMemberList memberList = SyntaxEditor.IntelliPrompt.MemberList;
memberList.ImageList = SyntaxEditor.ReflectionImageList;
int imageIndex = (int)ActiproSoftware.Products.SyntaxEditor.IconResource.InternalEvent;
memberList.Add(new IntelliPromptMemberListItem("if", imageIndex, null, "if>", "</mytag:if>"));
so far so good.

Now if the user selects "if" from the list I would like them to then be able to press " " (space) and get a list of valid attributes that are ONLY valid for the "if" (lets say "condition", "flag" and "on" are valid for if). However here is where I run into problems.

I tried to define a trigger for " " (space) character:

<KeyPressTrigger Key="MySpaceTagTrigger" Character=" ">
          <KeyPressTriggerValidState State="MyState" />
I have set it to be valid in the same State "MyState" as the other trigger ":", and then I check for it once more in SyntaxEditor_Trigger() however it never seems to fire. Now I *think* I might need to define another state but to be honest I am completely lost at this point.

nothing in the samples seem to do this sort of thing so i was hoping someone could tell me where I am going wrong and perhaps provide a small example?

The second thing I am unclear on is how I can trigger the closing tag when the user has finished entering their attributes:

<mytag:if condition="whatever" on="true" >

So when they finally type ">" I want to close off "mytag:if" like so:

How do I "look backwards" to see what to use? i.e. how can know to insert </mytag:if> upon input of the ">"? I think I might be able to do this via the _regionSyntaxEditor_KeyTyping() event but once more I am struggling. I know its done automatically when you select from the intellisense list if you provide the relevent parameters when adding a new IntelliPromptMemberListItem but I only want the completion to take place when the user finally hits ">"...

Many apologies for this huge post, I have been struggling with this for a while now and hope it might be more productive asking for advice/examples.

thanks for reading this far :-)


[Modified at 03/22/2006 09:31 AM]

Comments (1)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
You might have created the largest post ever on our forums! Hehe...

Ok, I'd probably need your language def to be able to know why the trigger wasn't working for the space. My guess is that the valid state is wrong.

For the >, you had the right idea. Basically you would Handle that in KeyTyping. Then use a TextStream (from Document.GetTextStream()) and iterate tokenwise back until you find the start tag name. At that point, cancel the KeyTyping event (in the event args) and use the editor.SelectedView.InsertSurroundingText method (I think that's it off the top of my head) to insert the ">" before the caret and the "</mytag:if>" after.

Actipro Software Support

The latest build of this product (v24.1.0) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.