Guidance
指路人
g.yi.org
software / rapidq / Examples / Tools - IDE, Designer, Builder / FreeQ IDE src / inc ide / ide_subs.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
      '******************* FUNCTIONS & SUBROUTINES *****************************

     SUB ParseSubIncRes(indx AS INTEGER, SourceText AS STRING)
      DEFINT i,  Cnt = 0, SubsFound = 0, CommFound = 0
      DEFSTR Search
      SCREEN.Cursor = crHourGlass

      tmpList.Text = SourceText

      MainListBoxIncludes.Clear                       'clear out, we are going to add items
      IDE.ListIncludes(indx).Clear                    'clear backups too
      MainListBoxResources.Clear
      IDE.ListResources(indx).Clear
      SubFuncListView(indx).Clear                     'clear listview
      SubFuncListView(indx).SortType = stNone         'wait for it...

      DEFSTR InclStr = "$"
      IF IDE.ModuleType(MFE_Tab.TabIndex) > 0 THEN InclStr = "#"          'compatible with freebasic
      InclStr = InclStr + "INCLUDE "


      FOR i = 0 TO tmpList.ItemCount - 1
       Search = LTRIM$(UCASE$(tmpList.Item(i)))
       IF (LEFT$(Search, 4) = "SUB ") THEN
            'put all information on one line for easy sorting, name, line#, image index ...  can separate subs from functions by first char as  CHR$(171) +
        SubFuncListView(indx).AddItems DELETE$(LTRIM$(tmpList.Item(i)), 1, 4) + SPACE$(90) + LineNumDelimitr + STR$(i) + LineNumDelimitr + "0"
'            SubFuncListView(indx).Item(Cnt).ImageIndex = 0
'            SubFuncListView(indx).AddSubItem Cnt, STR$(i)      'problem with sorting
        Cnt++
        SubsFound++

       ELSEIF (LEFT$(Search, 9) = "FUNCTION ") THEN
        SubFuncListView(indx).AddItems DELETE$(LTRIM$(tmpList.Item(i)), 1, 9) + SPACE$(90) + LineNumDelimitr + STR$(i) + LineNumDelimitr + "1"
        Cnt++
        SubsFound++

       ELSEIF (LEFT$(Search, 9) = InclStr) THEN
        Search = DELETE$(TRIM$( tmpList.Item(i) ), 1, 9)
        CommFound = RINSTR(Search, sQuot)                                    'get comments out
        IF  CommFound > 0 THEN Search = RTRIM$(LEFT$(Search, CommFound-1))
        CommFound = RINSTR(Search, Quot$)
        IF CommFound > 0 THEN
         MainListBoxIncludes.AddItems REPLACESUBSTR$(Search , Quot$ , "")  'hope quotes are not in file/path
         IDE.ListIncludes(indx).AddItems REPLACESUBSTR$(Search , Quot$ , "")  'make a backup for multiple file
        ELSE
         CommFound = RINSTR(Search, ">")                                 'get default inc path files
         IF CommFound > 0 THEN
          Search = REPLACESUBSTR$(Search , "<" , "")
          Search = REPLACESUBSTR$(Search , ">" , "")

          IF FILEEXISTS(Search) THEN
           MainListBoxIncludes.AddItems Search
           IDE.ListIncludes(indx).AddItems Search  'make a backup for multiple file
          ELSE
           IF FILEEXISTS(StripPath(IDE.MFEActiveFile) + Search) THEN
            MainListBoxIncludes.AddItems (StripPath(IDE.MFEActiveFile) + Search)
            IDE.ListIncludes(indx).AddItems (StripPath(IDE.MFEActiveFile) + Search)
           ELSE
            MainListBoxIncludes.AddItems IDE.CompilerIncPath + "\" + Search
            IDE.ListIncludes(indx).AddItems IDE.CompilerIncPath + "\" + Search  'make a backup for multiple file
           END IF
          END IF
         END IF
        END IF

       ELSEIF (LEFT$(Search, 10) = "$RESOURCE ") THEN
        Search = DELETE$(TRIM$( tmpList.Item(i) ), 1, 10)
        CommFound = RINSTR(Search, sQuot)                                    'get comments out
        IF  CommFound > 0 THEN Search = RTRIM$(LEFT$(Search, CommFound-1))
        CommFound = RINSTR(Search, Quot$)
        IF CommFound > 0 THEN
         MainListBoxResources.AddItems REPLACESUBSTR$(Search , Quot$ , "")  'hope quotes are not in file/path
         IDE.ListResources(indx).AddItems REPLACESUBSTR$(Search , Quot$ , "")  'make a backup for multiple file
        END IF

       ELSEIF (LEFT$(Search, 8) = "PRIVATE ") OR (LEFT$(Search, 7) = "PUBLIC ") THEN

        IF INSTR( LEFT$(Search, 12), " SUB ") THEN
         SubFuncListView(indx).AddItems DELETE$(LTRIM$(tmpList.Item(i)), 1, 11) + SPACE$(90) + LineNumDelimitr + STR$(i) + LineNumDelimitr + "0"
         Cnt++
         SubsFound++
        ELSE
         IF INSTR( LEFT$(Search, 18), " FUNCTION ") THEN
          SubFuncListView(indx).AddItems DELETE$(LTRIM$(tmpList.Item(i)), 1, 16) + SPACE$(90) + LineNumDelimitr + STR$(i) + LineNumDelimitr + "1"
          Cnt++
          SubsFound++
         END IF
        END IF

       END IF
      NEXT i

      tmpList.Text = ""                            'dealloc
      MainListBoxIncludes.ItemIndex = 0
      MainListBoxResources.ItemIndex = 0
      IF IDE.SortSubs THEN SubFuncListView(indx).SortType = stText         'now sort it..
      FOR i = 0 TO SubFuncListView(indx).ItemCount-1  'align icons now
       SubFuncListView(indx).Item(i).ImageIndex = VAL(FIELD$(SubFuncListView(indx).Item(i).CAPTION, LineNumDelimitr, 3))      'get value from line, SubItem crashes
      NEXT i

'    IF SubsFound > 0 THEN
      IF IDE.ShowSubsAfterLoad THEN              'switch to show the list of subs functions
       ProjPanel.Visible = False
       IncResPanel.Visible = False                 'turn off other panels
       FindAllPanel.Visible = False
       SubFuncsPanel.Visible = True
       TabControl3.TabIndex = 3
       SubFuncListView(indx).Visible = True
       SubFuncListView(indx).ItemIndex = 0
      END IF
'    END IF
      SCREEN.Cursor = 0
     END SUB




     SUB SubsCombo_Change_objects(Sender AS QCOMBOBOX)
      DEFSTR tmp = FIELD$(Sender.Item(Sender.ItemIndex), LineNumDelimitr, 2)
      DEFINT TheLineNum = VAL(tmp)

      re.GotoLine(TheLineNum)
      re.ActiveLineColor(RGB(255,200,128), 0)
      IDE.HiLightTurnOFF = True                                       'toggle to turn off compile error line
      re.SetFocus
     END SUB


     SUB IDE_GotoLineNumber
      gDialogLabel.CAPTION = "Go to line number:"
      gListOkButton.Tag = 1                       'signal this is for go to line
      gDialogEdit.Text = ""
      gDialogEdit.Width = 150
      gDialogForm.Width = 270
      gDialogOKButton.Left = 160
      gDialogCancelButton.Left = 200
      gDialogForm.Show
      SetFocus gDialogEdit.Handle
     END SUB


     SUB IDE_NextParagraph
      re.SetFocus
      re.FindLocation(CRLF+CRLF, 0, 0, 0)
      re.SetFocus
'     DEFINT i = re.Position                                        'no go
'     re.Set_AnchorPosition(i)                                        'remove selection
'     DEFINT r = re.FindLocation(CRLF+"SUB ", 0, 1, 0)               'keeps finding first one!!
'     re.Set_Position(i)
'     DEFINT r2 = re.FindLocation(CRLF+"FUNCTION", 0, 1, 0)
'     IF (r <> -1) AND (r2 <> -1) THEN
'         IF r < r2 THEN
'             re.Set_Position(r):     re.Set_AnchorPosition(r)
'         ELSE
'             re.Set_Position(r2):    re.Set_AnchorPosition(r2)
'         END IF
'     ELSE
'         re.Set_Position(i)
'     END IF
     END SUB


     SUB IDE_PrevParagraph
      re.SetFocus
      re.FindLocation(CRLF+CRLF, 0, 1, 1)
      re.SetFocus
     END SUB


     SUB IDE_CopyNameToClip
      Clipboard.OPEN
      ClipBoard.Text = IDE.MFEActiveFile
      ClipBoard.CLOSE
     END SUB



     SUB IDE_ExploreFolder_Click
      ShellExecute (0, "Open", StripPath(IDE.MFEActiveFile), "", "", 1)
     END SUB



     SUB RedoClick
      re.SendEditor(SCI_REDO, 0, 0)
      IF re.GetEditor(SCI_CANREDO, 0, 0) = 0 THEN RedoMenu.Enabled = False ELSE RedoMenu.Enabled = True
'    IF re.GetEditor(SCI_CANUNDO, 0, 0) = 0 THEN RedoMenu.Enabled = False ELSE RedoMenu.Enabled = True
     END SUB

     SUB UndoClick
      re.SendEditor(SCI_UNDO, 0, 0)
'     IF re.GetEditor(SCI_CANREDO, 0, 0) = 0 THEN RedoMenu.Enabled = False ELSE RedoMenu.Enabled = True
'     IF re.GetEditor(SCI_CANUNDO, 0, 0) = 0 THEN RedoMenu.Enabled = False ELSE RedoMenu.Enabled = True
     END SUB


     SUB CutClick
      re.CutToClipboard
     END SUB

     SUB CopyClick
      re.CopyToClipboard
     END SUB

     SUB PasteClick
      re.PasteFromClipboard
      re.Set_LineNumbers(Mnu_SetLineNumbers.Checked)          'reset line number width
     END SUB

     SUB SelectAllClick
      re.SelectAll
     END SUB


     SUB PrintClick
      LPRINT re.Text
      LFLUSH
     END SUB



     SUB IconsetClick
      IF MESSAGEDLG("Set to default icon?", mtConfirmation, mbYes OR mbNo, 0) = mrNo THEN

       DIM OpenDialog AS QOPENDIALOG
       OpenDialog.CAPTION = "Open icon for application"
       OpenDialog.FileName = IDE.IconName
       OpenDialog.Filter = "Icon Files (*.ico)|*.ico"
       IF OpenDialog.EXECUTE THEN
        IF FILEEXISTS(OpenDialog.FileName) THEN
         IDE.IconName = OpenDialog.FileName
         IconsetFlatButton.Hint = IDE.IconName
         IconsetFlatButton.Stretch = True
         IconsetFlatButton.AutoSize = True
         IconsetFlatButton.Icon = IDE.IconName
        END IF
       END IF

      ELSE

       IDE.IconName = ""           'setting to null makes default RQ icon
       IconsetFlatButton.ICOHandle = RapidQ_ico
      END IF

     END SUB



     SUB FBDLLClick
      DEFSTR tmp = IDE.FBCommandLine
      IDE.FBCommandLine = "-s gui -dll -b "
      FBCompileClick
      IDE.FBCommandLine = tmp
     END SUB



     SUB FBCompileClick
      DEFSTR TheCurrDir = CURDIR$                                 'get current working directory
      DIM TheCompilerScript AS STRING
      IDE.CompiledOK = False

      IF IDE.SaveAllBeforeCompile THEN                            'do saving if needed
       MFE_SaveAll
      ELSE
       IF IDE.SaveFileBeforeCompile THEN MFE_Save
      END IF

      RichEditCompile.Clear

    'run a batch, or script before compiling
      IF TRIM$(IDE.ScriptBeforeCompile) <> "" THEN Execute_ExternalApp(IDE.ScriptBeforeCompile)

    'want a compile script like this "\program files\freebasic\fbc.exe" -s gui "myprog.bas" > out.$$$
      TheCompilerScript = Quot$                'set up
      IF IDE.FBCompilerPath <> "" THEN
       TheCompilerScript = TheCompilerScript + IDE.FBCompilerPath + Quot$
      ELSE
       TheCompilerScript = TheCompilerScript + IDE_Conf_FBHelpFilePathEdit.Text + Quot$     'gotta do something
      END IF

      DEFSTR TheExeName = IDE.MFEActiveFile
      IF IDE.MainFileForCompiler <> "" THEN TheExeName = MFE_List.Item(MFE_GetFileIndex(IDE.MainFileForCompiler))

      IF TRIM$(IDE.FBCommandLine) <> "" THEN
       TheCompilerScript = TheCompilerScript + " " + TRIM$(IDE.FBCommandLine) + " " + Quote$(TheExeName) + " >DUMP.$$$"
      ELSE
       TheCompilerScript = TheCompilerScript + " " + Quote$(TheExeName) + " >DUMP.$$$"
      END IF


    'now run the script to compile
      RichEditCompile.AddStrings "Please wait, compiling..."
      SetCompileDirectory(StripPath(TheExeName))              'set our path
      CHDIR IDE.Path
      tmpList.Text = TheCompilerScript
      RichEditCompile.AddStrings tmpList.Text
      DOEVENTS

'    tmpList.Text = ShellReDir (TheCompilerScript, cmdlne, SW_SHOW)
      tmplist.SaveTofile "~~dump$$$.bat"                      'can't get DOS redirect to work alone with SHELL !!!
      DEFINT PID = SHELL("~~dump$$$.bat" , 0)                 'run the bat file instead
      RichEditCompile.AddStrings "Process ID Compiler = " + STR$(PID)
      WaitForSingleObject(PID , &HFFFF)
      DOEVENTS

      tmpList.LoadFromFile "DUMP.$$$"                         'rc.exe dumps results to this file
      KILL "DUMP.$$$"                                         'del temp file
      KILL "~~dump$$$.bat"                                    'del temp file
      RichEditCompile.AddStrings tmpList.Text
      DOEVENTS                   				                'update Richedit

    '---- parse for an error message, usually like
    'hello.bas(26) error 41: Variable not declared, xxx in 'xxx'END SUB
    'where (26) is the line #

      DEFINT LineInDump = -1                                  'get line with error, -1 = no errors
      DEFSTR TheErrLine = ""
      DEFINT i

      FOR i = 0 TO tmpList.ItemCount -1
        '*****  parse for line with error  *****

       TheErrLine = tmpList.Item(i)
       IF (INSTR(TheErrLine, "(") )  < (INSTR(2, TheErrLine, ") error")) THEN
        LineInDump = INSTR(TheErrLine, "(")                                     'temp, find start delimiter
        LineInDump = VAL(MID$(TheErrLine, LineInDump +1, INSTR(TheErrLine, ")") - LineInDump ) )

            '*****  parse for file with error   *****
        TheErrLine = TRIM$(LEFT$(TheErrLine, INSTR(TheErrLine, "(") -1))
        TheErrLine = REPLACESUBSTR$(TheErrLine, "/", "\")
        EXIT FOR
       END IF
      NEXT i

      IF IDE.HiLightCompileErr THEN
       IF (LineInDump > -1) THEN                                   'we have an error
        i = MFE_GetFileIndex(TheErrLine)                        'switch to that file
        IF i <> -1 THEN
         MFE_ChangeToIndex(i)                                '-1 means did not find file
         RichEditCompile.AddStrings "Alt + <right click> to go to line"
         re.GotoLine(LineInDump -1)                          'will go to start of line
         re.ActiveLineColor(RGB(255,200,128), 0)             'set bright red line error
         IDE.HiLightTurnOFF = True                           'toggle to turn off compile error line
         re.SetFocus
        ELSE
         SHOWMESSAGE "module " + TheErrLine + " not found in project"
        END IF
       END IF
      END IF

      CHDIR TheCurrDir            'go back to original directory before compile
      SCREEN.Cursor = crDefault
      tmpList.Text = ""           'dealloc
      tmpList.Clear               'dealloc
      IDE.CompiledOK = True

     END SUB



     SUB FBrunClick
      FBCompileClick
      IF IDE.CompiledOK = False THEN EXIT SUB             'bad compile
      DIM exeName AS STRING

      IF IDE.MainFileForCompiler <> "" THEN
       exeName = REPLACE$(IDE.MainFileForCompiler , ".exe" , LEN(IDE.MainFileForCompiler) - 3)
      ELSE
       exeName = REPLACE$(IDE.MFEActiveFile , ".exe" , LEN(IDE.MFEActiveFile) - 3)
      END IF

'    DEFSTR tmpDir = CURDIR$
      SetCompileDirectory(StripPath(exeName))              'set our path if needed
      CHDIR IDE.Path
      RUN "rundll32.exe url.dll,FileProtocolHandler " & exename
'    CHDIR tmpDir
     END SUB




     SUB CompileClick
    'rapidq command line parameters
    ' -CONS Generate CONSOLE App
    ' -GUI Generate GUI App
    ' -I<Path> Change Include Path
    ' -L<Path> Change Library Path
    ' -opt Turn on Optimizations
    ' -o Unix mode, GTK (Linux)
    ' -b Dump byte code only
    ' -g<Path\Filename.ico>
    ' -d<NAME> Add definition NAME
	' -vON|OFF Toggle verbose output
    ' -r output to DUMP.$$$

      IDE.CompiledOK = False                                      'set to fail in case we bail
      IF MFE_List.ItemCount = 0 THEN EXIT SUB                     'no file loaded, bail out otherwise crash

      DEFSTR TheExeName = ""                                      'executable file name
      DEFSTR TheCompilerScript = ""                               'compile line
      DEFSTR TheCurrDir = CURDIR$                                 'get current working directory
      DEFINT PID = 0                                              'external process ID
      DEFINT AddIcoAfterCompile = False                           'for adding icon larger than 766 bytes
      DEFINT i
'    Prog.Visible = True
      SCREEN.Cursor = crHourGlass

    'add TYPECHECK ON if requested before save
      IF IDE.TypeCheckOn THEN
       IF IDE.MainFileForCompiler <> "" THEN
        i = MFE_GetFileIndex(IDE.MainFileForCompiler)           'get tab for main compiler file
       ELSE
        i = MFE_Tab.TabIndex                                    'else get current tab
       END IF
       IF IDE.ModuleType(i) = 0 THEN IDE_InsertTypeCheck(i)        'insert TYPECHECK ON only for RapidQ
      END IF


    'Perform save operations if needed
      IF IDE.SaveAllBeforeCompile THEN
       MFE_SaveAll
      ELSE
       IF IDE.SaveFileBeforeCompile THEN MFE_Save
      END IF

    '---- set filename for compile TheExeName still has source file extension -----

      IF IDE.DebugFileName = "" THEN

       IF IDE.MainFileForCompiler <> "" THEN
        IF FILEEXISTS(IDE.MainFileForCompiler) = False THEN
         SHOWMESSAGE "File " + IDE.MainFileForCompiler + " does not exist"
         SCREEN.Cursor = crDefault
                'Prog.Visible = False
         EXIT SUB
        END IF
        TheExeName = MFE_List.Item( MFE_GetFileIndex(IDE.MainFileForCompiler) )
       ELSE
        TheExeName = IDE.MFEActiveFile
       END IF

      ELSE
       TheExeName = IDE.DebugFileName          'compile a debug file
      END IF


    '---- run a batch, or script before compiling -----
      RichEditCompile.Clear
      IF TRIM$(IDE.ScriptBeforeCompile) <> "" THEN
       RichEditCompile.AddStrings "executing pre-script..."
       Execute_ExternalApp(IDE.ScriptBeforeCompile)
      END IF


    '---- concatenate a command line for compiling -----
      TheCompilerScript = Quot$                               'setup
      IF IDE.CompilerPath <> "" THEN
       TheCompilerScript = TheCompilerScript + IDE.CompilerPath + Quot$ + " "
      ELSE
       TheCompilerScript = TheCompilerScript + "rc.exe" + Quot$ + " "               'gotta do something
      END IF
      TheCompilerScript = TheCompilerScript + "-r "
      IF IDE.OptimizeOn THEN TheCompilerScript = TheCompilerScript + "-opt "
      IF IDE.VerboseOn THEN TheCompilerScript = TheCompilerScript + "-vON "
      IF IDE.ByteCodeOn THEN TheCompilerScript = TheCompilerScript + "-b "
      IF IDE.CompilerLibPath <> "" THEN TheCompilerScript = TheCompilerScript + Quote$("-L" + IDE.CompilerLibPath) + " "
      IF IDE.CompilerIncPath <> "" THEN TheCompilerScript = TheCompilerScript + Quote$("-I" + IDE.CompilerIncPath) + " "


    '------ check icon size is standard ------------
      IF IDE.IconName <> "" THEN
       gFStream.OPEN(IDE.IconName , fmOpenRead)
       i = gFStream.Size
       gFStream.CLOSE
       IF i = 766 THEN
        TheCompilerScript = TheCompilerScript + "-g" + Quote$(IDE.IconName) + " "     'yes standard size
       ELSE
        AddIcoAfterCompile = True                                                           'no larger 32-bit, add after compile
       END IF
      END IF


    '---- add the filename to the compile line, TheExeName still has source file extension -----
      TheCompilerScript = TheCompilerScript + Quote$( TheExeName)
      RichEditCompile.AddStrings "Please wait, compiling..." + TheCompilerScript
      SetCompileDirectory(StripPath(TheExeName))
      CHDIR IDE.Path

    '---- Now set filename to executable file extension -----
      IF INSTR(TheExeName, ".") THEN TheExeName = FileNameNoExt(TheExeName) + ".exe"
      DOEVENTS                   				                        'update Richedit

    '---- now do the whole thing  -----
      PID = SHELL(TheCompilerScript , 1)                              'start the compile process
      IF PID THEN
       RichEditCompile.AddStrings "Process ID Compiler =" + STR$(PID)
       DOEVENTS
       WaitForSingleObject(PID , &HFFFF)
'        DEFDBL t = TIMER
'        DO
'            DOEVENTS
'        LOOP UNTIL (FILEEXISTS ("DUMP.$$$") = True) OR (TIMER - t) > 1200    'rc.exe dumps results to this file
      ELSE
       SHOWMESSAGE "Error: cannot start compiler. Process already active?"
       SCREEN.Cursor = crDefault
        'Prog.Visible = False
       EXIT SUB
      END IF

      IF FILEEXISTS ("DUMP.$$$") = False THEN                   'rc.exe dumps results to this file
       RichEditCompile.AddStrings "Error, could not complete compile..."
       EXIT SUB
      END IF
      tmpList.LoadFromFile "DUMP.$$$"
      KILL "DUMP.$$$"                                         'del temp file
      RichEditCompile.Text = tmpList.Text
      DOEVENTS                   				                'update Richedit


    '---- parse for an error message, usually like
    'Line 7, 10: Expected = but got end-of-line  OR
    'Line 437: ERROR: Dangling END IF without IF declaration
      DEFINT LineInDump = -1                                  'get line with error, -1 = no errors
      DEFINT ColInDump                                        'get column of line with error
      DEFSTR delimt$ = "", TheErrLine = ""

      FOR i = 0 TO tmpList.ItemCount -1
        '*****  parse for line with error  *****
       TheErrLine = tmpList.Item(i)
       IF (LEFT$(TheErrLine, 5) = "Line ") AND (INSTR(TheErrLine, ": ") > 0) THEN
        TheErrLine = TheErrLine - "Line "
        IF INSTR(TheErrLine, Comma) THEN delimt$ = Comma ELSE delimt$ = ":"
        LineInDump = VAL(FIELD$(TheErrLine, delimt$, 1)) -1
        ColInDump = VAL(FIELD$(TheErrLine, delimt$, 2))
       END IF

       IF (LEFT$(TheErrLine, 11) = "Can't open ") THEN                 'process may already be running...
       SHOWMESSAGE "Cannot open source or executable" + CRLF + "Current build already running?"
       SCREEN.Cursor = crDefault
            'Prog.Visible = False
       EXIT SUB
      END IF

        '*****  parse for file with error   *****
      IF (LineInDump > -1) AND (MFE_List.ItemCount > 1) THEN      'more than one file loaded with an error?
       TheErrLine = tmpList.Item(i)                            'filename follows line with error
       IF (LEFT$(TheErrLine, 15) = "File in error: ") THEN
        TheErrLine = TRIM$(RIGHT$(TheErrLine, LEN(TheErrLine) - 15))
        EXIT FOR
       END IF
      END IF
     NEXT i


     DEFINT FndIt                                                    'find file and line with our errors
     IF IDE.HiLightCompileErr THEN
      FndIt = False                                               'signal not found
      IF (LineInDump > -1) AND (MFE_List.ItemCount > 1) THEN      'more than one file loaded with an error?
       i = MFE_GetFileIndex(TheErrLine)                        'switch to that file
       IF i <> -1 THEN
        MFE_ChangeToIndex(i)                                '-1 means did not find file
        FndIt = True                                        'signal found
       ELSE                                                    'try to find it on name alone
        FOR i = 0 TO MFE_List.ItemCount -1
         IF UCASE$(StripFileName(TheErrLine)) = UCASE$(StripFileName(MFE_List.Item(i))) THEN
          MFE_ChangeToIndex(i)
          FndIt = True
          EXIT FOR
         END IF
        NEXT i
       END IF
      ELSE
       FndIt = True                                            'only one file with error, or no error
      END IF

      IF FndIt THEN
       IF LineInDump > -1 THEN                                 'is there an error?
        RichEditCompile.AddStrings "Alt + <right click> to go to line"
        re.GotoLine(LineInDump)                             'will go to start of line
        re.Set_Position(re.Position + ColInDump)            'go to column
        re.ActiveLineColor(RGB(255,200,128), 0)             'set bright red line error
        IDE.HiLightTurnOFF = True                           'toggle to turn off compile error line
        re.SetFocus
       END IF
      ELSE
       SHOWMESSAGE "Cannot locate file " + TheErrLine + " in project"
      END IF

      IF (LineInDump > -1) THEN       'bail out
       CHDIR TheCurrDir            'go back to original directory before compile
       SCREEN.Cursor = crDefault
            'Prog.Visible = False
       tmpList.Text = ""           'dealloc
       tmpList.Clear               'dealloc
       EXIT SUB
      END IF
     END IF                  'highlight error line


'------------------------------------------------------------------------------------------------------------
'******  Perform any embedding of resources with UPX and ResHacker, must be done after final assembly  ******
'------------------------------------------------------------------------------------------------------------


    '---- generate manifest if needed  -----
     IF IDE.GenerateManifest OR IDE_Conf_ManifestEmbedCheckBox.Checked THEN
      RichEditCompile.AddStrings "Generating Manifest..."
      GenerateManifest (TheExeName)
     END IF


     DEFSTR myUPX = REPLACESUBSTR$(IDE.upx, "%CURRPATH%", CURDIR$)                       'allow for "%CURRPATH% = Current Path"
     myUPX = REPLACESUBSTR$(myUPX, "%APPPATH%", Application.Path)                   'allow for "%APPPATH% = Path of FreeQ exe"
     myUPX = REPLACESUBSTR$(myUPX, "%PATH%", StripPath(IDE.MFEActiveFile))         'allow for Path of main file

     DEFSTR myResHacker = REPLACESUBSTR$(IDE.ResHacker, "%CURRPATH%", CURDIR$)
     myResHacker = REPLACESUBSTR$(myResHacker, "%APPPATH%", Application.Path)                   'allow for "%APPPATH% = Path of FreeQ exe"
     myResHacker = REPLACESUBSTR$(myResHacker, "%PATH%", StripPath(IDE.MFEActiveFile))

     IF (FILEEXISTS(myUPX)) AND (FILEEXISTS(myResHacker)) THEN    'do we have resource editors?

      IF IDE.DecompressEXE = True THEN
       RichEditCompile.AddStrings "decompressing file..."
       PID = SHELL(Quote$(myUPX) + " -d " + Quote$(TheExeName) , 4)
       DOEVENTS
       IF PID THEN WaitForSingleObject(PID , &HFFFF)
       DOEVENTS
       SLEEP .100
      END IF


        '---- Did the user want to add a large 32-bit 48x48 icon or Version info?  -----
      IF (AddIcoAfterCompile OR IDE_Conf_VersionInfoCheckBox.Checked) THEN

       IF IDE.DecompressEXE = False THEN                            'may already be decompressed
        RichEditCompile.AddStrings "decompressing file..."
        PID = SHELL(Quote$(myUPX) + " -d " + Quote$(TheExeName) , 4)
        DOEVENTS
        IF PID THEN WaitForSingleObject(PID , &HFFFF)
        DOEVENTS
        SLEEP .100
       END IF

       RichEditCompile.AddStrings "modifying resources..."

       IF AddIcoAfterCompile THEN
        RichEditCompile.AddStrings "Please Wait. Inserting icon..."
        PID = SHELL(Quote$(myResHacker) + " -addoverwrite " + _
         Quote$(TheExeName) + " , " +  _
         Quote$(TheExeName) + " , " + _
         Quote$(IDE.IconName) + " , ICONGROUP,MAINICON,0" , 4)
        DOEVENTS
        IF PID THEN WaitForSingleObject(PID , &HFFFF)
        DOEVENTS
        SLEEP .100
       END IF

       IF IDE_Conf_VersionInfoCheckBox.Checked OR IDE_Conf_ManifestEmbedCheckBox.Checked THEN
        IF FILEEXISTS(Application.Path + "\tools\gorc.exe") THEN
         RichEditCompile.AddStrings "Please Wait. Creating resource script..."       'Inserting VersionInfo..."
         IDE_GenerateResourceScript (TheExeName)                                     'generates same name file with .rc extension
         DEFSTR tmp2 = CURDIR$+"\"+TheExeName - ".exe" + ".rc"                       'must be same name with .rc extension
         IF FILEEXISTS(tmp2) = False THEN
          SHOWMESSAGE "unable to generate compiled resource"
         ELSE
          SHELL(Application.Path + "\tools\gorc /r " + Quote$(tmp2))      'compile into .res file
          KILL tmp2                                                               'don't need resource script

          tmp2 = CURDIR$+"\"+TheExeName - ".exe" + ".res"                             'load compiled script
          PID = SHELL(CHR$(34)+IDE.ResHacker +CHR$(34)+ _
           " -addoverwrite " + Quote$(TheExeName) + "," + _
           Quote$(TheExeName) + "," +_
           Quote$(tmp2) + ",,,")
          IF PID THEN WaitForSingleObject(PID , &HFFFF)
          DOEVENTS

                    'clean up unwanted files
          KILL tmp2                                                       'don't need compiled resource
          KILL (tmp2 - ".res" + ".aps")                                   'remove aps file from gorc
          IF IDE_Conf_ManifestEmbedCheckBox.Checked THEN KILL TheExeName + ".manifest.xml"
         END IF

'                IF FILEEXISTS(tmp2) THEN
'                    gFStream.Open(tmp2, fmOpenRead)
'                    tmp2 = gFStream.ReadBinStr(gFStream.Size)         '' Read entire file
'                    gFStream.Close
'                    UpdateVersionInfoRes (TheExeName, tmp2) 'IDE_Conf_VersionInfoRichEdit.Text)
'                END IF
        END IF
       END IF

       IF IDE.DecompressExe = False THEN
        RichEditCompile.AddStrings "compressing file..."
        PID = SHELL(Quote$(IDE.upx) + " -9 " + Quote$(TheExeName) , 4)
        IF PID THEN WaitForSingleObject(PID , &HFFFF)
        DOEVENTS
        SLEEP .100
       END IF

      END IF

     ELSE

      IF AddIcoAfterCompile THEN MESSAGEBOX("Cannot add icon: "+ IDE.IconName + CRLF + _
       "Please set the location of UPX.exe and ResHacker.exe in Options." , MainForm.CAPTION , 48)

     END IF                  'end modifying / adding resources


     CHDIR TheCurrDir            'go back to original directory before compile
     SCREEN.Cursor = crDefault
    'Prog.Visible = False
     tmpList.Text = ""           'dealloc
     tmpList.Clear               'dealloc
     IDE.CompiledOK = True       'made it!!

     END SUB




     SUB Runclick
      IF MFE_List.ItemCount = 0 THEN EXIT SUB                                 'no file loaded, bail out otherwise crash

      IF IDE.MainFileForCompiler <> "" THEN
       CompileClick                                                        'compile main file for project

      ELSE

       SELECT CASE IDE.ModuleType(MFE_Tab.TabIndex)
       CASE 0
        CompileClick                                                'target main compiler (RapidQ)
       CASE 1
        FBCompileClick                                              'module type for FB app
       CASE 2
        FBDLLClick                                                  'if we have no main program then do FreeBasic calls on f5 too!
       CASE ELSE
        SHOWMESSAGE "Module Type Error"
       END SELECT

      END IF

      IF IDE.CompiledOK = False THEN EXIT SUB                                 'bad compile, so bail

      IF (IDE.MainFileForCompiler = "") AND_
       (IDE.ModuleType(MFE_Tab.TabIndex) = 2) THEN EXIT SUB                'don't execute DLL


      DIM exeName AS STRING
      IF IDE.MainFileForCompiler <> "" THEN
       IF INSTR(IDE.MainFileForCompiler, ".") THEN
        exeName = FileNameNoExt(IDE.MainFileForCompiler) + ".exe"
       ELSE
        exeName = IDE.MainFileForCompiler + ".exe"
       END IF
      ELSE
       IF INSTR(IDE.MFEActiveFile, ".") THEN
        exeName = FileNameNoExt(IDE.MFEActiveFile) + ".exe"
       ELSE
        exeName = IDE.MFEActiveFile + ".exe"
       END IF
      END IF

      CHDIR IDE.Path          'set from compile click
      RUN "rundll32.exe url.dll,FileProtocolHandler " & exename
     END SUB





     FUNCTION IsProjectFile(InFileName AS STRING) AS INTEGER
      DEFSTR s = UCASE$(MFE_list.Text) , token
      RESULT = False
      IF INSTR(s, UCASE$(InFileName)) THEN RESULT = True
     END FUNCTION



     SUB DebugCompileClick
      DEFSTR TheDebugScript = ""                                  'command line
      DEFINT i = 0, j, k, brkptOffset = 0
      DEFINT curTab = MFE_Tab.TabIndex

    '---- set filename for compile TheExeName still has source file extension -----
      IF IDE.MainFileForCompiler <> "" THEN
       i = MFE_GetFileIndex(IDE.MainFileForCompiler)   'get tab for main compiler file
       IF i = -1 THEN SHOWMESSAGE "File " + IDE.MainFileForCompiler + " not open": EXIT SUB
       IF i <> curTab THEN MFE_ChangeToIndexSilent(i)
      ELSE
       i = curTab                                                          'set up for below
      END IF

      tmpList.Clear
      tmpList.Text = re.Text                                                  'get the text
      IF tmpList.ItemCount < 1 THEN SHOWMESSAGE "no source code to compile" : EXIT SUB

      RichEditCompile.AddStrings "starting debugger..."

    'make sure we have a program to run!
      IF FILEEXISTS(Application.Path + "\RapidDBG.exe") = True THEN
       TheDebugScript = Application.Path + "\RapidDBG.exe"
      ELSE
       IF FILEEXISTS(Application.Path + "\tools\RapidDBG.exe") = True THEN
        TheDebugScript = Application.Path + "\tools\RapidDBG.exe"
       ELSE
        SHOWMESSAGE "debugger not found," + CRLF + "please place RapidDBG.exe in the IDE folder"
        EXIT SUB
       END IF
      END IF

    'set paths...
      SetCompileDirectory(StripPath(IDE.MFEActiveFile))                       'set our path
    'temporarily move here, while we collect any files!!
      CHDIR IDE.Path

    'code below to incorporate all project files to debugger output
      DEFSTR TheFilename = ""                                                 'general filename cache
      DIM appendList AS QSTRINGLIST
      appendList.Clear
      DEFSTR TheSrcCode = ""                                                  'executable srcfile code

      SetCompileDirectory(StripPath(IDE.MFEActiveFile))                       ' Get the src path (IDE.Path)

    '-------------------------------------------------------------------
    'add include files to the source code so that breakpoints still work
    '-------------------------------------------------------------------
      FOR k = 0 TO tmpList.ItemCount -1
       IF UCASE$(LEFT$(LTRIM$(tmpList.Item(k)), 9)) = "$INCLUDE " THEN

        TheFilename = DELETE$(LTRIM$(tmpList.Item(k) ), 1, 9)
        j = INSTR(TheFilename, Quot$)                                    'get filename in quotes
        IF j THEN
         TheFilename = FIELD$(TheFilename, Quot$, 2)
        ELSE
         j = INSTR(TheFilename, "<")                                 'get default inc path files
         IF j > 0 THEN
          TheFilename = FIELD$(TheFilename, ">", 1)
          TheFilename = TRIM$(REPLACESUBSTR$(TheFilename , "<" , ""))
         END IF
        END IF

        TheFilename = UCASE$(TheFilename)
        IF (TheFilename <> "RAPIDQ2.INC") AND (TheFilename <> "RAPIDQ.INC") AND _
         (TheFilename <> "WINDOWS.INC") AND NOT!(IsProjectFile(TheFileName)) THEN
         appendList.Clear


         IF FILEEXISTS(TheFilename) THEN
          appendList.LoadFromFile(TheFilename)
          RichEditCompile.AddStrings "adding include file: " + TheFilename
         ELSE
          IF FILEEXISTS(IDE.CompilerIncPath + "\" + TheFilename) THEN         'last option
           appendList.LoadFromFile(IDE.CompilerIncPath + "\" + TheFilename)
           RichEditCompile.AddStrings "adding include file: " + TheFilename
          ELSE
           RichEditCompile.AddStrings "cannot find include file: " + IDE.CompilerIncPath + "\" + TheFilename
           RichEditCompile.AddStrings "..."
          END IF
         END IF

         TheSrcCode = TheSrcCode + appendList.Text                   'if file not found, null string
         brkptOffset = brkptOffset + appendList.ItemCount
        ELSE
         TheSrcCode = TheSrcCode + tmpList.Item(k) + CRLF
        END IF
       ELSE
        TheSrcCode = TheSrcCode + tmpList.Item(k) + CRLF
       END IF
      NEXT k

    'store source code in temp file
      tmpList.Clear
      tmplist.Text = TheSrcCode                                               ' FULL src code to debug
      tmpList.SaveToFile IDE.Path + cDebugFileName + ".bas"                   ' Save to default debug basic file name
      tmpList.Clear                                                           'dealloc
      appendList.Text = RichEditCompile.Text                                  'save a copy CompileClick will clear it

    ' Compile and ensure original src is ok!!!!
      IDE.DebugFileName = IDE.Path + cDebugFileName + ".bas"                  'set this name so compile knows we are debugging
      CompileClick                                                            'compile temp file
      IDE.DebugFileName = ""                                                  'reset
      IF IDE.CompiledOK = False THEN EXIT SUB                                 'bad compile, bail out of here
      RichEditCompile.Text = appendList.Text                                  'restore what was said
      appendList.Clear                                                        'dealloc
      RichEditCompile.AddStrings "First compile pass OK..."
      DOEVENTS

      TheDebugScript = TheDebugScript + " -d " + Quot$ + IDE.Path + cDebugFileName + ".bas" + Quot$
      IF IDE.BookMarkCount(i) > 0 THEN                                                        'any book marks?
       TheDebugScript = TheDebugScript + " -b "
       FOR j = 1 TO IDE.BookMarkCount(i) -1
        TheDebugScript = TheDebugScript + STR$(IDE.BookMark(i, j)+1) +","               ' delimit all breakpoints
       NEXT j
       TheDebugScript = TheDebugScript + STR$(IDE.BookMark(i, IDE.BookMarkCount(i))+1)     'add for line# in Scintilla
      END IF

      RichEditCompile.AddStrings TheDebugScript
      SHELL TheDebugScript                                                        'now run the debugger!!
      RichEditCompile.AddStrings "cleaning up files..."
      IF FILEEXISTS(IDE.Path + cDebugFileName + ".bas") THEN KILL IDE.Path + cDebugFileName + ".bas"
      IF FILEEXISTS(IDE.Path + cDebugFileName + ".exe") THEN KILL IDE.Path + cDebugFileName + ".exe"
      IF FILEEXISTS(IDE.Path + cDebugFileName + ".exe.manifest") THEN KILL IDE.Path + cDebugFileName + ".exe.manifest"
      IF FILEEXISTS(IDE.Path + "~" + cDebugFileName + ".bas") THEN KILL IDE.Path + "~" + cDebugFileName + ".bas"
      IF FILEEXISTS(IDE.Path + "~" + cDebugFileName + ".exe") THEN KILL IDE.Path + "~" + cDebugFileName + ".exe"
      IF FILEEXISTS(IDE.Path + "~" + cDebugFileName + ".exe.manifest") THEN KILL IDE.Path + "~" + cDebugFileName + ".exe.manifest"
      IF FILEEXISTS(IDE.Path + "DebugMap.txt") THEN KILL IDE.Path + "DebugMap.txt"
      IF FILEEXISTS(IDE.Path + "RapidDBG.ico") THEN KILL IDE.Path + "RapidDBG.ico"
      IF FILEEXISTS(IDE.Path + "RapidDBG.bmp") THEN KILL IDE.Path + "RapidDBG.bmp"

     END SUB




'SUB DebugCompileClick_DLL_Only
'    DEFSTR TheDebugScript = ""                                  'command line
'    DEFINT i = 0, j, k, brkptOffset = 0
'    DEFINT curTab = MFE_Tab.TabIndex
'
'    '---- set filename for compile TheExeName still has source file extension -----
'    IF IDE.MainFileForCompiler <> "" THEN
'        i = MFE_GetFileIndex(IDE.MainFileForCompiler)   'get tab for main compiler file
'        IF i = -1 THEN Showmessage "File " + IDE.MainFileForCompiler + " not open": EXIT SUB
'        IF i <> curTab THEN MFE_ChangeToIndexSilent(i)
'    ELSE
'        i = curTab                                                          'set up for below
'    END IF
'
'    tmpList.Clear
'    tmpList.Text = re.Text                                                  'get the text
'    IF tmpList.ItemCount < 1 THEN ShowMessage "no source code to compile" : EXIT SUB
'
'	RichEditCompile.AddStrings "starting debugger..."
'    SetCompileDirectory(StripPath(IDE.MFEActiveFile))                   'set our path
'    'temporarily move here, while we collect any files!!
'    CHDIR IDE.Path
'
'    'code below to incorporate all project files to debugger output
'    DEFSTR TheFilename = ""                                                 'general filename cache
'    DIM appendList AS QSTRINGLIST
'        appendList.Clear
'    DEFSTR TheSrcCode = ""                                                  'executable srcfile code
'
'    SetCompileDirectory(StripPath(IDE.MFEActiveFile))                       ' Get the src path (IDE.Path)
''   CHDIR IDE.Path                                                          ' NO!
'
'    FOR k = 0 TO tmpList.ItemCount -2'1
'        IF UCASE$(LEFT$(LTRIM$(tmpList.Item(k)), 9)) = "$INCLUDE " THEN
'
'            TheFilename = DELETE$(LTRIM$( tmpList.Item(k) ), 1, 9)
'            j = INSTR(TheFilename, Quot$)                                    'get filename in quotes
'            IF j THEN
'                TheFilename = FIELD$(TheFilename, Quot$, 2)
'            ELSE
'                j = INSTR(TheFilename, "<")                                 'get default inc path files
'                IF j > 0 THEN
'                    TheFilename = FIELD$(TheFilename, ">", 1)
'                    TheFilename = TRIM$(REPLACESUBSTR$(TheFilename , "<" , ""))
'                END IF
'            END IF
'
'            TheFilename = UCASE$(TheFilename)
'            IF (TheFilename <> "RAPIDQ2.INC") AND (TheFilename <> "RAPIDQ.INC") AND _
'                            (TheFilename <> "WINDOWS.INC") AND (IsProjectFile(TheFileName)) THEN
'                appendList.Clear
'                IF FILEEXISTS(TheFilename) THEN
'                    appendList.LoadFromFile(TheFilename)
'                    RichEditCompile.AddStrings "adding include file: " + TheFilename
'                ELSE
'                    IF FILEEXISTS(IDE.CompilerIncPath + "\" + TheFilename) THEN         'last option
'                        appendList.LoadFromFile(IDE.CompilerIncPath + "\" + TheFilename)
'                    ELSE
'                        RichEditCompile.AddStrings "cannot find include file: " + IDE.CompilerIncPath + "\" + TheFilename
'                        RichEditCompile.AddStrings "..."
'                    END IF
'                END IF
'                TheSrcCode = TheSrcCode + appendList.Text                   'if file not found, null string
'                brkptOffset = brkptOffset + appendList.ItemCount
'            ELSE
'                TheSrcCode = TheSrcCode + tmpList.Item(k) + CRLF
'            END IF
'        ELSE
'            TheSrcCode = TheSrcCode + tmpList.Item(k) + CRLF
'        END IF
'    NEXT k
'
'    tmpList.Clear
'    tmplist.Text = TheSrcCode                                               ' FULL src code to debug
'    tmpList.SaveToFile IDE.Path + cDebugFileName + ".bas"                   ' Save to default debug basic file name
'
'
'    'store for DLL file
'    DIM SrcStream AS QMEMORYSTREAM
'    SrcStream.Position = 0
'    SrcStream.WriteStr(tmpList.Text, LEN(tmpList.Text))                     ' Full src into mem stream
'    SrcStream.WriteNum(0,4)                                                 ' Appends 4 nuls (nulls?)
'    SrcStream.Position = 0                                                  'set pointer
'
'
'    ' Compile and ensure original src is ok!!!!
'    IDE.DebugFileName = IDE.Path + cDebugFileName + ".bas"
'    CompileClick
'    IDE.DebugFileName = ""                                                  'reset
'    IF IDE.CompiledOK = False THEN
'        SrcStream.Close
'        EXIT SUB                                                            'bad compile
'    END IF
'    RichEditCompile.AddStrings "First compile pass OK..."
'    DOEVENTS
'
'    'Move back to FreeQ directory where the dll resides!
'    CHDIR Application.Path
'
'    ' Prepare to call the dll function
'    DIM DatStream AS QMEMORYSTREAM
'    DatStream.ExtractRes(Resource(RESOURCECOUNT-1))                     ' debugger RapidDBG.dat
'    DatStream.WriteNum(0,4)                                             ' Appends 4 nulls for FB null terminator
'    DatStream.Position = 0                                              'set to beginning
'
'    DEFSTR initBuf = "$UNDEF TIDY_TEMP_FILES~" + _                      ' Gets around reliance on RapidDBG.exe BUT ....
'                    IDE.Path + cDebugFileName + ".bas" + "~" + _        ' ... must tidy temp files after debug session
'                    Application.Path + "~"
'
'    IF IDE.BookMarkCount(i) > 0 THEN                                    ' Any book marks (breakpoints)?
'        FOR j = 1 TO IDE.BookMarkCount(i)
'            initBuf = initBuf + STR$(IDE.BookMark(i, j) + 1 + brkptOffset) + Comma                  ' delimit all breakpoints
'        NEXT j
'    END IF
'
'    initBuf = initBuf + "~"                                                                  ' DVH: Terminate (any) breakpoints!!!!!!!!!
'    initBuf = initBuf + STR$((Screen.Width-500)\2) and STR$(Screen.Height-100) + "~"         'Set ProgressBar position
'
'    DEFSTR retbuf = SPACE$(255)                                         ' Return string from debugger
'    fbParserVersion(VARPTR(retBuf))
'    RichEditCompile.AddStrings "Debugger version: "+LEFT$(retbuf,5)
'    DOEVENTS
'
''    ' DVH: On error we have a bug in the debugger! Ooooops!
''    ' DVH: now should have a file "~"+cDebugFileName in the IDE.Path folder
''    '   ready to compile, and hopefully create the debug exe to "run"
'    j = fbParseFile(SrcStream.Pointer, DatStream.Pointer, VARPTR(initBuf), VARPTR(retbuf), LEN(retbuf))
'    IF j = False THEN
'        IF LEN(RTRIM$(retBuf)) > 0 THEN RichEditCompile.AddStrings "Parser : " + RTRIM$(retBuf)
'        EXIT SUB
'    END IF
'
'
'    IDE.DebugFileName = IDE.Path + "~" + cDebugFileName + ".bas"
'
'    EXTRACTRESOURCE Resource(RESOURCECOUNT-2), Application.Path + "\RapidDBG.ico"
'    EXTRACTRESOURCE Resource(RESOURCECOUNT-3), Application.Path + "\RapidDBG.bmp"
'    DO
'    LOOP UNTIL FILEEXISTS(Application.Path + "\RapidDBG.bmp")
'
'
'    CompileClick
'    IDE.DebugFileName = ""                                                  'reset
'    IF IDE.CompiledOK = False THEN
'        RichEditCompile.AddStrings "Could not compile debug code"
'        EXIT SUB                                                            'bad compile
'    END IF
'
'    RichEditCompile.AddStrings "Parsed OK!"
'    DOEVENTS
'    SHELL Quote$(IDE.Path + "~" + cDebugFileName + ".exe")
'
''    IF FileExists(IDE.Path + cDebugFileName + ".bas") THEN KILL IDE.Path + cDebugFileName + ".bas"              ' <= this is not deleted elsewhere..
''    IF FileExists(IDE.Path + cDebugFileName + ".exe") THEN KILL IDE.Path + cDebugFileName + ".exe"
''    IF FileExists(IDE.Path + "~" + cDebugFileName + ".bas") THEN KILL IDE.Path + "~" + cDebugFileName + ".bas"
''    IF FileExists(IDE.Path + "~" + cDebugFileName + ".exe") THEN KILL IDE.Path + "~" + cDebugFileName + ".exe"
''    IF FileExists(IDE.Path + "DebugMap.txt") THEN KILL IDE.Path + "DebugMap.txt"
''    IF FileExists(IDE.Path + "RapidDBG.ico") THEN KILL IDE.Path + "RapidDBG.ico"
''    IF FileExists(IDE.Path + "RapidDBG.bmp") THEN KILL IDE.Path + "RapidDBG.bmp"
''need to clean up freeqdebug and ~freeqdebug manifest files
'
''    'dealloc
'    SrcStream.Close
'    DatStream.Close
'    initBuf = ""
'    retbuf = ""
'    tmpList.Clear
'END SUB




     SUB IDE_InsertTypeCheck(TheIndex AS INTEGER)
      DEFINT i, j =  MFE_Tab.TabIndex

      MFE_ChangeToIndexSilent(TheIndex)
      tmpList.Text = re.Text
      i = 0
      DEFINT FndIt = False

      DO
       IF UCASE$(LEFT$(tmpList.Item(i), 13)) = "$TYPECHECK ON" THEN FndIt = True
       i++
      LOOP UNTIL (i > 39) OR (i > tmpList.ItemCount-1) OR FndIt        'check first 40 lines

      IF FndIt = False THEN
       MFE_GetCursor                           'get initial position
       re.Set_Position(0)
       re.AddStrings("")
       re.AddStrings("")
       re.AddStrings("$TYPECHECK ON" + CRLF)
       MFE_SetCursor                           'restore position
      END IF
      MFE_ChangeToIndex(j)
     END SUB



'generates a manifest on file for distribution with exe, pass in the exe name and it will automatically append .manifest
     SUB GenerateManifest (TheManifestExeName AS STRING)
      DEFSTR TheFileName = TheManifestExeName
      IF TheFileName = "" THEN TheFileName = IDE.MFEActiveFile
      TheFileName = TheFileName + ".manifest"
      IF FILEEXISTS(TheFileName) THEN KILL TheFileName       'manifest file already made, so overwrite it
      WITH tmpList
       .Clear
       .AddItems "<?xml version="+Quot$+"1.0"+Quot$+" encoding="+Quot$+"UTF-8"+Quot$+" standalone="+Quot$+"yes"+Quot$+"?>"
       .AddItems "<assembly xmlns="+Quot$+"urn:schemas-microsoft-com:asm.v1"+Quot$+" manifestVersion="+Quot$+"1.0"+Quot$+">"
       .AddItems "<assemblyIdentity"
       .AddItems "version = "+Quot$+"1.0.0.0"+Quot$+""
       .AddItems "processorArchitecture = "+Quot$+"X86"+Quot$+""
       .AddItems "name = "+Quot$+"[].[].[]"+Quot$+""
       .AddItems "type="+Quot$+"win32"+Quot$+""
       .AddItems "/>"
       .AddItems "<description></description>"
       .AddItems "<dependency>"
       .AddItems "<dependentAssembly>"
       .AddItems "<assemblyIdentity"
       .AddItems "type="+Quot$+"win32"+Quot$+""
       .AddItems "name = "+Quot$+"Microsoft.Windows.Common-Controls"+Quot$+""
       .AddItems "version = "+Quot$+"6.0.0.0"+Quot$+""
       .AddItems "processorArchitecture = "+Quot$+"X86"+Quot$+""
       .AddItems "publicKeyToken = "+Quot$+"6595b64144ccf1df"+Quot$+""
       .AddItems "language = "+Quot$+"*"+Quot$+""
       .AddItems "/>"
       .AddItems "</dependentAssembly>"
       .AddItems "</dependency>"
       .AddItems "</assembly>"
       .SaveToFile(TheFileName)
       .Clear
      END WITH
     END SUB


     SUB IDE_GenerateResourceScript(TheExeName AS STRING)
      DEFSTR TheFileName = TheExeName                                 'need to alloc new
      DEFSTR TheManifestName = TheExeName + ".manifest.xml"           'set for embedding manifest
'    IF TheFileName = "" THEN
'        IF IDE.MainFileForCompiler <> "" THEN TheFileName = IDE.MainFileForCompiler - ".exe" ELSE TheFileName = IDE.MFEActiveFile - ".exe"
'    END IF
      IF UCASE$(RIGHT$(TheFileName, 3)) <> ".RC" THEN TheFileName = TheFileName - ".exe" + ".rc"
      IF FILEEXISTS(TheFileName) THEN KILL TheFileName       'resource file already made, so overwrite it

      WITH tmpList
       .Clear
        'add manifest line to the rc file if needed
       IF IDE_Conf_ManifestEmbedCheckBox.Checked THEN
        RENAME  TheExeName + ".manifest", TheManifestName
        .AddItems "1 MANIFEST " + Quote$(TheManifestName)
        .AddItems ""
       END IF

       IF IDE_Conf_VersionInfoCheckBox.Checked THEN
        .AddItems "1 VERSIONINFO "
        .AddItems "FILEVERSION " + IDE_Conf_VersionInfoGrid.Cell(1,1)
        .AddItems "PRODUCTVERSION " + IDE_Conf_VersionInfoGrid.Cell(1,2)
        .AddItems "FILEFLAGSMASK 0x0000003FL "
        .AddItems "FILEFLAGS 0x0000000BL "
        .AddItems "FILEOS " + IDE_Conf_VersionInfoGrid.Cell(1,3)   '0x00010001L "
        .AddItems "FILETYPE " + IDE_Conf_VersionInfoGrid.Cell(1,4)   '0x00000001L "
        .AddItems "FILESUBTYPE 0x00000000L "
        .AddItems "BEGIN "
        .AddItems "BLOCK " + Quote$("StringFileInfo")
        .AddItems "BEGIN "
        .AddItems "BLOCK " + Quote$("040904E4")
        .AddItems "BEGIN "
        .AddItems "VALUE " + Quote$("CompanyName") + ", " + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,6))
        IF IDE_Conf_VersionInfoGrid.Cell(1,7) <> "" THEN .AddItems "VALUE "  + Quote$ ("Contact e-mail") + ", " + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,7))
        IF IDE_Conf_VersionInfoGrid.Cell(1,8) <> "" THEN .AddItems "VALUE "  + Quote$("FileDescription")   + ", " + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,8))
        IF IDE_Conf_VersionInfoGrid.Cell(1,9) <> "" THEN .AddItems "VALUE "  + Quote$("FileVersion")       + ", " + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,9))
        IF IDE_Conf_VersionInfoGrid.Cell(1,10) <> "" THEN .AddItems "VALUE " + Quote$("DevelopmentFile")  + ", " + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,10))
        IF IDE_Conf_VersionInfoGrid.Cell(1,11) <> "" THEN .AddItems "VALUE " + Quote$("LegalCopyright")   + ", " + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,11))
        IF IDE_Conf_VersionInfoGrid.Cell(1,12) <> "" THEN .AddItems "VALUE " + Quote$(IDE_Conf_VersionInfoGrid.Cell(0,12))  + "," + Quote$(IDE_Conf_VersionInfoGrid.Cell(1,11))
        .AddItems "END"
        .AddItems "END"
        .AddItems "BLOCK " + Quote$("VarFileInfo")
        .AddItems "BEGIN"
        .AddItems "VALUE " + Quote$("Translation") + ", 0x0409,1252"
        .AddItems "END"
        .AddItems "END"
       END IF
       .SaveToFile(TheFileName)
       .Clear
      END WITH
     END SUB





     SUB RightPanelCollapse_Click
      IF FindAllPanel.Visible THEN FindTreeView.FullCollapse
     END SUB

     SUB RightPanelExpand_Click
      IF FindAllPanel.Visible THEN FindTreeView.FullExpand
     END SUB


     SUB ExportPanelText_Click(Sender AS QBUTTON)
      DEFSTR TxtToAdd = ""
      DEFINT i

      IF Sender.Handle = RightPanelExportBut.Handle THEN
       IF ProjPanel.Visible THEN
        FOR i = 0 TO ProjFileList.ItemCount -1
         TxtToAdd = TxtToAdd + ProjFileList.Item(i) + CRLF
        NEXT i
       END IF

       IF IncResPanel.Visible THEN
        TxtToAdd = MainListBoxIncludes.Text
        TxtToAdd = TxtToAdd + CRLF + CRLF + CRLF
        TxtToAdd = TxtToAdd + MainListBoxResources.Text
       END IF

       IF FindAllPanel.Visible THEN
        FOR i = 0 TO FindTreeView.ItemCount -1
         TxtToAdd = TxtToAdd + RTRIM$(FIELD$(FindTreeView.Item(i).Text, "]", 2)) + CRLF      'FileTabDelimitr
        NEXT i
       END IF

       IF SubFuncsPanel.Visible THEN
        FOR i = 0 TO SubFuncListView(MFE_Tab.TabIndex).ItemCount -1
         TxtToAdd = TxtToAdd + RTRIM$(FIELD$(SubFuncListView(MFE_Tab.TabIndex).Item(i).CAPTION, LineNumDelimitr, 1)) + CRLF
        NEXT i
       END IF
      ELSE
       TxtToAdd = SubsCombo_objects.Text
      END IF

      IF TxtToAdd <> "" THEN
       MFE_NewFile
       re.AddStrings TxtToAdd
      END IF
     END SUB


     SUB RightTabChange
      DEFINT i
      SELECT CASE TabControl3.TabIndex

      CASE 0          'project panel button
       ProjPanel.Visible = True
       IncResPanel.Visible = False
       FindAllPanel.Visible = False
       SubFuncsPanel.Visible = False
      CASE 1          'include / resource panel button
       ProjPanel.Visible = False
       IncResPanel.Visible = True
       FindAllPanel.Visible = False
       SubFuncsPanel.Visible = False
       MainListBoxIncludes.Text = IDE.ListIncludes(MFE_Tab.TabIndex).Text
       MainListBoxResources.Text = IDE.ListResources(MFE_Tab.TabIndex).Text
      CASE 2          'find all in files button
       ProjPanel.Visible = False
       IncResPanel.Visible = False
       FindAllPanel.Visible = True
       FindAllPanel.Width = RightPanel.ClientWidth - RightSplitter.Width
       SubFuncsPanel.Visible = False
      CASE 3          'subs and functions
       ProjPanel.Visible = False
       IncResPanel.Visible = False
       FindAllPanel.Visible = False
       SubFuncsPanel.Visible = True
       SubFuncsPanel.Width = RightPanel.ClientWidth - RightSplitter.Width
       SubFuncsPanel.Height = TabControl3.ClientHeight
       FOR i = 0 TO IDE_MAX_FILES
        SubFuncListView(i).Visible = False
       NEXT i
       SubFuncListView(MFE_Tab.TabIndex).Visible = True
      END SELECT
     END SUB


     SUB ChangeDirectories
      ProjFileList.Directory = DirTree.Directory

      IF (IDE.UseAppDirectory = False) AND (IDE.ConstPath = "") THEN
       IDE.Path = DirTree.Directory
      END IF
     END SUB



     SUB SetCompileDirectory(TheDefaultDir AS STRING)  'this will have trailing "\"

    'app directory takes highest priority
      IF IDE.UseAppDirectory THEN IDE.Path = TheDefaultDir            : EXIT SUB

    'const directory takes next priority
      IF IDE.ConstPath <> "" THEN
       IDE.Path = IDE.ConstPath
       IF RIGHT$(IDE.Path, 1) <> "\" THEN IDE.Path = IDE.Path + "\"
       EXIT SUB
      END IF

    'else just use current working dir
      IDE.Path = CURDIR$ + "\"
     END SUB


      '______________________________________________________________________________

     FUNCTION GetResourceFileName (inText AS STRING) AS STRING

      DEFINT i = INSTR(UCASE$(inText), " AS ") + 4
      IF i > 0 THEN inText = TRIM$(MID$(inText, i, LEN(inText) -i +1))
      RESULT = ""                                                     'set to not found

      IF FILEEXISTS(inText) THEN RESULT = inText  :EXIT FUNCTION

      IF FILEEXISTS(CURDIR$ + "\" + inText) THEN
       RESULT = CURDIR$ + "\" + inText
       EXIT FUNCTION
      END IF

      IF LEFT$(inText, 2) = ".\" THEN
       IF FILEEXISTS(Application.Path + RIGHT$(inText, LEN(inText)-1)) THEN
        RESULT = Application.Path + RIGHT$(inText, LEN(inText)-1)
        EXIT FUNCTION
       END IF
      END IF

      IF LEFT$(inText, 3) = "..\" THEN
       IF FILEEXISTS(CURDIR$ + RIGHT$(inText, LEN(inText)-2)) THEN
        RESULT = CURDIR$ + RIGHT$(inText, LEN(inText)-2)
        EXIT FUNCTION
       END IF
      END IF

      IF FILEEXISTS(StripPath(IDE.MFEActiveFile) + inText) THEN
       RESULT = StripPath(IDE.MFEActiveFile) + inText              'may use default dir
       EXIT FUNCTION
      END IF

      IF FILEEXISTS(IDE.CompilerIconPath + inText) THEN             'last chance
       RESULT = IDE.CompilerIconPath + inText
       EXIT FUNCTION
      END IF

     END FUNCTION


     SUB ResourceListFileSelect
      DEFSTR s = MainListBoxResources.Item(MainListBoxResources.ItemIndex)
      DEFSTR totalfilename = UCASE$(GetResourceFileName(s))
      DEFSTR theExt = StripFileExt(totalfilename)

      IF (totalfileName <> "") AND INSTR(".BMP.JPG.JPEG.ICO.GIF.RLE.DIB.TGA.PCX", theExt) THEN
       Stat.Panel(5).CAPTION = "Viewing: " + totalfilename
       ImageViewerLoad(totalfilename)                              'if resource is an image, view it
      ELSE
       IDEimageViewerForm.CLOSE                                    'close it in case not found
       Stat.Panel(5).CAPTION = "Not found or not image: " + totalfilename
      END IF
     END SUB



     SUB ResourceListFileEdit
      DEFSTR s = TRIM$(MainListBoxResources.Item(MainListBoxResources.ItemIndex))
      DEFSTR totalfilename = GetResourceFileName(s)
      DEFSTR theExt = UCASE$(StripFileExt(totalfilename))
      IF INSTR(".BMP.JPG.JPEG.PNG.ICO.GIF.DIB.TGA.PCX", theExt) THEN
       Stat.Panel(5).CAPTION = "Editing: " + totalfilename
       WinExec "mspaint.exe " + totalfilename, 10     'SW_SHOWNORMAL
      END IF
     END SUB



     SUB IncludeListFileSelect
      DEFINT i
      DEFSTR totalfilename = TRIM$(MainListBoxIncludes.Item(MainListBoxIncludes.ItemIndex))

      i = INSTR(totalfilename, "'")
      IF i > 0 THEN
       totalfilename = LEFT$(totalfilename, i-1)           'strip comment
       totalfilename = TRIM$(totalfilename)                're-strip spaces
      END IF

   'use default include path before current path
      IF LEFT$(totalfilename, 1) = "<" THEN
       totalfilename = MID$(totalfilename, 2, INSTR(totalfilename, ">") -2)
       IF FILEEXISTS(IDE.CompilerIncPath + "\" + totalfilename) THEN           'found in include path
        totalfilename = IDE.CompilerIncPath + "\" + totalfilename
       END IF
      END IF


      IF FILEEXISTS(totalfilename) = False THEN                                   'yes this is redundant but works
                                                                                'let's start looking for that file
       IF FILEEXISTS(CURDIR$ + "\" + totalfilename) THEN
        totalfilename = CURDIR$ + "\" + totalfilename

       ELSEIF LEFT$(totalfilename, 2) = ".\" THEN
        IF FILEEXISTS(Application.Path + RIGHT$(totalfilename, LEN(totalfilename)-1)) THEN
         totalfilename = Application.Path + RIGHT$(totalfilename, LEN(totalfilename)-1)
        END IF

       ELSEIF LEFT$(totalfilename, 3) = "..\" THEN
        IF FILEEXISTS(CURDIR$ + RIGHT$(totalfilename, LEN(totalfilename)-2)) THEN
         totalfilename = CURDIR$ + RIGHT$(totalfilename, LEN(totalfilename)-2)
        END IF

       ELSEIF FILEEXISTS(StripPath(IDE.MFEActiveFile) + totalfilename) THEN
        totalfilename = StripPath(IDE.MFEActiveFile) + totalfilename              'may use default dir

       ELSEIF FILEEXISTS(IDE.CompilerIncPath + "\" + totalfilename) THEN             'last chance
        totalfilename = IDE.CompilerIncPath + "\" + totalfilename
       ELSE
        totalFileName = ""                                          'not found
       END IF

      END IF


      IF totalfileName <> "" THEN
       MFE_Load(totalfilename)
       Stat.Panel(5).CAPTION = "Loaded: " + totalfilename
      ELSE
        'ok I give up
       IF MESSAGEDLG("Include file not found, attempt download?", mtInformation,  mbYes OR mbNo, 0) = mrYes THEN
        totalfilename = "http://rapidq.phatcode.net/include/" + MainListBoxIncludes.Item(MainListBoxIncludes.ItemIndex)
        IF IDE_InsertWebFile(totalfilename) = False THEN ShellExecute(0,"open","http://rapidq.phatcode.net/include/","","",1)
       END IF
      END IF

     END SUB



     SUB DirListFileSelect
      DEFSTR Thefilename = ProjFileList.Filename
      IF FILEEXISTS(Thefilename) THEN MFE_Load(Thefilename)
      Splitter_Moved
     END SUB



      '______________________________________________________________________________
      '______________________   multiple files I/O       ____________________________
      '______________________________________________________________________________

     SUB MFE_NewFile
      MFE_MakeNewFile("")         'make a default new file
      re.SetFocus
     END SUB



     SUB MFE_MakeNewFile(TheNewName AS STRING)
'     ' with SCI_CREATEDOCUMENT the document is not selected into the editor and starts with a reference count
'     ' of 1. This means that you have ownership of it and must either reduce its
'     ' reference count by 1 after using SCI_SETDOCPOINTER so that the Scintilla
'     ' window owns it or you must make sure that you reduce the reference count by
'     ' 1 with SCI_RELEASEDOCUMENT before you close the application to avoid memory leaks.
'     'you must balance each call to SCI_CREATEDOCUMENT or SCI_ADDREFDOCUMENT with a call to SCI_RELEASEDOCUMENT.

      IF MFE_list.ItemCount -1 > IDE_MAX_FILES THEN
       SHOWMESSAGE "Sorry, maximum open files reached"
       EXIT SUB
      END IF

      IF CenterPanel.Visible = False THEN CenterPanel.Visible = True
      IDE.NewFileIndex++
      IF TheNewName = "" THEN TheNewName = CURDIR$ + "\" + IDE.NewFileName + STR$(IDE.NewFileIndex) + ".bas" 'set a default name
      IDE.MFEActiveFile = TheNewName
      MFE_Tab.AddTabs StripFilename(IDE.MFEActiveFile)                          'create new tab
      MFE_List.AddItems IDE.MFEActiveFile                                       'this is important for tab management
      MFE_Tab.TabIndex = MFE_List.ItemCount - 1                                 'need this, tab control index doesn't track new items

      IF MFE_Tab.TabIndex = 0 THEN                                              'added the first file
       IDE.DocPtr(MFE_Tab.TabIndex) = re.GetEditor(SCI_GETDOCPOINTER, 0, 0)  'store this document pointer
       re.SendEditor(SCI_ADDREFDOCUMENT, 0, IDE.DocPtr(MFE_Tab.TabIndex))    'need to (push) inc reference before SetDoc pointer!! Otherwise deletes it...
      ELSE
       IDE.LastTab = IDE.CurrTab                                             'transfer
       IDE.DocPtr(MFE_Tab.TabIndex) = re.GetEditor(SCI_CREATEDOCUMENT, 0, 0) 'new document pointer is created by Scintilla
       re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(MFE_Tab.TabIndex))     'make it our new window, all operations work on new document
      END IF

      IF IDE.DocPtr(MFE_Tab.TabIndex) = 0 THEN
       SHOWMESSAGE "Unknown Scintilla load Error"
       MFE_List.DelItems(MFE_Tab.TabIndex)                                                 'need to manage Tabcontrol here
       MFE_Delete(MFE_tab , MFE_Tab.TabIndex)
       EXIT SUB
      ELSE
       re.Clear
       re.Set_Selstart(0)
       Splitter_Moved          'need to resize forms
       IF Mnu_SetLineNumbers.Checked THEN re.Set_LineNumbers(1000)          'make margin wide enough for 4 digits
       re.Set_TabWidth(IDE.TabSpaces)					                     'new instance of Reference Pointer needs these set
       re.Set_WantTabs(IDE.UseTabs)
       re.Set_CodePage(IDE.CodePage)

       IDE.LexLanguage(MFE_Tab.TabIndex) = IDE.DefaultLexLanguage          'set lexer highlighter
       IDE_SetModuleType                                                   'set language/compiler attributes for compiling etc

       IF IDE.HiLighting THEN
        IDE_SetHighlighting(IDE.LexLanguage(MFE_Tab.TabIndex))
       END IF

       ParseSubIncRes(MFE_Tab.TabIndex, re.Text)                            'get an empty list of subs/functions, includes, resources
       IDE.CurrTab = MFE_Tab.TabIndex                                       'store this for next OnChange
      END IF
      LeftPanelRefresh                                                        'update project explorer
     END SUB



      '______________________________________________________________________________
     SUB MFE_Backup
      WITH gFStream
       .OPEN(Fullpathnoext(IDE.MFEActiveFile) + IDE.BackupFilesExt , fmCreate)
       .WriteStr(re.Text , LEN(re.Text))
       .CLOSE
       Stat.Panel(5).CAPTION = "Backup: " + IDE.MFEActiveFile + IDE.BackupFilesExt
      END WITH
     END SUB


     SUB MFE_UpdateSaveButton
      IF re.Modified THEN
       SaveToolBtn.Enabled = True
      ELSE
       SaveToolBtn.Enabled = False
      END IF
     END SUB



      '______________________________________________________________________________
     SUB MFE_ChangeActive
    'If you want to replace the current document in the Scintilla window and
    'take ownership of the current document, for example if you are editing
    'many documents in one window, do the following:
    ' 1. Use SCI_GETDOCPOINTER to get a pointer to the document, pDoc.
    ' 2. Use SCI_ADDREFDOCUMENT(0, pDoc) to increment the reference count.
    ' 3. Use SCI_SETDOCPOINTER(0, pNewDoc) to set a different document or SCI_SETDOCPOINTER(0, 0) to set a new, empty document.

      IDE.LastTab = IDE.CurrTab                                                   'transfer
      IDE.CurrTab = MFE_Tab.TabIndex                                              'this actually gets currently activated tab
      DEFINT pDoc = re.GetEditor(SCI_GETDOCPOINTER, 0, 0)                         'get object of current editor
      re.SendEditor(SCI_ADDREFDOCUMENT, 0, pDoc)                                  'this is like a "push on stack"
      IDE.MFEActiveFile = MFE_List.Item(MFE_Tab.TabIndex)
      re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(MFE_Tab.TabIndex))           'set our new window, all operations work on new document
      MFE_SetCursor                                                               'reset cursor location
      RightTabChange                                                              'update the right panel subs/inc/proj
      IF LeftPanel.Visible THEN LoadProjectTree(MFE_Tab.TabIndex, re.Text)         'reparse Qobjects
      re.SetFocus
      MFE_UpdateSaveButton
      re.Set_LineNumbers(Mnu_SetLineNumbers.Checked)                              'reset margin width for line numbering if needed
'    IF CheckFileChangeMonitor THEN Showmessage "files externally changed"  : ClearFileChangeMonitor
     END SUB


     SUB MFE_ChangeToIndexSilent(TheIndex AS INTEGER)                        'similar to ChangeActive but go to specific index
      DEFINT pDoc = re.GetEditor(SCI_GETDOCPOINTER, 0, 0)
      re.SendEditor(SCI_ADDREFDOCUMENT, 0, pDoc)
      MFE_Tab.TabIndex = TheIndex                                         'go to new tab
      re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(TheIndex))           'make it our new window, all operations work on new document
     END SUB

      '______________________________________________________________________________
     SUB MFE_ChangeToIndex(TheIndex AS INTEGER)                              'similar to ChangeActive but go to specific index
      IF MFE_Tab.TabIndex <> IDE.LastTab THEN IDE.LastTab = IDE.CurrTab : IDE.CurrTab =TheIndex  'store the last one viewed
      MFE_ChangeToIndexSilent(TheIndex)
      IDE.MFEActiveFile = MFE_List.Item(TheIndex)                         'set the global name
      MFE_SetCursor
      RightTabChange                                                      'update the right panel subs/inc/proj
      IF LeftPanel.Visible THEN LoadProjectTree(MFE_Tab.TabIndex, re.Text)
      re.SetFocus
      MFE_UpdateSaveButton
      re.Set_LineNumbers(Mnu_SetLineNumbers.Checked)                      'make margins for line numbering if needed
'    IF CheckFileChangeMonitor THEN Showmessage "files externally changed"  : ClearFileChangeMonitor
     END SUB



      '______________________________________________________________________________
     FUNCTION MFE_Load(TheFileName AS STRING) AS INTEGER

      IF MFE_list.ItemCount -1 > IDE_MAX_FILES THEN
       SHOWMESSAGE "Sorry, maximum open files reached"
       EXIT FUNCTION
      END IF

      DEFINT i = MFE_GetFileIndex(TheFileName)
      IF i <> -1 THEN                                  'already loaded
       MFE_ChangeToIndex(i)
       RESULT = False
       EXIT FUNCTION
      END IF

      IF FILEEXISTS(TheFileName) THEN
       IF CenterPanel.Visible = False THEN CenterPanel.Visible = True
       MFE_Tab.AddTabs StripFilename(TheFileName)                                'create new tab
       MFE_List.AddItems TheFileName                                             'this is important for tab management
       MFE_Tab.TabIndex = MFE_List.ItemCount - 1                                 'need this, tab control index doesn't track new items
       IF MFE_Tab.TabIndex = 0 THEN                                              'added the first file
        re.LoadFromFile TheFileName                                           'already exists on Init, load it
        re.SendEditor(SCI_EMPTYUNDOBUFFER, 0, 0)                              'clear undo, set unmodified
        IDE.DocPtr(MFE_Tab.TabIndex) = re.GetEditor(SCI_GETDOCPOINTER, 0, 0)  'store this document pointer
        re.SendEditor(SCI_ADDREFDOCUMENT, 0, IDE.DocPtr(MFE_Tab.TabIndex))    'need to (push) inc reference before SetDoc pointer!! Otherwise deletes it...
       ELSE
        IDE.DocPtr(MFE_Tab.TabIndex) = re.GetEditor(SCI_CREATEDOCUMENT, 0, 0) 'new document pointer is created by Scintilla
        re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(MFE_Tab.TabIndex))     'make it our new window, all operations work on new document
        re.LoadFromFile TheFileName                                           'now load it up
        re.SendEditor(SCI_EMPTYUNDOBUFFER, 0, 0)                              'clear undo, set unmodified
       END IF
       IF IDE.DocPtr(MFE_Tab.TabIndex) = 0 THEN
        SHOWMESSAGE "Unknown Scintilla load Error"
        RESULT = False
        EXIT FUNCTION
       END IF

       IDE.MFEActiveFile = TheFileName
       IF IDE.BackupFiles THEN MFE_Backup
       IDE_UpdateRecentList
       re.Set_LineNumbers(Mnu_SetLineNumbers.Checked)                          'make margins for line numbering if needed
       re.Set_TabWidth(IDE.TabSpaces)						                    'new instance of Reference Pointer needs these set
       re.Set_WantTabs(IDE.UseTabs)
       re.Set_CodePage(IDE.CodePage)
       IDE_SetModuleType                                                       'set language/compiler attributes for compiling etc

       IF = UCASE$(StripFileExt(TheFileName)) = ".BI" THEN
        IDE.ModuleType(MFE_Tab.TabIndex) = 1                                'this extension overwrites module type set as FreeBasic app
       END IF


       IDE.LexLanguage(MFE_Tab.TabIndex) = GetLanguageFromFile(TheFileName)
       IF IDE.HiLighting THEN
        IDE_SetHighlighting(IDE.LexLanguage(MFE_Tab.TabIndex))
       END IF

       ParseSubIncRes(MFE_Tab.TabIndex, re.Text)                               'get a list of subs/functions, includes, resources
       IF LeftPanel.Visible THEN LoadProjectTree(MFE_Tab.TabIndex, re.Text)
       Splitter_Moved                                                          'update IDE GUI
       IDE.CurrTab = MFE_Tab.TabIndex                                          'store this for next OnChange
'        SetFileChangeMonitor (StripPath(TheFileName), False, FILE_NOTIFY_CHANGE_ATTRIBUTES)
       RESULT = True
      ELSE
       Stat.Panel(5).CAPTION = TheFileName + " not found..."
       RESULT = False
      END IF

     END FUNCTION


      '______________________________________________________________________________
     SUB MFE_Open
      DIM i AS INTEGER

      fDialog.CAPTION = "Open Files"
      fDialog.Filter = IDE.FileFilter
      fDialog.FileName = ""
      fDialog.InitialDir = Strippath(IDE.MFEActiveFile)
      fDialog.Mode = fdOpen
      fDialog.MultiSelect = True
      IF fDialog.EXECUTE THEN
       FOR i = 1 TO fDialog.SelCount                           'item #0 is the directory
        MFE_Load(fDialog.Files(0)+fDialog.Files(i))         'array of selected file names
       NEXT i
       Splitter_Moved                                          'need to resize forms
      END IF
     END SUB


      '______________________________________________________________________________
     FUNCTION MFE_SaveCopyAs() AS STRING
'    fDialog.FileName = IDE.MFEActiveFile
'    fDialog.Filter = IDE.FileFilter
'    fDialog.Mode = fdSave
'    fDialog.MultiSelect = False
'    RESULT = ""
'    IF fDialog.Execute THEN           'new libs fixes save dialog overwrite
'        re.SaveToFile(fDialog.FileName)
'        re.SendEditor(SCI_SETSAVEPOINT, 0&, 0&)         'reached a point of saving, clear undo?
'        RESULT = fDialog.FileName
'        MFE_UpdateSaveButton
''        ClearFileChangeMonitor
'    END IF


      DIM SavDialog AS QSAVEDIALOG                        'QFileDialog.Filename needs fixing
      SavDialog.FileName = IDE.MFEActiveFile
      SavDialog.Filter = IDE.FileFilter

      RESULT = ""
      IF SavDialog.EXECUTE THEN                           'new libs fixes save dialog overwrite
       re.SaveToFile(SavDialog.FileName)
       re.SendEditor(SCI_SETSAVEPOINT, 0&, 0&)         'reached a point of saving, clear undo?
       RESULT = SavDialog.FileName
       MFE_UpdateSaveButton
'        ClearFileChangeMonitor
      END IF
     END FUNCTION




      '______________________________________________________________________________
     SUB MFE_Save

    'check if new file needs to be saved / save copy as
      IF IDE.NewFileAutoSave = False THEN
       DEFSTR tmp = FileNameNoExt(IDE.MFEActiveFile)               'do we have a new inserted file?
       IF (LEFT$(tmp, LEN(IDE.NewFileName)) = IDE.NewFileName) AND (LEN(tmp) <= LEN(IDE.NewFileName)+1) THEN
        tmp = MFE_SaveCopyAs                'get new name
        IF tmp <> "" THEN
         IDE.MFEActiveFile = tmp
         MFE_Tab.Tab(MFE_Tab.TabIndex) = Stripfilename(IDE.MFEActiveFile)
         MFE_List.Item(MFE_Tab.TabIndex) = tmp
        END IF
       END IF
      END IF

      re.SaveToFile(IDE.MFEActiveFile)
      re.SendEditor(SCI_SETSAVEPOINT, 0&, 0&)         'reached a point of saving, clear undo?
      Stat.Panel(5).CAPTION = "Saved " + IDE.MFEActiveFile
      MFE_UpdateSaveButton
'    ClearFileChangeMonitor
     END SUB



      '______________________________________________________________________________
     SUB MFE_SaveAs
      IF MFE_List.ItemCount > 0 THEN

       DIM sDialog AS QSAVEDIALOG                      'for some reason QFileDialog crashes this... fdialog.FileName
       sDialog.FileName = IDE.MFEActiveFile
       sDialog.Filter = IDE.FileFilter + "|Html|*.htm;*.html"
        'new libs fixes save dialog overwrite
       IF sDialog.EXECUTE THEN
        DEFSTR myExt = UCASE$(StripFileExt(sDialog.FileName))
        IF  myExt <> ".HTML" AND myExt <> ".HTM" THEN
         re.SaveToFile(sDialog.FileName)
         re.SendEditor(SCI_SETSAVEPOINT, 0&, 0&)         'reached a point of saving, clear undo?
         IDE.MFEActiveFile = sDialog.FileName
         MFE_Tab.Tab(MFE_Tab.TabIndex) = StripFileName(sDialog.FileName)
         MFE_List.Item(MFE_Tab.TabIndex) = sDialog.FileName
        ELSE
         File2Html(re.Text, sDialog.FileName, False)
        END IF
    '        ClearFileChangeMonitor
        Stat.Panel(5).CAPTION = "Saved as " + sDialog.FileName
        IDE_UpdateRecentList
        MFE_UpdateSaveButton
       END IF
      END IF
     END SUB



      '______________________________________________________________________________
     SUB MFE_SaveAll
      DEFINT i, lastIndx = MFE_Tab.TabIndex
      DEFSTR tmp
      MFE_SetCursor
      re.Visible = False

      FOR i = 0 TO MFE_List.ItemCount-1
       MFE_ChangeToIndexSilent(i)
       IF re.Modified THEN
            'check if new file needs to be save as..
        IF IDE.NewFileAutoSave = False THEN
         tmp = FileNameNoExt(MFE_List.Item(i))
         IF (LEFT$(tmp, LEN(IDE.NewFileName)) = IDE.NewFileName) AND (LEN(tmp) <= LEN(IDE.NewFileName)+1) THEN    'new file
          tmp = MFE_SaveCopyAs               'get new name
          IF tmp <> "" THEN
           IDE.MFEActiveFile = tmp
           MFE_TAb.Tab(MFE_Tab.TabIndex) = Stripfilename(IDE.MFEActiveFile)
           MFE_List.Item(MFE_Tab.TabIndex) = tmp
           re.SaveToFile(IDE.MFEActiveFile)
           re.SendEditor(SCI_SETSAVEPOINT, 0&, 0&)         'reached a point of saving, clear undo?
          END IF
         END IF
        END IF
        re.SaveToFile(MFE_List.Item(i))
        re.SendEditor(SCI_SETSAVEPOINT, 0&, 0&)             'reached a point of saving, clear undo?
       END IF
      NEXT i

      re.Visible = True
      Stat.Panel(5).CAPTION = "Saved all"
      MFE_UpdateSaveButton
      MFE_ChangeToIndex(lastIndx)
      MFE_SetCursor
     END SUB



      '______________________________________________________________________________
     FUNCTION MFE_GetFileIndex(name AS STRING) AS INTEGER
      DEFINT i, res = -1
      FOR i = 0 TO MFE_List.ItemCount-1
       IF UCASE$(name) = UCASE$(MFE_List.Item(i)) THEN res = i: EXIT FOR
      NEXT i
      RESULT = res
     END FUNCTION




      '______________________________________________________________________________
     SUB MFE_Delete(tc AS QTABCONTROL , id AS INTEGER)                               'need this to work correctly
      tc.DelTabs id
     END SUB


      '______________________________________________________________________________
     SUB MFE_Close
      IF MFE_List.ItemCount = 0 THEN EXIT SUB                                     'no doc loaded!
      IF MFE_Tab.TabIndex < 0 THEN EXIT SUB                                       'no active tab, or tab not created
      DEFINT i

      IDE.CancelOnClose = False                                                   'signal no cancel
      IF (re.Modified) THEN
       DEFINT MyVis = re.Visible                                               'are we in a mulifile operation?
       DEFINT MyEnable = re.Enabled
       IF MyVis = False THEN re.Visible = True
       IF MyEnable = False THEN re.Enabled = True
       i = MESSAGEDLG(IDE.MFEActiveFile + " has changed. Save Changes ?" , mtConfirmation , mbYes OR mbNo OR mbCancel , 0)
       IF MyVis = False THEN re.Visible = MyVis
       IF MyEnable = False THEN re.Enabled = MyEnable
       IF i = mrYes THEN MFE_Save
       IF i = mrCancel THEN IDE.CancelOnClose = True:   EXIT SUB               'Bail out completely
      END IF


      DEFINT pDoc, indx = MFE_Tab.TabIndex

      IF MFE_List.ItemCount-1 = 0 THEN                                            'only one doc, but don't remove scintilla component
       IDE.DocPtr(MFE_Tab.TabIndex) = 0                                        ' null it
       MFE_Delete(MFE_tab , indx)
       MFE_List.DelItems(indx)                                                 'need to manage Tabcontrol here
       IDE.MFEActiveFile = ""
       IDE.CursorPos(indx) = 0     :IDE.AnchorPos(indx) = 0    :IDE.FirstLine(indx) = 0
       IDE.BookMarkCount(indx) = 0
       MEMSET(VARPTR(IDE.BookMark(indx, 0)), -1, (IDE_MAX_FILES+1) * SIZEOF(INTEGER))
       SubFuncListView(indx).Clear
       IDE.ListIncludes(indx).Clear
       IDE.ListResources(indx).Clear
       IDE.LexLanguage(indx) = IDE.DefaultLexLanguage
       IDE.ModuleType(indx) = 0                                                'default compiler (rapidQ)
       CenterPanel.Visible = False                                             'don't release its memory
       re.Clear                                                                'clear it
      ELSE


       SELECT CASE MFE_Tab.TabIndex
       CASE -1                                                                 'somehow closed a tab not created
				'do nothing!

       CASE (MFE_List.ItemCount -1)                                            'close the last one
        re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(MFE_Tab.TabIndex-1)) 'view previous
        pDoc = IDE.DocPtr(MFE_Tab.TabIndex)
        re.SendEditor(SCI_RELEASEDOCUMENT, 0, pDoc)                         '(pop) pull off doc pointer (memory ID) release mem
        IDE.DocPtr(MFE_Tab.TabIndex) = 0                                    ' null it
        IDE.CursorPos(MFE_Tab.TabIndex) = 0
        IDE.AnchorPos(MFE_Tab.TabIndex) = 0
        IDE.FirstLine(MFE_Tab.TabIndex) = 0
        IDE.BookMarkCount(MFE_Tab.TabIndex) = 0
        MEMSET(VARPTR(IDE.BookMark(MFE_Tab.TabIndex, 0)), -1, (IDE_MAX_FILES+1) * SIZEOF(INTEGER))
        MFE_Delete(MFE_tab , indx)
        MFE_List.DelItems(indx)                                             'need to manage Tabcontrol here
        IDE.MFEActiveFile = MFE_List.Item(indx-1)                           'restore window
        MFE_Tab.TabIndex = indx-1
        SubFuncListView(indx).Clear
        IDE.ListIncludes(indx).Clear
        IDE.ListResources(indx).Clear
        IDE.LexLanguage(MFE_Tab.TabIndex) = IDE.DefaultLexLanguage
        IDE_SetModuleType                                                       'set language/compiler attributes for compiling etc
        MFE_SetCursor

       CASE ELSE                                                               'delete one then shift all above to previous slot
        DEFINT j, k, n
        DEFSTR lne
        MFE_Delete(MFE_tab , indx)                                          'get rid of the tab in tabcontrol
        pDoc = IDE.DocPtr(indx)                                             'save this first
        FOR i = indx TO (MFE_List.ItemCount -2)                             'shift down elements for each remaining tab
         IDE.DocPtr(i) = IDE.DocPtr(i+1)                                 'scintilla mem pointers
         MFE_List.Item(i) = MFE_List.Item(i+1)                           'file names
         IDE.CursorPos(i) = IDE.CursorPos(i+1)                           'cursor position
         IDE.AnchorPos(i) = IDE.AnchorPos(i+1)                           'cursor position
         IDE.FirstLine(i) = IDE.FirstLine(i+1)                           'first line visible
         IDE.BookMarkCount(i) = IDE.BookMarkCount(i+1)
         FOR k = 0 TO IDE_MAX_FILES
          IDE.BookMark(i,k) = IDE.BookMark(i+1,k)                     'transfer bookmarks
         NEXT k
         IDE.ListIncludes(i).Text = IDE.ListIncludes(i+1).Text           'include file names
         IDE.ListResources(i).Text = IDE.ListResources(i+1).Text         'Resource file names
         IDE.LexLanguage(i) = IDE.LexLanguage(i+1)                       'scintilla lexer
         IDE.ModuleType(i) = IDE.ModuleType(i+1)                         'type of document

         n = SubFuncListView(i+1).ItemCount                              'get how many we need to move
         SubFuncListView(i).Clear                                        'clear it, will add previous tabs info below
         SubFuncListView(i).Tag = SubFuncListView(i+1).Tag
         FOR j = 0 TO n-1                                                'all sub/functions in list
	'                  SubFuncListView(i).Item(j).Caption = SubFuncListView(i+1).Item(j).Caption      'crashes
          lne = SubFuncListView(i+1).Item(j).CAPTION
          SubFuncListView(i).AddItems lne
          SubFuncListView(i).Item(j).ImageIndex = VAL(FIELD$(lne, LineNumDelimitr, 3))      'get value from line, SubItem crashes
         NEXT j
        NEXT i
				'clear out last one
        IDE.DocPtr(MFE_List.ItemCount -1) = 0                               'null doc pointers
        SubFuncListView(MFE_List.ItemCount -1).Clear                        'clear out last lists
        SubFuncListView(MFE_List.ItemCount -1).Tag = MFE_List.ItemCount -1
        IDE.ListIncludes(MFE_List.ItemCount -1).Clear
        IDE.ListResources(MFE_List.ItemCount -1).Clear
        MFE_List.DelItems(MFE_List.ItemCount -1)                            'now release last name
        re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(indx))               'must view next window before delete
        re.SendEditor(SCI_RELEASEDOCUMENT, 0, pDoc)                         '(pop) pull off doc pointer (memory ID) release mem
        IDE.MFEActiveFile = MFE_List.Item(indx)                             'restore window
        MFE_Tab.TabIndex = indx
       END SELECT

      END IF

      IF LeftPanel.Visible THEN Properties_Clear                                  'if we have object viewer up it only keeps the current window
      re.Set_LineNumbers(Mnu_SetLineNumbers.Checked)                          	'reset margins for line numbering if needed
      MFE_GetCursor
      RightTabChange                                                              'update the right panel subs/inc/proj
      IDE.CurrTab = MFE_Tab.TabIndex                                              'store the last one viewed
     END SUB



      '______________________________________________________________________________
     SUB MFE_CloseAllExceptActive
      IF MFE_Tab.TabIndex > -1 THEN
       DEFSTR TheTabFile = MFE_List.Item(MFE_Tab.TabIndex)
       DIM i AS INTEGER

       MFE_ChangeToIndex(MFE_List.ItemCount - 1)               				'setting to the last will make it go faster
       DO
        FOR i = (MFE_List.ItemCount - 1) TO 0 STEP -1
         MFE_ChangeToIndexSilent(i)
         IF MFE_List.Item(i) <> TheTabFile THEN MFE_Close
         IF IDE.CancelOnClose THEN EXIT FOR
        NEXT i
        IF IDE.CancelOnClose THEN EXIT DO
       LOOP UNTIL MFE_List.ItemCount = 1
      END IF
      re.Set_LineNumbers(Mnu_SetLineNumbers.Checked)                          	'reset margins for line numbering if needed
      IDE.CurrTab = MFE_Tab.TabIndex                                              'store the last one viewed
     END SUB


      '______________________________________________________________________________
     SUB MFE_CloseAll
      IF MFE_List.ItemCount = 0 THEN EXIT SUB                 'no doc loaded!

      MFE_ChangeToIndex(MFE_List.ItemCount - 1)               'setting to the last will make it go faster
      DIM i AS INTEGER
      re.Enabled = False
      re.Visible = False
      FOR i = 0 TO MFE_List.ItemCount - 1
       MFE_Close
       IF IDE.CancelOnClose THEN EXIT FOR
      NEXT i

      re.Visible = True
      re.Enabled = True
      IF IDE.CancelOnClose THEN EXIT SUB
      MainListBoxResources.Clear
      MainListBoxIncludes.Clear
      FindTreeView.Clear                              'clear search results
      CenterPanel.Visible = False
      IDE.LastTab = -1                                '-1 = no file last viewed
      IDE.CurrTab = -1
      IDE.MainFileForCompiler = ""
      IDE.MFEActiveProject = ""                                   'clear
      IDE.MFEActiveFile = ""
     END SUB



      '_______________________________Project files _________________________________
      '______________________________________________________________________________

     SUB MFE_LoadProject(TheFileName AS STRING)
      DEFSTR OrigName = ini.FileName       'store old

      ini.FileName = TheFileName
      IF (ini.Exist = 0) THEN
       SHOWMESSAGE "Project file: " + TheFileName + " not found"
       ini.FileName = OrigName         'restore old
       EXIT SUB
      END IF

      IF MFE_List.ItemCount > 0 THEN
       IF MESSAGEDLG("Close All files?", mtWarning, mbYes OR mbNo, 0) = mrYes THEN MFE_CloseAll
      END IF


      DEFINT i = 0, j = 0, n = 0
      DEFSTR tmpStr, MyFileName

      ini.FileName = TheFileName                                                  'need to set this, MFE_Load will reset
      ReadIDEVariables                                                            'project files contain entire workspace
      DO
       ini.FileName = TheFileName                                              'need to set this, MFE_Load will reset
       ini.Section = "Open project files"                                      'try to follow PsPad rules
       TmpStr = ini.GET(STR$(i), "")
       IF TmpStr <> "" THEN
        MyFileName = FIELD$(TmpStr, ",", 1)                                 'first arg in comma separated list should be the filename
        MFE_Load(MyFileName)
        IDE.CursorPos(MFE_List.ItemCount-1) = VAL(FIELD$(TmpStr, ",", 2))   '2nd arg is get cursor position
        IDE.AnchorPos(MFE_Tab.TabIndex) = VAL(FIELD$(TmpStr, ",", 2))       'set to no selection
        IDE.BookMarkCount(MFE_Tab.TabIndex) = 0                             'set to null
        n = TALLY(TmpStr, ",")                                              'find out how many bookmarks
        IF n > 2 THEN
         FOR j = 3 TO n+1
          re.AddBookMark(VAL(FIELD$(TmpStr, ",", j)))                 'add a bookmark for each one
          INC(IDE.BookMarkCount(MFE_Tab.TabIndex), 1)
          IDE.BookMark(MFE_Tab.TabIndex, IDE.BookMarkCount(MFE_Tab.TabIndex)) = VAL(FIELD$(TmpStr, ",", j))
         NEXT j
        END IF
        IDE.ModuleType(MFE_Tab.TabIndex) = VAL(FIELD$(TmpStr, ",", n+2))    'last position indicates if it is a freebasic /DLL module etc
        i++
       END IF

       MFE_SetCursor                                                  'set the cursor after bookmarks
       re.Set_AnchorPosition(IDE.CursorPos(MFE_Tab.TabIndex))         'need to place anchor, otherwise it is selected

      LOOP UNTIL TmpStr = ""                                              'end opening all project files

      IF i > 0 THEN
       ini.Section = "Selected Project Files"
       TmpStr = ini.GET("Main", "")
       IF TmpStr <> "" THEN IDE.MainFileForCompiler = TmpStr       'load main file for compiler

       ini.Section = "Selected"
       TmpStr = ini.GET("Main", "")
       IF TmpStr <> "" THEN
        i = MFE_GetFileIndex(TmpStr)                          'go to last selected file window
        IF i > -1 THEN MFE_ChangeToIndex(i)
       END IF
      END IF

      MFE_UpdateRecentProj(TheFileName)			                    'update project menus
      IDE.MFEActiveProject = TheFileName                              'for later saving
      ini.FileName = OrigName                                         'restore old
     END SUB




     SUB MFE_OpenProject
      fDialog.CAPTION = "Open FreeQ Project"
      fDialog.Filter = "FreeQ proj|*.QProj|All Files|*.*"
      fDialog.FileName= ""
      fDialog.Mode = fdOpen
      fDialog.MultiSelect = False
      IF fDialog.EXECUTE THEN
       MFE_LoadProject(fDialog.FileName)
       Splitter_Moved                                          'need to resize forms
      END IF
     END SUB


     SUB MFE_CloseProjectFiles
      IF MESSAGEDLG("Save Project?", mtConfirmation, mbYes OR mbNo, 0) = mrYes THEN  MFE_SaveProject
      MFE_CloseAll
      IDE.MainFileForCompiler = ""
      IDE.MFEActiveProject = ""                                   'clear
      IDE.MFEActiveFile = ""
      ini.FileName = TheMainIniFile                               'get main ini file
      ReadIDEVariables                                            'restore default workspace
     END SUB



     SUB MFE_UpdateRecentProj(TheFileNam AS STRING)

      tmpList.Clear
      tmpList.AddItems(TheFileNam)
      IF mnuRecentProj0.CAPTION <> "" THEN tmpList.AddItems(mnuRecentProj0.CAPTION)
      IF mnuRecentProj1.CAPTION <> "" THEN tmpList.AddItems(mnuRecentProj1.CAPTION)
      IF mnuRecentProj2.CAPTION <> "" THEN tmpList.AddItems(mnuRecentProj2.CAPTION)

      IF tmpList.ItemCount > 1 THEN
       DEFINT i
       FOR i = (tmpList.ItemCount -1) TO 1 STEP -1
        IF TheFileNam = tmpList.Item(i) THEN tmpList.DelItems(i)
       NEXT i
      END IF

'    'set recent project menus ...
      IF tmpList.ItemCount > 0 THEN mnuRecentProj0.CAPTION = tmpList.Item(0)
      IF tmpList.ItemCount > 1 THEN mnuRecentProj1.CAPTION = tmpList.Item(1)
      IF tmpList.ItemCount > 2 THEN mnuRecentProj2.CAPTION = tmpList.Item(2)

      ini.FileName = TheMainIniFile                               'get main ini file
      ini.Section = "RecentProjects"
      ini.write("File0", mnuRecentProj0.CAPTION)
      ini.write("File1", mnuRecentProj1.CAPTION)
      ini.write("File2", mnuRecentProj2.CAPTION)
     END SUB




     SUB MFE_SaveProject
      IF MFE_List.ItemCount > 0 THEN
       fDialog.FileName = ""
       fDialog.CAPTION = "Save Project"
       fDialog.Filter = "FreeQ proj|*.QProj|All Files|*.*"
       fDialog.Mode = fdSave
       fDialog.MultiSelect = False
       fDialog.FileName = IDE.MFEActiveProject

       IF fDialog.EXECUTE THEN
        MFE_UpdateRecentProj(fDialog.FileName)                              'add to recent project menu  mnuRecentProj0
        DEFSTR OrigName = ini.FileName                                      'store old
        IF INSTR(StripFileExt(fDialog.FileName), ".") = 0 THEN fDialog.FileName = fDialog.FileName + ".Qproj"

        ini.FileName = fDialog.FileName                                     'this will create if not already created
        IDE.MFEActiveProject = fDialog.FileName                             'store any updated naming for later
        IF ini.Exist THEN ClearIni                                          'already exists, we need to clear out all old stuff!!
        WriteIDE_FormVariables                                              'store the main form settings
        IDE_Conf_VersionInfoForm_Close                                      'this sets the versionInfo!! need this here because of WriteIDEVariables...
        WriteIDEVariables(False)                                            'write the variables to the ini file but don't reset IDE

        DEFINT i, j
        DEFSTR TmpStr = ""
        ini.Section = "Open project files"                                  'try to follow PsPad rules
        FOR i = 0 TO MFE_List.ItemCount -1                                  'for all opened files
         TmpStr = MFE_List.Item(i) + "," + STR$(IDE.CursorPos(i))        'first arg is filename, 2nd is cursor position
         IF IDE.BookMarkCount(i) > 0 THEN                                'any book marks?
          FOR j = 1 TO IDE.BookMarkCount(i)
           TmpStr = TmpStr + "," + STR$(IDE.BookMark(i, j))        'comma delimit all lines with bookmarks
          NEXT j
         END IF
         TmpStr = TmpStr + "," + STR$(IDE.ModuleType(i))                 'last item is flag for freebasic module
         ini.write(STR$(i), TmpStr)                                      'final string with all arguments
        NEXT i

        ini.Section = "Selected Project Files"
        IF IDE.MainFileForCompiler <> "" THEN ini.write("Main", IDE.MainFileForCompiler)
        ini.Section = "Selected"
        ini.Write("Main", IDE.MFEActiveFile)
        ini.FileName = OrigName                                                 'restore old
        Stat.Panel(5).CAPTION = "Saved Project"
       END IF
      END IF
     END SUB


      '______________________________________________________________________________

     SUB MFE_GetCursor
      IDE.FirstLine(MFE_Tab.TabIndex) = re.GetEditor(SCI_GETFIRSTVISIBLELINE, 0&, 0&)
      IDE.CursorPos(MFE_Tab.TabIndex) = re.Position
      IDE.AnchorPos(MFE_Tab.TabIndex) = re.AnchorPosition
     END SUB


     SUB MFE_SetCursor
      re.Set_AnchorPosition(IDE.AnchorPos(MFE_Tab.TabIndex))
      re.Set_Position (IDE.CursorPos(MFE_Tab.TabIndex))
      DEFINT i = re.GetEditor(SCI_LINEFROMPOSITION, re.Position, 0&)
      re.EnsureLineVisible(i)                           'ensures visibility
'    re.EnsureLineVisible(IDE.FirstLine(MFE_Tab.TabIndex) )  '- re.GetEditor(SCI_LINESONSCREEN, 0&, 0&) \2)
     END SUB

     SUB MFE_SetActiveAsMainFileForCompiler
      IDE.MainFileForCompiler = ""            'removes specific file as default
     END SUB

     SUB MFE_SetAsMainFileForCompiler
      IDE.MainFileForCompiler = MFE_List.Item(MFE_Tab.TabIndex)
      Stat.Panel(5).CAPTION = "Main file for compile: " + IDE.MainFileForCompiler
     END SUB

     SUB mnuSetAsDefaultCompilerFile_Click
      IDE.ModuleType(MFE_Tab.TabIndex) = 0
     END SUB

     SUB mnuSetAsFBAppFile_Click
      IDE.ModuleType(MFE_Tab.TabIndex) = 1
     END SUB

     SUB mnuSetAsFBDLLFile_Click
      IDE.ModuleType(MFE_Tab.TabIndex) = 2
     END SUB



     SUB RightPanelRefresh           'refresh right panel objects
      IF MFE_List.ItemCount > 0 THEN ParseSubIncRes(MFE_Tab.TabIndex, re.Text)            'get new list of subs/functions include files
      ProjFileList.Update                                                                 'in Project tab, list of files
      DirTree.Reload                                                                      'directory tree in Project Tab
    'IF FindAllPanel.Visible   'don't need to refresh
     END SUB


     SUB LeftPanelRefresh
      LoadProjectTree(MFE_Tab.TabIndex, re.Text)         'reparse Qobjects
     END SUB





     SUB SubFuncListView_Click(Sender AS QLISTVIEW)
'    MFE_ChangeToIndex(Sender.Tag)       'switch to tab with file just in case
'    DEFINT TheLineNum = VAL(Sender.SubItem(Sender.ItemIndex, 0))
      IF Sender.ItemIndex > -1 THEN
       DEFSTR tmp = FIELD$(Sender.Item(Sender.ItemIndex).CAPTION, LineNumDelimitr, 2)
       DEFINT TheLineNum = VAL(tmp)

       re.GotoLine(TheLineNum)
       re.ActiveLineColor(RGB(255,200,128), 0)
       IDE.HiLightTurnOFF = True                                       'toggle to turn off compile error line
       re.SetFocus
      END IF
     END SUB



     SUB Widget_Click(Button%, X%, Y%, Shift%, Sender AS QCOOLBTN)

      tmpList.Clear
      DEFSTR TheObjName = TRIM$(LCASE$(Sender.Hint))
      IF TheObjName = "new application" THEN TheObjName = "new_application"               'won't work in directory with spaces
      TheObjName = TheObjName + ".tpl"
      DEFSTR s = IDE.CompilerTemplatePath + TheObjName
      Stat.Panel(5).CAPTION = "Loading template: " + s

      IF FILEEXISTS(s) = False THEN
       s = IDE.CompilerTemplatePath + "q" + TheObjName                                  'append as Qobject if not found
       IF FILEEXISTS(s) = False THEN
        IF MESSAGEDLG("Template: " + Sender.Hint + " not found." + CRLF + _
         "Do you want to set the template directory?", mtWarning, mbYes OR mbNo, 0) = mrYes THEN
         IDE_Conf_CompileOpt_Show                                                    'show compiler option tab
         EXIT SUB
        END IF
       END IF
      END IF

      IF Button% = MouseLtButton THEN
       tmpList.LoadFromFile(s)
       IF tmpList.Text <> "" THEN re.AddStrings(tmpList.Text)
       tmpList.Clear
      ELSE
       MFE_Load(s)
       Stat.Panel(5).CAPTION = "Editing template: " + s
      END IF

     END SUB




     SUB Execute_ExternalApp(TheCommand AS STRING)       '    'run a batch, exe, or script
      DEFSTR s = TheCommand
      s = REPLACESUBSTR$(s, "%FILENAME%", IDE.MFEActiveFile)
      s = REPLACESUBSTR$(s, "%FILE%", StripFileName(IDE.MFEActiveFile))
      s = REPLACESUBSTR$(s, "%EXT%", StripFileExt(IDE.MFEActiveFile))
      s = REPLACESUBSTR$(s, "%CURRPATH%", CURDIR$)
      s = REPLACESUBSTR$(s, "%PATH%", StripPath(IDE.MFEActiveFile))
      s = REPLACESUBSTR$(s, "%APPPATH%", Application.Path)
      Stat.Panel(5).CAPTION = "exec... " + s
      ShellExecute(0,"open", s, "","",1)
     END SUB


     FUNCTION IDE_GetKeywordFromText(inTxt AS STRING, RemovList AS STRING) AS STRING
      DEFSTR s = inTxt
      s = TRIM$(s)
      s = s - CHR$(13)                'remove EOL
      s = s - CHR$(10)

      IF RemovList <> "" THEN
       DEFINT i
        'get the parent object for a TYPE
       IF INSTR(RemovList, ".") > 0 THEN
            'IF INSTR(s, ".") THEN s = LEFT$(s, INSTR(s, ".") -1)
        IF INSTR(s, ".") THEN s = RIGHT$(s, LEN(s) - INSTR(s, "."))
       END IF
        'remove the function name for a bracket
       IF INSTR(RemovList, "(") > 0 THEN
        IF INSTR(s, "(") THEN s = LEFT$(s, INSTR(s, "(") -1)
       END IF
        'for the rest, remove the char from the text
       FOR i = 1 TO LEN(RemovList)
        s = s - RemovList[i]
       NEXT i
      END IF
      RESULT = s
     END FUNCTION



'--------------------------end subroutines for panels visibility-----------------------------------
     FUNCTION GetLanguageFromFile(TheFileName AS STRING) AS INTEGER

      RESULT = IDE.DefaultLexLanguage               'this is usually SCLEX_VB for RapidQ

      IF INSTR(".BAS.INC.RQB" , UCASE$(StripFileExt(TheFileName))) THEN
       RESULT = SCLEX_VB
       EXIT FUNCTION
      END IF

      IF INSTR(".BI" , UCASE$(StripFileExt(TheFileName))) THEN
       RESULT = SCLEX_FREEBASIC
       EXIT FUNCTION
      END IF

      IF INSTR(".H.CPP.CS.CXX.JAVA" , UCASE$(StripFileExt(TheFileName))) THEN
       RESULT = SCLEX_CPP
       EXIT FUNCTION
      END IF

      IF INSTR(".HTML.HTM.SHTML.JS" , UCASE$(StripFileExt(TheFileName))) THEN
       RESULT = SCLEX_HTML
       EXIT FUNCTION
      END IF

      IF INSTR(".TXT.INI.DOC.README" , UCASE$(StripFileExt(TheFileName))) THEN
       RESULT = SCLEX_NULL
       EXIT FUNCTION
      END IF


      IF UCASE$(StripFileExt(TheFileName)) = ".ASM" THEN
       RESULT = SCLEX_ASM
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".PAS.DPR " THEN
       RESULT = SCLEX_PASCAL
       EXIT FUNCTION
      END IF


      IF UCASE$(StripFileExt(TheFileName)) = ".VBS" THEN
       RESULT = SCLEX_VBSCRIPT
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".ISS" THEN
       RESULT = SCLEX_INNOSETUP
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".XML" THEN
       RESULT = SCLEX_XML
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".BAT" THEN
       RESULT = SCLEX_BATCH
       EXIT FUNCTION
      END IF

    'Various web scripting

      IF UCASE$(StripFileExt(TheFileName)) = ".PY" THEN
       RESULT = SCLEX_PYTHON
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".ASP" THEN
       RESULT = SCLEX_ASP
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".PHP" THEN
       RESULT = SCLEX_PHP
       EXIT FUNCTION
      END IF

      IF UCASE$(StripFileExt(TheFileName)) = ".CSS" THEN
       RESULT = SCLEX_CSS
       EXIT FUNCTION
      END IF

     END FUNCTION



     SUB IDE_SetFileLanguage(Sender AS QMENUITEM)
'    DEFINT TheLang = SCLEX_VB
'    SELECT CASE Sender.Tag
'    CASE SCLEX_ASP
'    CASE SCLEX_BATCH
'    CASE SCLEX_CPP
'    CASE SCLEX_CSS
'    CASE SCLEX_FREEBASIC
'    CASE SCLEX_HTML
'    CASE SCLEX_INNOSETUP
'    CASE SCLEX_NULL
'    CASE SCLEX_PASCAL
'    CASE SCLEX_PHP
'    CASE SCLEX_PYTHON
'    CASE SCLEX_VB
'    CASE SCLEX_VBSCRIPT
'    CASE SCLEX_XML

      IDE.LexLanguage(MFE_Tab.TabIndex) = Sender.Tag          'set lexer highlighter
      IDE_SetModuleType                                       'set language/compiler attributes for compiling etc
      IF IDE.HiLighting THEN
       IDE_SetHighlighting(IDE.LexLanguage(MFE_Tab.TabIndex))
      END IF
     END SUB


     SUB IDE_SetLanguage
    'set the main language lexer for highlighting
      IDE.DefaultLexLanguage = VAL(RIGHT$(IDE_Conf_MainLanguage.Item(IDE_Conf_MainLanguage.ItemIndex), 4))
      IDE_SetHighlighting(IDE.DefaultLexLanguage)
     END SUB



     SUB IDE_SetHighlighting(TheLanguage AS INTEGER)
      re.SetStyle(SCE_B_DEFAULT, IDE.MainFont.COLOR, IDE.BackGround)

        'set language
      re.Set_Language(TheLanguage)        'SCLEX_VB, SCLEX_FREEBASIC, SCLEX_POWERBASIC is compatible with RapidQ

        'dang must do this for RapidQ....
      IF TheLanguage = SCLEX_VB THEN
       IF IDE.KeyWordList.ItemCount > 0 THEN re.LoadKeywordList(0, IDE.KeyWordList)   ': IDE.KeyWordList.Clear
       IF IDE.KeyWordList2.ItemCount > 0 THEN re.LoadKeywordList(1, IDE.KeyWordList2)   ': IDE.KeyWordList2.Clear
       IF IDE.KeyWordList3.ItemCount > 0 THEN re.LoadKeywordList(2, IDE.KeyWordList3)   ': IDE.KeyWordList3.Clear
      END IF

       'set the font for the keywords
      re.SetStyle(SCE_B_COMMENT,      IDE.CommentFore,    IDE.CommentBack,    IDE.CommentBold, IDE.CommentItalic, IDE.CommentUnderL )
      re.SetStyle(SCE_B_NUMBER,       IDE.NumberFore,     IDE.NumberBack,     IDE.NumberBold, IDE.NumberItalic, IDE.NumberUnderL )
      re.SetStyle(SCE_B_STRING,       IDE.StringFore,     IDE.StringBack,     IDE.StringBold, IDE.StringItalic, IDE.StringUnderL )
      re.SetStyle(SCE_B_PREPROCESSOR, IDE.PreProcessorFore, IDE.PreProcessorBack, IDE.PreProcessorBold, IDE.PreProcessorItalic, IDE.PreProcessorUnderL )
      re.SetStyle(SCE_B_OPERATOR,     IDE.OperatorFore,   IDE.OperatorBack,   IDE.OperatorBold, IDE.OperatorItalic, IDE.OperatorUnderL )
      re.SetStyle(SCE_B_KEYWORD,      IDE.KeywordFore,    IDE.KeywordBack,    IDE.KeywordBold, IDE.KeywordItalic, IDE.KeywordUnderL )
      re.SetStyle(SCE_B_KEYWORD2,     IDE.Keyword2Fore,   IDE.Keyword2Back,   IDE.Keyword2Bold, IDE.Keyword2Italic, IDE.Keyword2UnderL )
      re.SetStyle(SCE_B_KEYWORD3,     IDE.Keyword3Fore,   IDE.Keyword3Back,   IDE.Keyword3Bold, IDE.Keyword3Italic, IDE.Keyword3UnderL )
        're.SendEditor(SCI_COLOURISE, 0&, -1&)
     END SUB


     SUB IDE_SetModuleType
      IF IDE_Conf_MainLanguage.ItemIndex <> 1 THEN
       IDE.ModuleType(MFE_Tab.TabIndex) = 0                              'default compiler (rapidQ)
      ELSE
       IDE.ModuleType(MFE_Tab.TabIndex) = 1                              'set as FreeBasic
      END IF
     END SUB


掌柜推荐
 
 
¥1,420.00 ·
 
 
¥950.00 ·
 
 
¥288.00 ·
 
 
¥738.00 ·
 
 
¥397.00 ·
 
 
¥750.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-12-07 21:18:03