diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2016-12-24 16:27:22 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2017-01-12 11:40:49 +0100 |
commit | 92608b890928b6d10931f4aad3385bb87284181d (patch) | |
tree | 8fc002080d7cb1beee902d7cead925d1aece28a0 /wizards/source/access2base/Application.xba | |
parent | 9017bcc76bd27b97c065dacf511f7fcdfe3060cb (diff) |
Access2Base - Addition of Module object
New Module Basic module
New AllModules() collection in Application module
Extension of regex to backward searches
Change-Id: Id58f3b29d08e9f0b73e192cfc0c2a99988e73fcf
Diffstat (limited to 'wizards/source/access2base/Application.xba')
-rw-r--r-- | wizards/source/access2base/Application.xba | 160 |
1 files changed, 157 insertions, 3 deletions
diff --git a/wizards/source/access2base/Application.xba b/wizards/source/access2base/Application.xba index 19a872007f9f..037d54b5091e 100644 --- a/wizards/source/access2base/Application.xba +++ b/wizards/source/access2base/Application.xba @@ -45,6 +45,7 @@ Global Const ERRSQLSTATEMENT = 1523 Global Const ERROBJECTNOTFOUND = 1524 Global Const ERROPENOBJECT = 1525 Global Const ERRCLOSEOBJECT = 1526 +Global Const ERRMETHOD = 1527 Global Const ERRACTION = 1528 Global Const ERRSENDMAIL = 1529 Global Const ERRFORMYETOPEN = 1530 @@ -74,6 +75,8 @@ Global Const ERRSUBFORMNOTFOUND = 1553 Global Const ERRWINDOW = 1554 Global Const ERRCOMPATIBILITY = 1555 Global Const ERRPRECISION = 1556 +Global Const ERRMODULENOTFOUND = 1557 +Global Const ERRPROCEDURENOTFOUND = 1558 REM ----------------------------------------------------------------------------------------------------------------------- Global Const DBCONNECTBASE = 1 ' Connection from Base document (OpenConnection) @@ -94,6 +97,7 @@ Global Const DBMS_SQLITE = 8 REM ----------------------------------------------------------------------------------------------------------------------- Global Const COLLALLDIALOGS = "ALLDIALOGS" Global Const COLLALLFORMS = "ALLFORMS" +Global Const COLLALLMODULES = "ALLMODULES" Global Const COLLCOMMANDBARS = "COMMANDBARS" Global Const COLLCOMMANDBARCONTROLS = "COMMANDBARCONTROLS" Global Const COLLCONTROLS = "CONTROLS" @@ -116,6 +120,7 @@ Global Const OBJDIALOG = "DIALOG" Global Const OBJEVENT = "EVENT" Global Const OBJFIELD = "FIELD" Global Const OBJFORM = "FORM" +Global Const OBJMODULE = "MODULE" Global Const OBJOPTIONGROUP = "OPTIONGROUP" Global Const OBJPROPERTY = "PROPERTY" Global Const OBJQUERYDEF = "QUERYDEF" @@ -160,6 +165,10 @@ Global Const CTLPARENTISGRID = "GRID" Global Const CTLPARENTISGROUP = "OPTIONGROUP" REM ----------------------------------------------------------------------------------------------------------------------- +Global Const MODDOCUMENT = "DOCUMENT" +Global Const MODGLOBAL = "GLOBAL" + +REM ----------------------------------------------------------------------------------------------------------------------- Type DocContainer Document As Object ' com.sun.star.comp.dba.ODatabaseDocument or SwXTextDocument or ScModelObj Active As Boolean @@ -205,9 +214,11 @@ Const cstSepar = "!" Set oMacLibraries = DialogLibraries vMacLibraries = oMacLibraries.getElementNames() 'Remove Access2Base from the list - For i = 0 To UBound(vMacLibraries) - If Left(vMacLibraries(i), 11) = "Access2Base" Then vMacLibraries(i) = "" - Next i + If _A2B_.ExcludeA2B Then + For i = 0 To UBound(vMacLibraries) + If Left(vMacLibraries(i), 11) = "Access2Base" Then vMacLibraries(i) = "" + Next i + End If vMacLibraries = Utils._TrimArray(vMacLibraries) If UBound(vDocLibraries) + UBound(vMacLibraries) < 0 Then ' No library @@ -394,6 +405,149 @@ Error_Function: End Function ' AllForms V0.9.0 REM ----------------------------------------------------------------------------------------------------------------------- +Public Function AllModules(ByVal Optional pvIndex As Variant, ByVal Optional pbAllModules As Boolean) As Variant +' Return either a Collection or a Module object +' The modules are selected only if library is loaded +' (UNPUBLISHED) pbAllModules = False collects only the modules located in the currently open document + + If _ErrorHandler() Then On Local Error Goto Error_Function +Const cstThisSub = "AllModules" + Utils._SetCalledSub(cstThisSub) + +Dim iMode As Integer, vModules() As Variant, i As Integer, j As Integer, iCount As Integer +Dim oMacLibraries As Object, vAllModules As Variant, oLibrary As Object, vNames() As Variant, bFound As Boolean +Dim sScript As String, sLibrary As String, oDocLibraries As Object, sStorage As String +Dim vLibraries() As Variant, vMacLibraries() As Variant, vDocLibraries() As Variant, oDocMacLib As Object +Const cstCount = 0, cstByIndex = 1, cstByName = 2 +Const cstDot = "." + + If IsMissing(pvIndex) Then + iMode = cstCount + Else + If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function + If VarType(pvIndex) = vbString Then + iMode = cstByName + ' Dtermine full name STORAGE.LIBRARY.MODULE + vNames = Split(pvIndex, cstDot) + If UBound(vNames) = 2 Then + ElseIf UBound(vNames) = 1 Then + pvIndex = MODDOCUMENT & cstDot & pvIndex + ElseIf UBound(vNames) = 0 Then + pvIndex = MODDOCUMENT & cstDot & "STANDARD" & cstDot & pvIndex + Else + GoTo Trace_Not_Found + End If + Else + iMode = cstByIndex + End If + End If + + If IsMissing(pbAllModules) Then pbAllModules = True + If Not Utils._CheckArgument(pbAllModules, 2, vbBoolean) Then Goto Exit_Function + + Set vAllModules = Nothing + + Set oDocLibraries = ThisComponent.BasicLibraries + vDocLibraries = oDocLibraries.getElementNames() + If pbAllModules Then + Set oMacLibraries = GlobalScope.BasicLibraries + vMacLibraries = oMacLibraries.getElementNames() + 'Remove Access2Base from the list + If _A2B_.ExcludeA2B Then + For i = 0 To UBound(vMacLibraries) + If Left(vMacLibraries(i), 11) = "Access2Base" Then vMacLibraries(i) = "" + Next i + End If + vMacLibraries = Utils._TrimArray(vMacLibraries) + End If + + If UBound(vDocLibraries) + UBound(vMacLibraries) < 0 Then ' No library + Set vAllModules = New Collect + vAllModules._CollType = COLLALLMODULES + vAllModules._ParentType = OBJAPPLICATION + vAllModules._ParentName = "" + vAllModules._Count = 0 + Goto Exit_Function + End If + + iCount = 0 + For i = 0 To UBound(vDocLibraries) + UBound(vMacLibraries) + 1 + bFound = False + If i <= UBound(vDocLibraries) Then + sLibrary = vDocLibraries(i) + sStorage = MODDOCUMENT + Set oDocMacLib = oDocLibraries + ' Sometimes library not loaded as should ?? + If Not oDocMacLib.IsLibraryLoaded(sLibrary) Then oDocMacLib.loadLibrary(sLibrary) + Else + sLibrary = vMacLibraries(i - UBound(vDocLibraries) - 1) + sStorage = MODGLOBAL + Set oDocMacLib = oMacLibraries + End If + If oDocMacLib.IsLibraryLoaded(sLibrary) Then + Set oLibrary = oDocMacLib.getByName(sLibrary) + If oLibrary.hasElements() Then + vModules = oLibrary.getElementNames() + Select Case iMode + Case cstCount + iCount = iCount + UBound(vModules) + 1 + Case cstByIndex, cstByName + For j = 0 To UBound(vModules) + If iMode = cstByIndex Then + If pvIndex = iCount Then bFound = True + iCount = iCount + 1 + Else + If UCase(pvIndex) = UCase(sStorage & cstDot & sLibrary & cstDot & vModules(j)) Then bFound = True + End If + If bFound Then + sScript = oLibrary.getByName(vModules(j)) ' Initiate Module object + iCount = i + Exit For + End If + Next j + End Select + End If + End If + If bFound Then Exit For + Next i + + If iMode = cstCount Then + Set vAllModules = New Collect + vAllModules._CollType = COLLALLMODULES + vAllModules._ParentType = OBJAPPLICATION + vAllModules._ParentName = "" + vAllModules._Count = iCount + Else + If Not bFound Then + If iMode = cstByIndex Then Goto Trace_Error_Index Else Goto Trace_Not_Found + End If + Set vAllModules = New Module + vAllModules._Name = vModules(j) + vAllModules._LibraryName = sLibrary + Set vAllModules._Library = oLibrary + vAllModules._Storage = sStorage + vAllModules._Script = sScript + vAllModules._Initialize() + End If + +Exit_Function: + Set AllModules = vAllModules + Utils._ResetCalledSub(cstThisSub) + Exit Function +Trace_Not_Found: + TraceError(TRACEFATAL, ERRMODULENOTFOUND, Utils._CalledSub(), 0, , pvIndex) + Goto Exit_Function +Trace_Error_Index: + TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0, 1) + Set vModules = Nothing + Goto Exit_Function +Error_Function: + TraceError(TRACEABORT, Err, cstThisSub, Erl) + Set vModules = Nothing + GoTo Exit_Function +End Function ' AllModules V1.7.0 + +REM ----------------------------------------------------------------------------------------------------------------------- Public Sub CloseConnection () ' Close all connections established by current document to free memory. |