1

I'm using AvalonEdit in a Microsoft Surface application. It's working great, but I have one problem with folding. There are this small + icons to enable folding. But I don't know how I can register the appropriate contact handlers. Any hints how to do that?

1 Answers1

1

I'm not sure what you mean by "contact handlers".

But you have to supply a folding strategy class based on AbstractFoldingStrategy. However folding strategy to go with most commonly used braces is not in the default AvalonEditor package, you can find one in the sample application or find it somewhere on the internet. But as you can't really do it to 100% without syntactic analysis of the code being edited, this simple BraceFoldingStrategy will occasionally behave in a rather odd way.

Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
  • The folding is working correctly if I use it as a WPF application. I already installed other than the default handling strategy. The problem is, in Microsoft Surface, the touch events aren't recognized a properly mapped to the +/- icons that are there to fold the folding sections. – RoflcoptrException Feb 15 '11 at 09:06
  • Ah, this. Have you tried looking into the AvalonEdit source code? It must be possible to add the touch events to the +/- boxes. You can find the source code as part of SharpDevelop sources. – Matěj Zábský Feb 15 '11 at 09:14
  • @mzabsky: yes i searched through the source code but couldn't find the correct part in it. – RoflcoptrException Feb 15 '11 at 09:42
  • @Roflcoptr Look at method OnMouseDown method in FoldingMarginMarker.cs – Matěj Zábský Feb 15 '11 at 09:59
  • @mzabsky: ah thanks, that is the correct place, now I have just to figure out how to register other contact handlers there – RoflcoptrException Feb 15 '11 at 10:10
  • @mzabsky: I registered a ContactHandler to each FoldingMargin. This works, each FoldingMargin has some markers as you pointed out. Do you know how I can find the correct FoldingMarginMarker based on the FoldingMargin? – RoflcoptrException Feb 15 '11 at 12:00
  • @Roflcoptr What are you trying to do? Just overload OnTouchDown the exact same way the OnMouseDown is overloaded. – Matěj Zábský Feb 15 '11 at 13:01
  • @mzabsky: I cant implement OnTouchDown in FoldingMarginMarker – RoflcoptrException Feb 15 '11 at 13:17
  • @Roflcoptr Why? It inherits UIElement and UIElement has protected virtual metthod OnTouchDown...Or am I missing somethong? – Matěj Zábský Feb 15 '11 at 13:24
  • @mzabsky: I don't think that OnTouchDown is the contact handler used by Microsoft Surface, but I'll try right now. Thanks! – RoflcoptrException Feb 15 '11 at 13:25
  • @mzabsky: No it is really not possible. I can't override an OnTouchDown method. The method isn't found. – RoflcoptrException Feb 15 '11 at 13:28
  • @Roflcoptr It was added in .NET 4.0, make sure you are not targeting .NET 3.5. – Matěj Zábský Feb 15 '11 at 13:30
  • @mzabsky: Ok I found it, but changing it to NET 4.0 has to many other infuences on the existing code. However Ill mark your answer as accepted. I found another solution that isn't really nice, but is working. Im iterationg over all FoldingMarginMarkers and check which one is next to the capture Contact. – RoflcoptrException Feb 15 '11 at 14:15
  • @Roflcoptr I'm glad your problem is solved, though I wonder what kind of issue prevents you from upping to .NET 4 (which is by all means significant improvement over 3.5, especially in context of WPF). Also, when you have a working solution, you should consider sending a patch file to the authors of SharpDevelop (or at least report them the issue). – Matěj Zábský Feb 15 '11 at 14:19