TypeMemberDropDownList - Switching documents doesn't refresh

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 16 years ago by Matt Adamson
Avatar
Guys

I use this drop down to show multiple Document instances which are switched back and forth by caching them for C# / other code files. The drop down is initialised to the editor through the designer and then at runtime the syntax editor control changes the Document property as required.

The issue appears to be when the cached Document using the C# add on is loaded and set to the Document property of the syntax editor, the drop downs don't get refreshed with the members for that file.

Other files simply use the LoadLanguageFromXml calls if the file isn't of cs or vb type
//
                    // Set the language parser to use from the file extension
                    //
                    // Firstly try and find an add on language specified for the file
                    // otherwise drop back to using a dynamic languaged definition.
                    //
                    SyntaxLanguage syntaxLanguage = GetAddOnLanguageForFileExtension(Path.GetExtension(sourceFile.FileName));
                    if (syntaxLanguage != null)
                    {
                        rightDocument.Language = syntaxLanguage;
                    }
                    else
                    {
                        //
                        // If language of file doesn't support add on features then try 
                        // retrieve a dynamic language definition
                        //
                        // If a dynamic language definition doesn't exist then no colour
                        // syntax highlighting will be applied.
                        //
                        String languageFile = LanguageSupport.GetLanguageFileFromExtension(Path.GetExtension(sourceFile.FileName));
                        if (languageFile != null)
                        {
                            try
                            {
                                rightDocument.LoadLanguageFromXml(languageFile, 0);

                                Trace.WriteLineIf(traceSwitchSourceCodeEditorBuilder.TraceInfo,
                                                    String.Format("Loaded dynamic language xml definition from file '{0}'",
                                                                    languageFile));
                            }
                            catch (Exception e)
                            {
                                Trace.WriteLineIf(traceSwitchSourceCodeEditorBuilder.TraceError,
                                                    String.Format("Failed to load dynamic language xml definition from file '{0}', Exception='{1}'",
                                                                    languageFile,
                                                                    e.Message));

                                throw;
                            }
                        }
                    }

                    leftEditorTypeMemberDropDownList.Visible = syntaxLanguage != null;
                    rightEditorTypeMemberDropDownList.Visible = syntaxLanguage != null;

Comments (17)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks we've attached internally to DocumentLanguageChanged to help handle this scenario for the next maintenance release.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Great however is there any workaround I can apply for now to get this working i.e. calling any methods in syntax editor or the drop down at certain points?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Change the Document.SemanticParseData to null. That is what kicks off the update in the drop-down list.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Thanks, won't that negate the benefit of the caching of document instances I'm doing though i.e. cause them to be reparsed? I don't mind this as a workaround for now though to get this working however just wondered?
Posted 16 years ago by Matt Adamson
Avatar
Actually I should have tried this anyway before responding :)

I've set the SemanticParseData property of the Document instance retrieved from the cached to null however the drop downs don't appear to change, anything else I could try?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That property value has to change for the update to occur. And the Document must already be in the SyntaxEditor that the drop-down is attached to when you make the property change. It should work if you do those things.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Actually I just noticed that the SemanticParseData is equal to null before I try and set it to null so that probably explains why.

Any other ways I can try and workaround this or will the next release be coming soon with this fix in?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
As mentioned, it needs to change. So maybe set it to an empty string ("") and then back to null, just so it changes. The SemanticParseData is an object so it can be anything but for the purposes of the drop-down list, that will only look for CompilationUnits.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Are you sure SemanticParseData property is only expecting an object as if I try to see it to an empty string I get this

(862,67): error CS0029: Cannot implicitly convert type 'string' to 'ActiproSoftware.SyntaxEditor.ISemanticParseData'

which indicates it's expecting an object of a type which implements ISemanticParseData.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sorry, my bad. Yes you can create any dummy object that implements ISemanticParseData and that will work.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
I think well have to give this workaround a miss as it's give me the run around more than anything :)

I created an object test implementing this interface then set the property to null and still the drop downs aren't refreshing.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Here's the code for the drop-down:
private void syntaxEditor_DocumentSemanticParseDataChanged(object sender, EventArgs e) {
    // Update the type/member drop down list 
    this.BindToCompilationUnit(syntaxEditor.Document.SemanticParseData as CompilationUnit, syntaxEditor.Caret.Offset);
}
When the compilation unit passed to BindToCompilationUnit is null, it will clear the combos. You must not be making the event fire. As I mentioned you must have the Document already assigned into the SyntaxEditor that is beign tracked or else this event won't occur. Double check that.

Actually you could probably call BindToCompilationUnit directly like above with null since it is public instead of trying to make the event fire.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Hi

Are you sure BindToCompilationUnit is supposed to be public as I can't call this method?

Also sometimes the drop downs are actually empty rather when a new document instance is set.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, it definitely is public and available for you to call.

Keep in mind that the drop-downs are based on the semantic parse data (CompilationUnit) and that is parsed in a separate thread. So there may be a brief delay while parsing is occuring before they update when they are populated from a parsed CompilationUnit.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Sorry I thought it was on the syntax editor control. Fantastic after calling it on the drop down it appears to refresh, thanks for your persistence in helping here :)
Posted 16 years ago by Matt Adamson
Avatar
You mentioned this would be fixed in the next maintainence release however it's been nearly 3 months since the last maintainence release. Is this on the horizon at all?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes definitely. All our resources have been working day and night to finish off WPF Studio v4.0 (which we are trying to get out today or at the latest tomorrow). After that we need to get the SyntaxEditor maintenance release completed and out. There are a lot of updates in the SyntaxEditor code for this next release already.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.