Persisting style changes

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by NSXDavid
Avatar
So it's nice the Style Editor form is included as sample code, but it doesn't show how to persist the changes one makes. Is there some easy way to do this? I see a way for a language to save itself out as XML, but that's more than just styles... it's the whole definition. I want to just load and save style changes from the defaults that user make.

-- David

Comments (10)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The reason we didn't include any specific method to do this is that different customers will probably save that information differently. We're open to suggestions that will keep the product generic though, like maybe persisting a HighlightingStyleCollection to XML somehow.

Anybody reading this, please post your ideas on how you'd like it to work.


Actipro Software Support

Posted 15 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar
All style information is held in the <Styles> tag of the language definition, right? If so, you could add a method called 'ExportStyles' to the Language class that would generate the XML data normally placed in the <Styles> tag. Likewise, an 'ImportStyles' method could take the same data and update the styles accordingly. This would also keep the implementation consistent between persisting the data and formatting the language definition. It would also make it easy to 'revert' the styles back to the orginal state by just importing the <Styles> tag data from the original definition file (since it would all be formatted the same).

Anyone else have other ideas?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
What should the parameters of those methods be, an XmlNode, or should we stick with some sort of stream?

The only issue I can think of is whether or not to clear the styles collection completely before loading or not. Say that you export a style collection with 10 styles in it. Later on in your language def, you enhance it and add a new style. If you would import your previously-exported style settings and it blows away existing ones and only creates what it knows of, then we're missing the new style in the collection. I'm thinking it's better to just overwrite any existing styles with the same name.

If a style being imported doesn't exist in the language definition (maybe it was removed from the def since when the export occurred) then we probably should not load it, correct?


Actipro Software Support

Posted 15 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar
Quote:
<font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Actipro Software Support:
What should the parameters of those methods be, an XmlNode, or should we stick with some sort of stream?<HR>

I say start with the implementation used by the SyntaxLanguage class to load a language (to be consistent). That would mean two overloads... one to take a stream and one to take a path to an XML file. The difference here is that most people probably won't store the data directly to a file. Instead, they'll probably embed it with other data that is already persisted for the application. That being said, a third overload to take an XmlNode would be better. If you had to choose one of the three, I'd say go with the XmlNode since you can easily get it from a stream or xml file. But the overloads would be nice.

Quote:
<font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Actipro Software Support:
The only issue I can think of is whether or not to clear the styles collection completely before loading or not. ...I'm thinking it's better to just overwrite any existing styles with the same name.<HR>


I agree... you shouldn't clear the styles. The programmer may not want to make all styles customizable, so this would give the flexibility of only including the desired styles in the 'Import' method. As you mentioned, it also prevents any unexpected behavior if a style disappears from the original language definition or a new one is added. Start with the default styles from the language definition and then only apply changes to styles that appear in the import (ignoring anything that doesn't match up).
Posted 15 years ago by NSXDavid
Avatar
Of course the issue for me is... I need to do this now... not when the next release comes along (unless that's tomorrow! hehe). Has anyone written code that does this or is this a re-invent the wheel thing?

-- David
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The next maintenance release now has two new methods in it, ExportStyleSettings and ImportStyleSettings.

To export user settings to an XmlNode, you would do this:
System.Xml.XmlNode node = editor.Document.Language.HighlightingStyles.ExportStyleSettings();

You can save the value of the node however you like.

To later restore the settings, you execute this method:
editor.Document.Language.HighlightingStyles.ImportStyleSettings(node);

Will that work for you?


Actipro Software Support

Posted 15 years ago by NSXDavid
Avatar
Sweet! You guys are good...... <IMG SRC="biggrin.gif" border="0"> That'll certainly work! I can persist the XmlNode easily enough. Makes me glad I dumped Syncfusion's edit control. <IMG SRC="biggrin.gif" border="0">

So when does this maintenance release pop out of the oven?

-- David
<IMG SRC="smile.gif" border="0">
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There are a couple other items we want to get in before the maintenance release comes out. It should be either this weekend or next weekend, depending on how quickly we get these other things in.


Actipro Software Support

Posted 15 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar
Quote:
<font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Actipro Software Support:
Will that work for you?<HR>


Looks great to me and I think you got NSXDavid's approval

<IMG SRC="biggrin.gif" border="0">
Posted 15 years ago by NSXDavid
Avatar
Thank you sir. <IMG SRC="smile.gif" border="0">
The latest build of this product (v2018.1 build 0341) was released 9 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.