27 Commits
Author SHA1 Message Date
Jean-Pierre Ledure 2821d29a87 ScriptForge (FileSystem) Manage ZIP archives
The FileSystem service provides simple
methods to manage compressed zip archives.

As an example, .odf and .oxt files being
formatted as such archives, massive or
punctual changes of file contents
with smart scripts can be facilitated.

New methods:
- IsZipFile(filename)
    returns True when filename is a valid
    zip file
- FilesInZip(filename, pattern)
    returns a list of archive members,
    optionally filtered with a Like pattern,
    stored in filename
- ExtractFromZip(filename, destination, source)
    stores the source file(s) found in the
    given ZIP file into a destination folder
- CompressToZip(filename, foldername, rootfolder)
    stores the content of folder, including
    its subfolders, into a zip archive,
    optionally under a root folder

The implementation is based on the python
zipfile standard library.

The methods area available both for Basic and
Python user scripts. For Python scripts, the
user is also free to use the native zipfile
library instead.

The user documentation shouid be updated
according to this commit.

Change-Id: I506a8583dc3fa38c7e05094562ade33f84a24747
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211891
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2026-10-07 14:26:54 +02:00
Jean-Pierre Ledure 9671c73922 ScriptForge (FileSystem) Title arg for PickFolder()
Only Windows implements the Description
property of the FolderPicker by displaying
it in the dialog's header. Otherwise it
is ignored.

This commit harmonizes the behaviour
among all environments, including Linux.

The previous signature:
   fs.PickFolder(defaultdirectory, freetext)
is replaced by:
   fs.PickFolder(defaultdirectory, title, freetext)

The 'freetext' parameter is kept for backward
compatibility. It becomes obsolete. When present,
and 'title' is absent, its content is pushed
to the dialog's title.

The change is valid both for Basic and Python scripts.
The documentation should be updated accordingly.

Change-Id: I888ee4afa5046212081bbdedc849147ebda1a3bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184719
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-04-28 16:56:28 +02:00
Jean-Pierre Ledure 2f9a4a80c0 ScriptForge (SF_Utils._Valudate) Improve robustness
All arguments passed to ScriptForge methods
are checked for validity.

A.o. a string may be compared with a closed
list of allowed values.
The comparison may now optionally be made
with a
   CaseSentitive As Boolean
parameter.

All occurrences where this check makes sense
were identified, inventoried and modified.
A True argument has been inserted where
appropriate.

Change-Id: I1a5cb7fb42618bc83fc8ec57c2727fc2a1bfcdb9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172530
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-08-29 10:01:17 +02:00
Jean-Pierre Ledure d5e1e4103b ScriptForge (SF_FileSystem) Fix typos
Typos in comment lines

Change-Id: I5e92417af0c9fb1f6f4d240a5a7731c9efa5230d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154802
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2023-07-23 16:10:06 +02:00
Andrea Gelmini 56edc523a4 Fix typo
Change-Id: I2a14c233aa09aec55b18dae2d4018a07c012ab52
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154795
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-23 10:05:28 +02:00
Andrea Gelmini 1d0adde905 Fix typo
Change-Id: Ia6252da165d734b752ea6cad96f8014556bb4bfd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154796
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-23 10:05:10 +02:00
Jean-Pierre Ledure c216a5fc49 ScriptForge (SF_FileSystem) IncludeSubfolders argument
In the FileSystem service, the
   - SubFolders()
   - Files()
methods receive an optional argument
   IncludeSubfolders (Boolean).

That argument determines whether or not only
the given FolderName is explored or also its subfolders
up to the bottom of the folders structure.

The argument must be used with caution as the number
of returned folders or files may increase rapidly.
anThis could consume excessive process time.

This patch will require an update of the
help page about the filesystem service.

The new argument is available both for Basic and Python
user scripts.

Change-Id: Id2a96cd63cb51f8681f20a203a711b47a636fc3a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154763
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2023-07-22 18:03:36 +02:00
Andrea Gelmini 83a169d04a Fix typo
Change-Id: I04d3440d121e6305b3435964b88d221bf4bce221
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154486
Tested-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-15 21:20:17 +02:00
Andrea Gelmini 38b7754d5e Fix typo
Change-Id: I62c3e5394e52591df08e2f6acd826718dc1a0cbd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154484
Tested-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-15 21:19:34 +02:00
Andrea Gelmini eb6da4a089 Fix typo
Change-Id: I5e1093f05a9916991304a178a73d81c073883479
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154483
Tested-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-15 21:19:10 +02:00
Andrea Gelmini 9e332f4125 Fix typo
Change-Id: I7a1afd67e976abe504f859f0f5561ac5ebc6df98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154482
Tested-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-15 21:18:41 +02:00
Andrea Gelmini 47a0a8d870 Fix typo
Change-Id: If692d47efd95e3383734b91ea72d4d665503b3d2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154481
Tested-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-07-15 21:18:17 +02:00
Jean-Pierre Ledure 44334328f7 ScriptForge (SF_FileSystem) support document(s internal file structure
1. The SF_Document services (document, base, calc,
   formdocument, writer) receive a new FileSystem
   property that returns the "root" of the
   component's file structure under the format:
      "vnd.sun.star.tdoc:/XXX"
   XXX being the document's identifier.
   The implementation does not use the RuntimeUID
   (UNO property of the OfficeDocument service) which
   is optional and, f.i. not present for Base documents.
   Instead the
    css.frame.TransientDocumentsDocumentContentFactory
   service is used.

2. The SF_FileSystem and SF_TextStream modules have been
   reviewed to support the new context.
   Next restrictions have been met:
   - The FileNaming property is always cnsidered as 'URL'
   - CompareFiles() is not applicable
   - GetFileLen() always returns zero
   - HashFile() is not applicable
   - Normalize() always returns the input string unchanged
   - PickFile() is not applicable
   - PickFolder() is not applicable
   Additionally,
   - CreatetextFile()
   - OpenTextFile() in write or append modes
   copy or initialize the file in a temporary storage
   and write it back in the document when it is being closed.
   The process is transparent for the user.

3. The GetTempName() method accepts an option
      Extension
   argument, for better convenience.

The new functionalities are available in Basic and Python.

Changes require an update of the help documentation.

Change-Id: Ibf8dd9983656923cf6ab43d9f48398dc4d1e6307
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154443
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2023-07-15 09:54:01 +02:00
Jean-Pierre Ledure 9c60996fc2 ScriptForge - (SF_FileSystem) tdf#154462 2nd call of PickFile() fails
Error happens in gen and gtk3 modes.
Does not happen in kf5 mode.

Linux only. Windows OK.

Change-Id: Ia5dd21f6879c1a732d291d15d6fb9f4bf20c76e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150238
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2023-04-11 18:59:39 +02:00
Jean-Pierre Ledure 6814e4375c ScriptForge - tdf#150203 Use RANDBETWEEN.NV i.o. RANDBETWEEN
Extract of the bug report (Rafael Lima)

This bug affects a method from the ScriptForge library,
more specifically the GetTempName method from
the FileSystem service, which relies on calling RANDBETWEEN.
Because of this bug, GetTempName only works in English,
but fails in other languages. Below is a sample code
for testing the GetTempName error.

Sub TestTempName
  GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
  fs = CreateScriptService("FileSystem")
  MsgBox fs.GetTempName()
End sub

Interestingly changing RANDBETWEEN for RANDBETWEEN.NV
in the macro above will work.

Occurrences of the use of RANDBETWEEN:
   wizards/source/scriptforge/SF_FileSystem.xba
   wizards/source/sfdocuments/SF_Calc.xba

Change-Id: Iea38f11acb7113aa5eaab1feff7a0e64a739aada
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137691
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2022-08-02 15:55:48 +02:00
Jean-Pierre Ledure 7c0f0afd58 ScriptForge - (SF_FileSystem) new Normalize() method
Normalize a pathname by collapsing redundant
separators and up-level references
so that A//B, A/B/, A/./B and A/foo/../B
all become A/B.

On Windows, it converts forward slashes
to backward slashes.

The Basic Normalize() method invokes the
_SF_FileSystem__Normalize() function located in
the ScriptForgeHelper.py module for execution
with the os.path builtin library

The os.path.normpath() function can easily be
executed directly from python user scripts.
However the FileSystem.Normalize() method is
proposed as well for Python scripts
- for compatibility Basic/Python reasons
- to manage the FileNaming notation

Change-Id: I1e089612432bd2c75b2e76ffa984289ef7f9d75c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136835
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2022-07-06 12:27:09 +02:00
Jean-Pierre Ledure 74a638011d ScriptForge - (scriptforge.py) get lists of properties and methods
To allow object introspection and some help
files automatic generation (see Telegram discussions),
the possibility to make the list of properties
and methods used in Basic  available in Python
has been requested.

These changes are for internal use only.

Main changes:
- the SFServices parent class receives new basicproperties()
  and basicmethods() methods
- Basic PythonDispatcher() is adapted to provide the lists to
  the Python caller
- Methods lists are reviewed in SFDocuments to NOT include
  the methods implemented in the parent SF_Document class, to
  avoid redundant entries in the list

Change-Id: I80758e225b039426b46f52dd67efe54c50f9f31e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129969
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2022-02-15 17:50:45 +01:00
Andrea Gelmini 571be264d9 Fix typos
Change-Id: I50e8988c320c0068f7adf4a3429d7639df0cbcd1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129596
Tested-by: Jenkins
Reviewed-by: Andrea Gelmini <andrea.gelmini@gelma.net>
2022-02-09 12:55:48 +01:00
Jean-Pierre Ledure b52016e5d0 ScriptForge - (SF_Platform,SF_FileSystem) Manage extensions
New properties and methods
--------------------------

SF_Platform.Extensions : (property)
   provide a list of the installed extensions
   as an array of strings

SF_FileSystem.ExtensionFolder(Extension as string) : (method)
   provides the location in FileNaming notation of the
   folder where the given extension is installed

The SF_FileSystem.ExtensionsFolder (notice the additional "s")
is kept as a property providing the folder containing the
extensions installed by the user.

All methods and properties are available with an identical
syntax and semantics both from Basic and Python scripts.

The difference between a propert or a method is
irrelevant for Basic but is essential in Python:
a property must not have brackets, a method must have them.
Hence the distinction between
   ExtensionFolder being a method requiring an argument
   ExtensionsFolder being a property without argument

Change-Id: Idd18a5624f4abd84095d146e467e8fdcf497bd0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129572
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2022-02-07 09:16:03 +01:00
Jean-Pierre Ledure 9688e4970e ScriptForge - (SF_Session, SF_Document) add arguments to RunCommand()
Next wiki page
 https://wiki.documentfoundation.org/Development/DispatchCommands
facilitates the use of commands with the
DispatchHelper service, including with arguments

This commit
- adds the RunCommand() method in the Session service
- extends the scope of existing RunCommand() methods
  for the Document, Base, Calc and Writer services
  with the addition of command arguments
Syntax by examples:
 (Basic)
  session.RunCommand("BasicIDEAppear", _
    "Document", "LibreOffice Macros & Dialogs", _
    "LibName", "ScriptForge", _
    "Name", "SF_Session", _
    "Line", 100)
 (Python) (1)
  session.RunCommand("BasicIDEAppear",
    "Document", "LibreOffice Macros & Dialogs",
    "LibName", "ScriptForge",
    "Name", "SF_Session",
    "Line", 100)
 (Python) (2)
  session.RunCommand("BasicIDEAppear",
    Document = "LibreOffice Macros & Dialogs",
    LibName = "ScriptForge",
    Name = "SF_Session",
    Line = 100)

Change-Id: I60cd5eb1ed0a057420215ce7aebe92b2aafabd53
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129175
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2022-01-30 18:26:36 +01:00
Julien Nabet 240b3ccaec Fix case for "ByVal", "Variant", "UCase"
Change-Id: I136d292cd535d4208457ef91a7773fc7ac00d5c8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127716
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
2021-12-30 10:34:54 +01:00
Jean-Pierre Ledure 2a38a064df ScriptForge - Comments in code: pointers to help pages
Insert in each service module a pointer to the
help page on https://help.libreoffice.org
containing the user documentation of the given
service.

Example:
SF_Array.xba contains a pointer to next help page
https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_array.html?DbPAR=BASIC

Only addition of comments lines.
No code change.

Change-Id: I83899d9fab247d23e2d5123378e2fb3fd0ade60e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117370
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2021-06-17 14:40:49 +02:00
Jean-Pierre Ledure 055ba70145 ScriptForge - (scriptforge.py) FileSystem and TextStream classes
Addition of SF_FileSystem and SF_TextStream classes

Machinery tuning:
- freeze a predefined list of standard modules
in the python persistent storage
- error management reviewed to mimic Basic behaviour on wrong
arguments

Standard modules are predefined in scriptforge.py as well

Both lists must be synchronized on a hardcoded entry number

Basic has minor revisions:
- complex boolean expressions return -1 and 0 to Python
i.o. True and False => Add a CBool() function
- [User]TemplatesFolder properties of FileSystem omitted the final "/"

Change-Id: Ice138de956f5f87269557cdb3db023849081b99d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112199
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2021-03-09 15:36:32 +01:00
Jean-Pierre Ledure f66a479225 ScriptForge - (scriptforge.py) Python-Basic machinery
Python scripts can now invoke usual Basic builtin functions
Example:
    from ScriptForge import CreateScriptService
    bas = CreateScriptService('Basic')
    bas.MsgBox('This is the text to be displayed', bas.MB_ICONEXCLAMATION)

Python scripts can use most ScriptForge services written in Basic
Example:
    from scriptforge import CreateScriptService
    FSO = CreateScriptService('FileSystem')
    a = FSO.BuildPath('/tmp', 'xyz')
Syntax and semantic are as close as possible to the Basic syntax

Implemented are a SFServices class and its subclasses representing each
a ScriptForge service and where the interfaces are defined (properties,
methods and arguments)

Their execution goes through the "machinery", i.e. a set of python
and basic routines that manage the call from the python process to
the appropriate service in an as much agnostic and generic way

Only a limited set of services are implemented so far: SF_FileSystem
(partially) and SF_Timer: they served as prototypes and initial tests

Change-Id: I0b383b59359c12710e7165139e498cca5a7856bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111971
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2021-03-05 10:26:51 +01:00
Jean-Pierre Ledure 9e2a5240ee ScriptForge - Fix typos
Change-Id: Idc0bbdd37023f010c8fdb70356f9b55c132e4065
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105433
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2020-11-07 16:19:47 +01:00
Andrea Gelmini efca0ebee5 Fix typos
Change-Id: I7ba612d8880833057269290212bcd9d864bb7395
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105399
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2020-11-07 10:54:01 +01:00
Jean-Pierre Ledure 09c1bee1f9 ScriptForge - core library
Additional "LibreOffice Macros & Dialogs" library

Change-Id: I7380cf3f9ee56b73cfcf7b9e33d0cf50ecb40429
2020-11-05 15:55:39 +01:00