Page 1 of 2
A Way to Update Style Templates After Changes?
Posted: Tue Aug 17, 2021 2:57 pm
by standay
Hi Sergey,
OK, let's say I create a style template: st1. I open or create an RVF and apply the st1 to some text, then save the file. All that works fine.
Now, while the file is closed, let's say I change some parameters of st1 in Delphi. Now, I reopen that saved file again in my app. Any st1 text in that file has the old parameters since it was saved that way.
Now, is there a way from code to update any old instances of st1 in that file to the new parameters of the updated st1 without manually selecting it and reapplying the st1 template again?
Edit: I see UpdateModifiedTextStyleProperties, UpdateModifiedParaStyleProperties in the help file. Would that be the way?
Just curious, this is not a big deal but I thought I'd ask just in case.
Stan
Re: A Way to Update Style Templates After Changes?
Posted: Wed Aug 18, 2021 10:46 am
by Sergey Tkachenko
Was this file saved with rvfoSaveStyleTemplatesOnlyNames in RVFOptions?
If yes, no additional code is required, everything is performed automatically.
In
this demo, modified StyleTemplates are applied when loading records, without any additional code.
RVF contains information about properties of TextStyles and ParaStyle, values of which of them were taken from StyleTemplates, and values of which of them were changed on top of StyleTemplates. Values of the first group of properties are changed according to the changed StyleTemplates.
Re: A Way to Update Style Templates After Changes?
Posted: Wed Aug 18, 2021 3:49 pm
by standay
Hi Sergey,
OK, I'm using rvfoSaveStyleTemplatesOnlyNames and so far, yes, that seems to work.
Thanks!
Stan
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 6:52 am
by edwinyzh
Sergey Tkachenko wrote: ↑Wed Aug 18, 2021 10:46 am
Was this file saved with rvfoSaveStyleTemplatesOnlyNames in RVFOptions?
If yes, no additional code is required, everything is performed automatically.
In
this demo, modified StyleTemplates are applied when loading records, without any additional code.
RVF contains information about properties of TextStyles and ParaStyle, values of which of them were taken from StyleTemplates, and values of which of them were changed on top of StyleTemplates. Values of the first group of properties are changed according to the changed StyleTemplates.
Does `rvfoSaveStyleTemplatesOnlyNames ` work the same with documents saved in XML with `TRichViewXML`?
I mean, I too need to share a single TRVStyle with multiple documents, I use SaveTo/LoadFromIni to persist the styles and style templates.
This will work, right?
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 9:19 am
by Sergey Tkachenko
This option is not implemented in RVXML yet.
I'll do it in one of future updates.
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 9:39 am
by edwinyzh
Sergey Tkachenko wrote: ↑Wed Jun 15, 2022 9:19 am
This option is not implemented in RVXML yet.
I'll do it in one of future updates.
Oh, bad news for me! Because I use XML instead of rvf as the persisting format...
Any other features of rvf persistence not available in XML persistence?
And more importantly, how can I implement one shared TRVStyle object for multiple documents in my case?
Thanks.
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 9:55 am
by edwinyzh
edwinyzh wrote: ↑Wed Jun 15, 2022 9:39 am
Sergey Tkachenko wrote: ↑Wed Jun 15, 2022 9:19 am
This option is not implemented in RVXML yet.
I'll do it in one of future updates.
Oh, bad news for me! Because I use XML instead of rvf as the persisting format...
Any other features of rvf persistence not available in XML persistence?
And more importantly, how can I implement one shared TRVStyle object for multiple documents in my case?
Thanks.
To be more specific, I guess the following 3 properties are related to shared styles for multiple documents:
StyleTemplateInsertMode, RvfTextStylesReadMode, RvfParaStylesReadMode.
Does XML format respect all these properties?
Thanks.
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 10:02 am
by Sergey Tkachenko
You can use the same TRVStyle and RichViewXML.
If RichViewXML.SaveStyles = False, properties of TRVStyle is not saved to XML, including collections of styles.
(but if it is True, all properties of TRVStyle are saved, unlike RVF).
When loading XML containing styles, RichViewXML.StyleLoadingMode is used, this is the analog of RVFTextStylesReadMode and RVFTextStylesReadMode.
Normally, RichViewXML documents contain the same information as RVF and even more.
For example:
- as I said, it can contain all properties of TRVStyle
- if SaveBackground = True, it saves not only background but layout properties, but also Options, RTFOptions, EditorOptions
- it contains images from ImageLists (instead of requesting them in an event)
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 10:05 am
by Sergey Tkachenko
RichView.StyleTemplateInsertMode property is respected by RichViewXML
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 11:46 am
by edwinyzh
Sergey Tkachenko wrote: ↑Wed Jun 15, 2022 10:02 am
When loading XML containing styles, RichViewXML.StyleLoadingMode is used, this is the analog of RVFTextStylesReadMode and RVFTextStylesReadMode.
Great! So in order to achieve "shared-style-for-multi-documents", I should use slmMap for RichViewXML.StyleLoadingMode, right?
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 1:11 pm
by edwinyzh
Do you think my Object Inspector settings for TRichViewXml is good for shared-style-for-multiple-documents:
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 4:07 pm
by Sergey Tkachenko
It depends on what you want from shared styles.
1.a. You can save documents without TextStyles, ParaStyles, ListStyles.
This option is useful if you have a hard-coded predefined set of styles that are used in multiple documents. Usually, in this mode, each item in TextStyles and ParaStyles has its own meaning. You cannot use UI for applying arbitrary text and paragraph attributes (such as RichViewActions), because they add new text and paragraph styles.
Property settings for this option: RichViewXML.SaveStyles = False.
In this mode, value of StyleLoadingMode is not so important, because it defines how styles from XML document are used, but your documents will not contain styles. More important to prevent new styles from appearing when inserting/pasting RVF, RTF and DocX files.
1.b. Actually, a set of styles is not necessary must be predefined. You can modify it (but you need to make sure that indexes of styles in documents remain correct), and save styles separately from documents (TRVStyle.SaveINI).
There are two reasons for using this mode:
- smaller file sizes
- each TextStyle and ParaStyle may have specific meaning, and can be customized.
2. Shared StyleTemplates (that are not implemented in RichViewXML yet) are completely different. Unlike the methods (1), they do not restrict text and paragraph formatting.
Collections of TextStyles, ParaStyles, and ListStyles must be saved in documents.
You can use UI for applying arbitrary text and paragraph attributes, including RichViewActions.
The only shared thing is a collection of StyleTemplates (that should be stored outside of documents, TRVStyle.SaveToRVST).
StyleTemplates are not used by text items and paragraphs directly (unlike TextStyles and ParaStyles). Instead, StyleTemplates are linked to items of TextStyles and ParaStyles and allow modify them. Shared StyleTemplates can modify multiple documents (they are applied on loading).
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 4:41 pm
by edwinyzh
My requirement is like #2, but in addition to sharing StyleTemplates between documents, both TextStyles and ParaStyles need to be shared too.
Moreover, I need to use the UI (richViewActions) and let the user apply/change the styles as usual.
Yes, I'm using `TRVStyle.SaveToINI` (should be same as TRVStyle.SaveToRVST?)
Do you think I can achieve the above goal?
Re: A Way to Update Style Templates After Changes?
Posted: Wed Jun 15, 2022 5:22 pm
by Sergey Tkachenko
Well, in this case you do not need the "shared StyleTemplates" feature.
The purpose of shared StyleTemplates: a single collection of StyleTemplates is used by multiple collections of TextStyles and ParaStyles.
But, as I understand, you want to use the same collections of TextStyles and ParaStyles (and ListStyles, and StyleTemplates) for all documents.
In this case, a simple not-saving styles to XML does this work.
Styles must be saved outside of documents (the simplest way is using RVStyle.SaveINI/LoadINI; these methods save everything, including collection of styles and StyleTemplates).
You want to use arbitrary text attributes when editing. Ok, it's not a problem. All editing operation on styles only add new styles, so indexes of styles in existing documents remain valid. Just do not forget to call RVStyle.SaveINI to store updates collections of styles.
After some time, there may be a problem: too many styles, some of them are not used in any document, and you may wish to optimize them.
You cannot use RichView.DeleteUnusedStyles, because it does not work properly for styles used in multiple documents.
However, this problem can be solved, see
TRVDeleteUnusedStylesData
Notes:
1. I assume that only one of documents that use shared styles is displayed and edited at any time. Otherwise, you will need to solve additional problems.
2. Make sure that you do not use operations that replace collections of styles (loading RVF and XML with options of replacing styles)
Re: A Way to Update Style Templates After Changes?
Posted: Thu Jun 16, 2022 3:17 am
by edwinyzh
Very detailed info and instruction, I appreciate it!
Yes, as you said, I "want to use the same collections of TextStyles and ParaStyles (and ListStyles, and StyleTemplates) for all documents."
And this is how I'm currently trying to implement it:
- In the program I have only a
single instance of TRVStyle managed by a data module, its content is saved to and loaded from INI, as you said.
- I have
multiple "editor forms" that has a TRichViewEdit which links to the same TRVStyle object described above.
- The "editor form" is copied and modified from "\TRichView\RichViewActions\Demos\DelphiUnicode\ActionTest"
- So each of these "editor forms" also has a `
TRVStyleTemplateComboBox` which I need.
Does my design above makes sense?
in this case you do not need the "shared StyleTemplates" feature
I'm not sure if we are talking about the same thing, but since TRVStyle loads and saves StyleTemplates, and since I use only a single TRVStyle in the entire program, it's "shared StyleTemplates", isn't it?
And I assume all the TRVStyleTemplateComboBox instances on multiple "editor forms" uses the same "shared StyleTemplates" from that single TRVStyle instance.
Am I correct?
I assume that only one of documents that use shared styles is displayed and edited at any time. Otherwise, you will need to solve additional problems.
Actually, I'm planning to have multiple "editor forms"
managed by TPageControl, while only one is visible at the same time, there are multiple "editor form" instances at the same time.
Do you think my above design allows this possibility? What additional problems will I have?
Thank you again!