How to set some areas to be unselectable?

SyntaxEditor for WPF Forum

Posted 2 months ago by Morton Koopa
Version: 25.1.1
Avatar

Hello Actipro Developers,

I have a requirement. I set some areas in the SyntaxEditor to be uneditable. However, when I select all, the uneditable areas are also selected, so I can't delete them. I want to be able to delete everything except the uneditable areas normally. Is this possible? Can I set the uneditable areas to be unselectable so that they are not included when I select all?

Thank you!

Comments (8)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm sorry but we don't have any functionality built-in like that.  You would need to get a list of the text ranges that are read-only and then set the view's selection to the inverse of those ranges.  This documentation topic talks about setting selections.  Then calling this should delete all the selected text ranges:

editor.ActiveView.DeleteSelectedText(TextChangeTypes.Delete);


Actipro Software Support

Posted 2 months ago by Morton Koopa
Avatar

Is there a way to programmatically get the position (position or offset) of a special character?

Posted 2 months ago by Morton Koopa
Avatar

I have the following questions:

  1. Can I set the foreground color for read-only areas?
  2. Can I set two non-contiguous code blocks to read-only? According to the case, I can only set one block.

[Modified 2 months ago]

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Can you provide more information about your request about a special character?  I'm not sure what you're after there.  This documentation topic talks about offsets and positions though, in case it helps.

1) The BuiltInClassificationTypeProvider.ReadOnlyRegion classification type is used for read-only regions.  However the default style is set to IsForegroundEditable = false.  You can alter the highlighting style associated with that classification type to set that to true and assign a Foreground if you wish.  For instance:

var p = new BuiltInClassificationTypeProvider();
AmbientHighlightingStyleRegistry.Instance[p.ReadOnlyRegion].IsForegroundEditable = true;
AmbientHighlightingStyleRegistry.Instance[p.ReadOnlyRegion].Foreground = Colors.Red;

2) Yes, you shoudl be able to.  In our ReadOnlyRegions QuickStart, our OnMakeSelectionReadOnlyButtonClick method clears any existing tags first before adding a second, mainly to avoid overlapping for the sample.  If you remove that line, you can add multiple read-only ranges.  They can even be contiguous.


Actipro Software Support

Posted 2 months ago by Morton Koopa
Avatar
  • I want to calculate the offset of a certain word in the editor. Is it possible to do it?
  • How do I associate BuiltInClassificationTypeProvider with my Editor? I tried injecting it in Language, but it didn't work.

In addition, I followed the implementation of your ReadOnlyRegions QuickStart and set the style for the read-only region in the constructor:

var style = new HighlightingStyle(Colors.Blue, Colors.Red);

AmbientHighlightingStyleRegistry.Instance.Register(ClassificationTypes.ReadRegion, style);

I set the foreground and background colors of the read-only area in the style, but they didn't work. What could be the reason? By the way, I customized my own editor, inherited from the ISyntaxEditor, and implemented the ISyntaxLanguage interface.

[Modified 2 months ago]

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

If you mean you want to search for a word programmatically, you can use the search APIs described in this documentation topic.

For the style question, I suspect a style is already registered and the Register method will not overwrite an existing one unless you use the optional parameter like this:

var p = new BuiltInClassificationTypeProvider();
var style = new HighlightingStyle(Colors.Blue, Colors.Red);
AmbientHighlightingStyleRegistry.Instance.Register(p.ReadOnlyRegion, style, overwriteExisting: true);


Actipro Software Support

Posted 2 months ago by Morton Koopa
Avatar

Can the transparency of the read-only area be modified? Or reset Classification Types only for read-only zones.

[Modified 2 months ago]

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Highlighting style background colors can be semi-transparent, but not foregrounds, at least via styles.

We do have a way to reduce the opacity of a tagged region though, via the unused region feature.  There is documentation on how to use that feature and a related QuickStart sample as well.  It is intended to fade out areas of code that are inactive and may be what you want to do.  If you make a class that inherits ReadOnlyRegionTag and implements IUnusedRegionTag, you can achieve that effect.


Actipro Software Support

The latest build of this product (v25.1.2) 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.