diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2022-02-03 16:54:00 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2022-02-04 14:20:10 +0100 |
commit | a1513003543e4a7a47da47659a715eec2b6af452 (patch) | |
tree | f356cda52b2fc149635aea945aaa636ceac6bce1 /wizards/source | |
parent | 1a62f3383dfda9c35d46adbbdfbc3a9c2278eeb5 (diff) |
ScriptForge - (SF_UI) Import RunCommand() from SF_Session
Functionally SF_UI groups methods impacting the
user interface, while the Session service groups general-purpose
actions.
The RunCommand() method (newly introduced in 7.4) simulates
menu commands applied on the active window.
RunCommand() fits better in the UI service.
It is removed from SF_Session.
Change-Id: Ia72150efea2f50de13d15a4c1f5fea79777d1760
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129453
Tested-by: Jenkins
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards/source')
-rw-r--r-- | wizards/source/scriptforge/SF_Session.xba | 60 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_UI.xba | 61 | ||||
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 16 |
3 files changed, 69 insertions, 68 deletions
diff --git a/wizards/source/scriptforge/SF_Session.xba b/wizards/source/scriptforge/SF_Session.xba index 748daf597f46..f02a958768ce 100644 --- a/wizards/source/scriptforge/SF_Session.xba +++ b/wizards/source/scriptforge/SF_Session.xba @@ -599,66 +599,6 @@ Catch: End Function ' ScriptForge.SF_Session.RunApplication REM ----------------------------------------------------------------------------- -Public Sub RunCommand(Optional ByVal Command As Variant _ - , ParamArray Args As Variant _ - ) -''' Run on the current window the given menu command. The command is executed with or without arguments -''' A few typical commands: -''' About, Delete, Edit, Undo, Copy, Paste, ... -''' Dozens can be found on next page: https://wiki.documentfoundation.org/Development/DispatchCommands -''' Args: -''' Command: Case-sensitive. The command itself is not checked. -''' If the command does not contain the ".uno:" prefix, it is added. -''' If nothing happens, then the command is probably wrong -''' Args: Pairs of arguments name (string), value (any) -''' Returns: -''' Examples: -''' session.RunCommand("BasicIDEAppear", _ -''' "Document", "LibreOffice Macros & Dialogs", _ -''' "LibName", "ScriptForge", _ -''' "Name", "SF_Session", _ -''' "Line", 600) - -Dim oDispatch ' com.sun.star.frame.DispatchHelper -Dim vProps As Variant ' Array of PropertyValues -Dim vValue As Variant ' A single value argument -Dim sCommand As String ' Alias of Command -Dim i As Long -Const cstPrefix = ".uno:" - -Const cstThisSub = "Session.RunCommand" -Const cstSubArgs = "Command, [arg0Name, arg0Value], [arg1Name, arg1Value], ..." - - If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch - -Check: - If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then - If Not SF_Utils._Validate(Command, "Command", V_STRING) Then GoTo Finally - If Not SF_Utils._ValidateArray(Args, "Args", 1) Then GoTo Finally - For i = 0 To UBound(Args) - 1 Step 2 - If Not SF_Utils._Validate(Args(i), "Arg" & CStr(i/2) & "Name", V_STRING) Then GoTo Finally - Next i - End If - -Try: - ' Build array of property values - vProps = Array() - For i = 0 To UBound(Args) - 1 Step 2 - If IsEmpty(Args(i + 1)) Then vValue = Null Else vValue = Args(i + 1) - vProps = SF_Array.Append(vProps, SF_Utils._MakePropertyValue(Args(i), vValue)) - Next i - Set oDispatch = SF_Utils._GetUNOService("DispatchHelper") - If SF_String.StartsWith(Command, cstPrefix) Then sCommand = Command Else sCommand = cstPrefix & Command - oDispatch.executeDispatch(StarDesktop.ActiveFrame, sCommand, "", 0, vProps) - -Finally: - SF_Utils._ExitFunction(cstThisSub) - Exit Sub -Catch: - GoTo Finally -End Sub ' ScriptForge.SF_Session.RunCommand - -REM ----------------------------------------------------------------------------- Public Sub SendMail(Optional ByVal Recipient As Variant _ , Optional ByRef Cc As Variant _ , Optional ByRef Bcc As Variant _ diff --git a/wizards/source/scriptforge/SF_UI.xba b/wizards/source/scriptforge/SF_UI.xba index 4c9907ec39e3..c1726d1cdcb9 100644 --- a/wizards/source/scriptforge/SF_UI.xba +++ b/wizards/source/scriptforge/SF_UI.xba @@ -625,6 +625,7 @@ Public Function Methods() As Variant , "OpenBaseDocument" _ , "OpenDocument" _ , "Resize" _ + , "RunCommand" _ , "SetStatusbar" _ , "ShowProgressBar" _ , "WindowExists" _ @@ -883,6 +884,66 @@ Catch: End Sub ' ScriptForge.SF_UI.Resize REM ----------------------------------------------------------------------------- +Public Sub RunCommand(Optional ByVal Command As Variant _ + , ParamArray Args As Variant _ + ) +''' Run on the current window the given menu command. The command is executed with or without arguments +''' A few typical commands: +''' About, Delete, Edit, Undo, Copy, Paste, ... +''' Dozens can be found on next page: https://wiki.documentfoundation.org/Development/DispatchCommands +''' Args: +''' Command: Case-sensitive. The command itself is not checked. +''' If the command does not contain the ".uno:" prefix, it is added. +''' If nothing happens, then the command is probably wrong +''' Args: Pairs of arguments name (string), value (any) +''' Returns: +''' Examples: +''' ui.RunCommand("BasicIDEAppear", _ +''' "Document", "LibreOffice Macros & Dialogs", _ +''' "LibName", "ScriptForge", _ +''' "Name", "SF_Session", _ +''' "Line", 600) + +Dim oDispatch ' com.sun.star.frame.DispatchHelper +Dim vProps As Variant ' Array of PropertyValues +Dim vValue As Variant ' A single value argument +Dim sCommand As String ' Alias of Command +Dim i As Long +Const cstPrefix = ".uno:" + +Const cstThisSub = "UI.RunCommand" +Const cstSubArgs = "Command, [arg0Name, arg0Value], [arg1Name, arg1Value], ..." + + If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch + +Check: + If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not SF_Utils._Validate(Command, "Command", V_STRING) Then GoTo Finally + If Not SF_Utils._ValidateArray(Args, "Args", 1) Then GoTo Finally + For i = 0 To UBound(Args) - 1 Step 2 + If Not SF_Utils._Validate(Args(i), "Arg" & CStr(i/2) & "Name", V_STRING) Then GoTo Finally + Next i + End If + +Try: + ' Build array of property values + vProps = Array() + For i = 0 To UBound(Args) - 1 Step 2 + If IsEmpty(Args(i + 1)) Then vValue = Null Else vValue = Args(i + 1) + vProps = SF_Array.Append(vProps, SF_Utils._MakePropertyValue(Args(i), vValue)) + Next i + Set oDispatch = SF_Utils._GetUNOService("DispatchHelper") + If SF_String.StartsWith(Command, cstPrefix) Then sCommand = Command Else sCommand = cstPrefix & Command + oDispatch.executeDispatch(StarDesktop.ActiveFrame, sCommand, "", 0, vProps) + +Finally: + SF_Utils._ExitFunction(cstThisSub) + Exit Sub +Catch: + GoTo Finally +End Sub ' ScriptForge.SF_UI.RunCommand + +REM ----------------------------------------------------------------------------- Public Function SetProperty(Optional ByVal PropertyName As Variant _ , Optional ByRef Value As Variant _ ) As Boolean diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 94d5a3de7d58..7edc737acec4 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1332,14 +1332,6 @@ class SFScriptForge: def RunApplication(self, command, parameters): return self.ExecMethod(self.vbMethod, 'RunApplication', command, parameters) - def RunCommand(self, command, *args, **kwargs): - params = tuple(list(args) + ScriptForge.unpack_args(kwargs)) - if len(params) == 0: - params = (command,) + (None,) - else: - params = (command,) + params - return self.SIMPLEEXEC('@SF_Session.RunCommand', params) - def SendMail(self, recipient, cc = '', bcc = '', subject = '', body = '', filenames = '', editmessage = True): return self.ExecMethod(self.vbMethod, 'SendMail', recipient, cc, bcc, subject, body, filenames, editmessage) @@ -1548,6 +1540,14 @@ class SFScriptForge: def Resize(self, left = -1, top = -1, width = -1, height = -1): return self.ExecMethod(self.vbMethod, 'Resize', left, top, width, height) + def RunCommand(self, command, *args, **kwargs): + params = tuple(list(args) + ScriptForge.unpack_args(kwargs)) + if len(params) == 0: + params = (command,) + (None,) + else: + params = (command,) + params + return self.SIMPLEEXEC('@SF_UI.RunCommand', params) + def SetStatusbar(self, text = '', percentage = -1): return self.ExecMethod(self.vbMethod, 'SetStatusbar', text, percentage) |