A Way to Update Style Templates After Changes?

General TRichView support forum. Please post your questions here
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

A Way to Update Style Templates After Changes?

Post 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
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: A Way to Update Style Templates After Changes?

Post 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.
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: A Way to Update Style Templates After Changes?

Post by standay »

Hi Sergey,

OK, I'm using rvfoSaveStyleTemplatesOnlyNames and so far, yes, that seems to work.

Thanks!

Stan
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: A Way to Update Style Templates After Changes?

Post by Sergey Tkachenko »

This option is not implemented in RVXML yet.
I'll do it in one of future updates.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post 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.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: A Way to Update Style Templates After Changes?

Post 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)
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: A Way to Update Style Templates After Changes?

Post by Sergey Tkachenko »

RichView.StyleTemplateInsertMode property is respected by RichViewXML
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post 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?
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post by edwinyzh »

Do you think my Object Inspector settings for TRichViewXml is good for shared-style-for-multiple-documents:

Image
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: A Way to Update Style Templates After Changes?

Post 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).
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: A Way to Update Style Templates After Changes?

Post 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)
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: A Way to Update Style Templates After Changes?

Post 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!
Post Reply