Description
Browses the next library object, belonging to the same class (number of columns).
Syntax
BrowseLib |
Code
Public Sub BrowseLib()
Dim w = Page.GetSelectionWidth
Dim h = Page.GetSelectionHeight
Dim nPhoto As Short = 0
Dim sPhSuff As String = ""
Dim libname As String = ""
If Page.GetSelectionCount = 0 Then Exit Sub ' if no selection, nothing to browse
' get data of current selection
Dim aO = PushSelectionEx()
If aO(1, 34) > 0 Then
Dim oA = Fred.GetActiveArticle
Dim nTxt As Integer = oA.NTxts
For t = 0 To nTxt - 1
Dim objNode = oA.GetTxtNode(t)
If Left(objNode.Label, Len(photoname)) = photoname Then
nPhoto += 1
End If
Next
End If
' different objects are selected depending on number of columns
Dim nCols, nColsObj, nColsSel As Short
nColsObj = GetObjTypeProp(bodyname, aO, 4) ' get ncols from object, not from default grid
nColsSel = Int(w / (Page.GetColW + Page.GetInterCol) + 1) ' this is for ncols from default grid
If nColsSel > nColsObj Then
nCols = nColsSel
Else
nCols = nColsObj
End If
' different set of objects is selected for following ranges of heights
If h <= Units.ToVal(SystemUserOptions.fr_shortH) Then ' shorter than 100pt, head goes on left side
libname = SystemUserOptions.fr_shortLib
ElseIf h > Units.ToVal(SystemUserOptions.fr_shortH) And h <= Units.ToVal(SystemUserOptions.fr_medH) Then
libname = SystemUserOptions.fr_medLib
ElseIf h > Units.ToVal(SystemUserOptions.fr_medH) And h <= Units.ToVal(SystemUserOptions.fr_tallH) Then
libname = SystemUserOptions.fr_tallLib
ElseIf h > Units.ToVal(SystemUserOptions.fr_tallH) Then
libname = SystemUserOptions.fr_verytallLib
End If
If libname = "" Then libname = "defblocks"
Dim libId = Editorial.EditorialLogin.Get().GetLibraryId(libname)
If libId = 0 Then
MsgBox(String.Format(My.Resources.IDS_NoLib, libname), vbCritical, m_Label)
Return
End If
Dim libobjs = Editorial.EditorialLogin.Get().GetLibrary(libId)
Dim iNextIdx As Integer = IIf(SystemUserOptions.LibObjIdx = 1, 2, SystemUserOptions.LibObjIdx + 1)
If nPhoto > 0 Then sPhSuff = "p"
Dim objname = nCols & sPhSuff & iNextIdx
Dim maxIdx As Short = 9
Dim bRestart As Boolean = False
Dim bHasAny As Boolean = False
Dim bAnyIdx As Short = 0
Dim e As Integer = Page.AddLibObj(libname, objname, 0, 0, 1 + 4)
If e = 1202 Then ' object on iNextIdx is not found
' check if there are other objects for the same number of columns
Dim bNoFirst As Boolean = False
If iNextIdx = 1 Then bNoFirst = True ' this means the first object is missing
Do
iNextIdx += 1
If iNextIdx > maxIdx Then ' the max objects number is reached
If bNoFirst Then ' and the first was missing...this means no object was found at all
MsgBox(String.Format(My.Resources.IDS_NoObj, libname, nCols), vbCritical, m_Label)
Return
End If
bRestart = True
Exit Do ' no object found on idx >= iNextIdx
End If
objname = nCols & sPhSuff & iNextIdx
e = Page.AddLibObj(libname, objname, 0, 0, 1 + 4)
If e = 0 Then
bHasAny = True
bAnyIdx = iNextIdx
Exit Do ' an object is found on idx >= iNextIdx
End If
Loop
If bRestart Then
If bNoFirst Then
If bHasAny Then
SystemUserOptions.LibObjIdx = iNextIdx
Else
MsgBox(String.Format(My.Resources.IDS_NoObj, libname, nCols), vbCritical, m_Label)
Return
End If
Else
SystemUserOptions.LibObjIdx = 1
iNextIdx = 1
End If
End If
objname = nCols & sPhSuff & iNextIdx
e = Page.AddLibObj(libname, objname, 0, 0, 1 + 4)
If e = 1202 Then
MsgBox(String.Format(My.Resources.IDS_NoObj2, objname, libname), vbCritical, m_Label)
Return
End If
Else
SystemUserOptions.LibObjIdx = iNextIdx
End If
End Sub
All commands/scripts related to library objects