wizards/source/scriptforge/python/scriptforge.py | 18 +++---- wizards/source/scriptforge/python/scriptforge.pyi | 5 + wizards/source/sfdatabases/SF_Datasheet.xba | 52 ++++++++++++++------ wizards/source/sfdatabases/script.xlb | 8 +-- wizards/source/sfdocuments/SF_Base.xba | 6 ++ wizards/source/sfdocuments/SF_Calc.xba | 6 ++ wizards/source/sfdocuments/SF_Document.xba | 56 +++++++++++++++------- wizards/source/sfdocuments/SF_FormDocument.xba | 6 ++ wizards/source/sfdocuments/SF_Writer.xba | 6 ++ wizards/source/sfdocuments/script.xlb | 20 +++---- 10 files changed, 127 insertions(+), 56 deletions(-)
New commits: commit 970ad633e4fc374798d4f2591b73098d44c0986b Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Mon Feb 3 16:44:35 2025 +0100 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Tue Feb 4 10:16:01 2025 +0100 ScriptForge (SFDocuments) new MenuHeaders property The %enuHeaders property returns, as an array/tuple of strings the list of the menus present in the menubar. This is a helper for the CreateMenu() method: - check if the menu exists already to avoid duplicates - ease the choice of the Before argument The property is applicable to next classes: - Document, and its subclasses Base, Calc, Writer, FormDocument - Datasheet The property is made available to Basic and Python user scripts. This new property will require an update of the user documentation/help Change-Id: Ia14daf6c58973e06d576b350e416eb178f70feb3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181065 Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 3e3e91cfcde2..9cf19e4d85f5 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1969,8 +1969,8 @@ class SFDatabases: servicename = 'SFDatabases.Datasheet' servicesynonyms = ('datasheet', 'sfdatabases.datasheet') serviceproperties = dict(ColumnHeaders = 0, CurrentColumn = 1, CurrentRow = 1, - DatabaseFileName = 0, Filter = 2, IsAlive = 1, LastRow = 0, OrderBy = 2, - ParentDatabase = 0, Source = 0, SourceType = 0, XComponent = 0, + DatabaseFileName = 0, Filter = 2, IsAlive = 1, LastRow = 0, MenuHeaders = 1, + OrderBy = 2, ParentDatabase = 0, Source = 0, SourceType = 0, XComponent = 0, XControlModel = 0, XTabControllerModel = 0) def Activate(self): @@ -2296,8 +2296,8 @@ class SFDocuments: serviceproperties = dict(CustomProperties = 3, Description = 3, DocumentProperties = 1, DocumentType = 0, ExportFilters = 0, FileSystem = 0, ImportFilters = 0, IsAlive = 1, IsBase = 0, IsCalc = 0, IsDraw = 0, IsFormDocument = 0, - IsImpress = 0, IsMath = 0, IsWriter = 0, Keywords = 3, Readonly = 1, - StyleFamilies = 1, Subject = 3, Title = 3, XComponent = 0, + IsImpress = 0, IsMath = 0, IsWriter = 0, Keywords = 3, MenuHeaders = 1, + Readonly = 1, StyleFamilies = 1, Subject = 3, Title = 3, XComponent = 0, XDocumentSettings = 0) @classmethod @@ -2392,7 +2392,7 @@ class SFDocuments: servicesynonyms = ('base', 'scriptforge.base') serviceproperties = dict(DocumentType = 0, FileSystem = 0, IsAlive = 1, IsBase = 0, IsCalc = 0, IsDraw = 0, IsFormDocument = 0, IsImpress = 0, IsMath = 0, - IsWriter = 0, XComponent = 0) + IsWriter = 0, MenuHeaders = 1, XComponent = 0) @classmethod def ReviewServiceArgs(cls, windowname = ''): @@ -2451,7 +2451,7 @@ class SFDocuments: DocumentProperties = 1, DocumentType = 0, ExportFilters = 0, FileSystem = 0, ImportFilters = 0, IsAlive = 1, IsBase = 0, IsCalc = 0, IsDraw = 0, IsFormDocument = 0, IsImpress = 0, IsMath = 0, - IsWriter = 0, Keywords = 3, Readonly = 1, Sheets = 1, + IsWriter = 0, Keywords = 3, MenuHeaders = 1, Readonly = 1, Sheets = 1, StyleFamilies = 0, Subject = 3, Title = 3, XComponent = 0, XDocumentSettings = 0) @@ -2815,7 +2815,7 @@ class SFDocuments: servicesynonyms = ('formdocument', 'sfdocuments.formdocument') serviceproperties = dict(DocumentType = 0, FileSystem = 0, IsAlive = 1, IsBase = 0, IsCalc = 0, IsDraw = 0, IsFormDocument = 0, IsImpress = 0, IsMath = 0, - IsWriter = 0, Readonly = 0, StyleFamilies = 0, XComponent = 0, + IsWriter = 0, MenuHeaders = 1, Readonly = 0, StyleFamilies = 0, XComponent = 0, XDocumentSettings = 0) @classmethod @@ -2854,8 +2854,8 @@ class SFDocuments: serviceproperties = dict(CustomProperties = 3, Description = 3, DocumentProperties = 1, DocumentType = 0, ExportFilters = 0, FileSystem = 0, ImportFilters = 0, IsAlive = 1, IsBase = 0, IsCalc = 0, IsDraw = 0, IsFormDocument = 0, - IsImpress = 0, IsMath = 0, IsWriter = 0, Keywords = 3, Readonly = 1, - StyleFamilies = 1, Subject = 3, Title = 3, XComponent = 0, + IsImpress = 0, IsMath = 0, IsWriter = 0, Keywords = 3, MenuHeaders = 1, + Readonly = 1, StyleFamilies = 1, Subject = 3, Title = 3, XComponent = 0, XDocumentSettings = 0) @classmethod diff --git a/wizards/source/scriptforge/python/scriptforge.pyi b/wizards/source/scriptforge/python/scriptforge.pyi index b04fa691b6ac..2d34c0f32e31 100644 --- a/wizards/source/scriptforge/python/scriptforge.pyi +++ b/wizards/source/scriptforge/python/scriptforge.pyi @@ -3129,6 +3129,8 @@ class SFDatabases: """ Returns True when the datasheet component has not been closed by the user. """ LastRow: int """ Returns the number of rows in the datasheet. """ + MenuHeaders: Tuple[str, ...] + """ Returns the list, as a tuple of strings, of the menus present in the menubar. """ OrderBy: str """ Specifies the order in which records are shown expressed as the ``ORDER BY`` clause of a ``SQL`` query without the ``ORDER BY`` keyword. If an empty string is specified then the active ``OrderBy`` is removed. """ @@ -4466,6 +4468,8 @@ class SFDocuments: Keywords: str """ Get/set the ``Keywords`` property of the document as a comma-separated list of keywords. This property is not applicable to ``Base`` documents. """ + MenuHeaders: Tuple[str, ...] + """ Returns the list, as a tuple of strings, of the menus present in the menubar. """ Readonly: bool """ ``True`` if the document is actually in read-only mode. This property is not applicable to ``Base`` documents. """ @@ -4933,7 +4937,6 @@ class SFDocuments: """ ... - # pylint: disable=arguments-renamed def PrintOut(self, formdocument: str, pages: str = ..., copies: int = ...) -> bool: """ Send the content of the form document to the printer. diff --git a/wizards/source/sfdatabases/SF_Datasheet.xba b/wizards/source/sfdatabases/SF_Datasheet.xba index c505dd45f104..ce7a38fab7c0 100644 --- a/wizards/source/sfdatabases/SF_Datasheet.xba +++ b/wizards/source/sfdatabases/SF_Datasheet.xba @@ -159,6 +159,12 @@ Property Get LastRow() As Long LastRow = _PropertyGet("LastRow") End Property ' SFDatabases.SF_Datasheet.LastRow +REM ----------------------------------------------------------------------------- +Property Get MenuHeaders() As Variant +''' Returns the list, as an array of strings, of the menu headers present in the menubar + MenuHeaders = _PropertyGet("MenuHeaders") +End Property ' SFDocuments.SF_Datasheet.MenuHeaders + REM ----------------------------------------------------------------------------- Property Get OrderBy() As Variant ''' The Order is a SQL ORDER BY clause without the ORDER BY keywords @@ -586,6 +592,7 @@ Public Function Properties() As Variant , "Filter" _ , "IsAlive" _ , "LastRow" _ + , "MenuHeaders" _ , "OrderBy" _ , "ParentDatabase" _ , "Source" _ @@ -834,6 +841,9 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant ''' psProperty: the name of the property Dim lRow As Long ' Actual row number +Dim oMenuBar As Object ' com.sun.star.awt.XMenuBar +Dim sMenus As String ' List of menus in the menubar +Dim i As Long, j As Long Dim cstThisSub As String Const cstSubArgs = "" @@ -845,20 +855,20 @@ Const cstSubArgs = "" If Not _IsStillAlive() Then GoTo Finally End If - Select Case psProperty - Case "ColumnHeaders" + Select Case UCase(psProperty) + Case UCase("ColumnHeaders") _PropertyGet = _ColumnHeaders - Case "CurrentColumn" + Case UCase("CurrentColumn") _PropertyGet = _ColumnHeaders(_ControlView.getCurrentColumnPosition()) - Case "CurrentRow" + Case UCase("CurrentRow") _PropertyGet = _TabControllerModel.Row - Case "DatabaseFileName" + Case UCase("DatabaseFileName") _PropertyGet = ScriptForge.SF_FileSystem._ConvertFromUrl(_BaseFileName) - Case "Filter" + Case UCase("Filter") _PropertyGet = _TabControllerModel.Filter - Case "IsAlive" + Case UCase("IsAlive") _PropertyGet = _IsStillAlive(False) - Case "LastRow" + Case UCase("LastRow") With _TabControllerModel If .IsRowCountFinal Then _PropertyGet = .RowCount @@ -873,19 +883,31 @@ Const cstSubArgs = "" End If End If End With - Case "OrderBy" + Case UCase("MenuHeaders") + Set oMenuBar = _Component.Frame.LayoutManager.getElement("private:resource/menubar/menubar").XMenuBar + ' Join all menu headers, then split the whole string + sMenus = "" + With oMenuBar + For i = 0 To .ItemCount - 1 + j = .getItemId(i) + sMenus = sMenus & .getItemText(j) & "," + Next i + End With + If Len(sMenus) > 0 Then sMenus = Left(sMenus, Len(sMenus) - 1) ' Suppress final comma + _PropertyGet = Split(Replace(sMenus, "~", ""), ",") + Case UCase("OrderBy") _PropertyGet = _TabControllerModel.Order - Case "ParentDatabase" + Case UCase("ParentDatabase") Set _PropertyGet = _ParentDatabase - Case "Source" + Case UCase("Source") _PropertyGet = _Command - Case "SourceType" + Case UCase("SourceType") _PropertyGet = _SheetType - Case "XComponent" + Case UCase("XComponent") Set _PropertyGet = _Component - Case "XControlModel" + Case UCase("XControlModel") Set _PropertyGet = _ControlModel - Case "XTabControllerModel" + Case UCase("XTabControllerModel") Set _PropertyGet = _TabControllerModel Case Else _PropertyGet = Null diff --git a/wizards/source/sfdatabases/script.xlb b/wizards/source/sfdatabases/script.xlb index 8e12f56515d5..38571cfa0512 100644 --- a/wizards/source/sfdatabases/script.xlb +++ b/wizards/source/sfdatabases/script.xlb @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDatabases" library:readonly="false" library:passwordprotected="false"> - <library:element library:name="SF_Register"/> - <library:element library:name="__License"/> - <library:element library:name="SF_Database"/> - <library:element library:name="SF_Datasheet"/> <library:element library:name="SF_Dataset"/> + <library:element library:name="SF_Datasheet"/> + <library:element library:name="SF_Database"/> + <library:element library:name="__License"/> + <library:element library:name="SF_Register"/> </library:library> \ No newline at end of file diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba index 5c0feaec5c63..f4f58cd17029 100644 --- a/wizards/source/sfdocuments/SF_Base.xba +++ b/wizards/source/sfdocuments/SF_Base.xba @@ -695,6 +695,7 @@ Public Function Properties() As Variant , "IsImpress" _ , "IsMath" _ , "IsWriter" _ + , "MenuHeaders" _ , "XComponent" _ ) @@ -881,6 +882,11 @@ REM ---------------------------------------------------------------------------- ' [_Super].Keywords = pvKeywords 'End Property ' SFDocuments.SF_Base.Keywords +REM ----------------------------------------------------------------------------- +Property Get MenuHeaders() As Variant + MenuHeaders = [_Super].GetProperty("MenuHeaders") +End Property ' SFDocuments.SF_Base.MenuHeaders + REM ----------------------------------------------------------------------------- 'Property Get Readonly() As Variant ' Readonly = [_Super].GetProperty("Readonly") diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 7bd5e4e8d251..2aef72167281 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -2648,6 +2648,7 @@ Public Function Properties() As Variant , "LastCell" _ , "LastColumn" _ , "LastRow" _ + , "MenuHeaders" _ , "Range" _ , "Readonly" _ , "Region" _ @@ -3762,6 +3763,11 @@ Property Let Keywords(Optional ByVal pvKeywords As Variant) [_Super].Keywords = pvKeywords End Property ' SFDocuments.SF_Calc.Keywords +REM ----------------------------------------------------------------------------- +Property Get MenuHeaders() As Variant + MenuHeaders = [_Super].GetProperty("MenuHeaders") +End Property ' SFDocuments.SF_Calc.MenuHeaders + REM ----------------------------------------------------------------------------- Property Get Readonly() As Variant Readonly = [_Super].GetProperty("Readonly") diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba index 0ad019315a5f..4f69c9cb3986 100644 --- a/wizards/source/sfdocuments/SF_Document.xba +++ b/wizards/source/sfdocuments/SF_Document.xba @@ -364,6 +364,12 @@ Finally: Exit Property End Property ' SFDocuments.SF_Document.Keywords +REM ----------------------------------------------------------------------------- +Property Get MenuHeaders() As Variant +''' Returns the list, as an array of strings, of the menu headers present in the menubar + MenuHeaders = _PropertyGet("MenuHeaders") +End Property ' SFDocuments.SF_Document.MenuHeaders + REM ----------------------------------------------------------------------------- Property Get Readonly() As Boolean ''' Returns True if the document must not be modified @@ -1011,6 +1017,7 @@ Public Function Properties() As Variant , "IsMath" _ , "IsWriter" _ , "Keywords" _ + , "MenuHeaders" _ , "Readonly" _ , "StyleFamilies" _ , "Subject" _ @@ -2152,6 +2159,9 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant Dim oProperties As Object ' Document or Custom properties Dim oTransient As Object ' com.sun.star.frame.TransientDocumentsDocumentContentFactory Dim oContent As Object ' com.sun.star.comp.ucb.TransientDocumentsContent +Dim oMenuBar As Object ' com.sun.star.awt.XMenuBar +Dim sMenus As String ' List of menus in the menubar +Dim i As Long, j As Long Dim cstThisSub As String Const cstSubArgs = "" @@ -2167,48 +2177,60 @@ Const cstSubArgs = "" If Not _IsStillAlive() Then GoTo Finally End If - Select Case psProperty - Case "CustomProperties" + Select Case UCase(psProperty) + Case UCase("CustomProperties") _CustomProperties = CreateScriptService("Dictionary", True) ' Always reload as updates could have been done manually by user ' (with case-sensitive comparison of keys) _CustomProperties.ImportFromPropertyValues(_Component.getDocumentProperties().UserDefinedProperties.getPropertyValues) _PropertyGet = _CustomProperties - Case "Description" + Case UCase("Description") _PropertyGet = _Component.DocumentProperties.Description - Case "DocumentProperties" + Case UCase("DocumentProperties") _LoadDocumentProperties() ' Always reload as updates could have been done manually by user Set _PropertyGet = _DocumentProperties - Case "DocumentType" + Case UCase("DocumentType") _PropertyGet = _DocumentType - Case "ExportFilters" + Case UCase("ExportFilters") _PropertyGet = _GetFilterNames(True) - Case "FileSystem" + Case UCase("FileSystem") ' Natural choice would have been to use the component.RunTimeUID property ' However it is optional in the OfficeDocument service and not available for Base documents ' Below a more generic alternative derived from the get_document_uri() method found in apso.py Set oTransient = ScriptForge.SF_Utils._GetUnoService("TransientDocumentFactory") Set oContent = oTransient.createDocumentContent(_Component) _PropertyGet = oContent.getIdentifier().ContentIdentifier & "/" - Case "ImportFilters" + Case UCase("ImportFilters") _PropertyGet = _GetFilterNames(False) - Case "IsAlive" + Case UCase("IsAlive") _PropertyGet = _IsStillAlive(False, False) - Case "IsBase", "IsCalc", "IsDraw", "IsFormDocument", "IsImpress", "IsMath", "IsWriter" + Case UCase("IsBase"), UCase("IsCalc"), UCase("IsDraw"), UCase("IsFormDocument"), UCase("IsImpress"), UCase("IsMath"), UCase("IsWriter") _PropertyGet = ( Mid(psProperty, 3) = _DocumentType ) - Case "Keywords" + Case UCase("Keywords") _PropertyGet = Join(_Component.DocumentProperties.Keywords, ", ") - Case "Readonly" + Case UCase("MenuHeaders") + Set oMenuBar = _Component.CurrentController.Frame.LayoutManager.getElement("private:resource/menubar/menubar").XMenuBar + ' Join all menu headers, then split the whole string + sMenus = "" + With oMenuBar + For i = 0 To .ItemCount - 1 + j = .getItemId(i) + sMenus = sMenus & .getItemText(j) & "," + Next i + End With + If Len(sMenus) > 0 Then sMenus = Left(sMenus, Len(sMenus) - 1) ' Suppress final comma + _PropertyGet = Split(Replace(sMenus, "~", ""), ",") + Case UCase("Readonly") _PropertyGet = _Component.isReadonly() - Case "StyleFamilies" + Case UCase("StyleFamilies") If UBound(_StyleFamilies) < 0 Then _StyleFamilies = _Component.getStyleFamilies().getElementNames() _PropertyGet = _StyleFamilies - Case "Subject" + Case UCase("Subject") _PropertyGet = _Component.DocumentProperties.Subject - Case "Title" + Case UCase("Title") _PropertyGet = _Component.DocumentProperties.Title - Case "XComponent" + Case UCase("XComponent") Set _PropertyGet = _Component - Case "XDocumentSettings" + Case UCase("XDocumentSettings") With _Component If IsNull(_DocumentSettings) Then Select Case _DocumentType diff --git a/wizards/source/sfdocuments/SF_FormDocument.xba b/wizards/source/sfdocuments/SF_FormDocument.xba index 6f055ff359ef..3c05c5fd8d57 100644 --- a/wizards/source/sfdocuments/SF_FormDocument.xba +++ b/wizards/source/sfdocuments/SF_FormDocument.xba @@ -430,6 +430,7 @@ Public Function Properties() As Variant , "IsFormDocument" _ , "IsImpress" _ , "IsMath" _ + , "MenuHeaders" _ , "Readonly" _ , "StyleFamilies" _ , "XComponent" _ @@ -480,6 +481,11 @@ Property Get IsMath() As Boolean IsMath = [_Super].GetProperty("IsMath") End Property ' SFDocuments.SF_FormDocument.IsMath +REM ----------------------------------------------------------------------------- +Property Get MenuHeaders() As Variant + MenuHeaders = [_Super].GetProperty("MenuHeaders") +End Property ' SFDocuments.SF_FormDocument.MenuHeaders + REM ----------------------------------------------------------------------------- Property Get Readonly() As Variant Readonly = [_Super].GetProperty("Readonly") diff --git a/wizards/source/sfdocuments/SF_Writer.xba b/wizards/source/sfdocuments/SF_Writer.xba index 38767666300e..307f9f6682c4 100644 --- a/wizards/source/sfdocuments/SF_Writer.xba +++ b/wizards/source/sfdocuments/SF_Writer.xba @@ -453,6 +453,7 @@ Public Function Properties() As Variant , "IsMath" _ , "IsWriter" _ , "Keywords" _ + , "MenuHeaders" _ , "Readonly" _ , "StyleFamilies" _ , "Subject" _ @@ -608,6 +609,11 @@ Property Let Keywords(Optional ByVal pvKeywords As Variant) [_Super].Keywords = pvKeywords End Property ' SFDocuments.SF_Writer.Keywords +REM ----------------------------------------------------------------------------- +Property Get MenuHeaders() As Variant + MenuHeaders = [_Super].GetProperty("MenuHeaders") +End Property ' SFDocuments.SF_Writer.MenuHeaders + REM ----------------------------------------------------------------------------- Property Get Readonly() As Variant Readonly = [_Super].GetProperty("Readonly") diff --git a/wizards/source/sfdocuments/script.xlb b/wizards/source/sfdocuments/script.xlb index 8188fd53bb1f..3d2264bd3f6d 100644 --- a/wizards/source/sfdocuments/script.xlb +++ b/wizards/source/sfdocuments/script.xlb @@ -1,15 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDocuments" library:readonly="false" library:passwordprotected="false"> - <library:element library:name="SF_Chart"/> - <library:element library:name="SF_FormDocument"/> - <library:element library:name="SF_FormControl"/> - <library:element library:name="SF_Base"/> - <library:element library:name="SF_Register"/> - <library:element library:name="SF_Writer"/> - <library:element library:name="SF_Calc"/> - <library:element library:name="SF_Document"/> - <library:element library:name="SF_DocumentListener"/> - <library:element library:name="SF_Form"/> <library:element library:name="__License"/> + <library:element library:name="SF_Form"/> + <library:element library:name="SF_DocumentListener"/> + <library:element library:name="SF_Document"/> + <library:element library:name="SF_Calc"/> + <library:element library:name="SF_Writer"/> + <library:element library:name="SF_Register"/> + <library:element library:name="SF_Base"/> + <library:element library:name="SF_FormControl"/> + <library:element library:name="SF_FormDocument"/> + <library:element library:name="SF_Chart"/> </library:library> \ No newline at end of file