Adding intellisense for other language(s) (not html)

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Hi,

I'm trying to add intellisense for CSS, just to learn how it's done, but I can't activate it somehow. I've included my test-application so perhaps you can tell what I'm doing wrong. As soon as I'm starting to type the intellisense should appear, but no result.

- first I included the CssDynamicSyntaxLanguage.vb and added:
"Protected Overrides Sub OnSyntaxEditorTriggerActivated(ByVal syntaxEditor..." with a few lines, but that work, so I removed it.

http://www.mediafire.com/?nc7v5ubka42qbj7

Thanks in advance.

Comments (27)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

In past support conversations I believe we already helped you with this sort of thing. In your Form1.SyntaxEditor1_KeyTyped method you have an example.

You could do similar code to that. Just watch for letters to be typed that are in a lexical state that is a CSS one. If that scenario occurs, you may want to populate and show the member list.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Happy new year ;)

Hi, sorry for the late reply.
I added a list into the CssDynamicSyntaxLanguage just like in the HtmlDynamicSyntaxLanguage. When I start typing the "{" the memberlist doesn't show.

This is what I added into the CssDynamicSyntaxLanguage

Protected Overrides Sub OnSyntaxEditorTriggerActivated(ByVal syntaxEditor As SyntaxEditor, ByVal e As TriggerEventArgs)

            Dim memberList As IntelliPromptMemberList = syntaxEditor.IntelliPrompt.MemberList

            '   Set IntelliPrompt ImageList
            memberList.ImageList = ActiproSoftware.SyntaxEditor.SyntaxEditor.ReflectionImageList

            '   Add items to the list
            Dim _blue As Integer = CInt(ActiproSoftware.Products.SyntaxEditor.IconResource.XmlTag)
            Dim _orange As Integer = CInt(ActiproSoftware.Products.SyntaxEditor.IconResource.XmlTag)
            Dim _red As Integer = CInt(ActiproSoftware.Products.SyntaxEditor.IconResource.XmlTag)

            Select Case e.Trigger.Key
                Case "TagAutoCompleteTrigger"
                    ' Call the base method
                    MyBase.OnSyntaxEditorTriggerActivated(syntaxEditor, e)
                Case "TagListTrigger"
                    ' Get the member list
                    With memberList
                        .ResetAllowedCharacters()
                        .AllowedCharacters.Add("!"c)
                        .AllowedCharacters.Add("-"c)
                        .Clear()

                        '    see which reference has been selected

                        Select Case Form1.combobox_reference.Text

                            Case "CSS 2.1"

                                .Add(New IntelliPromptMemberListItem("azimuth", _orange, "Used to give the impression that a sound is coming from a specific horizontal direction", "{", "}"))
                                .Add(New IntelliPromptMemberListItem("background-attachment", _orange, "Specifies whether background images should scroll or be fixed in a browser window", "{", "}"))
                                .Add(New IntelliPromptMemberListItem("background-color", _orange, "Specifies the background color of an element", "{", "}"))
                                .Add(New IntelliPromptMemberListItem("background-image", _orange, "Specifies the background image of an element", "{", "}"))
                                .Add(New IntelliPromptMemberListItem("background-position", _orange, "Specifies the initial position of a background image", "{", "}"))
                                .Add(New IntelliPromptMemberListItem("background-repeat", _orange, "Specifies whether the image is repeated (tiled), and how", "{", "}"))

                            Case "CSS 3"

                                .Add(New IntelliPromptMemberListItem("azimuth", _orange, "Used to give the impression that a sound is coming from a specific horizontal direction", "{", "}"))
                                .Add(New IntelliPromptMemberListItem("background-attachment", _orange, "Specifies whether background images should scroll or be fixed in a browser window", "{", "}"))

                        End Select

                        ' Show the list
                        If .Count > 0 Then
                            .Show()
                        End If
                    End With
            End Select
        End Sub 'OnSyntaxEditorTriggerActivated
Here's the example: http://www.mediafire.com/?cynf9l3jb8lq1y6

Please tell me where I'm going wrong.

[Modified at 01/03/2012 10:43 AM]
Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Do you have some time to look at the example?
Thanks in advance.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

Sorry for the late reply, for some reason I don't believe we received the notification email on this one.

I don't see anywhere in your language that you are looking to capture a "{" character. It looks like you watch for characters like space to be typed but not '{'. If you look at the triggers in the css.xml you can see that.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
I added the following to the css.xml, but I don't think that it is correct cause I don't see the values.

    <KeyPressTrigger Key="TagListTrigger" Character="{">
      <KeyPressTriggerValidStates>
        <KeyPressTriggerValidState State="DefaultState" />
      </KeyPressTriggerValidStates>
    </KeyPressTrigger>
When I add the { to the <KeyPressTrigger Key="PropertyListTrigger" Character=" "> nothing happens.

This is what I'm trying to achieve:
[IMG]http://i40.tinypic.com/2nv5anl.png[/IMG]
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

When I added that trigger to css.xml in your sample and put a breakpoint in HtmlDynamicSyntaxLanguage.OnSyntaxEditorTriggerActivated, it stopped on the trigger fine. Note that you made your css.xml file use HtmlDynamicSyntaxLanguage as a code-behind language class, which is probably a mistake.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
He, thanks for pointing that out.

This is my trigger which works...almost:

<KeyPressTrigger Key="TagListTrigger" Character=" ">
<KeyPressTriggerValidStates>
<KeyPressTriggerValidState State="DefaultState" />
</KeyPressTriggerValidStates>
</KeyPressTrigger>


When I press the spacebar within the {....} the OnSyntaxEditorTriggerActivated isn't activated. (breakpoint added)
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Radjesh,

I pasted your trigger into css.xml and it came up fine for me when in the "default" state (outside {...}). You need to change your valid state above to allow it within {...}.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
2 questions:
1) What do I need to change?
2) What does the following part of the trigger do?:

<KeyPressTrigger Key="PropertyListTrigger" Character=" ">
<KeyPressTriggerValidStates>
<KeyPressTriggerValidState State="PropertyState" />
</KeyPressTriggerValidStates>
</KeyPressTrigger>
<KeyPressTrigger Key="ValueListTrigger" Character=" ">
<KeyPressTriggerValidStates>
<KeyPressTriggerValidState State="ValueState" />
</KeyPressTriggerValidStates>
</KeyPressTrigger>
</Triggers>
Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Scrap question 2. I'm starting to understand it.
At least... The "PropertyListTrigger" is called in the OnSyntaxEditorTriggerActivated (Select Case). Am I correct? (of course I need to add it in the Select Case)
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

Something like this is probably more efficient:
<KeyPressTrigger Key="TagListTrigger" Character=" "> 
    <KeyPressTriggerValidStates> 
        <KeyPressTriggerValidState State="PropertyState" /> 
        <KeyPressTriggerValidState State="ValueState" /> 
    </KeyPressTriggerValidStates> 
</KeyPressTrigger>
Valid states tell the trigger which lexical states to fire in, as defined in your language's XML definition.

Yes the key is something you can trigger on in a Select Case.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Thanks, it works 100%, but still a few small questions left.

1- How do I trigger the taglist with characters [a-zA-Z]?

After I pressed the Enter-key in the memberlist the following is for example added: "radjesh:"
2- How do I trigger a new memberlist instantly after hitting the Enter-key. I tried it in the SyntaxEditor1_KeyTyped, but I can't seem to grasp the idea on how to do it.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

You'd probably want to use KeyTyped instead of triggers if you are trying to show it for all letter characters. Actually it appears you asked these same questions in the past:
http://www.actiprosoftware.com/support/forums/viewforumtopic.aspx?ForumTopicID=5872


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Hi,

After some good thinking and trying I realized that I took the wrong approach. I'll try some more and let you know.

There is something that I really want to know. How can I have multiple triggers within the xml? Let's say: "<KeyPressTrigger Key="PropertyListTrigger" Character=" ">"
The memberlist will be activated on spacebar key. How can I activate it on multiple keys using the XML-file?

Please don't look at my example any more. Like I said: I took the wrong approach.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

Each KeyPressTrigger only works for a single typed Character. So you'd have to define a separate KeyPressTrigger for each character you want to trigger on.

If you want to have some event fire for a lot of keys, you are better off just handling KeyTyped, using a TextStream to check the state (to mimic a trigger valid state check), and executing your code there since it's much easier to set up a switch statement for multiple possible typed characters there.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
Thanks I have learned more.

I'm having however problems opening the memberlist for values:
Dim memberList As IntelliPromptMemberList = SyntaxEditor1.IntelliPrompt.MemberList
Dim stream = SyntaxEditor1.Document.GetTextStream(SyntaxEditor1.Caret.Offset)

' If the member list is not yet visible and the character typed is a space...
If (Not memberList.Visible) AndAlso (e.KeyChar = " "c) Then
Dim showList As Boolean = False

' Check if token is in a proper state
Select Case stream.Token.LexicalState.Key
Case "ValueState"
If (stream.Token.Key = "ValueStartToken") Then
   showList = True
Else
   If stream.GoToPreviousTokenWithKey("ValueStartToken") Then showList = True
End If

If (showList) Then
   Dim tagName As String = stream.TokenText.Trim()
   Select Case tagName
      Case "azimuth:"
         With memberList
            .Clear()        '   clear the list and add new members
            .Add(New IntelliPromptMemberListItem("test CSS1", image_index, "Line 1 <br/> Line 2 <br /> <b>Line 3 BOLD</b>"))
            .Add(New IntelliPromptMemberListItem("test CSS2", image_index, "test2"))
            .Show()
         End With
   End Select   
End if
The memberlist isn't shown when I press the spacebar.

[Modified at 02/16/2012 03:46 AM]
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

You need to put a breakpoint in the top of your method and debug it with Visual Studio to see where the logic is going wrong and verify that the Show method is being called.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar
It seems none of them are "triggered", besides the "ValueState", so that part seems to be correct.

</code>
Case "ValueState"
If (stream.Token.Key = "ValueStartToken") Then
showList = True
End If
css xml:
<State Key="ValueState" TokenKey="ValueDefaultToken" Style="ValueDefaultStyle">
   <!-- Scopes -->
   <Scopes>
      <Scope>
      <ExplicitPatternGroup Type="StartScope" TokenKey="ValueStartToken" Style="ValueDelimiterStyle" PatternValue=":" />
      <ExplicitPatternGroup Type="EndScope" TokenKey="ValueEndToken" Style="ValueDelimiterStyle" PatternValue=";" />    
      </Scope>
   </Scopes>
here's the example: http://www.mediafire.com/?6no7087hz8e1tgx
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Radjesh,

Again, you need to debug your code. When I do so and step through all your code lines in that method after pressing space in a CSS value region, you can see that you never hit the lines that show a member list, due to your Select Case.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar

Trust me. I did debug as you told me to do. Because it does work for the HTML I don't undestand why it doesn't for the CSS. The HTML also uses the Select Case. I don't see what is wrong with the code.

Congrats wit the new look by the way.

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Radjesh,

With the sample you sent, what exactly are you trying to do that isn't working?  Please give specific directions to repro the issue.

I thought you had been talking about pressing space in a CSS value area?  When I try that it works fine, but gets down to line #99 in Form1.vb where you do "Select Case tagName" and it falls through that because the tagName variable isn't set properly to a value it will pick a Select Case for.  So in that case you need to update your logic for picking tagName's value.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar

Hi, thanks for the reply.

When opening the project a css -file is loaded. Add the following:

{
azimuth:
}

Now press space after the 'azimuth:'. Nothing happens. It should trigger the "Select Case" in the 'KeyTyped'

I've improved the example: http://www.mediafire.com/?jbc7rg2vvv7jh6j

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Well again if you put a breakpoint at the start of your event handler, you can see what happens.  In the scenario you described, you hit this line in your "Check if token is in a proper state" region:

If (stream.Token.Key = "StartScope") Then

The problem is that the 'If' isn't true so nothing shows.  There are several tokens that can be in the ValueState, so you need to debug and look at the various scenarios you want to handle and update that part appropriately.

Then as I mentioned in my previous post, your "tagName" logic below there is also not going to work right as you have it now.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar

Hmm... In what way will it work? Sorry, but I can't figure it out.
Been trying to make it work for several days now.

EDIT: Forgot to mention that there are only 2 scopes in the "ValueState" (Start and End)

Sorry for being such a noob.

[Modified 12 years ago]

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

stream.Token is a token, not a lexical scope.  So it will never have the key "StartScope".  If you put a breakpoint on your If statement and as you are typing, use the watch window to see what the stream.Token values are, then you should get a better idea of what possible values are coming through there.

I'm sorry you're having trouble figuring it out.  We've tried hard to provide you a lot of free assistance on all this via this thread and other tickets.  But unfortunately if you'd like us to work on modifying the code for this procedure to get your CSS values showing better, we'd have to ask that you order an hour of consulting service.


Actipro Software Support

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar

Thanks. Will give it a go. (again :P)

[Modified 12 years ago]

Posted 12 years ago by Radjesh Klauke - X-impress
Avatar

sigh... I give up.

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

Add Comment

Please log in to a validated account to post comments.