Quantcast
Channel: SyntaxEditor for Windows Forms - Recent Posts
Viewing all 930 articles
Browse latest View live

Collapsible blocks

$
0
0

What should I change in the Pascal xml language definition to make the blocks collapsible like in c#?


Re: Collapsible blocks

$
0
0

Hi Dragos,

You could possibly set up the "begin" and "end" keywords to function as a token-based outlining block.  Look at the JavaDynamicSyntaxLanguage codebehind class in the sample project for an example of how outlining is set up based on tokens.  You'd do something similar for Pascal.  Also note that you need to set up a SyntaxLanguageTypeName attribute in the root element of the XML definition to tie it to a codebehind class.

The problem is that Pascal has other blocks like "case...end" that also use "end" as a keyword, which causes problems because a token-based outliner wouldn't know that the "end" keyword there is tied to a "case" vs. some other kind of higher level block.  That is why we don't have token based outlining in the samples, as it wouldn't be accurate.

You really would need a parser defined for the language to build an AST, at least of the collapsible blocks, and then build outlining off of that.  You can look at our documentation or the Simple language example for how to do some of that.  But it can get time consuming to build a parser for a full complex language like Pascal.

SaveFile / LoadFile fails if file contains ANSI chars > x'7F'

$
0
0

Your 'default' LoadFile / SaveFile functions (where encoding is not specified) say they save/load UTF8 format.

However if I use SaveFile to save a file that contains european accented characters (in the x'80' to x'FF' range) it does in deed save those characters using UTF8 encoding, but it does not include the UTF8 BOM.

If I open the file in Notepad everything works fine, but if I open it using your default LoadFile() method the high range characters are loaded as though they were 2 'low range' ASCII characters. i.e. it screws up the data.

Since I work with a lot of european customers this is a major issue.

I originally got around the issue by always specifying a UTF8 encoding - which does write the BOM on the file.

However customers want to be able to open the files on non-Windows systems that do not understand a Windows BOM, so they want the files to be saved as ANSI (i.e. the current code page) unless those files contain characters that are not in the current code page. In which case we would save as UTF8 - but with a BOM.

This is exactly how the default SaveFile() function in my previous tool worked... and appears to be how Notepad works.

You do not apparently have a version of SaveFile that can do this so my real question is whether you have a method that can examine the text and tell me if it contains any characters that are not in the current code page, so that I can do this myself.
(I would also ask that you consider changing your default SaveFile() function, or add an additional overload, that works in this 'standard' fashion.)

Re: SaveFile / LoadFile fails if file contains ANSI chars > x'7F'

$
0
0

Hi Mike,

Our SaveFile and LoadFile methods are very simple and pretty much follow the methods that .NET makes available to us for working with files.

The basic SaveFile just does "StreamWriter writer = File.CreateText(path)" and then outputs the text to that writer.  The other overload calls "File.Create(path)" to create the file and then makes a new StreamWriter that specifies the Encoding you pass, forcing it to use that.

Similarly the basic LoadFile uses File.OpenText and reads the string to the end.  The other overload uses File.OpenRead(path) and creates a StreamReader with the Encoding you pass, forcing it to use that.

If you are looking for more complicated logic, you could create it yourself since our logic is just about 3 lines long for each of those methods.  We don't have anything that scans text for adhering to particular encodings since we are only calling the core I/O methods described above for input/output.  I would be interested in seeing whatever logic you come up with for that, as I'm sure other customers could use it.

Re: SaveFile / LoadFile fails if file contains ANSI chars > x'7F'

$
0
0

In that case you should change your documentation for the LoadFile() method since it doesn't really open a UTF8 file (which is what SaveFile creates) it actually EXPECTS to load a UTF8 file - but if it doesn't find a UTF8 BOM it will load the file as though it were an ANSI file. (effectively corrupting the file if it was not saved with ANSI encoding.)

The way to handle this is to use the following:

        If IsInCodePage() Then
            Document.SaveFile(fileName, Encoding.Default, LineTerminator.CarriageReturnNewline)
        Else
            Document.SaveFile(fileName, Encoding.UTF8, LineTerminator.CarriageReturnNewline)
        End If

    Private Function IsInCodePage() As Boolean
        'Check to see if the text is all within the current code page
        Dim encoder As Encoding = Encoding.GetEncoding(Encoding.Default.WindowsCodePage,
                                                       New EncoderExceptionFallback(),
                                                       New DecoderExceptionFallback())
        Try
            encoder.GetBytes(Document.Text)
            Return True
        Catch
            Return False
        End Try

    End Function

This is rather ineficient though if the document is large.

GetBytes() actually performs the encoding so if the text is entirely within the code page this encoding gets performed twice. Once in my code and a second time in your SaveFile method.
That is why this logic would normally be performed by the controls 'Save' method itself.

I realize I could simply open the output file myself and then write the byte array that was returned, but that would mean that the logic used to save the file in this specific case would look very different from when I save it with a user specified encoding. 

Re: SaveFile / LoadFile fails if file contains ANSI chars > x'7F'

$
0
0

Hi Mike,

The MSDN documentation on File.CreateText(path), which is what we use in the one overload, says:  "Creates or opens a file for writing UTF-8 encoded text."  Based on that, I would have assumed that it would write no UTF8 BOM if the chars 0-127 are only used, but would use a BOM if any other characters were used.

Similarly, the MSDN docs say for File.OpenText(path):  "Opens an existing UTF-8 encoded text file for reading." 

From doing more searching on the web and looking at the StreamWriter source in Reflector, it does appear that the File.CreateText(path) documentation is misleading as it only seems to output UTF8 without a BOM.

As for your custom logic above, why not just wrap it up as an extension method for the Document class?  Then it wouldn't look any different to the callers.

Re: SaveFile / LoadFile fails if file contains ANSI chars > x'7F'

$
0
0

You are correct. The MSDN info is also misleading.

As you say CreateText() writes UTF8 - but without a BOM
and OpenText() reads UTF8  - but only if it starts with a UTF8 BOM.

That means that OpenText() can not [always] correctly open a file that was saved using CreateText().
Which I think is a bug ... but getting Microsoft to fix something is like banging your head against a brick wall.
(I know this from trying for years to get them to fix some of the many bugs in their Data Provider for ODBC )

It would be helpful if you could change your docs to describe what really happens rather than what Microsoft implies in their own docs.

I do use an extension class already so I guess I could look at adding my own method to take care of the issue.

But if you sell your app to a lot of folks in Canada or Europe I suspect many of them will hit this issue also, so it would be very useful if you changed the way that specific SaveFile() method works so that it will work the way people expect a Save/Load pair to work.

Syntax: mark as obsolete?

$
0
0

Hello,

we are using Actipro-SyntaxEditor Version 4.0.290.0 in our Software to edit our own pascal-like programming language.

Now, with a brand new version of our software, we have some changes in our programming language.

Is it possible to mark old keywords, which are not valid any more, as obsolete?

 

 

Regards,

R. Scheller

GTI-Control


Re: Syntax: mark as obsolete?

$
0
0

Hi Ralph,

Yes, there are several things you could do.  You could have a special highlighting style in your lexer that would be different for these keywords than the others, making it clear to the user that something changed.  To do that, you'd tokenize these keywords differently than the standard ones.

Or alternatively, if you use a semantic parser, you could have it scan the document for them and return an ICompilationUnit that has HasErrors=true and SyntaxErrors filled in.  See the Language Definition Guide / Other Features / Error Wave Lines documentation topic for some info on that.

Re: How to change Keyboard shortcut mappings

$
0
0

Hi, the question above concerning Block selection via the mouse was not answered:

Block Selection - we use Ctrl+LeftMouse vs your Alt+LeftMouse
(Alt+ does match VS 2008 but we generally avoid Alt if we can)

The use of the Alt key is problematic and would like to change the block selection using the ctrl key as mentioned above. Please advice.

Re: How to change Keyboard shortcut mappings

$
0
0

Hi Michael,

I'm sorry but the mouse interaction code is defined in a large 'if'...'else if' block in our EditorView MouseDown logic.  There isn't any option at this time to alter how that all functions.

Ctrl+clicks handle word selection and Atl+clicks handle block selection in the same way Visual Studio does things.  What specifically is problemmatic with using Alt keys?

Re: How to change Keyboard shortcut mappings

$
0
0

For mouse wheel actions you can do something like:

    Protected Overrides Sub OnMouseWheel(ByVal e As System.Windows.Forms.MouseEventArgs)
        'Zoom the font size or scroll the text when Mouse Wheel is rotated
        If My.Computer.Keyboard.CtrlKeyDown Then
            ChangeZoomFactor(e.Delta > 0)  'Zoom
        Else
            MyBase.OnMouseWheel(e)         'Scroll
        End If
    End Sub

This handles zooming vs scrolling if the Ctrl key is down, but you can do anything you want while handling the MouseWheel event.

For Alt vs Ctrl to perform block selection see the first response in this thread.
(I didn't try the solution as I don't see any issue with simply using Alt. There were however issues with block selection itself but these were fixed a while back.) 

Wrapping user's source with my own header/footer

$
0
0

I'd like to offer my users the ability to use C# or VB.NET as if they were scripting languages. In simple terms I mean that the user would enter code that is effectively just the body of a method.

I would then wrap that in auto-generated class/method declaration to produce compilable source.

But I want the Actipro editor to do all the great intellisense/autocompletion stuff. Hence I need the editor to analyse the code as if it was wrapped in the class/method declaration, but not display the wrapper code.

So the user just writes/sees:

log.WriteLine("Hello world");

For compilation I would wrap that as follows:

public static class UserScript
{
    public void UserMethod(TextWriter log)
    {
        log.WriteLine("Hello world");
    }
}

The user should get intellisense etc. when they type log because it's declared as a parameter to the wrapper method.

Is this possible with Actipro?

Re: Wrapping user's source with my own header/footer

$
0
0

Hi Daniel,

Yes, we fully support that.  Please see the Code Fragments QuickStart in the Sample Browser project.  It shows exactly how to achieve this scenario using SyntaxEditor and the .NET Languages Add-on.

Adding External Reference throws Dependency Exception

$
0
0

Hi All,

Trying to load an external refernece that itself has some dependencies

dotNetProjectResolver.AddExternalReference("MyDll");

 

Throws the following exception

"System.ApplicationException: Could not load exported type data for assembly 'Ice.Lib.EpiClientLib, Version=3.0.7.0, Culture=neutral, PublicKeyToken=5d3fa3c7105d7992'. ---> System.IO.FileLoadException: Cannot resolve dependency to assembly 'Infragistics4.Win.v12.2, Version=12.2.20122.2018, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.\r\n at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)\r\n at System.Reflection.RuntimeAssembly.GetExportedTypes()\r\n at #Rye.#eze..ctor(Assembly assembly, String assemblyFullName, String assemblyLocation, String cachePath, Boolean documentationEnabled)\r\n --- End of inner exception stack trace ---\r\n at #Rye.#eze..ctor(Assembly assembly, String assemblyFullName, String assemblyLocation, String cachePath, Boolean documentationEn
abled)\r\n at ActiproSoftware.SyntaxEditor.Addons.DotNet.Dom.AssemblyCodeRepository.#2ye.#BGe(AssemblyCodeRepositoryOptions #qgb, ResolveEventHandler #B1f)\r\n at ActiproSoftware.SyntaxEditor.Addons.DotNet.Dom.AssemblyCodeRepository.#2ye.#BGe(AssemblyCodeRepositoryOptions #qgb, ResolveEventHandler #B1f)\r\n at ActiproSoftware.SyntaxEditor.Addons.DotNet.Dom.AssemblyCodeRepository.Add(String assemblyName, DotNetProjectResolver projectResolver)\r\n at ActiproSoftware.SyntaxEditor.Addons.DotNet.Dom.DotNetProjectResolver.AddExternalReference(String assemblyName)\r\n at AppAutoComplete.Form1.button1_Click(Object sender, EventArgs e) in c:\\Users\\jose\\Documents\\Visual Studio 2013\\Projects\\AppAutoComplete\\AppAutoComplete\\Form1.cs:line 57"

 

Which i thought I could get fixed by loading the dependent Assembly First

dotNetProjectResolver.AddExternalReference("DLLMYDLLDEPENDSON");

dotNetProjectResolver.AddExternalReference("MYDLL");

 

But although the initial DLL loads ok, whe MyDLL tries to load it still complains about not having the dependency (that I previously loaded)

Any ideas?


Re: Adding External Reference throws Dependency Exception

$
0
0

Hi Jose,

The assemblies load in a separate temporary AppDomain so that's why it doesn't necessarily matter if you referenced other ones already. 

If you are having trouble with assembly resolution, you could use the overload of DotNetProjectResolver that accepts a ResolveEventHandler.  When you pass that in, it will be used instead of our default one, allowing you to have full control over the resolution process.

Re: Adding External Reference throws Dependency Exception

$
0
0

Thanks! I just tried this and my handler isn't getting called... am I missing something? It is still throwing an exception when loading my EpiClientLib and my handler isn't being invoked.

 

public void SetupEditor()

{

SemanticParserService.Start();
dotNetProjectResolver = new DotNetProjectResolver(CurrentDomain_AssemblyResolve);
dotNetProjectResolver.CachePath = @"C:\Temp";
dotNetProjectResolver.AddExternalReferenceForMSCorLib();
dotNetProjectResolver.AddExternalReferenceForSystemAssembly("System");
dotNetProjectResolver.AddExternalReferenceForSystemAssembly("System.Data");
dotNetProjectResolver.AddExternalReferenceForSystemAssembly("System.Drawing");
dotNetProjectResolver.AddExternalReferenceForSystemAssembly("System.Windows.Forms");
dotNetProjectResolver.AddExternalReference(@"E:\Epicor Installs\E10.700.2\Client\Ice.Lib.EpiClientLib.dll");
CSharpSyntaxLanguage cSharpLanguage = new CSharpSyntaxLanguage();
syntaxEditor1.Document.Filename = "BaseControl.cs";
syntaxEditor1.Document.Language = cSharpLanguage;
syntaxEditor1.Document.LanguageData = dotNetProjectResolver;

}

Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
       return Assembly.LoadFrom(@"E:\Epicor Installs\E10.700.2\Client\Infragistics4.Win.v12.2.dll");
}

Re: Adding External Reference throws Dependency Exception

$
0
0

I would think that what you have would work in general.  Looking over our code, it also does appear that when setting up the AppDomain for assembly loading, we add the paths of all previous external references to the app domain's PrivateBinPath.  So based on that, adding the dependecy assembly first would allow the second one to find it.

If you'd like us to look into it further, please make a new very simple sample project that we can debug the issue with and email it to our support address.  Please reference this thread and rename the .zip file extension of what you send so it doesn't get spam blocked.  Thanks!

Re: Adding External Reference throws Dependency Exception

$
0
0

I submited the request,

 

Thanks!

Question on Memory Leaks

$
0
0

I'm having an issue with memory leaks when I create (and later dispose) a temporary SyntaxEditor object.

This object is created programatically at runtime - with no UI, no triggers, no outlining, etc.
It is then used to perform some parsing and is then disposed.
(while allowing the user to continue to edit the 'real' editor)

The new profiling tools in VS2015 showed that the leak was caused by a Document object and thousands of DynamicToken objects.

I found that by adding

   editor.Document.Dispose()
before
   editor.Dispose()

the leak was reduced by about 30%, with virtually all the remaining leak related to DynamicToken objects and their related LexicalPatterns .

Since there is one and only one Document per editor it seems that this should be taken care of by disposing the editor itself - but apparently it is not.

My real question is how do I get rid of all those DynamicToken objects.

The profiler shows the reference tree to these objects as:

Document
    TokenCollection
        ArrayList
            DynamicToken

Thanks
Mike

Viewing all 930 articles
Browse latest View live