' Gambas module file

Private $aLine As String[]
Private $sId As String
Private $hForm As FEditor

Private $aIsType As String[] = ["IsBoolean", "IsByte", "IsShort", "IsInteger", "IsLong", "IsSingle", "IsFloat", "IsDate", "IsString", "IsObject"]

Private $aTestFunc As String[] = 
  ["Boolean?", "Byte?", "Short?", "Integer?", "Long?", "Single?", "Float?", "Date?", "String?", "Object?", "Number?", "Null?", "Dir?",
    "Ascii?", "Letter?", "LCase?", "Lower?", "UCase?", "Upper?", "Digit?", "Hexa?", "Space?", "Blank?", "Punct?"]


Private Sub AddDeclarationToClass(sPath As String, sDeclare As String)
  
  Dim aLine As String[]
  
  aLine = Split(File.Load(sPath), "\n")
  aLine.Add("", 1)
  aLine.Add(sDeclare, 2)
  If aLine[3] Then aLine.Add("", 3)
  File.Save(sPath, aLine.Join("\n"))
  
End


Private Sub ConvertForm(sPath As String)
  
  Dim hFile As File
  Dim sFullLine, sLine As String
  Dim sClass As String
  Dim aCoord As String[]
  Dim fW, fH As Float
  Dim iIndent As Integer
  Dim sVal As String
  Dim aVal As String[]
  Dim sName As String
  Dim sGroup As String
  Dim iLevel As Integer
  Dim cVirtualPos As New Collection
  Dim sNewClass As String
  Dim sProp As String
  Dim sValue As String
  Dim aScan As String[]
  
  $aLine = New String[]
  hFile = Open sPath 
  Line Input #hFile, sFullLine
  If sFullLine = Project.FORM_MAGIC Then Return
  $aLine.Add(Project.FORM_MAGIC)
  While Not Eof(hFile)
    Line Input #hFile, sFullLine
    sLine = LTrim(sFullLine)
    iIndent = Len(sFullLine) - Len(sLine)
    sLine = RTrim(sLine)
    'If Left(sLine) = "#" Then sLine = Mid$(sLine, 2)
    
    If Left(sLine) = "{" Then
      
      aVal = Split(Mid$(sLine, 2), " ", "", True)
      sName = aVal[0]
      sClass = aVal[1]
      sGroup = ""
      Try sGroup = aVal[2]
      'If Left(sClass) = "#" Then sClass = Mid$(sClass, 2)
      
      If sClass = "#TrayIcon" Then
        
        AddDeclarationToClass(File.SetExt(sPath, "class"), 
          If(Project.ControlPublic, "Public", "Private") & " " & sName & " As TrayIcon = New TrayIcon As " & Quote(If(sGroup, sGroup, sName)))
          
        Repeat
          Line Input #hFile, sFullLine
        Until Trim(sFullLine) = "}"
        Continue
        
      Endif
      
      If sClass = "URLLabel" Then
        sNewClass = "Label"
      Else If sClass = "WebBrowser" Then
        sNewClass = "WebView"
      Else If sClass = "ColorBox" Then
        sNewClass = "ColorButton"
      Else
        sNewClass = sClass
      Endif
      
      sFullLine = "{ " & sName & " " & sNewClass & " " & sGroup
      
      Inc iLevel
      cVirtualPos[iLevel] = 0
      
    Else If sLine = "}"
      Dec iLevel
    Else If sLine Begins "MoveScaled(" Then
      aCoord = Split(Mid$(sLine, 12, -1))
      If aCoord.Count = 4 Then
        fW = CFloat(aCoord[2])
        fH = CFloat(aCoord[3])
        If fW <= 3 Then Inc fW
        If fH <= 3 Then Inc fH
        sFullLine = "MoveScaled(" & aCoord[0] & "," & aCoord[1] & "," & CStr(fW) & "," & CStr(fH) & ")"
      Endif
    Else If sLine Begins "'Move" Then
      Continue
    Else
      
      aScan = Scan(sLine, "* = *")
      sProp = ""
      Try sProp = aScan[0]
      Try sValue = aScan[1]
      
      If sProp = "Border" Then
        If sClass = "Form" Then
          Select Case Trim(Scan(sLine, "*=*")[1])
            Case "Window.None"
              sFullLine = "Border = False"
            Case "Window.Resizable"
              Continue
            Case "Window.Fixed"
              sFullLine = "Resizable = False"
          End Select
        Endif
      Else If sProp == "ToolBox" Then
        If sClass = "Form" Then
          sFullLine = "Utility = " & sValue
        Endif
      Else If sLine Begins "List = " & Chr$(34) Then
        If sClass = "ListBox" Or If sClass = "ComboBox" Then
          sVal = UnQuote$(Trim(Mid$(sLine, 7)))
          aVal = Split(sVal, "\n")
          sFullLine = "List = " & CControl.StringArrayPropertyToString(aVal, True)
        Endif
      Else If sLine = "Text = (\"\")" Then
        Continue
      Else If sLine = "#(Scaled) = False" Then
        sFullLine = "#Scaled = False"
      Else If sProp = "URL" Then
        If sClass = "URLLabel" Then Continue
      Else If sProp = "#X" Then
        sFullLine = "#MoveScaled(" & cVirtualPos[iLevel - 1] & "," & cVirtualPos[iLevel - 1] & ")"
        Inc cVirtualPos[iLevel - 1]
      Else If sProp = "#Y" Then
        Continue
      Else If sProp = "Padding" Then
        If sClass <> "Label" And If sClass <> "TextLabel" Then
          sFullLine = "Margin = True"
          If CInt(sValue) <= 4 Then
            sFullLine &= "\nPadding = " & sValue
          Endif
        Endif
      Else If sProp = "Spacing" Then
        sFullLine = "Spacing = True"
      Else If sProp = "Arrangement" Then
        If sValue = "LeftRight" Then
          sFullLine = "Arrangement = Arrange.Row"
        Else If sValue = "TopBottom" Then
          sFullLine = "Arrangement = Arrange.Column"
        Endif
      Else If sClass = "WebBrowser" Then
        If ["Java", "JavaScript", "Path", "Plugins", "Zoom"].Exist(sProp) Then Continue
      Else If sClass = "ValueBox" Then
        If sProp = "MaxLength" Then Continue
      Endif
    Endif
    
    For Each sFullLine In Split(sFullLine, "\n")
      If Left(sFullLine) <> " " And If iIndent > 0 Then sFullLine = Space$(iIndent) & sFullLine
      $aLine.Add(sFullLine)
    Next
    
  Wend
  
  File.Save(sPath, $aLine.Join("\n"))
  
End

' Private Sub CheckAnalyze(aCheck As String[]) As Boolean
'   
'   Dim I, J As Integer
'   Dim aSym As String[] = Highlight.Symbols
'   Dim bNot As Boolean
'   Dim bTest As Boolean
'   
'   Highlight.Analyze(sLine)
'   
'   Do
'     If J >= aSym.Count And If I >= aCheck.Count Then Return False
'     If J >= aSym.Count Or If I >= aCheck.Count Then Return True
'     
'     sCheck = aCheck[I]
'     If Left(sCheck) = "!" Then
'       bTest = Not (aSym[J] Like Mid$(sCheck, 2))
'     Else
'       bTest = aSym[J] Like sCheck
'     Endif
'     
'     If bTest Then
'       Inc I
'     Else
'       J -= I
'       I = 0
'     Endif
'     Inc J
'   Loop
'   
' End


Private Sub CheckArrayInstanciation(sLine As String) As String
  
  Dim aSym As String[]
  Dim iPos As Integer
  Dim iInd As Integer
  
  aSym = Highlight.Analyze(sLine, True)
  
  If aSym.Count < 6 Then Return
  If Not ["DIM", "PRIVATE", "PUBLIC"].Exist(aSym[0], gb.IgnoreCase) Then Return
  
  iInd = 1
  
  Do
    If iInd > aSym.Max Then Return  
    If Highlight.Types[iInd] <> Highlight.Symbol Then Return
    Inc iInd
    If aSym[iInd] = "," Then
      Inc iInd
      Continue
    Endif
    If aSym[iInd] == "AS" Then 
      Inc iInd
      Break
    Endif
    Return
  Loop
  
  If iInd > (aSym.Max - 2) Then Return
  
  If Highlight.Types[iInd] <> Highlight.DataType Then Return
  If aSym[iInd + 1] <> "[" Then Return
  If aSym[iInd + 2] = "]" Then Return

  iPos = InStr(sLine, "AS " & aSym[iInd], 1, gb.IgnoreCase)
  sLine = Left(sLine, iPos - 1) & "As New " & Mid$(sLine, iPos + 3)
  
  $sId = "ARRD"
  Return sLine
  
Catch
  
End

Private Sub CheckOpen(sLine As String) As String
  
  Dim aSym As String[]
  Dim iPos As Integer
  Dim sVar As String
  Dim sTry As String
  
  aSym = Highlight.Analyze(sLine, True)
  
  If aSym.Count < 5 Then Return
  
  If aSym[iPos] == "TRY" Then 
    sLine = Trim(Mid$(sLine, 4))
    sTry = "Try "
    Inc iPos
  Endif
  If Not (aSym[iPos] == "OPEN") Then Return
  
  iPos = InStr(sLine, " AS ", 1, gb.IgnoreCase)
  If iPos = 0 Then Return
  
  sVar = Mid$(sLine, iPos + 4)
  If Left(sVar) = "#" Then sVar = Trim(Mid$(sVar, 2))
  sLine = sTry & sVar & " = " & Left(sLine, iPos - 1)
  
  $sId = "OPEN"
  Return sLine
  
Catch
  
End

Private Sub FindRightBrace(aSym As String[], iPos As Integer) As Integer
  
  Dim iLevel As Integer
  
  While iPos < aSym.Count
    Select Case aSym[iPos]
      Case ")", "]"
        Dec iLevel
        If iLevel = 0 Then Return iPos
      Case "(", "["
        Inc iLevel
    End Select
    Inc iPos
  Wend
  
  Return -1
  
End

Private Sub CheckQuestionMark(sLine As String) As String
  
  Dim aSym As String[]
  Dim I As Integer
  Dim bFound As Boolean
  
  aSym = Highlight.Analyze(sLine, True)
  
  For I = aSym.Max - 1 DownTo 0
    If $aTestFunc.Exist(aSym[I], gb.IgnoreCase) And aSym[I + 1] = "(" Then
      sLine = String.Left(sLine, Highlight.Positions[I]) & "Is" & Left(aSym[I], -1) & String.Mid$(sLine, Highlight.Positions[I + 1] + 1) 
      bFound = True
    Endif
  Next
  
  If Not bFound Then Return

  $sId = "QUES"
  Return sLine
  
Catch
  
End


Private Sub CheckIsType(sLine As String) As String
  
  Dim aSym As String[]
  Dim I, J As Integer
  Dim bFound As Boolean
  
  aSym = Highlight.Analyze(sLine, True)
  
  For I = aSym.Max DownTo 0 
    If $aIsType.Exist(aSym[I], gb.IgnoreCase) Then 
      J = FindRightBrace(aSym, I + 1)
      If J < 0 Then Continue
      sLine = String.Left(sLine, Highlight.Positions[I]) & "TypeOf" & String.Mid$(sLine, Highlight.Positions[I + 1] + 1, Highlight.Positions[J] - Highlight.Positions[I + 1] + 1) & " = gb." & Mid$(aSym[I], 3) & " " & String.Mid$(sLine, Highlight.Positions[J] + 2) 
      bFound = True
    Else If aSym[I] == "IsNumber" Then
      J = FindRightBrace(aSym, I + 1)
      If J < 0 Then Continue
      sLine = String.Left(sLine, Highlight.Positions[I]) & "TypeOf" & String.Mid$(sLine, Highlight.Positions[I + 1] + 1, Highlight.Positions[J] - Highlight.Positions[I + 1] + 1) & " <= gb.Float " & String.Mid$(sLine, Highlight.Positions[J] + 2) 
      bFound = True
    Endif
  Next
  
  If Not bFound Then Return
  
  $sId = "ISTY"
  Return sLine
  
Catch
  
End

Private Sub CheckQuoteShell(sLine As String) As String
  
  Dim aSym As String[]
  Dim I As Integer
  Dim bFound As Boolean
  
  aSym = Highlight.Analyze(sLine, True)
  
  For I = aSym.Max - 3 DownTo 0 
    If aSym[I] == "Quote" And If aSym[I + 1] = "." And If aSym[I + 2] == "Shell" And If aSym[I + 3] = "(" Then
      sLine = String.Left$(sLine, Highlight.Positions[I]) & "Shell$" & String.Mid$(sLine, Highlight.Positions[I + 3] + 1)
      bFound = True
    Endif
  Next
  
  If Not bFound Then Return
  
  $sId = "QUOT"
  Return sLine
  
End

Private Sub FindClassSymbol(sClass As String, sSymbol As String, aSym As String[], aType As Integer[], I As Integer, Optional bAllowAnonymous As Boolean) As Boolean

  Dim sType As String
  Dim hClass As CClassInfo
  
  If aSym[I] == sSymbol And If aSym[I - 1] = "." Then
    
    sType = $hForm.GetExpressionType(aSym.Copy(0, I - 1), aType.Copy(0, I - 1), True)
    
    If Not sType Then
      If bAllowAnonymous Then
        sType = sClass
      Else
        Return
      Endif
    Endif
    
    If sType <> sClass Then
      hClass = Project.Documentation.Classes[sType]
      If Not hClass Then Return
      If Not hClass.Inherits(sClass) Then Return
    Endif
    
    Return True
    
  Endif
  
End


Private Sub CheckReplaceClassSymbol(sId As String, sLine As String, sClass As String, sSymbol As String, sNewSymbol As String, Optional bAllowAnonymous As Boolean) As String
  
  Dim aSym As String[]
  Dim I As Integer
  Dim aPos As Integer[]
  Dim aType As Integer[]
  Dim sRest As String
  
  aSym = Highlight.Analyze(sLine, False).Copy()
  aType = Highlight.Types.Copy()
  aPos = Highlight.Positions.Copy()
  
  For I = aSym.Max DownTo 1
    
    If FindClassSymbol(sClass, sSymbol, aSym, aType, I, bAllowAnonymous) Then
      
      sRest = String.Mid$(sLine, aPos[I] + Len(sSymbol) + 1)
      If sId = "FNTH" And If sRest Begins "()" Then sRest = "(\"\")" & Mid$(sRest, 3)
      sLine = String.Left$(sLine, aPos[I]) & sNewSymbol & sRest
      $sId = sId
      Return sLine
      
    Endif
    
  Next
  
End

Private Sub CheckUdpSocketBind(sId As String, sLine As String) As String
  
  Dim aSym As String[]
  Dim I As Integer
  Dim aPos As Integer[]
  Dim aType As Integer[]
  Dim sRest As String
  
  aSym = Highlight.Analyze(sLine, False).Copy()
  aType = Highlight.Types.Copy()
  aPos = Highlight.Positions.Copy()
  
  For I = aSym.Max DownTo 1
    
    If FindClassSymbol("UdpSocket", "Bind", aSym, aType, I) Then
      
      sRest = String.Mid$(sLine, aPos[I] + Len("Bind") + 1)
      If Left(sRest) <> "(" Then Return
      If Mid$(sRest, 2, 1) = ")" Then Return
      
      sLine = String.Left$(sLine, aPos[I]) & "Port = " & Mid$(sRest, 2, -1) & "\n" & String.Left$(sLine, aPos[I] + Len("Bind")) & "()"
      $sId = sId
      Return sLine
      
    Endif
  
  Next
  
End


Private Sub CheckSplitterLayout(sId As String, sLine As String) As String
  
  Dim aSym As String[]
  Dim I As Integer
  Dim aPos As Integer[]
  Dim aType As Integer[]
  Dim iPos As Integer
  Dim iStart As Integer
  
  aSym = Highlight.Analyze(sLine, False).Copy()
  aType = Highlight.Types.Copy()
  aPos = Highlight.Positions.Copy()
  
  For I = aSym.Max DownTo 1
    
    If FindClassSymbol("HSplit", "Layout", aSym, aType, I) Or If FindClassSymbol("VSplit", "Layout", aSym, aType, I) Then
      
      If I <= (aSym.Max - 2) And If aSym[I + 1] = "=" And InStr(String.Left(sLine, aPos[I]), "(") = 0 Then ' Assignment detection badly done
      
        If UCase(aSym[I + 2]) <> "SPLIT" Then
          sLine = String.Left$(sLine, aPos[I + 1]) & " = Split(" & String.Mid$(sLine, aPos[I + 2] + 1) & ", \",\")"
          $sId = sId
          Return sLine
        Endif
      
      Else
        
        If I <= (aSym.Max - 3) And If aSym[I + 1] = ")" And If aSym[I + 2] = "." And If UCase(aSym[I + 3]) = "JOIN" Then Continue
        
        iStart = FEditor.ExpressionStart
        iPos = aPos[I] + Len("Layout")
        
        sLine = String.Left$(sLine, aPos[iStart]) & "String[](" & String.Mid$(sLine, aPos[iStart] + 1, iPos - aPos[iStart]) & ").Join(\",\")" & String.Mid$(sLine, iPos + 1)
        $sId = sId
        Return sLine
        
      Endif
      
    Endif
      
  Next
  
End


Private Sub CheckReplaceFunction(sId As String, sLine As String, sFunc As String, sNewFunc As String) As String
  
  Dim aSym As String[]
  Dim I As Integer
  Dim bFound As Boolean
  Dim aPos As Integer[]
  Dim sRest As String
  
  aSym = Highlight.Analyze(sLine, False)
  aPos = Highlight.Positions
  
  For I = 1 To aSym.Max - 1
    
    If aSym[I] == sFunc And If aSym[I + 1] = "(" Then
      
      sRest = Mid$(sLine, aPos[I] + Len(sFunc) + 1)
      'If sId = "FNTH" And If sRest Begins "()" Then sRest = "(\"\")" & Mid$(sRest, 3)
      sLine = Left$(sLine, aPos[I]) & sNewFunc & sRest
      bFound = True
      
      aSym = Highlight.Analyze(sLine, False)
      aPos = Highlight.Positions
      
    Endif
    
  Next
  
  If Not bFound Then Return
  
  $sId = sId
  Return sLine
  
End

Private Sub CheckPublicProperty(sLine As String) As String
  
  Dim aSym As String[]
  Dim iPos As Integer
  Dim bStatic As Boolean
  Dim bPublic As Boolean
  
  aSym = Highlight.Analyze(sLine, True)
  
  If aSym.Count < 5 Then Return
  
  For iPos = 0 To 3
    If UCase(aSym[iPos]) = "PUBLIC" Then 
      bPublic = True
      Continue
    Endif
    If UCase(aSym[iPos]) = "STATIC" Then 
      bStatic = True
      Continue
    Endif
    Break
  Next
  
  If Not bPublic Then Return
  If UCase(aSym[iPos]) <> "PROPERTY" Then Return
  
  $sId = "PPRO"
  iPos = InStr(sLine, "PROPERTY ", 1, gb.IgnoreCase)
  sLine = "Property " & Mid$(sLine, iPos + 9)
  If bStatic Then sLine = "Static " & sLine
  Return sLine
  
Catch
  
End

Private Sub CheckNewKeyword(sLine As String) As String

  Dim aSym As String[]
  Dim iPos As Integer
  Dim bRepl As Boolean

  Do
    
    aSym = Highlight.Analyze(sLine, True)
    
    iPos = aSym.Find("ON", gb.IgnoreCase)
    If iPos < 0 Then Break
    
    iPos = Highlight.Positions[iPos]
    sLine = Left$(sLine, iPos) & "{On}" & Mid$(sLine, iPos + 3)
    bRepl = True
    
  Loop
  
  If bRepl Then 
    $sId = "KEYW"
    Return sLine
  Endif

End

Private Sub CheckEventAs(sLine As String) As String
  
  Dim aSym As String[]

  aSym = Highlight.Analyze(sLine)
  
  If aSym.Count <= 3 Then Return
  
  If aSym[0] == "EVENT" And If aSym[aSym.Max - 1] = "AS" Then
    $sId = "EVAS"
    sLine = Left$(sLine, Highlight.Positions[aSym.Max - 1] - 1)
    Return sLine
  Endif
  
  
End


Private Sub ConvertClass(sPath As String)
  
  Dim sLine As String
  Dim hEditor As TextEditor
  Dim iLine As Integer
  Dim sNewLine As String
  Dim sIndent As String
  Dim aLine As String[]
  Dim iInd As Integer
  
  $aLine = New String[]
  
  $hForm = Project.LoadFile(sPath)
  hEditor = $hForm.GetEditor()
  
  For iLine = 0 To hEditor.Count - 1
    
    hEditor.Goto(0, iLine)
    sLine = hEditor[iLine].Text
    
    If Left(LTrim(sLine)) <> "'" Then
      
      sIndent = hEditor.GetIndent(iLine)
      sLine = Trim(sLine)
      
      Do
      
        $sId = ""
        
        sNewLine = CheckArrayInstanciation(sLine) 
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckOpen(sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckQuestionMark(sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckIsType(sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckQuoteShell(sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("FNTH", sLine, "Font", "Height", "TextHeight")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("FNTW", sLine, "Font", "Width", "TextWidth")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("BCOL", sLine, "Control", "BackColor", "Background", True)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("FCOL", sLine, "Control", "ForeColor", "Foreground", True)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("BCOL", sLine, ".GridViewData", "BackColor", "Background", True)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("FCOL", sLine, ".GridViewData", "ForeColor", "Foreground", True)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("BCOL", sLine, "Draw", "BackColor", "Background", True)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("FCOL", sLine, "Draw", "ForeColor", "Foreground", True)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("DBGV", sLine, "DataBrowser", "GridView", "View")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceClassSymbol("TEXT", sLine, "gb", "Text", "IgnoreCase")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceFunction("CSNG", sLine, "CSng", "CSingle")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceFunction("CLNG", sLine, "CLng", "CLong")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckReplaceFunction("CFLT", sLine, "CFlt", "CFloat")
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckUdpSocketBind("BIND", sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckSplitterLayout("SLAY", sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckPublicProperty(sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckNewKeyword(sLine)
        If sNewLine Then Goto NEW_LINE
        
        sNewLine = CheckEventAs(sLine)
        If sNewLine Then Goto NEW_LINE
        
        $aLine.Add(sIndent & sLine)
        Break

      NEW_LINE:

        $aLine.Add(sIndent & "' [GB2:" & $sId & "] " & sLine)
        '$aLine.Add(sIndent & sNewLine)
        
        If InStr(sNewLine, "\n") Then
          aLine = Split(sNewLine, "\n")
          For iInd = 0 To aLine.Max - 1
            $aLine.Add(sIndent & aLine[iInd])
          Next
          sNewLine = aLine[aLine.Max]
        Endif
        
        sLine = sNewLine
        
      Loop
      
    Else
      
      $aLine.Add(sLine)
      
    Endif
    
  Next
  
  File.Save(sPath, $aLine.Join("\n"))
  $hForm.Delete
  $hForm = Null
  Project.Files[sPath] = Null
  
'Catch
  
'  Print Error.Where; ": "; Error.Text
    
End


Public Sub ConvertFile(sPath As String)
  
  Select Case File.Ext(sPath)
    
    Case "module", "class"
      ConvertClass(sPath)
    Case "form"
      ConvertForm(sPath)
    
  End Select
  
End

Public Sub ConvertComponent(sComp As String) As String[]
  
  Dim aComp As String[]
  Dim iInd As Integer
  Dim hComp As CComponent
  
  Select Case sComp
    Case "gb.qt"
      aComp = ["gb.qt4"]
    Case "gb.qt.ext"
      aComp = ["gb.qt4.ext"]
    Case "gb.qt.kde.html"
      aComp = ["gb.qt4.webkit"]
    Case "gb.gtk.svg"
      aComp = New String[]
    Case "gb.image"
      aComp = ["gb.image.effect"]
    Default
      aComp = [sComp]
  End Select
  
  While iInd < aComp.Count
    
    hComp = Project.Documentation[aComp[iInd]]
    If hComp Then
      For Each sComp In hComp.Require
        If Not aComp.Exist(sComp) Then aComp.Add(sComp)
      Next
    Endif
    Inc iInd
    
  Wend
  
  Return aComp
  
End

