From 77f51afc9223e752950b42306385cbbcbdf24473 Mon Sep 17 00:00:00 2001 From: Alain Romedenne Date: Mon, 6 Nov 2023 16:41:12 +0100 Subject: ScriptForge (SF_Document) new XDocumentSettings property + Styles management + Toolbars Change-Id: I3c9b979a26a44aadb8dff0ab18122e1fb32ccb2a Reviewed-on: https://gerrit.libreoffice.org/c/help/+/158903 Tested-by: Jenkins Reviewed-by: Alain Romedenne --- source/text/sbasic/shared/03/sf_document.xhp | 242 +++++++++++++++++++++++---- 1 file changed, 209 insertions(+), 33 deletions(-) diff --git a/source/text/sbasic/shared/03/sf_document.xhp b/source/text/sbasic/shared/03/sf_document.xhp index fa59801c3f..4c9d927507 100644 --- a/source/text/sbasic/shared/03/sf_document.xhp +++ b/source/text/sbasic/shared/03/sf_document.xhp @@ -8,21 +8,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. * --> - SFDocuments.Document service /text/sbasic/shared/03/sf_document.xhp -
Document service
-

SFDocuments.Document service

The SFDocuments library provides methods and properties to facilitate the management and manipulation of %PRODUCTNAME documents. @@ -36,15 +33,12 @@
- The properties, methods or arguments marked with (*) are NOT applicable to Base documents. Methods and properties that are specific to certain %PRODUCTNAME components are stored in separate services, such as SFDocuments.SF_Calc and SFDocuments.SF_Base. Although the Basic language does not offer inheritance between object classes, the latter services may be considered as subclasses of the SFDocuments.Document service. Such subclasses can invoke the properties and methods described below. -

Service invocation

Before using the Document service the ScriptForge library needs to be loaded or imported: - Below are three variants of how the Document service can be invoked. Using the getDocument method from the ScriptForge.UI service: @@ -106,7 +100,6 @@ # (...) The use of the prefix "SFDocuments." while calling the service is optional. - API;Duration API;XComponent @@ -121,13 +114,17 @@ Document service;IsBase property Document service;IsCalc property Document service;IsDraw property + Document service;IsFormDocument property Document service;IsImpress property Document service;IsMath property Document service;IsWriter property Document service;Keywords property Document service;Readonly property + Document service;StyleFamilies property Document service;Subject property Document service;Title property + Document service;XComponent property + Document service;XDocumentSettings property

Properties

@@ -204,7 +201,7 @@ - ExportFilters + ExportFilters (*) Yes @@ -218,7 +215,7 @@ - FileSystem + FileSystem (*) Yes @@ -233,7 +230,7 @@ - ImportFilters + ImportFilters (*) Yes @@ -291,13 +288,27 @@ - Subject (*) + StyleFamilies (*) + + + Yes + + + String array + + + List of available style families. Applicable to all document types except Base. + + + + + Subject (*) No - String + String Gives access to the Subject property of the document. @@ -319,7 +330,7 @@ - XComponent + XComponent Yes @@ -328,12 +339,25 @@ UNO Object - The UNO object com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument representing the document + The UNO object com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument representing the document. + + + + + XDocumentSettings (*) + + + Yes + + + UNO Object + + + A com.sun.star.XXX.DocumentSettings UNO object - where XXX is sheet, text, drawing or presentation - that gives access to UNO internal properties, that are specific to the document's type.
- The example below prints all the properties of a document. Note that the oDoc object returned by the UI.OpenDocument method is a SFDocuments.Document object. @@ -360,7 +384,6 @@ bas.MsgBox(msg) doc.CloseDocument() -
@@ -372,29 +395,33 @@ Activate
CloseDocument
CreateMenu
+ DeleteStyles
Echo
+ ExportAsPDF
- ExportAsPDF
+ ImportStylesFromFile
PrintOut
RemoveMenu
RunCommand
+ Save
+ SaveAs
- Save
- SaveAs
SaveCopyAs
SetPrinter
+ Style
+ Toolbars
+ XStyle

-
Activate -------------------------------------------------------------------- @@ -422,7 +449,6 @@ Keep in mind that you can invoke the Document service by passing to CreateScriptService either "Document" or "SFDocuments.Document"
-
CloseDocument ---------------------------------------------------------------- @@ -451,7 +477,6 @@ # ...
-
CreateMenu --------------------------------------------------------------------------------------------- @@ -497,7 +522,37 @@ Refer to the SFWidgets.Menu help page to learn more about how to create/remove menus in %PRODUCTNAME document windows.
- +
+ DeleteStyles --------------------------------------------------------------------------------------------- + + Document service;DeleteStyles + +

DeleteStyles

+ Suppresses a single style or an array of styles given by their names within a specific styles family. Only user-defined styles may be deleted, built-in styles are ignored. It applies to all document types except Base and FormDocument. + + + svc.DeleteStyles(family: str, stylelist: str[1..*]) + + +
+ family: One of the style families present in the actual document, as a case-sensitive string. Valid family names can be retrieved using StyleFamilies property. +
+ stylelist: A single style name as a string or an array of style names. The style names may be localized or not. The StylesList is typically the output of the execution of a Styles() method. + + + + ' Removing unused paragraph styles + Const family = "ParagraphStyles" + aList = oDoc.Styles(family, used := False, userDefined := True) + oDoc.DeleteStyles(family, aList) + + + + # Removing styles according to a prefix + a_list = doc.Styles('ParagraphStyles', namepattern = "Py*") + doc.Styles('ParagraphStyles', a_list) + +
Echo ------------------------------------------------------------------------------------------------ @@ -531,7 +586,6 @@ doc.Echo()
-
ExportAsPDF -------------------------------------------------------------------------------------------- @@ -578,7 +632,41 @@ doc.ExportAsPDF(r"C:\User\Documents\myFile.pdf")
- +
+ ImportStylesFromFile ---------------------------------------------------------------- + + Document service;ImportStylesFromFile + +

ImportStylesFromFile

+ This method loads all the styles belonging to one or more style families from a closed file into the actual document. The actual document must be a Calc or a Writer document. + Are always imported together: + + + ParagraphStyles and CharacterStyles + + + NumberingStyles and ListStyles + + + Returns True if styles were successfully imported. + + + svc.ImportStylesFromFile(filename: str, families: str[1..*], overwrite = False): bool + + + filename: The file from which to load the styles in the FileSystem notation. The file is presumed to be of the same document type as the actual document. + families: One of the style families present in the actual document, as a case-sensitive string or an array of such strings. Default = all families. + overwrite: When True, the actual styles may be overwritten. Default is False. + + + + oDoc.ImportStylesFromFile("C:\User\Documents\myFile.ods", "ParagraphStyles", True) + + + + doc.ImportStylesFromFile('C:\User\Documents\myFile.ods', ("ParagraphStyles",), False) + +
PrintOut ---------------------------------------------------------------- @@ -607,7 +695,6 @@ # ...
-
RemoveMenu --------------------------------------------------------------------------------------------- @@ -637,7 +724,6 @@
-
RunCommand --------------------------------------------------------------- @@ -684,7 +770,6 @@ Each %PRODUCTNAME component has its own set of commands available. One easy way to learn commands is going to Tools - Customize - Keyboard. When you position your mouse over a function in the Function list, a tooltip will appear with the corresponding UNO command.
-
Save ------------------------------------------------------------------------ @@ -711,7 +796,6 @@ # ...
-
SaveAs --------------------------------------------------------------------------------------- @@ -741,7 +825,6 @@ doc.SaveAs(r"C:\Documents\NewCopy.odt", overwrite = True)
-
SaveCopyAs ------------------------------------------------------------------- @@ -771,7 +854,6 @@ doc.SaveCopyAs(r"C:\Documents\Copy2.odt", overwrite = True)
-
SetPrinter ------------------------------------------------------------------- @@ -800,7 +882,101 @@ doc.SetPrinter(paperformat='TABLOID')
- +
+ Styles --------------------------------------------------------------------------------------------- + + Document service;Styles + +

Styles

+ Retrieves a list of styles matching an optional compound criteria, the returned array may be empty. It applies to all document types except Base. + + + svc.Styles(family, opt namepattern: str, opt used: bool, opt userdefined: bool, opt parentstyle: str, opt category: str): str[0..*]) + + + category: A case-insensitive string: TEXT, CHAPTER, LIST, INDEX, EXTRA, HTML. For their respective meanings, refer to paragraph style category API documentation. + This argument is ignored when the Family differs from "ParagraphStyles". + namepattern: A filter on the style names, as a case-sensitive string pattern. The names include the internal and localized names. + Admitted wildcard are: + + + the "?" representing any single character. + + + the "*" representing zero, one, or multiple characters + + + parentstyle: When present, only the children of the given, localized or not, parent style name are retained. + used: When True, the style must be used in the document, when absent the argument is ignored. + userdefined: When True, the style must have been added by the user, either in the document or its template, when absent, the argument is ignored. + + + + Dim vStyles As Variant + vStyles = oDoc.Styles("ParagraphStyles") ' All styles in the family + vStyles = oDoc.Styles("ParagraphStyles", "H*") ' Heading, Heading 1, ... + vStyles = oDoc.Styles("ParagraphStyles", Used := False, UserDefined := True) ' All user-defined styles that are not used + vStyles = oDoc.Styles("ParagraphStyles", ParentStyle := "Standard") ' All styles derived from the 'Default Paragraph Style' + + + + + vStyles = doc.Styles('ParagraphStyles') # All styles in the family + vStyles = doc.Styles('ParagraphStyles', 'H*') # Heading, Heading 1, ... + vStyles = doc.Styles('ParagraphStyles', Used = False, UserDefined = True) # All user-defined styles that are not used + vStyles = doc.Styles('ParagraphStyles', ParentStyle = 'Standard") # All styles derived from the "Default Paragraph Style" + +
+
+ XStyles --------------------------------------------------------------------------------------------- + + Document service;Toolbars + +

Toolbars

+ This method returns either a list of the available toolbar names in the actual document or a Toolbar object instance from the SFWidgets library. + + + svc.Toolbars(opt ToolbarName: str): uno + svc.Toolbars(): str[0..] + + + + ToolbarName: The usual name of one of the available toolbars. + + + + Dim oToolbar As Object + Set oToolbar = oDoc.Toolbars("myToolbar") + + + + a_list = doc.Toolbars() + +
+ XStyles --------------------------------------------------------------------------------------------- + + Document service;XStyles + +

XStyles

+ This method returns the UNO representation of a given style for all document types except Base. Nothing is returned when the StyleName does not exist in the given Family. + + + svc.XStyles(family: str, stylename: str): uno + + + + stylename: One of the styles present in the given family, as a case-sensitive string. The StyleName may be localized or not. + + + + Dim oStyle As Object + Set oStyle = oDoc.XStyle("ParagraphStyle", "Heading 2") + + + + oStyle = doc.XStyle('ParagraphStyle', 'Heading 2') + +
@@ -808,4 +984,4 @@
- + \ No newline at end of file -- cgit