#HEADER
//TH-Header
//*****************************************************************************************
// Copyright (c) 2000 Michael Kurz
// All rights reserved.
// If you want to use this source in your applications conatct: <MichaelKurz@gmx.at>
//
// $FileName    : Editor.src
// $ProjectName : CODEMAX EDITOR
// $Author      : Michael Kurz <MichaelKurz@gmx.at>
// $Created     : 02-20-2001 @ 19:00
//
// Contents:
//      Main file for the CodeMax Editor, which is trimmed specially for editing
//      working with Visual DataFlex CodeFiles.
//
//*****************************************************************************************
//TH-RevisionStart
// 16.05.2001 13:14  Inserting Revisionmarks is possible   Mk     SERVER
//                   now.
// 30.05.2001 18:21  Compiling in the Background           Mk     SERVER
// 30.05.2001 18:21  Registering Classes in the IDE and    MB     SERVER
//                   creating *.DFC files
// 06.06.2001 16:51  Save all Button in the ToolBar        Mk     SERVER
//TH-RevisionEnd

    // General Packages...
    // 03-02-03 **WvA: Moved up to first line so that the precompile is used
Use DfAllEnt.pkg            // All Standard VDF Includes.
Use wave.pkg                // for playing system sounds

// First of all, we required to identify - what files we use
// Fill this section if any new file added!
Define TH_DBFILE_VDFCLS     For 1
Define TH_DBFILE_SYSFILE    For 2
Define TH_DBFILE_VDFPROP    For 3
Define TH_DBFILE_ASDB       For 4
Define TH_DBFILE_VDFPRNT    For 5
Define TH_DBFILE_CUSTMENU   For 6
Define TH_DBFILE_THTODO     For 7
Define TH_DBFILE_EDITOR     For 20


    // For a better readable code.
Define CM_NewFileName       For "Untitled"
Define TO_EDIT              For True
Define TO_VIEW              For False

String gsProjectName
String gsProgrammname
String gsVerionsNr
Move "KURANT Project"   To gsProjectName
Move "The Hammer"       To gsProgrammname
Move "2.0"              To gsVerionsNr

    // Constants for the AppToolBarItems.
Enum_List
    Define TBItem_New       For 0
    Define TBItem_Open
    Define TBItem_Open_Pkg
    Define TBItem_Open_DD
    Define TBItem_Save
    Define TBItem_SaveAll
    Define TBItem_Print
    Define TBItem_Cut
    Define TBItem_Copy
    Define TBItem_Paste
    Define TBItem_Undo
    Define TBItem_Redo
    Define TBItem_Find
    Define TBItem_Replace
    Define TBItem_Compile
    Define TBItem_Run
    Define TBItem_Debug
    Define TBItem_Execute
    Define TBItem_Todo
End_Enum_List


Integer ghoNativeFiles
Object oTHNativeFiles Is a Array
    Send Delete_Data
    Set Value Item TH_DBFILE_VDFCLS     To 1
    Set Value Item TH_DBFILE_SYSFILE    To 1
    Set Value Item TH_DBFILE_VDFPROP    To 1
    Set Value Item TH_DBFILE_ASDB       To 1
    Set Value Item TH_DBFILE_VDFPRNT    To 1
    Set Value Item TH_DBFILE_CUSTMENU   To 1
    Set Value Item TH_DBFILE_THTODO     To 1
    Set Value Item TH_DBFILE_EDITOR     To 1
    Move Self To ghoNativeFiles
End_Object


// Save the real startupDirectory.
String gsCurrentProgramFile     255
String gsCurrentCommandLinePara 255


Move "" To gsCurrentProgramFile

//  Set date attributes as needed
Set_Date_Attribute sysdate4_State To (True)
Set_Date_Attribute Date4_State    To (True)
Set_Date_Attribute epoch_value    To -10101




#IF (FMAC_VERSION < 8)
// 2001-01-09 -RvdW
Define CURRENT$WORKSPACE    For "Hammer"

Use cWorkspaceEx.pkg
Use Startup.pkg                              //@
Object Splash_Screen Is A SplashScreenPanel  //@
    Set Bitmap To "LOGO.BMP"                 //@
    Send Activate                            //@
End_Object                                   //@

//  Set date attributes as needed
Set_Date_Attribute sysdate4_State To (True)
Set_Date_Attribute Date4_State    To (True)
Set_Date_Attribute epoch_value    To 30

    // Modified WorkSpace, to allow variable WrkSpc name.
Object ProgramWorkspace Is A cWorkspaceEx
    Set piCmdLineSupport    To True                 // Use it for CommandLine Parameters.
    Set WorkspaceName       To CURRENT$WORKSPACE

        // Propeties to store some global flags.
    Property String  psWrkSpcOpenFileName           Public ""
    Object oWrkSpcOpenFileNames Is An Array
    End_Object
        // Sends the given Message to the given Object with all given
        // Parameters.
    Procedure WrkSpcDoForAllFiles Integer iMsg Integer hoDest
        Integer hoID iC
        String  sFile
        Move (oWrkSpcOpenFileNames(Self)) To hoID
        For iC From 0 To (Item_Count(hoID)-1)
            Get value Of hoID Item iC   To sFile
            If sFile Ne "" If iMsg If hoDest Begin
                Send iMsg To hoDest sFile
            End
        End
    End_Procedure

    Property Integer piWrkSpcNewFile                Public False
    Property Integer piWrkSpcSetVersion             Public False
    Property Integer piWrkSpcRegister               Public False

        // Procedure which are called when the CommandLineParameters are received.
    Procedure WrkSpcRegister
    	Set piWrkSpcRegister	To True
    End_Procedure
    Procedure WrkSpcOpenFile String sFile
        Integer iArg
        String  sArg
        Set psWrkSpcOpenFileName    To sFile
        Send Delete_Data            To (oWrkSpcOpenFileNames(Self))
        For iArg From 1 To NUM_Arguments
            Movestr iArg&   To sArg
            If (Trim(sArg)) Ne "" Begin
                Set value Of (oWrkSpcOpenFileNames(Self)) Item (Item_Count(oWrkSpcOpenFileNames(Self))) To sArg
            End
        End
    End_Procedure
    Procedure WrkSpcNewFile
        Set piWrkSpcNewFile         To True
    End_Procedure
    Procedure WrkSpcSetVersion
        Set piWrkSpcSetVersion      To True
    End_Procedure

        // Commands which should been handled from the CmdLine:
    Send RegisterCommand "-REGISTER"    Msg_WrkSpcRegister      0 "Associates all VDF Filetypes to the Hammer."
    Send RegisterCommand "-OPEN"        Msg_WrkSpcOpenFile      0 "Opens the given file."
    Send SetDefaultCommand              // -OPEN is the default Command.
    Send RegisterCommand "-NEW"         Msg_WrkSpcNewFile       0 "Opens a empty file view."
    Send RegisterCommand "-SETVERSION"  Msg_WrkSpcSetVersion    0 "Opens the Version/ Workspace dialog on startup"
End_Object

// **WvA. Only needed for VDF7 and below
Use DllHandler.pkg


// Only neccesary for developing this editor itself, because if we compile the hammer
// from within the hammer then the DLL is loaded from the current windows directory :-(
// as a result we get errors when trying to run the hammer.
// Thanks to this we can keep our DLLs in one place, the programs application folder.
Procedure LoadDllLibraries
  Send doLoadLibrary Of oDllHandler "PARSER.DLL"
  Send doLoadLibrary Of oDllHandler "TabControlShadow.Dll"
  Send doLoadLibrary Of oDllHandler "RunProgramNotify.Dll"
  Send doLoadLibrary Of oDllHandler "THCS23.DLL"
End_Procedure // LoadDllLibraries

Send LoadDllLibraries

#ELSE
// 2001-01-09 -RvdW
#Replace CURRENT$WORKSPACE   "Hammer"

// 2001-01-09 -RvdW
// *** Add Appication Object for vdf8, The hole workspace stuff need clean up...
Use cApplicationEx.pkg
Use Startup.pkg                              //@
Object Splash_Screen Is A SplashScreenPanel  //@

    //#IF (!@ >= 140)
    //Set pbSizeToClientArea To False
    //#ENDIF
    Set Bitmap To "LOGO.BMP"                 //@
    Send Activate                            //@
End_Object                                   //@

Object oApplication Is A cApplicationEx
    Set piCmdLineSupport    To True                 // Use it for CommandLine Parameters.
    Set psCompany To gsProjectName
    Set psProduct To gsProgrammname
    Set psVersion To gsVerionsNr

    //Set pbPreserveEnvironment To False // This will stop the program reading/writing its settings to the registry
    //Set psHelpFile To "HelpName.hlp" // Please provide the name of your Windows help file.
    //Set pbEnterKeyAsTabKey To True // Will make the enter key act like the tab key

        // Propeties to store some global flags.
    Property String  psWrkSpcOpenFileName           Public ""
    Object oWrkSpcOpenFileNames Is An Array
    End_Object
        // Sends the given Message to the given Object with all given
        // Parameters.
    Procedure WrkSpcDoForAllFiles Integer iMsg Integer hoDest
        Integer hoID iC
        String  sFile
        Move (oWrkSpcOpenFileNames(Self)) To hoID
        For iC From 0 To (Item_Count(hoID)-1)
            Get value Of hoID Item iC   To sFile
            If sFile Ne "" If iMsg If hoDest Begin
                Send iMsg To hoDest sFile
            End
        End
    End_Procedure

    Property Integer piWrkSpcNewFile                Public False
    Property Integer piWrkSpcSetVersion             Public False
    Property Integer piWrkSpcRegister               Public False

        // Procedure which are called when the CommandLineParameters are received.
    Procedure WrkSpcRegister
    	Set piWrkSpcRegister	To True
    End_Procedure

    Procedure WrkSpcOpenFile String sFile
        Integer iArg
        String  sArg
        Set psWrkSpcOpenFileName    To sFile
        Send Delete_Data            To (oWrkSpcOpenFileNames(Self))
        For iArg From 1 To NUM_Arguments
            Movestr iArg&   To sArg
            If (Trim(sArg)) Ne "" Begin
                Set value Of (oWrkSpcOpenFileNames(Self)) Item (Item_Count(oWrkSpcOpenFileNames(Self))) To sArg
            End
        End
    End_Procedure

    Procedure WrkSpcNewFile
        Set piWrkSpcNewFile         To True
    End_Procedure

    Procedure WrkSpcSetVersion
        Set piWrkSpcSetVersion      To True
    End_Procedure

        // Commands which should been handled from the CmdLine:
    Send RegisterCommand "-REGISTER"    Msg_WrkSpcRegister      0 "Associates all VDF Filetypes to the Hammer."
    Send RegisterCommand "-OPEN"        Msg_WrkSpcOpenFile      0 "Opens the given file."
    Send SetDefaultCommand              // -OPEN is the default Command.
    Send RegisterCommand "-NEW"         Msg_WrkSpcNewFile       0 "Opens a empty file view."
    Send RegisterCommand "-SETVERSION"  Msg_WrkSpcSetVersion    0 "Opens the Version/ Workspace dialog on startup"

    Procedure OnCreate
        Send DoOpenWorkspace (CURRENT$WORKSPACE)
    End_Procedure

End_Object // oApplication

#ENDIF


// Showln Replacement that uses debugviewer. ShowDebug {string} {string}...
// 28.01.2003 BP
//Use windebug


Use cWorkSpaceHandlerEx.pkg     // Workspace handler (needs to be at the top)

Use cTH_StatusPanel.pkg         // Status panel for batch processing (used in the utilities)
//
Use cCodeMax.pkg                // class: cCodeMaxEdit, all definitions for the DLL Control use.
Use Start_UIExcl.Pkg            // Some abilities to check if another instance of the program is running
Use mExecute.Pkg                // Covers calls to ShellExecute.
Use cSplitterControl.Pkg        // Splitters
Use cDirectorySelector.pkg      // Directory Selection.
Use vWin32fh.pkg
#ENDHEADER
Use cParser.Pkg                 // Parses the Text
Use Bitmaps.pkg                 // Get Bitmaps for Classes
Use DrgNDrop.pkg                // Drag&Drop Handler from Stuart Booth
Use oKeysArray.pkg              // An Array which contains all KeyNames.
Use mWinAPIGetKeyNameText.pkg   // Conversion of VKKeys to ANSI keycodes.
Use cFDFileReader.Pkg           // Reads Field names out of an *.FD file.
Use KPHammer-About.dg


    // This Procedure should no longer be neccessary.
    // MK 27.06.2001 21:41
Procedure IncludeMakePath
    String sMake sMake2 sOpenPath
    Get_Attribute DF_OPEN_PATH                          To sOpenPath
    Get_Profile_String "DFCOMP"     "MakePath"          To sMake
    Get_Profile_String "WorkSpaces" "SystemMakePath"    To sMake2
    Set_Attribute DF_OPEN_PATH              To (sOpenPath+";"+sMake+";"+sMake2)
End_Procedure
Send IncludeMakePath

Integer ghoFileTabs             // Define a global integer for the file-tab window 03.03.2003 BP
Integer ghoElementsTree
//
Register_Object oMain
Register_Object oClientArea
Register_Object oErrors
Register_Object oFileFinder
Register_Object oTabPage1
Register_Object oErrorList
Register_Object oFindFiles
Register_Object oTabFindObjects

    // Codemax Editor specific Packages
Use mEditorMacros.pkg
Use mEditorGeneral.Pkg          // General Functions and Definitions as: TabDialog KeyDefinitions, FileOpenDialog
Use cEditorProperties.Pkg       // Contains all Properties which can be Save (SaveIni) and loaded (LoadIni) to disk.
Use cCodeTip.Pkg                // Class for CodeTip (New feature) support
Use cCodeList.pkg               // Class for CodeList (New feature) support
Use oIDETagsArray.pkg           // An Array that contains all the currently existing IDE/DDB/Studio tags (old now, but let's move it in for easy code syncing)
Use cEditorEdit.Pkg             // subclasses the cCodeMaxEdit for the use in this editor
Use cEditorEditPopup.pkg        // One PopupMenu for all CodemaxEdits
Use cEditorEditView.Pkg         // creates a cEditorEdit in itself. (cIconView)
Use cEditorToolView.Pkg         // Standard view for showing others then files in the editor.
Use mUserAndComputerName.pkg    // gsComputerName && gsUserName
Use mEditorEditor.Pkg           // Procedures to acces dbms: Editor.Dat

Use cCD_Popup.Pkg               // Extends the CD_Client class with general purpose Properties.
Use WorkSpace.Sl
Use oObjectsMethods.Sl
Use oRegisterCls.Sl
Use EditorCmdLinePara.Sl        // Simple ModalPanel to enter a commandline. Used with get GetCommandLineParameter "Init" to sCmd
Use cDependencyScanner.pkg      // Scans all adjusted filetypes in the current directory for their #include and Use statements.
// ** SVN 28/01-2003
//Use CodeArt.pkg
Use CodePub.pkg
//
Use cMultiOpenDialog.pkg        // Provides and standard OpenDialog with the ability to select multiple files. Added 28.01.2003 BP
Use cDyntabdialog.pkg
Use cFolderTabs.pkg

Use Help_Ids.inc    // Developer should provide this file of help context links.
Use Std_Help.pkg    // Help
Use cExtMenu.pkg    // Allows Bitmaps in Menu!
Use cRPCServer.pkg  // To control from one Editor to another.
Use findfiles.dg

// This function returns Current Editor view.
Function GetCurrentEditView Global Returns Integer
    Integer hCl hVw
    Move (oClientArea(oMain(Self))) To hCl
    If (hCl) Begin
       Get Next_Mdi_Dialog Of hcl True To hVw // find first view
       While hVw
          If (Active_state(hVw)) Begin
             // if this is the focus view, mark it.
             If (current_scope(desktop)=hVw And View_mode(hVw)<>VIEWMODE_ICONIZE) Begin
                Function_Return (oEdit(hVw))
             End
          End
          Get Next_Mdi_Dialog Of hcl False To hVw // find next
       End
    End
End_Function


    // A Procedure which assigns a keystring to a menu item (Either PopupMenu or PullDownMenu)
    // correspondinf to a CommandID.
Procedure AddKeyStringToMenuItem Integer hoID Integer iItem Integer iCmd
    Integer iPos
    String  sKey sVal
    Get CMCommandToHotKeyStr iCmd To sKey
    If sKey Ne "" If hoID Ne 0 Begin
        Get value Of hoID Item iItem                To sVal
        Move (Pos("\a",sVal))                       To iPos
        If iPos Eq 0 Move (Pos(Character(9),sVal))  To iPos
        If iPos Gt 0 Move (Left(sVal,iPos-1))       To sVal
        Move (RTrim(sVal))                          To sVal
        Append sVal (Character(9)) sKey
        Set value Of hoID Item iItem                To sVal
    End
End_Procedure

Procedure RegisterEditor
    	Send AsociateAllFileTypes
    	Abort
End_Procedure
#IF (FMAC_VERSION < 8)
If (piWrkSpcRegister(ghoWorkSpace)) Send RegisterEditor
#ELSE
If (piWrkSpcRegister(ghoApplication)) Send RegisterEditor
#ENDIF

Object oRPCEditorClient Is A cRPCClient
    Set psServerName To "EDITOR"

        // Functions which are called in an RPCServer.
    RPC_External_Procedure ExtCAFileOpen String sFileName
    RPC_External_Procedure ExtCANewFile

    Procedure TryToTransferCommandLineParameters
        Handle hwnd
        Move (isServerRunning(Self))    To hwnd
        If hwnd Begin
#IF (FMAC_VERSION < 8)
            If (psWrkSpcOpenFileName(ghoWorkSpace)) Ne "" Begin
                Send WrkSpcDoForAllFiles  To ghoWorkSpace Msg_ExtCAFileOpen Self
//                Send ExtCAFileOpen (psWrkSpcOpenFileName(ghoWorkSpace))
                Abort
            End
            If (piWrkSpcNewFile(ghoWorkSpace)) Begin
                Send ExtCANewFile
                Abort
            End
#ELSE
            If (psWrkSpcOpenFileName(ghoApplication)) Ne "" Begin
                Send WrkSpcDoForAllFiles  To ghoApplication Msg_ExtCAFileOpen Self
//                Send ExtCAFileOpen (psWrkSpcOpenFileName(ghoWorkSpace))
                Abort
            End
            If (piWrkSpcNewFile(ghoApplication)) Begin
                Send ExtCANewFile
                Abort
            End
#ENDIF
        End
    End_Procedure
    Send TryToTransferCommandLineParameters
End_Object

Function CreateProgramLabel Global Returns String
    String sRet
    // **WvA: Removed "project part" prefix from caption so that
    // you can see more details when using the Cool tab switch (==Alt+tab)
    //Append sRet gsProjectName " - " gsProgrammname " " gsVerionsNr
    Append sRet gsProgrammname " " gsVerionsNr
    Function_Return sRet
End_Function

Use proppage.dg
Use THToolPanel.pkg

Object oMain Is A cIconPanel

    #IF (!@ >= 140)
    Set pbSizeToClientArea To False
    #ENDIF
    Set Label                       To (CreateProgramLabel())
    Set LargeTaskbarIcon            To "PANEL32.bmp"
    Set SmallTaskbarIcon            To "PANEL16.bmp"
    Set IconTransparentColor        To (Rgb(255,0,255))


    // SetRedraw set's the redraw flag of oMain and oClientArea directly via API
    // if set true, the objects are repainted.
    // 28.02.2003 BP
    Property Integer piRedrawState Public True
    Procedure SetRedraw GLOBAL Integer iState
        Integer iRet iHideFileTabs iRedrawFlags hoObj
        String sRect
        Pointer pRect
        If iState Eq (piRedrawState(oMain(desktop))) Procedure_Return
        Set piRedrawState Of (oMain(desktop)) To iState

        Move (SendMessage(window_handle(oMain(desktop)),WM_SETREDRAW,iState,0)) To iRet
        If (iState) Begin
            Move (RedrawWindow(window_handle(oMain(desktop)),0,0,(RDW_NOCHILDREN Ior RDW_ERASE Ior RDW_INVALIDATE Ior RDW_ERASENOW))) To iRet
            Move (RedrawWindow(window_handle(oMain(desktop)),0,0,(RDW_ALLCHILDREN Ior RDW_INVALIDATE Ior RDW_UPDATENOW Ior RDW_NOFRAME Ior RDW_NOERASE))) To iRet
        End
    End_Procedure

        // To trap these changes
    Procedure SetCurrentProgramFile String sName
        Move sName  To gsCurrentProgramFile
        Move ""     To gsCurrentCommandLinePara
        Send ShadowToolBarItem TBItem_Compile   (sName Eq "")
        Send ShadowToolBarItem TBItem_Run       (sName Eq "")
        Send ShadowToolBarItem TBItem_Debug     (sName Eq "")
        Send ShadowToolBarItem TBItem_Execute   (sName Eq "")
    End_Procedure

    Object oParserControl Is a cParserControl
        Move (Self) To ghoParserControl
        Procedure destroy_object
            Move 0 To ghoParserControl
            Forward Send destroy_object
        End_Procedure
    End_Object

    Object oFileFinder Is a cFileFinder
        Property String psCurrentFindText Public ""
        Property Integer phoTargetObject Public 0
        Property Integer piMaxUseTabPages Public 4

        Procedure StartFileFind String sPath String sType String sText Integer bSubFolders Integer bMatchCase Integer bMatchWord Integer bShowAll Integer bRegExp
            String sVal
            Move (Trim(sText)) To sVal
            If (length(sVal)) Gt 15 Move ( (Left(sVal,12)) + "..." ) To sVal
            Set psCurrentFindText To sVal
            Forward Send StartFileFind sPath sType sText bSubFolders bMatchCase bMatchWord bShowAll bRegExp
        End_Procedure

        Procedure AddLine String sVal
            If (phoTargetObject(Self)) Send AddLine To (phoTargetObject(Self)) sVal
        End_Procedure

        Procedure CreateFindPage
            Integer hoObj
            If (phoTargetObject(Self)) Eq 0 Begin
                If (item_count(oTabFindObjects(oErrors(Self)))) Ge (piMaxUseTabPages(Self)) Begin
                    Send RemovePage To (oErrors(Self)) (value(oTabFindObjects(oErrors(Self)),0))
                End
                Get AddFindPage Of (oErrors(Self)) ("Searching:'" + (Trim(psCurrentFindText(Self))) + "'" ) To hoObj
                Get phoClientObject Of hoObj To hoObj
                Set phoTargetObject To hoObj
            End
        End_Procedure
        Procedure OnStart
            Send OnStartFind To (oFindFiles(Self))
            If (phoTargetObject(Self)) Ne 0 Set piCanCancel Of (phoTargetObject(Self)) To True
        End_Procedure
        Procedure OnFinish
            If (phoTargetObject(Self)) Set label Of (parent(phoTargetObject(Self))) To ("Results:'" + (Trim(psCurrentFindText(Self))) + "'" )
            Send OnFinishFind To (oFindFiles(Self))
            If (phoTargetObject(Self)) Ne 0 Set piCanCancel Of (phoTargetObject(Self)) To False
            Set phoTargetObject To 0
        End_Procedure
    End_Object

        // Allows other instances of the Editor to take control over some actions.
    Object oRPCEditorServer Is A cRPCServer
        Set ConnectName To "EDITOR"
        RPC_Procedure ExtCAFileOpen String sFileName Integer iLine
            Send CAOpenFile To (oClientArea(Self)) sFileName
        RPC_End_Procedure
        RPC_Procedure ExtCANewFile
            Send CANewFile To (oClientArea(Self))
        RPC_End_Procedure
    End_Object

    #Include RunProgramNotify.inc   // Allows to start the compiler in the background and beeing notified when finished!

    Use THToolBar.Pkg
    //

    Object oClientArea Is A AppClientArea

    Property Integer piViewsZoomed      Public (piViewMode(ghoEditorProperties))
    Property Integer piActiveView       Public 0

    Procedure add_mdi_dialog Integer iObjectID
        If (iObjectID Eq 0) Procedure_Return
        If (Not(active_state(iObjectID))) Procedure_Return
        Forward Send add_mdi_dialog iObjectID
    End_Procedure

    // Additional MDI Navigation:

    Define WM_MDIACTIVATE                  For |CI$0222

    // Inserts an Item into the mdi_dialogs set.
    Procedure Insert_Mdi_Dialog Integer iNr Integer hoId
        Integer iC hoMdiSet
        If (Not(active_state(hoID))) Procedure_Return
        Move (mdi_dialogs(Self))        To hoMdiSet
        Move (Item_Count(hoMdiSet)-1)   To iC
        While (iC Ge iNr)
            Set value Of hoMdiSet Item (iC+1) To (Value(hoMdiSet,iC))
            Decrement iC
        End
        Set value Of hoMdiSet Item iNr To hoId
    End_Procedure
    // Is called during Activate of the cEditorEditView, so an active file is always the 1st MDI Child!
    Procedure Make_Mdi_Dialog_First Integer hoId
        Integer hoFirst iInsertTop
        If (find_element(mdi_dialogs(Self),hoID)) Eq ( (item_count(mdi_dialogs(Self))) -1) Move 1 To iInsertTop
        If (Not(iInsertTop)) Begin
            Get value Of (mdi_dialogs(Self)) Item 0 To hoFirst  // Take the current first position
            Send Remove_mdi_dialog hoFirst                      // Remove current first Position
        End
        Send Remove_Mdi_Dialog hoId                         // Remove the old entry
        Send Insert_Mdi_Dialog 0 hoId                       // Add it on the 1st position
        If (Not(iInsertTop)) Send add_mdi_dialog hoFirst                         // Insert the previous first position at last position
        // Make the correct Button active in the File-Tab Page
        // 03.03.2003 BP
        Send ActivateFileButton To ghoFileTabs hoID
    End_Procedure
    // Is called during Close_Panel of cEditorEditView, so always the previously active
    // files is set active when the active files is closed.
    Procedure Mdi_Dialog_Closed Integer hoID
        Integer hoMdiSet hoVW iRet
        // Remove the button from the tab-page
        // 03.03.2003 BP
        Send RemoveFileButton To ghoFileTabs hoID
        Move (mdi_dialogs(Self))        To hoMdiSet
        Get value Of hoMdiSet Item ( (item_count(hoMdiSet))-1)    To hoVW
        If ( (hoVW) And (active_state(hoVw)) ) Move (SendMessage(window_handle(Self),WM_MDIACTIVATE,(window_handle(hoVW)),0)) To iRet
    End_Procedure


        // Sets the Location and Size of this Dummy TextBox which should look like
        // the client area when the clientare's visible_state is set to false during
        // Files are reopened.
    Procedure Set GuiSize Integer iY Integer iX
        Forward Set GuiSize To iY iX
        Send FitErrorContainerToMdiMargin True
    End_Procedure
    Procedure Set GuiLOcation Integer iY Integer iX
        Forward Set GuiLocation To iY iX
    End_Procedure

        // Checks the key.
    Function CATestKey Integer iExt Integer iKey Integer iKeyDown Returns Integer
        If iKey Ne iKeyDown                                               Function_Return 0
        If (iExt Iand CM_KEY_SHIFT    ) If (Not(GetKeyState(VK_SHIFT  ))) Function_Return 0
        If (iExt Iand CM_KEY_ALT      ) If (Not(GetKeyState(VK_MENU   ))) Function_Return 0
        If (iExt Iand CM_KEY_CTRL     ) If (Not(GetKeyState(VK_CONTROL))) Function_Return 0
        Function_Return 1
    End_Function
        // Delivers true if the Keys for the checked command are pressed.
    Function CAIsCodeMaxCommand Integer iCmd Integer iKeyUp Returns Integer
        Integer iC iCount iKey
        Get CMGetKeyForCommand iCmd -1      To iCount
        For iC From 0 To (iCount-1)
            Get CMGetKeyForCommand iCmd iC  To iKey
            If (CATestKey(Self,Low(iKey),Hi(iKey),iKeyUp)) Function_Return 1
        End
        Function_Return 0
    End_Function
        // To assign the key for opening a file, when no edit is opened
    Procedure onkeyUp Integer wParam Integer lParam
        If (CAIsCodeMaxCommand(Self,CMD_FileOpenFile,wParam)) Send CAOpenMultipleFiles
        Else If (CAIsCodeMaxCommand(Self,CMD_FileNewFile,wParam)) Send CANewFile
        Forward Send onKeyUp wParam lParam
    End_Procedure


//    Property Integer piLastActiveView
    Procedure Activate
        Forward Send Activate
        If (piActiveView(Self)) Send activate To (piActiveView(Self))
    End_Procedure

    Procedure NotifyActiveView Integer iOID
        Set piActiveView    To iOID
    End_Procedure

    Use TheTool_Paras.dg    // Parameters
    Use CustMenu.dg         // Customize the tools menu
    Use Class_Explorer.vw
    Use dfcbldr.pkg         // Registering classes in the IDE and creating *.DFC files.

    // Tests if the current focus is an Edit...
    Function isFileWindow Integer hoID Returns Integer
        Integer iDel iOK
        If hoID Eq 0 Function_Return False
        Get Delegation_Mode     Of hoID To iDel
        Set Delegation_Mode     Of hoID To No_Delegate_or_Error
        Get iscWinMaxEdit       Of hoID To iOK
        Set Delegation_Mode     Of hoID To iDel
        Function_Return iOK
    End_Function
        // Tests if the current focuse is a Edit...
    Function isFileViewWindow Integer hoID Returns Integer
        Integer iDel iOK
        If hoID Eq 0 Function_Return False
        Get Delegation_Mode     Of hoID To iDel
        Set Delegation_Mode     Of hoID To No_Delegate_or_Error
        Get isEditView          Of hoID To iOK
        Set Delegation_Mode     Of hoID To iDel
        Function_Return iOK
    End_Function

        // *WvA: Nov 6, 2005 Added checks to make sure the rest is only executed if the object exists,
        //       otherwise a crash can happen.
        //       This particular patch addresses a problem when trying to switch to the code explorer if the
        //       code explorer had been disabled.
        // Tries to get a function | message from the view or the edit
    Function RequestGetFromViewEx Integer iMsg Integer bEdit Integer iPara1 Integer iPara2 Returns Integer
        Integer hoID iRet iOK
        Move (Focus(Desktop))         To hoID
        If (hoID<>0) Begin
        Get GetEditViewID Of hoID     To hoID
          If (hoID<>0) Begin
        If bEdit     If (isFileWindow(Self,oEdit(hoID))) Move 1 To iOK
        If Not bEdit If (isFileViewWindow(Self,hoID))    Move 1 To iOK
        If iOK Begin
            If bEdit Move (oEdit(hoID))                             To hoID
            If NUM_Arguments Eq 2 Get iMsg  Of hoID                 To iRet
            If NUM_Arguments Eq 3 Get iMsg  Of hoID iPara1          To iRet
            If NUM_Arguments Ge 4 Get iMsg  Of hoID iPara1 iPara2   To iRet
            End
          End
        End
        Function_Return iRet
    End_Function
    Function RequestGetFromView Integer iMsg Integer bEdit Returns Integer
        Function_Return (RequestGetFromViewEx(Self,iMsg,bEdit,0,0))
    End_Function
        // Find View by FileName.
        // Tries to get a function | message from the view or the edit
    Function FindViewByFileName String sFile Returns Integer
        Integer hoVw iRet
        String  sFile2
        Get Next_Mdi_Dialog True            To hoVw // find first view
        While (hoVw)
            If (oEdit(hoVw)) If (isFileWindow(Self,oEdit(hoVw)))  Begin
                Indicate err False
                Get GetFileName Of hoVw To sFile2
                If (Uppercase(sFile)) Eq (Uppercase(sFile2)) Function_Return hoVw
                [err] Showln (Label(hoVw))
            End
            Get Next_Mdi_Dialog False  To hoVw // find next view
        End
        Function_Return 0
    End_Function
        // Tries to send a message to the view or the edit
    Procedure RequestSendToView Integer iMsg Integer bEdit Integer iPara1 Integer iPara2
        Integer iRet
        If NUM_Arguments Eq 2 Get RequestGetFromViewEx iMsg bEdit                 To iRet
        If NUM_Arguments Eq 3 Get RequestGetFromViewEx iMsg bEdit iPara1          To iRet
        If NUM_Arguments Ge 4 Get RequestGetFromViewEx iMsg bEdit iPara1 iPara2   To iRet
        Function_Return iRet
    End_Procedure
        // Tries to send a Msg to all open views.
    Procedure RequestSendToAllViews Integer iMsg
        Integer hoVw iRet iDel
        Get Next_Mdi_Dialog True            To hoVw // find first view
        While (hoVw)
            If (Active_State(hoVw)) Begin
                //get Delegation_Mode of hoVw to iDel
                //set Delegation_Mode of hoVw to no_delegate_or_error
                Get iMsg Of hoVw                To iRet
                //set Delegation_Mode of hoVw to iDel
                If iRet Procedure_Return 1
            End
            Get Next_Mdi_Dialog False        To hoVw // find next view
        End
        Function_Return 0
    End_Procedure

    Procedure CAOnLabelChanged Integer hoObj
        Send OnLabelChanged To ghoFileTabs hoObj
    End_Procedure

    Procedure CANewFile
        Integer hoID iRet iRedraw
        // Deactivate Find in Files Window if active
        // 28.02.2003 BP
        If (active_state(oFindFiles(Self))) Send close_panel To (oFindFiles(Self))
        Move (piRedrawState(oClientArea(Self))) To iRedraw
        If (iRedraw) Send SetRedraw False
        Object oFile Is A cEditorEditView
            Set Parent To (oClientArea(Self))
            Set Name   to "oNewFile"
            Move Self   To hoID
            Set GuiSize     To (piViewSize.Y(ghoEditorProperties)) (piViewSize.X(ghoEditorProperties))
        End_Object
        Send OpenFile   To hoID ""
        // Create a button in the opened file tab page
        // 03.03.2003 BP
        Send AddFileButton To ghoFileTabs hoID
        If (iRedraw) Send SetRedraw True
    End_Procedure


    // Displays a Standard Open Dialog Box, where the user can select more Files
    // Added 28.01.2003 BP

    Procedure CAOpenMultipleFiles
        Integer hoDialog hoSelectedArray iCou
        String sDir sTypes sFile
        Get_Current_Directory   To sDir
        Get psFileTypes Of ghoEditorProperties To sTypes
        Object oFileSelect Is a cMultiOpenDialog
            Move Self To hoDialog
            Set Filter_String       To sTypes
            Set Dialog_Caption      To "Open Multiple Files"
            Set NoChangeDir_State   To True
            Set File_Title          To ""
            Set Initial_Folder      To sDir
        End_Object
        Get Show_Dialog Of hoDialog To hoSelectedArray
        If hoSelectedArray Begin
            For iCou From 0 To ((item_count(hoSelectedArray))-1)
                Get value Of hoSelectedArray Item iCou To sFile
                Send CaOpenFile sFile
            Loop
            Send delete_data To hoSelectedArray
            Send destroy_object To hoSelectedArray
        End
        Send destroy_object To hoDialog
    End_Procedure

    // Displays a Standard Open Dialog Box, where the user can select more Files
    // Added 28.01.2003 BP

    Procedure CAOpenMultipleFilesByType Integer iType
        Integer hoDialog hoSelectedArray iCou
        String sDir sTypes sFile
        Get_Current_Directory   To sDir
        Get psFileTypes Of ghoEditorProperties To sTypes
        Object oFileSelect Is a cMultiOpenDialog
            Move Self To hoDialog
            Set Filter_String       To sTypes
            Set Filter_Index        To iType
            Set Dialog_Caption      To "Open Multiple Files"
            Set NoChangeDir_State   To True
            Set File_Title          To ""
            Set Initial_Folder      To sDir
        End_Object
        Get Show_Dialog Of hoDialog To hoSelectedArray
        If hoSelectedArray Begin
            For iCou From 0 To ((item_count(hoSelectedArray))-1)
                Get value Of hoSelectedArray Item iCou To sFile
                Send CaOpenFile sFile
            Loop
            Send delete_data To hoSelectedArray
            Send destroy_object To hoSelectedArray
        End
        Send destroy_object To hoDialog
    End_Procedure

    Procedure CAOpenFile String sFileE
        Integer hoID hoIDOld iRet iRedraw
        String  sFile sDir
        String  sShortFileName
        // Deactivate Find in Files Window if active
        // 28.02.2003 BP
        If (active_state(oFindFiles(Self))) Send close_panel To (oFindFiles(Self))

        Send activate To Self
        Get ParseFileName sFileE to sShortFileName
        Move (Replaces(".",sShortFileName,"_")) To sShortFileName
        Object oFile Is A cEditorEditView
            Move Self    To hoID
            Set Name     To ("oFile_"+sShortFileName)
            Set GuiSize  To (piViewSize.Y(ghoEditorProperties)) (piViewSize.X(ghoEditorProperties))
        End_Object

        If NUM_Arguments Gt 0 Move sFileE           To sFile
        If sFile Eq "" Begin
            Move (GetOpenFile(hoID))     To sFile
        End

        Move (piRedrawState(oClientArea(Self))) To iRedraw
        If (iRedraw) Send SetRedraw False

        // Change relative .\ path to absolute path since this will be a problem if
        // the workspace is changed while the file is opened and edited 17.05.01 Bernhard

        If (Left(sFile,2)) Eq ".\" Begin
            get_current_directory To sDir
            Move (Replace(".\",sFile,"")) To sFile
            Move (sDir + "\" + sFile) To sFile
        End
        If sFile Ne "" Begin
            Move (FindViewByFileName(Self,sFile))       To hoIDOld
            If hoIDOld Begin
                Send DestroyObject     To hoID
                Move (SendMessage(window_handle(Self),WM_MDIACTIVATE,(window_handle(hoIDOld)),0)) To iRet
                If (iRedraw) Send SetRedraw True
                Procedure_Return
            End
        End
        If sFile Eq "" Begin
            Send DestroyObject     To hoID
            If (iRedraw) Send SetRedraw True
            Procedure_Return
        End
        Else Begin
            If gsCurrentProgramFile Eq ""  If (Uppercase(Right(Trim(CString(sFile)),4))) Eq ".SRC" Send SetCurrentProgramFile sFile //move sFile to gsCurrentProgramFile
            Get Msg_OpenFile      Of hoID sFile    To iRet
            If (Not(iRet)) Begin
                If (iRedraw) Send SetRedraw True
                Send Info_Box (Append("File could not be opened: ",sFile)) (Label(Main_Panel_ID(Self)))
                Send DestroyObject To hoID
                Procedure_Return
            End
        End
        // Create a button in the opened file tab page
        // 03.03.2003 BP
        Send AddFileButton To ghoFileTabs hoID
        If (iRedraw) Send SetRedraw True
    End_Procedure

    Procedure CAOpenPKG
        String sDir sDirPKG

        Get_Current_Directory   To sDir
        Get CurrentRuntimePkgPath Of ghoWorkSpaceHandlerEx To sDirPKG
        Set_Directory sDirPKG
        // Changed for MultipleFile Open 28.01.2003 BP
        Send CAOpenMultipleFiles
        Set_Directory sDir
    End_Procedure

    Procedure CAOpenFile_Pkg
        String sPkgDir sAppDir sTmpDir sOri sDir
        Get_Current_Directory   To sDir
        Get CurrentAppSrcPath Of ghoWorkSpaceHandlerEx To sAppDir
        // Check if multi pass
        If ";" In sAppDir Move (Left(sAppDir, (Pos(";", sAppDir)-1) )) To sOri
        Else Move sAppDir To sOri
        While ";" In sAppDir
            Move (Left(sAppDir, (Pos(";", sAppDir)-1))) To sTmpDir
            Move (Replace((sTmpDir+";"), sAppDir, "")) To sAppDir
            If "PKG" In (Uppercase(sTmpDir)) Move sTmpDir To sPkgDir
        Loop
        If (sPkgDir="") If "PKG" In (Uppercase(sAppDir)) Move sAppDir To sPkgDir
        //
        If (sPkgDir="") Move sOri To sPkgDir
        //
        Set_Directory sPkgDir
        Send CAOpenMultipleFiles
        Set_Directory sDir
    End_Procedure

    Procedure CAOpenFile_DD
        String sDDDir sDir
        Get_Current_Directory   To sDir
        Get CurrentDDSrcPath    Of ghoWorkSpaceHandlerEx To sDDDir
        // Check if multi pass
        If ";" In sDDDir Move (Left(sDDDir, (Pos(";", sDDDir)-1) )) To sDDDir
        //
        Set_Directory sDDDir
        Send CAOpenMultipleFiles
        Set_Directory sDir
    End_Procedure

    Function FindNextViewFromCurrentView Returns Integer
        Integer hoCur hoID iPos
        Move (mdi_dialogs(Self)) To hoID
        Move (current_scope(desktop)) To hoCur
        Move (find_element(hoID,hoCur)) To iPos
        If iPos Eq -1 Function_Return 0
        If iPos Eq ( (item_count(hoID)) -1) Function_Return (value(hoID,0))
        Function_Return (value(hoID,(iPos + 1) ))
    End_Function

    Function FindPreviousViewFromCurrentView Returns Integer
        Integer hoCur hoID iPos
        Move (mdi_dialogs(Self)) To hoID
        Move (current_scope(desktop)) To hoCur
        Move (find_element(hoID,hoCur)) To iPos
        If iPos Eq -1 Function_Return 0
        If iPos Eq 0 Function_Return (value(hoID,( (item_count(hoID))-1) ))
        Function_Return (value(hoID,(iPos -1) ))
    End_Function


        // Switches to the next View.
    Procedure CASwitchToNextView
        Integer hoVW iRet iRedraw
        Move (FindNextViewFromCurrentView(Self)) To hoVw
        If ( (hoVW) And (active_state(hoVw)) ) Begin
            Move (piRedrawState(Self)) To iRedraw
            If (iRedraw) Send SetRedraw False
            Move (SendMessage(window_handle(Self),WM_MDIACTIVATE,(window_handle(hoVW)),0)) To iRet //Send activate to hoVW
            If (iRedraw) Send SetRedraw True
        End
    End_Procedure
    Procedure switch_next_view
        Send CASwitchToNextView
    End_Procedure
        // Switches to previous View.
    Procedure CASwitchToPreviousView
        Integer hoVW iRet iRedraw
        Move (FindPreviousViewFromCurrentView(Self)) To hoVw
        If ( (hoVW) And (active_state(hoVw)) ) Begin
            Move (piRedrawState(Self)) To iRedraw
            If (iRedraw) Send SetRedraw False
            Move (SendMessage(window_handle(Self),WM_MDIACTIVATE,(window_handle(hoVW)),0)) To iRet
            If (iRedraw) Send SetRedraw True
        End
    End_Procedure
    Procedure switch_prior_view
        Send CASwitchToPreviousView
    End_Procedure

        // Flicker free activating a view from menu
    Procedure activate_mdi_view_menu Integer hoVw
        Integer iRet iRedraw
        If num_arguments Eq 0 Procedure_Return
        Move (piRedrawState(Self)) To iRedraw
        If (iRedraw) Send SetRedraw False
        If ( (hoVW) And (active_state(hoVw)) ) Move (SendMessage(window_handle(Self),WM_MDIACTIVATE,(window_handle(hoVW)),0)) To iRet
        If (iRedraw) Send SetRedraw True
    End_Procedure

    Procedure CAEditHeaderGlobal
        String sSrc
        Get_File_Path "Header.Tpl"  To sSrc
        If sSrc Eq "" Send Stop_Box "Cant create userspecific headerfile.\nHeader.Tpl not found."
        If sSrc Eq "" Procedure_Return
        Send CAOpenFile sSrc
    End_Procedure
    Procedure CAEditHeaderUser
        String  sSrc sDest
        Integer iNotExist
        Get_File_Path ("Header"+gsUserName+".tpl") To sDest
        If sDest Eq "" Begin
            Get_File_Path "Header.Tpl"  To sSrc
            If sSrc Eq "" Send Stop_Box "Cant create userspecific headerfile.\nHeader.Tpl not found."
            If sSrc Eq "" Procedure_Return
            Move (Lowercase(sSrc))  To sSrc
            Move (Replace("header.tpl",sSrc,("Header"+gsUserName+".tpl")))  To sDest
            CopyFile sSrc   To sDest
        End
        Send CAOpenFile sDest
    End_Procedure
    
    //
    // Create a default template header file name based of the .sws filename
    //
    Function DefaultWorkspaceTemplateName Returns String
      String  sFileName
      String  sProgram
      String  sWSName sExt
           
      Move "" To sFileName
      Get CurrentProgramPath   Of ghoWorkspaceHandlerEx To sProgram
      Get CurrentWorkspaceName Of ghoWorkspaceHandlerEx To sWSName
      If (Pos("\",sWSName)) Begin  // take out file parts, no need if old style workspace
        Get ParseFileExtension sWSName To sExt
        Get ParseFileName      sWSName To sWSName
        If (sExt<>"") Begin
          Move (Replace("."+sExt,sWSName,"")) To sWSName
        End
      End
      Get vFolderFormat sProgram to sProgram
      Move (sProgram+sWSName+".tpl") To sFilename
      Function_Return sFileName
    End_Function // DefaultWorkspaceTemplateName
    
    Procedure CAEditHeaderWorkspace
        String  sSrc
        String  sDest
        Integer iFail
        Boolean bExists
        
        Get_File_Path ("Header.tpl") To sSrc
        If (sSrc <> "") Begin
          Get DefaultWorkspaceTemplateName To sDest
          Get vFilePathExists sDest To bExists
          If (bExists=false) Begin
            Get vCopyFile sSrc sDest to iFail
          End
          Send CAOpenFile sDest
        End
        Else Send Stop_Box "Can not create workspace specific headerfile!\nHeader.Tpl not found."
    End_Procedure

        // Creates the Enties for all opened file, so that the files
        // can be reopened when the editor is started again.

        // Also FindFiles settings are saved
        // 29.02.2003 BP
    Procedure CACreateEditorEntries
        Send RequestSendToAllViews Msg_CreateEditorEntry
        Send SaveSettings To oFindFiles
    End_Procedure
        // Closes one File. (Focus)
    Procedure CACloseFile
        Send RequestSendToView Msg_CloseFileXButton TO_VIEW
    End_Procedure
        // Close all Files.
        // Always search the 1st view becouse if the view is destroyed...
    Procedure CACloseAllFiles
        Integer hoVw iRet iDel iLast
        Send SetRedraw False
        Repeat
            Move hoVw To iLast
            Get Next_Mdi_Dialog True            To hoVw // find first view
            If (hoVw Eq iLast) Move 0 To hoVw
            If hoVw Begin
                If (Active_State(hoVw)) Begin
                    Get Msg_CloseFile Of hoVw       To iRet
                    If iRet Begin
                        Send SetRedraw True
                        Procedure_Return 1
                    End
                End
            End
        Until (hoVw Eq 0)
        Send SetRedraw True
        Function_Return 0
    End_Procedure
        // Prints the File.
    Procedure CAPrintFile
        Send RequestSendToView Msg_PrintFile TO_VIEW
    End_Procedure

    Procedure CAPopUpFindInFiles
        Send activate To (Self)
        Send popUp To (oFindFiles(oClientArea(Self)))
        Send SaveSettings To oFindFiles
    End_Procedure

        // Save as a file   (Focus)
    Procedure CASaveFileAs
        Send RequestSendToView Msg_SaveFileAs False
    End_Procedure
        // Save a File      (Focus)
    Procedure CASaveFile
        Send RequestSendToView Msg_SaveFile False
    End_Procedure
        // Save all Files.
    Procedure CASaveAllFiles
        Send RequestSendToAllViews Msg_SaveFile False
    End_Procedure
        // Splits the current window horizontally.
    Procedure CASplitWindowHorizontal
        Send RequestSendToView Msg_SplitWindowHorizontal True
    End_Procedure
        // Splits the current window Vertically.
    Procedure CASplitWindowVertical
        Send RequestSendToView Msg_SplitWindowVertical True
    End_Procedure
        // Duplicates the window.
    Procedure CADuplicateWindow
        Send RequestSendToView Msg_DuplicateWindow True
    End_Procedure
    Function CAisDuplicatePossible Returns Integer
        Function_Return (RequestGetFromView(Self,Get_isDuplicatePossible,TO_EDIT))
    End_Function
        // Synchronisiert die Element View mit der aktuellen Zeilen position
    Procedure CAWindowSyncCodeView
        Send RequestSendToView Msg_SyncCodeView TO_EDIT
    End_Procedure
        // Closes the window.
    Procedure CACloseWindow
        Integer iRet
        Get  RequestGetFromView Get_isWindowDuplicated TO_EDIT To iRet
        If iRet Send RequestSendToView Msg_CloseWindow TO_EDIT
        Else    Send RequestSendToView Msg_CloseFile   TO_VIEW
    End_Procedure
        // Switches to the CodeExplorer area.
    Procedure CAWindowSwitchToCodeExplorer
        Send RequestSendToView Msg_WindowSwitchToCodeView TO_VIEW
    End_Procedure
        // Should activate the ParmeterView as Property page when nothing else is defined.
    Procedure Properties
        // **WvA: 27-6-2003 Under windows 9x this function is always called
        // even if a codemax editor window is activated.
        If (Item_Count(mdi_dialogs(Self)) > 0) Begin
          Send RequestSendToView Msg_Properties TO_EDIT
        End
        Else Begin
          Send Info_Box "Unable to invoke the properties dialog, you will have to open a document first."
          // If you want to keep the original behaviour then uncomment
          // next line and remove the info_box
          //Send Activate_oParas
        End
    End_Procedure
        // Invoke the workspace selector
    Procedure CASelectWorkspace
      Send Popup To (oWorkSpace(Self))
    End_Procedure // CASelectWorkspace

    Function ProcessOptionMacros String sString String sFile Returns String
        String  sVdfRoot
        String  sProgramPath
        String  sRoot
        String  sDfrun
        String  sStartup
        Number  nVersion

        Get fnCurrentVdfVersion of ghoWorkspaceHandlerEx To nVersion
        If (Pos("%VDFROOT%",sString) <> 0) Begin
#IF (FMAC_VERSION < 8)
            If (ghoWorkSpace <> 0) Begin
              Get CurrentProgramPath Of ghoWorkSpace To sProgramPath
            End
#ELSE
            If (ghoApplication <> 0) Begin
              Get psProgramPath Of (phoWorkSpace(ghoApplication)) To sProgramPath
            End
#ENDIF
            Move (Replace("Programs",sProgramPath,"")) To sRoot
            Move (Replace("%VDFROOT%",sString,sRoot))  To sString
        End

        Get psVdfRootDir   Of ghoWorkSpaceHandlerEx To sVdfRoot
        Move (Left(sVDFRoot, (Length(sVDFRoot)-1))) To sVdfRoot // Trimming last slash
        If (nVersion<80) Begin
          Get psDfrun of ghoEditorProperties to sDfrun
        End
        Else Move "" To sDfrun // no need to add a dfrun.exe in front of any command after VDF7
        Move (Replaces("@DFRUN@",sString,sDfrun )) To sString

        If (Pos("@CURDIR@",sString)) Begin
          // Cannot use current directory as it doesn't always contain the same folder
          // as the Hammer executable.
          Get VDFStartupPath To sStartUp

          Move (Replaces("@CURDIR@",sString,sStartUp))    To sString
        End
        Move (Replaces("@PROGRAM@",sString,gsCurrentProgramFile)) To sString
        Move (Replaces("@VDFROOT@",sString,sVdfRoot)) To sString
        // File Parameter...
        Move (Replaces("%1", sString, sFile)) To sString

        If (Pos("PROGRAM FILES",Uppercase(sString))) Begin
          Move (Uppercase(sString)) To sString
          Move (Replaces("PROGRAM FILES",sString,"PROGRA~1")) To sString
        End
        Move (Replaces("\\",sString,"\")) To sString
        Function_Return (Ltrim(sString))
    End_Function

    Procedure LaunchUtility String sPath String sFile
      String sCmd
      String sParams
      
      If (sPath<>"") Begin
        Move "" To sParams
        Get ProcessOptionMacros sPath sFile To sCmd
        If (pos("%1",sPath)=0 and sFile<>"") Begin
          Move sFile To sParams
        End
        RunProgram background sCmd sParams
      End
    End_Procedure

    // **WvA: 28-10-2004
    // In VDF8 and higher DAW compiled their utilities from a .vd? file
    // to 'true' executables. As a result of this the tools have been
    // moved from the lib folder towards the bin folder
    // This method will automatically adjust the path settings
    // and change lib and bin accordingly.
    Function AdjustUtilityPathToVDFversion String sPath Returns String
        Number nVersion
        Get fnCurrentVdfVersion Of ghoWorkSpaceHandlerEx To nVersion

        Move (Uppercase(sPath)) To sPath
        If (nVersion >= 80) Begin
          Move (Replace("@DFRUN@ @VDFROOT@\LIB",sPath,"@VDFROOT@\BIN")) To sPath

          // We don't need to add a .vd? extension to start the
          // application as long as we call the runtimer first.
          Move (Replace(".VDF",sPath,"")) To sPath
          Move (Replace(".VD5",sPath,"")) To sPath
          Move (Replace(".VD6",sPath,"")) To sPath
          Move (Replace(".VD7",sPath,"")) To sPath
          If (nVersion>=91) Begin
            Move (Replace("@VDFROOT@\BIN\IDE",sPath,"@VDFROOT@\BIN\STUDIO")) To sPath
          End
        End
        Else Begin
          Move (Replace("@VDFROOT@\BIN",sPath,"@VDFROOT@\LIB")) To sPath
          Move (Replace("@VDFROOT@\LIB\STUDIO",sPath,"@VDFROOT@\LIB\IDE")) To sPath
        End
        Function_Return sPath
    End_Function // AdjustUtilityPathToVDFversion
    
    Function InsertCurrentWorkspace String sTmp Returns String
      String sWSTag
      Number nVersion
      
      Get fnCurrentVdfVersion of ghoWorkSpaceHandlerEx to nVersion
      If (nVersion>=120) Begin
        // open Studio/DBB on current workspace only
        Get CurrentWorkspaceTag of ghoWorkSpaceHandlerEx to sWSTag
        Move ('"-x'+sWSTag+'" '+sTmp) to sTmp
      End
      Function_Return sTmp
    End_Function

    //
    // Will normally pass the currently opened file in the Hammer, but no
    // file if there's none open.
    //
    Procedure LaunchIDEUtility String sFile
        String sPath sTmp
        
        If (Num_Arguments>0) Move ('"'+sFile+'"') To sTmp
        Else Move "" To sTmp
        
        Get InsertCurrentWorkspace sTmp to sTmp

        Get psIdePath of ghoEditorProperties to sPath
        Get AdjustUtilityPathToVDFversion sPath to sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchMergeUtility String sFile
        String sPath sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psMergePath Of ghoEditorProperties To sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchVCSUtility String sFile
        String sPath sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psVCSPath Of ghoEditorProperties To sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchDBBUtility String sFile
        String sPath sTmp
        
        If (Num_Arguments>0) Move ('"'+sFile+'"') To sTmp
        Else Move "" to sTmp
        
        Get InsertCurrentWorkspace sTmp to sTmp

        Get psDBBPath of ghoEditorProperties to sPath
        Get AdjustUtilityPathToVDFversion sPath to sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchDBEUtility String sFile
        String sPath sTmp
        
        Move "" To sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psDbePath Of ghoEditorProperties To sPath
        Get AdjustUtilityPathToVDFversion sPath to sPath
        If (sTmp<>"") Begin
          Move (sPath+" %1") To sPath // without that the file parameter never gets expanded
        End
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchDBCUtility String sFile
        String sPath sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psDbcPath Of ghoEditorProperties To sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchDBUUtility String sFile
        String sPath sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psDbuPath Of ghoEditorProperties To sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchRptUtility String sFile
        String sPath sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psRptPath Of ghoEditorProperties To sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchMenuUtility String sFile
        String sPath sTmp
        If (Num_Arguments>0) Move sFile To sTmp
        Get psMenuPath Of ghoEditorProperties To sPath
        Send LaunchUtility sPath sTmp
    End_Procedure
    //
    Procedure LaunchCodeArt String sFile
        String sErr sTmp sPath
        If (Num_Arguments>0) Move sFile To sTmp
//        If (psCodeArtPath(ghoEditorProperties)="") Begin
//            Get CodeArt Of ghoCodeArt sTmp To sErr
//            If "ERROR:" In sErr Send Stop_Box sErr "Error Occured During Processing"
//            Else                Begin
//                Send Info_Box sErr "CodeArt Completed Successfully!"
//                Send CAOpenFile To (oClientArea(Self)) (psOutFile(ghoCodeArt))
//            End
//        End
//        Else Begin
            Get psCodeArtPath Of ghoEditorProperties To sPath
            Send LaunchUtility sPath sTmp
//        End
    End_Procedure
    //
    Procedure LaunchCodeSpy String sFile
        String sErr sTmp sPath
        If (Num_Arguments>0) Move sFile To sTmp
//        If (psCodeArtPath(ghoEditorProperties)="") Begin
//            Get CodeArt Of ghoCodeArt sTmp To sErr
//            If "ERROR:" In sErr Send Stop_Box sErr "Error Occured During Processing"
//            Else                Begin
//                Send Info_Box sErr "CodeArt Completed Successfully!"
//                Send CAOpenFile To (oClientArea(Self)) (psOutFile(ghoCodeArt))
//            End
//        End
//        Else Begin
            Get psCodeArtPath Of ghoEditorProperties To sPath
            Send LaunchUtility sPath sTmp
//        End
    End_Procedure
    //
    Procedure LaunchCodePub String sFile
        String  sErr sTmp sPath
        String  sHtmlFileName
        Integer eResponse
        
        If (Num_Arguments>0) Move sFile To sTmp
        If (psCodePubPath(ghoEditorProperties)="") Begin
            Get CodePub   Of ghoCodePub sTmp To sErr
            Get psOutFile Of ghoCodePub To sHtmlFileName
            If "ERROR:" In sErr Send Stop_Box sErr "Error Occured During Processing"
            Else Begin
              Move (YesNo_Box(sErr+"\nOpen this file in the browser?", "CodePub Completed Successfully", MB_DEFBUTTON1)) to eResponse
              If (eResponse = MBR_YES) Begin
                Send vShellExecute "OPEN" sHtmlFileName "" ""
              End
              Send CAOpenFile To (oClientArea(Self)) sHtmlFileName
            End
        End
        Else Begin
            Get psCodePubPath Of ghoEditorProperties To sPath
            Send LaunchUtility sPath sTmp
        End
    End_Procedure
    //


    //____EDIT_Actions...____________________________________
        // Undo
    Function CACanUndo Returns Integer
        Function_Return (RequestGetFromView(Self,Get_CM_CanUndo,True))
    End_Function
    Function CACanRedo Returns Integer
        Function_Return (RequestGetFromView(Self,Get_CM_CanRedo,True))
    End_Function
    Procedure CAUndo
        Send RequestSendToView Get_CM_Undo True
    End_Procedure
    Procedure CARedo
        Send RequestSendToView Get_CM_Redo True
    End_Procedure
        // Cut
    Function CACanCut Returns Integer
        Function_Return (RequestGetFromView(Self,Get_CM_CanCut,True))
    End_Function
    Procedure CACut
        Send RequestSendToView Get_CM_Cut True
    End_Procedure
        // Copy
    Function CACanCopy Returns Integer
        Function_Return (RequestGetFromView(Self,Get_CM_CanCopy,True))
    End_Function
    Procedure CACopy
        Send RequestSendToView Get_CM_Copy True
    End_Procedure
        // Paste
    Function CACanPaste Returns Integer
        Function_Return (RequestGetFromView(Self,Get_CM_CanPaste,True))
    End_Function
    Procedure CAPaste
        Send RequestSendToView Get_CM_Paste True
    End_Procedure
        // Delete line...
    Procedure CADeleteLine
        Send RequestSendToView Msg_DeleteLine True
    End_Procedure
        // Select All
     Procedure CASelectAll
        Send RequestSendToView Msg_SelectAll True
     End_Procedure
        // Select Line
     Procedure CASelectLine
        Send RequestSendToView Msg_SelectLine True
     End_Procedure
        // Find...
    Procedure CAFind
        Send RequestSendToView Msg_Find True
    End_Procedure
        // Find next
    Procedure CAFindNext
        Send RequestSendToView Msg_FindNext True
    End_Procedure
        // Replace
    Procedure CAReplace
        Send RequestSendToView Msg_Replace True
    End_Procedure
        // Goto line...
    Procedure CAGotoLine Integer iLine
        If NUM_Arguments Eq 0 Send RequestSendToView Msg_GotoLine True
        Else                  Send RequestSendToView Msg_GotoLine True iLine
    End_Procedure

    //____BUILD_Actions...____________________________________

        // Delivers the filename of the current view
    Function CAFileNameCur Returns String
        Integer hoID iRet
        Move (Focus(Desktop))       To hoID
        If (isFileWindow(Self,hoID))  Begin
            Function_Return (GetFileName(hoID))
        End
        Function_Return ""
    End_Function

    Function CAFileName Returns String
        Integer hoVw iRet
        String  sFile
        Get Next_Mdi_Dialog True            To hoVw // find first view
        While (hoVw)
            If (Active_State(hoVw)) If (oEdit(hoVw)) If (isFileWindow(Self,oEdit(hoVw))) Begin
                Move (GetFileName((oEdit(hoVw))))   To sFile
                Move (Trim(sFile))                  To sFile
                If (Uppercase(Right(sFile,4))) Eq ".SRC" Function_Return sFile
            End
            Get Next_Mdi_Dialog False        To hoVw // find next view
        End
        Function_Return (CAFileNameCur(Self))
    End_Function

    Procedure CALookIfErrors String sFile
        Integer iErr
        Send Delete_Data To (oErrorList(oTabPage1(oErrors(Self))))
        Move (FileWithoutExt(sFile))  To sFile
        Append sFile ".ERR"
        Direct_Input sFile
            [Not seqeof] Move 1 To iErr
        Close_Input
        If ghoCompilerMessages Ne 0 Begin
            Set piCanCancel Of ghoCompilerMessages To False
            Set label Of (parent(ghoCompilerMessages)) To "Build"
            If ( (iErr) And (Not(visible_state(oErrors(Self))))) Send PAWindowErrorListONOFF iErr
            If ( (Not(iErr)) And (piDisplayWatchAutomatic(ghoEditorProperties)) ) Send PAWindowErrorListONOFF False
        End
        Else Send PAWindowErrorListONOFF iErr
        If iErr Begin
            Send Fill To (oErrorList(oTabPage1(oErrors(Self)))) sFile
            If (piCompileShowErrorMsg(ghoEditorProperties)) ;
            Send Info_Box (Append(Item_Count(oErrorList(oTabPage1(oErrors(Self))))," Errors!"))
            Send activate To (oErrorList(oTabPage1(oErrors(Self))))
            Procedure_Return 1
        End
    End_Procedure

        // Added support for webapp
        // **WvA: 15-7-03
        // Changed this "Run VDF Program" procedure so that it is
        // VDF8 compatible.

        // **BP: 02-01-04
        // Added the Option to "Always start with Debugger".
        // Also made the Debugger-Call VDF9 compatible

        // **BP: 18-03-04
        // Let the Program start from the ProgramPath Directory and not from the AppSrc

    Procedure CARunInt String sFile
        String sCmd sVer sDebugSource sProgramPath sCurDir sWorkspace sWebAppTestURL
        Number nVer                                // For example:
        Get ConvertPRGFile  Of Desktop sFile    To sFile // P:\Dev\Vdf7\Hammer\Programs\Hammer
        Get DFrunCmdLine    Of Desktop          To sCmd  // D:\Df\Vdf7\Bin\Dfrun.exe

        Get psVDFVersion    Of ghoWorkSpaceHandlerEx   To sVer
        Get StringVdfVersionToNum  Of ghoWorkSpaceHandlerEx sVer To nVer // 70=VDF7, 82=VDF8.2

        Move (CurrentProgramPath(ghoWorkspaceHandlerEx)) To sProgramPath

        get_current_directory To sCurDir
        If ( (sProgramPath<>"") And (Left(sProgramPath,2)<>".\") ) Begin // Only if ProgramPath is Set and not relative!
            set_directory sProgramPath
        End

        If (nVer < 80) Begin
            If (piDebugAlways(ghoEditorProperties)) Begin
                Get DebuggerCmdLine Of Desktop              To sCmd
          Runprogram BACKGROUND sCmd ('"'+sFile+'" '+gsCurrentCommandLinePara)
        End
        Else Begin
                Runprogram BACKGROUND sCmd ('"'+sFile+'" '+gsCurrentCommandLinePara)
            End
        End
        Else Begin
            If (piDebugAlways(ghoEditorProperties) ) Begin
                If (nVer < 90) Begin
                    Get DebuggerCmdLine Of Desktop              To sCmd
                    If (lowercase(FileFromPath(sFile))<>"hammer.src") Begin // *WvA: added a personal preference, don't start the compiler as there's often
                      runprogram BACKGROUND sCmd ('"'+sFile+'" '+gsCurrentCommandLinePara)
                    End
                End
                Else Begin
                    Get DebuggerCmdLine Of Desktop              To sCmd
                    Get FileFromPath sFile                      To sFile
                    Move (sCmd+' -f "'+(CurrentProgramPath(ghoWorkspaceHandlerEx))+"\"+(FileWithoutExt(sFile))+'.exe '+gsCurrentCommandLinePara+'"') To sCmd
                    Get CAFileNameCur To sDebugSource
                    // *WvA: added for supporting webapp debug compile runs
                    // and debug-run your web applications straight from within the Hammer.
                    If (lowercase(sFile)="webapp") Begin
                      // We need to stick in some more parameters for the debugger
                      // because the debugger just needs a tad bit more info from the app.
                      // between the -f and -s switch we now also have to add:
                      //
                      //  Arg 3 :-w
                      //  Arg 4 :<workspacetag>
                      //  Arg 5 :-u
                      //  Arg 6 :<virtual foldername>/default.asp
                      //
                      Get psCurWrkSpace Of ghoWorkSpaceHandlerEx To sWorkspace
                      Move (sCmd+' -w "'+sWorkspace+'"') To sCmd
                      Get WebAppTestURL Of ghoWorkSpaceHandlerEx To sWebAppTestURL
                      Move (sCmd+' -u "'+sWebAppTestURL+'"') To sCmd
                    End
                    If (sDebugSource<>"") Begin
                        Move (sCmd+' -s "'+sDebugSource+'"') To sCmd
                    End
                    //Showln sCmd
                    Runprogram BACKGROUND sCmd
                End
            End
            Else Begin
              If (Pos("webapp",lowercase(sFile))<>0) Begin
                Get WebAppTestURL Of ghoWorkSpaceHandlerEx To sWebAppTestURL
                Send vShellExecute "OPEN" sWebAppTestURL "" ""
              End
              Else Begin
                Runprogram BACKGROUND ('"'+sFile+'.exe" '+gsCurrentCommandLinePara)
              End
        End
        End
        set_directory sCurDir
    End_Procedure

    Property String  psLastCompiledFileName     Public ""
    Property Integer piLastCompiledMode         Public 0
    Property Integer piLastCompiledRun          Public 0
    Property Integer piLastCompileHide          Public False


        // **BP: 02-01-04
        // Made the Debugger-Call VDF9 compatible
        // **BP: 18-03-04
        // Let the Program start from the ProgramPath Directory and not from the AppSrc
    Procedure CACompleteCompileAction
        String  sFile sCmd sVer sDebugSource sProgramPath sCurDir
        Integer iMode iRun iRet
        Number nVer
        Send PAShadowMainMenuItem 4 False
        Get psLastCompiledFileName              To sFile
        Get piLastCompiledMode                  To iMode
        Get piLastCompiledRun                   To iRun
        Get Msg_CALookIfErrors sFile            To iRet
        Move (FileWithoutExt(sFile))  To sFile
        If iMode Ne 3 If Not iRet If iRun Send CARunInt sFile
        Else If iRun Begin
            Get psVDFVersion    Of ghoWorkSpaceHandlerEx   To sVer
            Get StringVdfVersionToNum  Of ghoWorkSpaceHandlerEx sVer To nVer // 70=VDF7, 82=VDF8.2

            Get DebuggerCmdLine Of Desktop              To sCmd

            If (nVer < 90) Begin
                Append sCmd " " (sFile+" "+gsCurrentCommandLinePara)
            End
            Else Begin
                Get FileFromPath sFile                      To sFile
                Move (sCmd+' -f "'+(CurrentProgramPath(ghoWorkspaceHandlerEx))+"\"+(FileWithoutExt(sFile))+'.exe '+gsCurrentCommandLinePara+'"') To sCmd
                Get CAFileNameCur To sDebugSource
                If (sDebugSource<>"") Begin
                    Move (sCmd+' -s "'+sDebugSource+'"') To sCmd
                End
            End
            Move (CurrentProgramPath(ghoWorkspaceHandlerEx)) To sProgramPath

            get_current_directory To sCurDir
            If ( (sProgramPath<>"") And (Left(sProgramPath,2)<>".\") ) Begin // Only if ProgramPath is Set and not relative!
                set_directory sProgramPath
            End

            Runprogram BACKGROUND sCmd
            set_directory sCurDir
        End
    End_Procedure

    Procedure CAStartCompileAction Handle hProcess Integer iThreadID
        Integer iRet iFocus
        String sFile
        If ghoCompilerMessages Eq 0 Procedure_Return
        Move (psLastCompiledFileName(Self)) To sFile
        Get FileFromPath sFile To sFile
        Set label Of (parent(ghoCompilerMessages)) To ("Building " + (Trim(sFile)) )
        If (piDisplayWatchAutomatic(ghoEditorProperties)) Send PAWindowErrorListONOFF True
        If (Visible_State(oErrors(Self))) Begin
            Get focus Of desktop To iFocus
            Send Request_Tab_Display To ghoCompilerMessages 0
            If iFocus Ne (focus(desktop)) Send activate To iFocus
        End
        Send delete_data To ghoCompilerMessages
        Move (MKSpyCompiler(iThreadID,hProcess,(piLastCompileHide(Self)) )) To iRet
        Set piCanCancel Of ghoCompilerMessages To True
    End_Procedure

    Procedure CAPreCompileSys String sFile
        String sCmd sVdfRoot sOpt
        //
        Move "/x- /E0 /p" To sOpt
        //
        Get psVdfRootDir Of ghoWorkSpaceHandlerEx To sVdfRoot
        Move ('"'+sVDFRoot+"Pkg\"+sFile+'"') To sFile
        //
        Get CompilerCmdLine Of Desktop To sCmd
        Move (sCmd*sFile*sOpt) To sCmd
        //
        Runprogram background sCmd
        //
    End_Procedure

    Procedure PreCompileDFAllEnt
        Send CAPreCompileSys "dfAllEnt.pkg"
    End_Procedure

    Procedure PreCompileWindows
        Send CAPreCompileSys "Windows.pkg"
    End_Procedure

    Procedure CASaveChangedFilesBeforeCompile
        Integer hoVw iRet iDel iChanged
        Move 0 To iChanged
        Get Next_Mdi_Dialog True            To hoVw // find first view
        While ( (hoVw) And (Not(iChanged)) )
            If (Active_State(hoVw)) Begin
                If (CM_IsModified(oEdit(hoVW))) Move 1 To iChanged
            End
            Get Next_Mdi_Dialog False        To hoVw // find next view
        End
        If iChanged Begin
            If (yesno_box("Do you want to save all changes before compiling?","Question",0)) Eq MBR_YES Begin
                Get Next_Mdi_Dialog True            To hoVw // find first view
                While (hoVw)
                    If (Active_State(hoVw)) Begin
                        If (CM_IsModified(oEdit(hoVW))) Send SaveFile To hoVw
                    End
                    Get Next_Mdi_Dialog False        To hoVw // find next view
                End
            End
        End
    End_Procedure

        // **BP: 02-01-04
        // Made the Debugger-Call VDF9 compatible
        // **BP: 18-03-04
        // Let the Program start from the ProgramPath Directory and not from the AppSrc
    Procedure CACompileIntern Integer iMode Integer iRun Integer iCurrent
        Integer iRet iCompile
        String  sCmd sParas sFile sFileC sVer sDebugFile sDebugSource sProgramPath sCurDir
        Number  nVer
        Boolean bConfigure

        Get CompilerCmdLine Of Desktop              To sCmd
        If iCurrent Get CAFileNameCur           To sFile
        Else Move gsCurrentProgramFile          To sFile
        If sFile Eq "" Procedure_Return

        Send CASaveChangedFilesBeforeCompile

        Move ('"'+sFile+'"') To sFileC

        If iMode Eq 1 Move (psCompiler.PreCompOptions(ghoEditorProperties)) To sParas
        If iMode Eq 2 Move (psCompiler.CompOptions(ghoEditorProperties))    To sParas
        If iMode Eq 3 Move (psDebugCompiler(ghoEditorProperties))           To sParas

        Set piLastCompileHide To False
        If ( (ghoCompilerMessages Ne 0) And (Pos("I0",(uppercase(sParas))) Ne 0) ) Begin
            Move (Replace("i0",sParas,"I2")) To sParas
            Move (Replace("I0",sParas,"I2")) To sParas
            Set piLastCompileHide To True
        End
        Move (sParas + " " + sFileC) To sParas
        If iMode Ne 3 Move 1                                To iCompile
        Else Move (piCompiler4Debug(ghoEditorProperties))   To iCompile
        //Append sCmd " " sParas

        If iCompile Begin
            //RunProgram WAIT sCmd
            Send PAShadowMainMenuItem 4 True
            Send RunProgramNotify sCmd sParas SW_MINIMIZE Msg_CACompleteCompileAction Self Msg_CaStartCompileAction
            Set psLastCompiledFileName  To sFile
            Set piLastCompiledMode      To iMode
            Set piLastCompiledRun       To iRun

            Procedure_Return    // Abbrechen
            Get Msg_CALookIfErrors sFile            To iRet
        End
        Move sFile To sDebugFile
        Move ('"'+FileWithoutExt(sFile)+'"')  To sFile
        If iMode Ne 3 If Not iRet If iRun Send CARunInt sFile
        Else If iRun Begin
            Get psVDFVersion    Of ghoWorkSpaceHandlerEx   To sVer
            Get StringVdfVersionToNum  Of ghoWorkSpaceHandlerEx sVer To nVer // 70=VDF7, 82=VDF8.2

            Get DebuggerCmdLine Of Desktop              To sCmd

            If (nVer < 90) Begin
            Append sCmd " " sFile
            End
            Else Begin
                Get FileFromPath sDebugFile To sDebugFile
                Move (sCmd+' -f "'+(CurrentProgramPath(ghoWorkspaceHandlerEx))+"\"+(FileWithoutExt(sDebugFile))+'.exe '+gsCurrentCommandLinePara+'"') To sCmd
                Get CAFileNameCur To sDebugSource
                If (sDebugSource<>"") Begin
                    Move (sCmd+' -s "'+sDebugSource+'"') To sCmd
                End
            End
            Move (CurrentProgramPath(ghoWorkspaceHandlerEx)) To sProgramPath

            get_current_directory To sCurDir
            If ( (sProgramPath<>"") And (Left(sProgramPath,2)<>".\") ) Begin // Only if ProgramPath is Set and not relative!
                set_directory sProgramPath
            End
            Runprogram BACKGROUND sCmd
            set_directory sCurDir
        End
    End_Procedure // CACompileIntern

    Procedure CACurrentCompile
        String sFile
        Get CAFileNameCur To sFile
        Move (Uppercase(Trim(Right(sFile, 4)))) To sFile
        If (sFile<>".SRC")  Send CABuildPreCompile
        Else                Send CABuildCompile
    End_Procedure
    Procedure CABuildRun
        If (Right(uppercase(Trim(CAFileNameCur(Self))),4)) Eq ".SRC" Send CACompileIntern 2 True True
        Else Send CACompileIntern 2 True False
    End_Procedure
    Procedure CABuildRunCurrent
        Send CACompileIntern 2 True True
    End_Procedure
    Procedure CABuildCompile
        Send CACompileIntern 2 False True
    End_Procedure
    Procedure CABuildPreCompile
        Send CACompileIntern 1 False True
    End_Procedure
    Procedure CABuildExecute
        String sFile
        If (Right(uppercase(Trim(CAFileNameCur(Self))),4)) Eq ".SRC" Move (FileWithoutExt(CAFileNameCur(Self))) To sFile
        Else Move (FileWithoutExt(gsCurrentProgramFile)) To sFile
        Send CARunInt sFile
    End_Procedure
    Procedure CABuildCommandLineParameter
        String sRet
        Get GetCommandLineParameter gsCurrentCommandLinePara To sRet
        If sRet Ne "#ERR" Move sRet To gsCurrentCommandLinePara
    End_Procedure

    Procedure CABuildDebugRun
        Send CACompileIntern 3 True False
    End_Procedure
    Procedure CABuildDebugRunCurrent
        Send CACompileIntern 3 True True
    End_Procedure

    Procedure CAWindowCodeExplorerONOFF Integer iFlag
        Broadcast Send SetCodeViewVisible iFlag
    End_Procedure

    Procedure InitMdiBottomMargin
        If (pbErrorListVisible(ghoEditorProperties)) Begin
            If (piErrorListHeight(ghoEditorProperties)) Gt 40 Set MDI_Bottom_Margin   To ( (piErrorListHeight(ghoEditorProperties)) + (hi(guiSize(ghoFiletabs))) +2 )
            Else Set MDI_Bottom_Margin   To (80 + (hi(guiSize(ghoFiletabs))) +2 )
        End
        Else Set MDI_Bottom_Margin To ((hi(guiSize(ghoFiletabs)))+2)
    End_Procedure

    Procedure RequestStartFileFind String sPath String sType String sText Integer bSubFolders Integer bMatchCase Integer bMatchWord Integer bShowAll Integer bRegExp
        Integer hoResult hoBefore iTab iRedraw
        Get focus Of desktop To hoBefore
        Move (piRedrawState(oClientArea(Self))) To iRedraw
        If (iRedraw) Send SetRedraw False
        Send CancelFileFind To (oFileFinder(Self))
        Send PAWindowErrorListONOFF True
        Send StartFileFind To (oFileFinder(Self)) sPath sType sText bSubFolders bMatchCase bMatchWord bShowAll bRegExp
        Send CreateFindPage To (oFileFinder(Self))
        Send activate To hoBefore
        If (iRedraw) Send SetRedraw True
    End_Procedure

    Procedure RequestCancelFileFind
        Send CancelFileFind To (oFileFinder(Self))
        Send OnFinish To (oFileFinder(Self))
    End_Procedure

    Procedure CAShortcutItem1
        Send ShortcutItemSelected To ghoFileTabs 1
    End_Procedure
    Procedure CAShortcutItem2
        Send ShortcutItemSelected To ghoFileTabs 2
    End_Procedure
    Procedure CAShortcutItem3
        Send ShortcutItemSelected To ghoFileTabs 3
    End_Procedure
    Procedure CAShortcutItem4
        Send ShortcutItemSelected To ghoFileTabs 4
    End_Procedure
    Procedure CAShortcutItem5
        Send ShortcutItemSelected To ghoFileTabs 5
    End_Procedure
    Procedure CAShortcutItem6
        Send ShortcutItemSelected To ghoFileTabs 6
    End_Procedure
    Procedure CAShortcutItem7
        Send ShortcutItemSelected To ghoFileTabs 7
    End_Procedure
    Procedure CAShortcutItem8
        Send ShortcutItemSelected To ghoFileTabs 8
    End_Procedure
    Procedure CAShortcutItem9
        Send ShortcutItemSelected To ghoFileTabs 9
    End_Procedure
    Procedure CAShortcutItem10
        Send ShortcutItemSelected To ghoFileTabs 10
    End_Procedure
    
    
    //
    // The treeview on the left hand side will not respect the
    // custom defined hotkeys for the editor component unless
    // we add them here.
    //
    Procedure Define_EditViewHotkeys Handle hoEditView
      
      // File Menu
      Send DefineOnKey Of hoEditView CMD_FileOpenFile      msg_CAOpenFile
      Send DefineOnKey Of hoEditView CMD_FileSaveFile      msg_CASaveFile
      Send DefineOnKey Of hoEditView CMD_FileSaveFileAs    msg_CASaveFileAs
      Send DefineOnKey Of hoEditView CMD_FileSaveAll       msg_CASaveAllFiles
      Send DefineOnKey Of hoEditView CMD_FileCloseFile     msg_CACloseFile
      Send DefineOnKey Of hoEditView CMD_FileCloseAllFiles msg_CACloseAllFiles
      Send DefineOnKey Of hoEditView CMD_FileNewFile       msg_CANewFile

      // Edit Menu
      Send DefineOnKey Of hoEditView CMD_FindInFiles       msg_CAPopUpFindInFiles

      // Options Menu
      Send DefineOnKey Of hoEditView CMD_SelectWorkSpace   msg_CASelectWorkSpace
      
      // Build Menu
      Send DefineOnKey Of hoEditView CMD_BuildRun          msg_CABuildRun
      Send DefineOnKey Of hoEditView CMD_BuildRunCurrent   msg_CABuildRunCurrent
      Send DefineOnKey Of hoEditView CMD_BuildCompileCurrent msg_CABuildCompile
      Send DefineOnKey Of hoEditView CMD_BuildPreCompile   msg_CABuildPreCompile
      Send DefineOnKey Of hoEditView CMD_BuildExecute      msg_CABuildExecute
      Send DefineOnKey Of hoEditView CMD_BuildDebugRun     msg_CABuildDebugRun
      Send DefineOnKey Of hoEditView CMD_BuildDebugRunCurrent msg_CABuildDebugRunCurrent
      
      // There are more hotkeys in the codemax control, but a lot of them only
      // make sense when you are actually editing int he control.
      // So we'll add more on a case by case bases (if needed)
    End_Procedure // Define_EditViewHotkeys
    

    On_Key (KEY_ALT+KEY_1) Send CAShortcutitem1
    On_Key (KEY_ALT+KEY_2) Send CAShortcutitem2
    On_Key (KEY_ALT+KEY_3) Send CAShortcutitem3
    On_Key (KEY_ALT+KEY_4) Send CAShortcutitem4
    On_Key (KEY_ALT+KEY_5) Send CAShortcutitem5
    On_Key (KEY_ALT+KEY_6) Send CAShortcutitem6
    On_Key (KEY_ALT+KEY_7) Send CAShortcutitem7
    On_Key (KEY_ALT+KEY_8) Send CAShortcutitem8
    On_Key (KEY_ALT+KEY_9) Send CAShortcutitem9
    On_Key (KEY_ALT+KEY_0) Send CAShortcutitem10

    End_Object  // oClientArea

    Use cFolderTabsPopupmenu.pkg

    Object oOpenedFilesTabs Is a cFolderTabs
        Set Size To 13 100
        Set visible_state To False
        //Set autosize_height_state to TRUE
        Set piTabsColor To clWhite // (GetSysColor(COLOR_BTNFACE))
//        Set piSelectedItemColor To clWhite
        Set piShowNumbersForFirst To True
        Set Color To clBgClr // clLtGray

        Object oFile_pm is a cFolderTabsPopupmenu
        End_Object // oFile_pm

        Move (Self) To ghoFileTabs
        Procedure AddFileButton Integer hoObj
            String sLabel sToolTip
            Integer hoPage hDC iRet iReadOnly
            If (Trim(label(hoObj))) Eq "" Procedure_Return
            Get psFileName Of (oEdit(hoObj)) To sLabel
            Get CM_IsReadOnly Of (oEdit(hoObj)) To iReadOnly
            If (Trim(sLabel)) Eq "" Move CM_NEWFILENAME To sLabel
            Move sLabel To sToolTip
            Get FileFromPath sLabel To sLabel
            Send add_item msg_none sLabel
            If iReadOnly Move (sToolTip + " (Read Only)") To sToolTip
            Set tooltip_value Item (item_count(Self)-1) To sToolTip
            Set aux_value Item (item_count(Self)-1) To hoObj
            If iReadOnly Set ItemTextColor Item (Item_count(Self)-1) To clRed
            Set current_item To (item_count(Self)-1)
            Set visible_state To True
        End_Procedure

        Procedure RemoveFileButton Integer hoObj
            Integer iCou hoTest hoFocus

            For iCou From 0 To ( (item_count(Self)) -1)
                Get aux_value Item iCou To hoTest
                If hoTest Eq hoObj Begin
                    Send Delete_Item iCou
                    Procedure_Return
                End
            Loop
        End_Procedure

        Procedure ActivateFileButton Integer hoObj
            Integer iCou hoTest hoFocus

            For iCou From 0 To ( (item_count(Self)) -1)
                Get aux_value Item iCou To hoTest
                If hoTest Eq hoObj Begin
                    Set Current_Item To iCou
                    Procedure_Return
                End
            Loop
        End_Procedure

        Procedure OnClick Integer iItem
            Integer hoObj iRedraw iRet
            Get aux_value Item iItem To hoObj
            If ( (hoObj) And (active_state(hoObj)) ) Begin
                Move (piRedrawState(oClientArea(Self))) To iRedraw
                If (iRedraw) Send SetRedraw False
                Move (SendMessage(window_handle(oClientArea(Self)),WM_MDIACTIVATE,(window_handle(hoObj)),0)) To iRet
                If (iRedraw) Send SetRedraw True
            End
        End_Procedure


        Procedure OnRightClick Integer iItem
          Handle hoObj
          String sFilename
          Get aux_value Item iItem To hoObj
          If ((hoObj) and active_state(hoObj)) Begin
            Get psFileName Of (oEdit(hoObj)) To sFilename
            //Get FileFromPath sFileName To sFileName
            Set psFileName of oFile_Pm to sFileName
            Set phoSelectedEditWindow Of oFile_pm To hoObj
          End
          Else Begin
            Set psFileName of oFile_Pm to ""
            Set phoSelectedEditWindow Of oFile_pm To 0
          End
          Send Popup To (oFile_pm(Self))
        End_Procedure

        Procedure OnLabelChanged Integer hoObj
            Integer iItem hoTest iIsChanged iReadOnly
            Integer iTextColor
            Integer iCount
            String sLabel sToolTip
            
            Get item_Count To iCount
            For iItem From 0 To ( iCount -1)
                Get aux_value Item iItem To hoTest
                If hoTest Eq hoObj Begin
                    Get psFileName    Of (oEdit(hoObj)) To sLabel
                    Get CM_IsModified Of (oEdit(hoObj)) To iIsChanged
                    Get CM_IsReadOnly Of (oEdit(hoObj)) To iReadOnly
                    If (Trim(sLabel)) Eq "" Move CM_NEWFILENAME To sLabel
                    Move sLabel To sToolTip
                    Get FileFromPath sLabel To sLabel
                    If iIsChanged Move (sLabel + " *") To sLabel
//                    If sLabel Eq (value(Self,iItem)) Procedure_Return
                    Set value Item iItem To sLabel
                    If iReadOnly Begin
                      Move (sToolTip + " (Read Only)") To sToolTip
                      Set ItemTextColor Item iItem To clRed
                    End
                    Else Begin
                      Get piItemTextColor To iTextColor
                      Set ItemTextColor Item iItem To iTextColor
                    End
                    Set tooltip_value Item iItem To sToolTip
                    Send refresh
                    Procedure_Return
                End
            Loop
        End_Procedure

        Procedure ShortcutItemSelected Integer iItem
            Integer hoObj iRedraw iRet
            Calc (iItem -1) To iItem
            If iItem Gt ( (item_count(Self)) -1) Procedure_Return
            Get aux_value Item iItem To hoObj
            If ( (hoObj) And (active_state(hoObj)) ) Begin
                Move (piRedrawState(oClientArea(Self))) To iRedraw
                If (iRedraw) Send SetRedraw False
                Move (SendMessage(window_handle(oClientArea(Self)),WM_MDIACTIVATE,(window_handle(hoObj)),0)) To iRet
                If (iRedraw) Send SetRedraw True
            End
        End_Procedure
    End_Object

    Send InitMdiBottomMargin To (oClientArea(Self))

        // Repostitioning the Errorlist with a splitter.
    Object oHorizontalSplitter Is A cHorizontalSplitter
        Set Size To 2 153
        Set Location To 72 5
        // this procedure is overwritten because normaly the call to
        // DoMoveSelf is done after the DoNotify. In this case, the
        // size of splitters parent is changed and so we need to notify
        // the objects before the splitter is redrawn. Otherwise the
        // splitter is placed on a wrong place and is no longer accessable.
        // 03.03.2003 BP
        Procedure OnSplitterMouseUp Integer wParam Integer lParam
           Integer iMinTrack iMaxTrack iTrack

           Send Release_Mouse_Capture

           Send DoDrawDrag 65536 // Special value to erase last line

           Move (Hi (lParam)) To iTrack
           If (iTrack > 32000) Begin
              Move (iTrack - 65536) To iTrack
           End

           Get piMinTrack To iMinTrack
           Get piMaxTrack To iMaxTrack

           Move (iMaxTrack Min (iMinTrack Max iTrack)) To iTrack

           Send DoMoveSelf iTrack
           Send DoNotify iTrack
        End_Procedure // OnSplitterMouseUp
    End_Object    // oHorizontalSplitter
    Send DoAddObjectToNotify To (oHorizontalSplitter(Self)) Self
    Procedure OnSplitterChange Integer iTrack
       Integer iPy
       If Not (Visible_State(oErrors(Self))) Procedure_Return
       Set MDI_Bottom_Margin Of (oClientArea(Self)) To ;
        (MDI_Bottom_Margin(oClientArea(Self))-iTrack)
       //Send FitErrorContainerToMdiMargin false
       Set piErrorListHeight Of ghoEditorProperties To (MDI_Bottom_Margin(oClientArea(Self)))
       Send Adjust_Logicals
    End_Procedure // OnSplitterChange

    // We don't want the splitter to be canceled so return 0 here.
    // 03.03.2003 BP
    Procedure OnRequestSplitter
        Procedure_Return 0
    End_Procedure

//    Object oErrorTools Is a cSysToolBar
//        Set GUILocation  To 0 0
//        Set GUISize      To 100 20
//        Object oCloseErrors Is a cETButton
//            Set psTooltip To 'Close "Message List" Panel'
//            Set pbWrap To True
//            Procedure OnClick
//                Send PAWindowErrorListONOFF False
//            End_Procedure
//        End_Object
//        Object oCloseErrorsInfo Is a cETInfoButton
//            Set psTooltip To "This panel is used to display the compiler errors\n and the other messages."
//            Set pbWrap To True
//        End_Object
//    End_Object

    Object oErrors Is A cDynTabDialog
        Set Visible_State To (pbErrorListVisible(ghoEditorProperties))
        Set piButtonState    To Button_Bottom    // Buttons on the bottom!
        Set skip_button_mode To SBM_ALWAYS
        Set size To 50 1000

        Object oTabFindObjects Is an Array
        End_Object

        If (piWatchCompiler(ghoEditorProperties)) Begin
            Object oTabPage0 Is a cDynTabPage
                Set label To "Build"
                Object oCompilerMessages Is a cCompilerMessages
                    Set size To 50 1000
                    Move (Self) To ghoCompilerMessages
                    Procedure mCancel
                        Integer iRet
                        If (piCanCancel(Self)) Move (MKAbortCurrentCompile()) To iRet
                        Else Send mClose
                    End_Procedure
                    Procedure addLine String sVal
                        String sLabel
                        Forward Send addLine sVal
                        If (uppercase(Left(Trim(sVal),6))) Eq "ERROR:" Begin
                            Send Play_Wave "SystemExclamation" SND_ASYNC
                            Get label Of (parent(Self)) To sLabel
                            If (Pos("(Errors found)",sLabel)) Eq 0 Begin
                                Move (sLabel + " (Errors found)") To sLabel
                                Set label Of (parent(Self)) To sLabel
                            End
                        End
                    End_Procedure
                End_Object
                Set phoClientObject To ghoCompilerMessages
            End_Object
        End
        Else Move 0 To ghoCompilerMessages

        Object oTabPage1 Is a cDynTabPage
            Set Label   To "Errors"
            //
            Object oErrorList Is A cErrorList
                Set size To 50 1000
            End_Object
            Set phoClientObject To (oErrorList(Self))

        End_Object

        Function AddFindPage String sLabel Returns Integer
            Integer hoID hoTab
            Object oDynTabPage Is a cDynTabPage
                Set label To sLabel
                Move (Self) To hoTab
                Object oFindResults Is a cFindResults
                    Move (Self) To hoID
                End_Object
                Set phoClientObject Of hoTab To hoID
            End_Object
            Send Request_Switch_To_Tab ( (button_count(Self)) -1) 2
            Set GuiSIze Of hoID To ((Hi(Client_Size(hoTab)))-10) ((low(Client_Size(hoTab)))-3)
            Set value Of (oTabFindObjects(Self)) Item (item_count(oTabFindObjects(Self))) To hoTab
            Function_Return hoTab
        End_Function

        Procedure RemovePage Integer hoObj
            Integer hoClient iCou hoCompare
            Get phoClientObject Of hoObj To hoClient
            If hoClient Ne 0 Send delete_data To hoClient
            Send DeleteByObjectId hoObj
            For iCou From 0 To (item_count(oTabFindObjects(Self))-1)
                Get value Of (oTabFindObjects(Self)) Item iCou To hoCompare
                If hoCompare Eq hoObj Begin
                    Send delete_item To (oTabFindObjects(Self)) iCou
                    Move (item_count(oTabFindObjects(Self))) To iCou
                End
            Loop
        End_Procedure

        Procedure mClose
            Send PAWindowErrorListONOFF False
            Send next
        End_Procedure
        On_Key KCANCEL Send mClose

        Procedure mCancelFileFind
            Send RequestCancelFileFind To (oClientArea(Self))
        End_Procedure
    End_Object

        // Pos. the errorlist and the splitter if neccassarry.
    Procedure FitErrorContainerToMdiMargin Integer iStartUp
        Integer hoID hoCA hoErr
        Integer iPy iPx iRet
        Move (oErrors(Self))     To hoID
//        Move (oErrorTools(Self)) To hoErr
        Move (oClientArea(Self)) To hoCA
        Move ( Hi(GuiLocation(hoCA))+ Hi(GuiSize(hoCA))+2)  To iPy
        If ghoFiletabs Begin
            Move 0 To iPx
            Set GuiLocation Of ghoFiletabs To iPy iPx
            Set GuiSize Of ghoFiletabs To (hi(GuiSize(ghoFiletabs))) ((low(client_size(Self)))-iPx-2)
        End
        Move ( Hi(GuiLocation(hoCA))+ Hi(GuiSize(hoCA))+2+(hi(guiSize(ghoFileTabs)))+4)  To iPy
        If hoID Begin
            Set GuiLocation Of hoID To iPy 2
//            Set GuiLocation Of hoID To iPy 15 //0
//            Set GuiLocation Of hoErr To iPy 1
//            Set GuiSize     Of hoErr To (Hi(Client_Size(Self))-iPy-20) 20
//            Set GuiSize     Of hoID To (Hi(Client_Size(Self))-iPy-20) (Low(Client_Size(Self))-15)
            Set GuiSize     Of hoID To (Hi(Client_Size(Self))-iPy-20) (Low(Client_Size(Self))-2)
            If iStartUp Begin
                Set GuiSize     Of (oHorizontalSplitter(Self)) To 3     (Low(Client_Size(Self)))
                Set GuiLocation Of (oHorizontalSplitter(Self)) To (iPy-3) 0
            End
        End
    End_Procedure


        // Pos. the error list.
    Procedure Activate
        Forward Send Activate
        Send FitErrorContainerToMdiMargin True
    End_Procedure
    //Procedure Set GuiSIze Integer iY Integer iX
    //    Local Integer hoID hoID2
    //    Forward Set GuiSize     to iY iX
    //    Send FitErrorContainerToMdiMargin True
    //End_Procedure

    // *WvA 05-11-2003
    // In Vdf9.1 there is a problem with the statusbar and
    // the icon to open the messages panel in particular
    // If you hover your cursor over the icon, suddenly a
    // Notify error pops up. It appears that the notify
    // message is send to the clipboard object (object with handle=1)
    // By overriding this here we are getting rid of the error.
    Procedure Notify For Clipboard Integer wParam Integer lParam
//      //Send info_box "Plop"
    End_Procedure // Notify


    Use THStatusBar.pkg //  Status-Bar object.



    #Include Editor.mn

        // Is used to deactivate the build menu when compiling.
    Procedure PAShadowMainMenuItem Integer iItem Integer iFlag
        Set Shadow_State Of (Main_Menu(Self)) Item iItem To iFlag
    End_Procedure

        // Better place then Exit_Application, becouse this functions is
        // triggered when the System closes the App, too.
    Function verify_exit_application Returns Integer
        Integer iRet
        Forward Get verify_exit_application  To iRet
        If Not iRet Begin
            Indicate MKNoParsing True
            Send CACreateEditorEntries                        To (oClientArea(Self))
            Get MSg_CACloseAllFiles Of (oClientArea(Self))    To iRet
            If Not iRet Send MKCleanUp
            Indicate MKNoParsing False
            If (ghoWorkspaceHandlerEx) Begin
              // No crash on quit please.
              Send UnloadNonEmbeddedDrivers of ghoWorkspaceHandlerEx
            End
        End
        Function_Return iRet
    End_Function
        // Save Settings during exit.
    Procedure MKCleanUp
        Integer iRet
        Send SaveIni                    To ghoEditorProperties  // Save the INI file
        Move (CMUnregisterControl())    To WindowIndex          // Unregister the control
    End_Procedure

    Function PAIsErrorListFilled Returns Integer
        Integer hoID
        Move (oErrorList(oTabPage1(oErrors(Self)))) To hoID
        Function_Return (Item_Count(hoID) Gt 0)
    End_Function
    Procedure PAGotErrorList
        Integer hoID
        Move (oErrorList(oTabPage1(oErrors(Self))))        To hoID
        If (Visible_State(hoID)) If (Item_Count(hoID)) Gt 0 Send Activate To hoID
    End_Procedure

    Procedure PAWindowSwtichToErrorView
        Send PAGotErrorList
    End_Procedure

    Procedure PAWindowErrorListONOFF Integer iFlag
        Integer iRet iRedraw
        // Do nothing if already visible/not visible
        // 28.02.2003 BP
        If (visible_state(oErrors(Self))) Eq iFlag Procedure_Return
        Move (piRedrawState(oClientArea(Self))) To iRedraw
        If (iRedraw) Send SetRedraw False
        If (Not(iFlag)) Send CancelFileFind To (oFileFinder(Self))
        Set pbErrorListVisible Of ghoEditorProperties               To iFlag
        Set Visible_State       Of (oErrors(Self))                  To iFlag
//        Set Visible_State       Of (oErrorTools(Self))              To iFlag
        Set Object_Shadow_State Of (oErrors(Self))                  To (Not(iFlag))
        Set Visible_State       Of (oHorizontalSplitter(Self))      To iFlag
        If  iFlag Set MDI_Bottom_Margin   Of (oClientArea(Self))    To ( (piErrorListHeight(ghoEditorProperties)) + (hi(guiSize(ghoFiletabs))) + 2)
        Else      Set MDI_Bottom_Margin   Of (oClientArea(Self))    To (20 + (hi(guiSize(ghoFiletabs))) +2 )
        Send FitErrorContainerToMdiMargin True
        If (iRedraw) Send SetRedraw True
    End_Procedure

    Procedure ConvertFile
        Integer hoID iC
        String sL
        String sFile

        Get FileDialog Of Desktop False "Choose a file to convert" "" "" To sFile
        If sFile Eq "" Procedure_Return
        Object oTmp Is An Array
            Move Self   To hoID
        End_Object

        Direct_Input sFile
        Repeat
            Readln sL
            [Not seqeof] Set Value Of hoID Item (Item_Count(hoID))  To sL
        Until [seqeof]
        Close_Input
        Direct_Output sFile
        For iC From 0 To (Item_Count(hoID)-1)
            Writeln (Value(hoID,iC))
        End
        Close_Output
        Send Request_Destroy_Object To hoID
    End_Procedure
    On_Key key_alt+key_v Send ConvertFile

        // Added to support Reopen of Files based on Workspace
        // 18.01.01 Bernhard
    Procedure OnWorkspaceChanged
        Set pbWorkspaceChanging To True
        Send ShowWorkspaceInfo
        Send ReOpenAllFiles
        Send LoadSettings To oFindFiles
        Set pbWorkspaceChanging To False
//        Set view_mode To viewmode_zoom
    End_Procedure

        // Added to support Reopen of Files based on Workspace
        // 18.01.01 Bernhard
    Function RequestChangeWorkspace String sWrkSpace Returns Integer
        Integer iRet
        Send CACreateEditorEntries To (oClientArea(Self))
        Get MSG_CACloseAllFiles Of (oClientArea(Self)) sWrkSpace To iRet
        If (iRet) Function_Return False
        Function_Return True
    End_Function

    Function FileDialog Integer iSave String titel String hfilter String sFile Returns String
       String Fname sDir
       String PropVal
       Integer retval
       Integer OpenFileObj
       Get_Current_Directory   To sDir
        If Not iSave Begin
            Object OpenFile Is a OpenDialog
                Set Filter_String       To hFilter
                Set Dialog_Caption      To titel
                Set NoChangeDir_State   To True
                Set File_Title          To sFile
                Set Initial_Folder      To sDir
                Move Current_Object To OpenFileObj
            End_Object
        End
        Else Begin
            Object SaveFile Is a SaveasDialog
                Set Filter_String       To hFilter
                Set Dialog_Caption      To titel
                Set NoChangeDir_State   To True
                Set File_Title          To sFile
                Set Initial_Folder      To sDir
                Move Current_Object To OpenFileObj
            End_Object
        End
        Get Show_Dialog Of OpenFileObj To Retval
        If RetVal ;
            Move (File_Name(OpenFileObj)) To fName
        Send Destroy_Object To OpenFileObj
        Function_Return Fname
    End_Function

    Property Integer phoDependencyScanner   Public 0
    Procedure Request_CreatecDependencyScanner
        Integer hoId
        If (phoDependencyScanner(Self)) Eq 0 Begin
            Object oDependencyScanner Is a cDependencyScanner
                Move Self To hoId
            End_Object
            Set phoDependencyScanner    To hoId
        End
    End_Procedure
    Procedure PADependencyConfig
        Integer hoId
        Send Request_CreatecDependencyScanner
        Move (phoDependencyScanner(Self))   To hoId
        If hoId Send DoConfig               To hoId
    End_Procedure
    Procedure PADependencyScan
        Integer hoId
        Send Request_CreatecDependencyScanner
        Move (phoDependencyScanner(Self))   To hoId
        If hoId Begin
            Send DoScan                     To hoId
            Send DoWriteDefault             To hoId
            If (piOutputMode(hoId)) Eq 0 Begin
                Send CAOpenFile To (oClientArea(Self)) (psTextFile(hoId))
            End
        End
    End_Procedure

    Procedure Toggle_Overtype
    End_Procedure

    Procedure GoToLine
    End_Procedure

    //  Added 31.05.2005 by Raveen
    //@ Deactivate Splash Screen
    //@ Remove splash screen
    Send Deactivate To (Splash_Screen(Self)) //@
End_Object

    // Changed to support Reopen of Files based on Workspace
    // 18.01.01 Bernhard
Procedure ReOpenAllFiles
    Integer iRec hoID iC
    Boolean bExists
    String  sFile
    String  sWrkSpace
    String  sVal

    Object oTmp Is An Array
        Move Self       To hoID
    End_Object
    Indicate MKNoParsing True

    Get EditorWorkspaceID To sWrkSpace
    //
    Move ( (Uppercase(Trim(sWrkSpace))) + "OPENED")  To sWrkSpace
    Clear Editor
    Move gsUserName To Editor.User
    Move sWrkSpace  To Editor.Type
    Repeat
        Find Gt Editor by Index.1
        If Editor.Type Ne sWrkSpace     Indicate found False
        If Editor.User Ne gsUserName    Indicate found False
        If (found) Begin
            Move (Trim(Editor.File)) To sFile
            Get vFilePathExists sFile to bExists
            If (bExists=false) Begin
              // If file cannot be found, then do not try to open it again next time.
              Lock
                Delete Editor
              Unlock
            End
            // We can silently fail here, but not sure if that's smart
            Set value Of hoID Item (Item_Count(hoID))   To sFile
        End
    Until [Not found]

    //Set Visible_State Of (oClientArea(oMain(self)))          to False
    Send SetRedraw To (oClientArea(oMain(Self))) False
    For iC From 0 To (Item_Count(hoID)-1)
        If iC Eq (Item_Count(hoID)-1) Indicate MKNoParsing False
        Send CAOpenFile To (oClientArea(oMain(Self))) (Value(hoID,iC))
    End
    //Set Visible_State Of (oClientArea(oMain(self))) to True
    Send SetRedraw To (oClientArea(oMain(Self))) True
    Indicate MKNoParsing False
    Send Request_Destroy_Object To hoID
End_Procedure

    // Is done in OnWorkSpaceChanged
    // 18.01.01 Bernhard
//Send ReOpenAllFiles

// Added 17.05.01 Bernhard
// Changed 18.05.01 Bernhard
Function RequestChangeWorkSpace String sWorkSpace Returns Integer
    Function_Return (RequestChangeWorkSpace(oMain(Self),sWorkSpace))
End_Procedure
Procedure OnWorkSpaceChanged
    Send OnWorkSpaceChanged To (oMain(Self))
    Send OnWorkSpaceChanged To (oIDETagsArray(Self))
End_Procedure
Send OnWorkSpaceChanged

#IF (FMAC_VERSION < 8)
    // Opens a file when -OPEN is given.
If (psWrkSpcOpenFileName(ghoWorkSpace)) Ne "" Send WrkSpcDoForAllFiles  To ghoWorkSpace Msg_CAOpenFile (oClientArea(oMain(Self)))
 //Send CAOpenFile To (oClientArea(oMain(Self))) (psWrkSpcOpenFileName(ghoWorkSpace))

    // Creates an empty file viw on startup when -NEW is given.
If (piWrkSpcNewFile(ghoWorkSpace))            Send CANewFile  To (oClientArea(oMain(Self)))
    // Popups the WorkSpace/ VDF Version ModalPanel when -SETVERSION is given.
If (piWrkSpcSetVersion(ghoWorkSpace)) Begin
    Send Popup      To (oWorkSpace(Self))
    Send SaveIni    To ghoEditorProperties
End
#ELSE
    // Opens a file when -OPEN is given.
If (psWrkSpcOpenFileName(ghoApplication)) Ne "" Send WrkSpcDoForAllFiles  To ghoApplication Msg_CAOpenFile (oClientArea(oMain(Self)))
 //Send CAOpenFile To (oClientArea(oMain(Self))) (psWrkSpcOpenFileName(ghoWorkSpace))

    // Creates an empty file viw on startup when -NEW is given.
If (piWrkSpcNewFile(ghoApplication))            Send CANewFile  To (oClientArea(oMain(Self)))
    // Popups the WorkSpace/ VDF Version ModalPanel when -SETVERSION is given.
If (piWrkSpcSetVersion(ghoApplication)) Begin
    Send Popup      To (oWorkspace(Self))
    Send SaveIni    To ghoEditorProperties
End
#ENDIF

If (psVDFRegistryVersion(ghoEditorProperties)) Eq "" Begin
    Send Popup      To (oWorkSpace(Self))
    Send SaveIni    To ghoEditorProperties
End

Start_UI oMain

