Making (and keeping) lines readonly in AvalonEdit - readonly

What is a robust way of making certain lines readonly in an AvalonEdit control? Users are allowed to change certain method bodies in a C# or VB template file but nothing else. The readonly state per line needs to be kept intact when users add or remove lines, i.e. the readonly blocks below the edited content need to shift up and down accordingly.
I'm using AvalonEdit in a WPFHost on winforms.

You can set textEditor.TextArea.ReadOnlySectionProvider to an implementation of IReadOnlySectionProvider.
AvalonEdit contains the implementation TextSegmentReadOnlySectionProvider which allows marking segments as read-only. These read-only segments will move around when the user adds/inserts text.
TextSegmentReadOnlySectionProvider doesn't allow you to prevent insertions at the very beginning and end of the document (as those positions are never are within any segment), but you can inherit from the class and override CanInsert() to fix this special case.

Related

Can a YAML anchor be defined elsewhere than its first usage?

I'm writing a fairly complex YAML document (such as for several Bitbucket Pipelines) and I have a section that is repeated in multiple places. I'd like to use a YAML anchor for modularity, that is, to ensure the section can be easily maintained (without drift or unintended discrepancies between these multiple places).
Does my &anchor have to be defined inline in the first place where the repeated node occurs? Or is it possible to just have a *reference in that location, and to instead define the anchor somewhere separate (i.e., either at the very top or bottom of the YAML file, preferably somehow outside of the node tree for the document, like as for a subroutine called from multiple places inside a main function)? I think this would be more readable in my case, because there would be more obvious symmetry between the lines of config that share the repetition (rather than making the initial instance look completely different from the subsequent instances).

Supress cross reference hyperlink using exclamation mark

Prefixing the link with an ! suppresses the creation of a reference (e.g. :ref:`!no link` will be simply rendered as no link):
If you prefix the content with !, no reference/hyperlink will be created.
However, I can't think of any practical usage of this. Why should I first create a reference and then don't want to use it - it would be far easier to write plain text from the very beginning.
So - what is a typical use case of such a suppressed reference?
(Sphinx itself for instance doesn't use it in its docs.)
I can't think of any practical usage of this.
The use I can think of is before a build if you wanted to "turn of" hyperlink generation for one given cross-reference (that appears multiple times) how would you do it?
Well, the simplest way might be using some text editor's "find and replace", and arguably the least invasive way would be to add or remove a single character !. That way the length and structure of the cross-reference is kept in the source (and the title is still rendered in place). This could be convenient in several places, like a table where removing the whole cross-reference could misalign the source.
The most economical change possible would be turning this:
:ref:`a very long title <an.extremely.long.link.target>`
into this:
:ref:`!a very long title <an.extremely.long.link.target>`
The same could possibly be achieved programmatically using the Sphinx API, but a lot of Sphinx users are likely to prefer a text editing solution over a programmatic one.

How can I separate properties visually for an EPiServer ContentType?

I want to make the editor experience better and more visually pleasing when filling in content on a page (In all properties view). Could be a simple divider or a heading..
I am already using tabs, whenever it makes sense. Also, I have been experimenting with using blocks as properties. This adds a nice separation with at clear heading, but it is so much more code to maintain and a bit of a mess to be honest when the properties truly belong to the page type.
Out-of-the-box, it is not possible to decorate properties with headlines, unless you use block-properties, as you mention yourself.
However, I thought your question was quite interesting, and I discovered that extending Episerver to accommodate this behavior is surprisingly easy. I have written an example solution, which you're free to use as you like: https://arlc.dk/grouping-properties-with-headlines-without-property-blocks.
If you dislike the solution, an alternative approach would be to introduce your own Property-type (Headline), and create a 1) a custom dojo-widget to simply display a headline, and 2) an EditorDescriptor to set the ClientEditingClass.
Linus wrote an excellent blog post on this here: https://world.episerver.com/blogs/Linus-Ekstrom/Dates/2012/7/Creating-a-custom-editor-for-a-property/.
EDIT:
I see, I have skipped too quickly over the overriding part.
You don't have to override any files by replacing them, and you won't have to extract Shell.zip (unless you're curious how Episerver has implemented their widgets). The part that overrides the specific component is define("epi/shell/form/Field". As long as your definition of this widget is loaded after shell, dojo will use your implementation, whenever something is requiring "epi/shell/form/Field". The thing that ensures your implementation is loaded after, is in module.config, under 'This injects our field-implementation [...]'.
The path ~/ClientResources/Scripts/Shell/Field/Field.js is simply the location I have chosen to put the overriden version of Field.js. You can put it wherever you like, as long as you update module.config accordingly, with the new path.
It works like this: First, Episerver defines widget A. Then you define a widget with the same name, A. When anything tries to fetch A, it returns your implementation, rather than Episerver's.

Webtest : Editing the context parameter during test run

I'm using Visual Studio 2015 Web Performance test (.webtest) and have an Extraction Rule in place to capture a 8-digit number that references a check number (via inner text) into a context parameter.
If the number only contains 6-digits, then it has two blank spaces in front of the check number. This causes an issue because I'm using the check number in a form parameter and those blank spaces need to be switch to zeroes (0).
My question is what's the best way to handle the comparison? Is there a way to edit the context parameter (named "CheckNBR"), or can I overwrite the Extraction Rule to manipulate the parameter? Maybe create a custom Extraction Rule instead? I'm kinda going in all directions on this and not sure what options work the best.
[Update]
Instead of determining the best way, I'm re-directing the question towards the editing of the context parameter. Once I set the parameter from the Extraction rule, how can I edit it?
There are several possible approaches.
You could write a custom extraction rule that finds the required text, modifies it as needed and then save it to a context variable. This is probably the most complicated version to write.
You could write a custom extraction rule that uses the built in extraction rule and then modifies the result. Code based on the following (not tested, not compiled) should work. Of course you need to write your own version of ModifyTheTextAsNeeded. Then change the web test to use the extraction below instead of the original.
public class ExtractAndModifyHtmlTagInnerText : ExtractHtmlTagInnerText
{
public override void Extract(object sender, ExtractionEventArgs e)
{
base.Extract(sender, e);
string extractedText = e.WebTest.Context[this.ContextParameterName].ToString();
string modifiedText = ModifyTheTextAsNeeded(extractedText);
e.WebTest.Context[this.ContextParameterName] = modifiedText
}
}
Another approach is to put something similar to last three lines of the body of the method shown above above into a plugin. It might be a PreRequest plugin used on the next request after the one with the extraction rule.

What is a proper way for naming of message properties in i18n?

We do have a website which should be translate into different languages. Some of the wording is in message properties files ready for translation. I want now add the rest of the text into these files.
What is a good way to name the text blocks?
<view>.<type>.<name>
We mostly have webpages and some of the elements/modules are repeating on some sites.
As far as I know, no "standard" exists. Therefore it is pretty hard to tell what is proper and what is improper way of naming resource keys. However, based on my experience, I could recommend this way:
property file name: <module>.properties
resource keys: <view or dialog>[.<sub-context>].<control-type>.<name>
We may discuss if it is proper way to put every strings from one module into one property files - probably it could be right if updates doesn't happen often and there are not so many messages. Otherwise you might think about one file per view.
As for key naming strategy: it is important for the Translator (sounds like film with honorable governor Arnold S. isn't it?) to have a Context. Translation may actually depend on it, i.e. in Polish you would translate a message in a different way if it is page/dialog/whatever title and in totally different way if it is text on a button.
One example of such resource key could be:
preferences.password_area.label.username=User name
It gives enough hints to the Translator about what it actually is, which could result in correct translation...
We have come up with the following key naming convention (Java, btw) using dot notation and camel case:
Label Keys (form labels, page/form/app titles, etc...i.e., not full sentences; used in multiple UI locations):
If the label represents a Java field (i.e., a form field) and matches the form label: label.nameOfField
Else: label.sameAsValue
Examples:
label.firstName = First Name
label.lastName = Last Name
label.applicationTitle = Application Title
label.editADocument = Edit a Document
Content Keys:
projectName.uiPath.messageOrContentType.n.*
Where:
projectName is the short name of the project (or a derived name from the Java package)
uiPath is the UI navigation path to the content key
messageOrContentType (e.g., added, deleted, updated, info, warning, error, title, content, etc.) should be added based on the type of content. Example messages: (1) The page has been updated. (2) There was an error processing your request.
n.* handles the following cases: When there are multiple content areas on a single page (e.g., when the content is separated by, an image, etc), when content is in multiple paragraphs or when content is in an (un)ordered list - a numeric identifier should be appended. Example: ...content.1, ...content.2
When there are multiple content areas on a page and one or more need to be further broken up (based on the HTML example above), a secondary numeric identifier may be appended to the key. Example: ...content.1.1, ...content.1.2
Examples:
training.mySetup.myInfo.content.1 = This is the first sentence of content 1. This is the second sentence of content 1. This content will be surrounded by paragraph tags.
training.mySetup.myInfo.content.2 = This is the first sentence of content 2. This is the second sentence of content 2. This content will also be surrounded by paragraph tags.
training.mySetup.myInfo.title = My Information
training.mySetup.myInfo.updated = Your personal information has been updated.
Advantages / Disadvantages:
+ Label keys can easily be reused; location is irrelevant.
+ For content keys that are not reused, locating the page on the UI will be simple and logical.
- It may not be clear to translators where label keys reside on the UI. This may be a non-issue for translators who do not navigate the pages, but may still be an issue for developers.
- If content keys must be used in more than one location on the UI (which is highly likely), the key name choice will not make sense in the other location(s). In our case, management is not concerned with a duplication of values for content areas, so we will be using different keys (to demonstrate the location on the UI) in this case.
Feedback on this convention - especially feedback that will improve it - would be much appreciated since we are currently revamping our resource bundles! :)
I'd propose the below convention
functionalcontext.subcontext.key
logicalcontext.subcontext.key
This way you can logically group all the common messages in a super context (id in the below example). There are few things that aren't specific to any functional context (like lastName etc) which you can group into logical-context.
order.id=Order Id
order.submission.submit=Submit Order
name.last=Last Name
the method that I have personally used and that I've liked more so far is using sentence to localisee as the key. For example: (pls replace T with the right syntax dependably on the language)
for example:
print(T("Hello world"))
in this case T will search for a key "Hello world". If it is not found then the key is returned, otherwise the value of the key.
In this way, you do not need to edit the message (in your default language) at least that you need to use parameters.... It saved me a LOT of dev time

Resources