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

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

  
'----------------------------------------------------------------
     CREATE FindTreeView AS QTREEVIEW
      PARENT = FindAllPanel
      ReadOnly = True
      Align = 5
      Font.AddStyles(fsBold) ', fsItalic)
      Font.Bold = True
      FullExpand
      OnClick = FindTreeChange
      OnDblClick = FindTreeChange     'FindTreeOpenItem  <== use for search dir files
    'OnMouseMove = FindTreeHotTrack
     END CREATE
'----------------------------------------------------------------

     CREATE FindReplaceForm AS QFormEx
'      Parent = MainForm            'no!
      FormStyle = fsStayOnTop
      CAPTION = "Find/ Replace"
      Top     = 80
      Left    = Screen.Width - 450
      Width   = 417
      Height  = 250     '370 full size
      BorderStyle = bsDialog
      Font.Name = "Tahoma"
      Font.COLOR = -2147483640
      Font.Size = 8
      Transparent = 255
      OnShow = FindReplaceForm_Show

      CREATE GroupBoxReplaceOptions AS QGROUPBOX
       Font.Size = 9
       Top     = 72
       Left    = 8
       Width   = 145
       Height  = 96
       CAPTION = "Options"
       COLOR   = &HD8E9EC

       CREATE ReplaceCaseSensitive AS QCHECKBOX
        Top     = 18
        Left    = 8
        Width   = 105
        Height  = 17
        CAPTION = "Case Sensitive"
       END CREATE

       CREATE ReplaceWholeWord AS QCHECKBOX
        Top     = 38
        Left    = 8
        Width   = 105
        Height  = 17
        CAPTION = "Whole Word"
       END CREATE

       CREATE ReplaceWordStart AS QCHECKBOX
        Top     = 55
        Left    = 8
        Width   = 121
        Height  = 17
        CAPTION = "Word Start"
       END CREATE

       CREATE ReplaceRegularExpression AS QCHECKBOX
        Top     = 72
        Left    = 8
        Width   = 121
        Height  = 17
        CAPTION = "Regular Expression"
       END CREATE
      END CREATE


      CREATE GroupBoxReplaceDirection AS QGROUPBOX
       Font.Size = 9
       Top     = 72
       Left    = 161
       Width   = 100
       Height  = 67   '83
       CAPTION = "Direction"
       COLOR   = &HD8E9EC

       CREATE ReplaceForward AS QRADIOBUTTON
        PARENT  = GroupBoxReplaceDirection
        Top     = 18
        Left    = 8
        Width   = 70
        Height  = 17
        CAPTION = "Forward"
        Checked = True
       END CREATE

       CREATE ReplaceBackward AS QRADIOBUTTON
        PARENT  = GroupBoxReplaceDirection
        Top     = 38
        Left    = 8
        Width   = 70
        Height  = 17
        CAPTION = "Backward"
       END CREATE
      END CREATE


      CREATE GroupBoxReplaceScope AS QGROUPBOX
       Font.Size = 9
       Top     = 72  '158
       Left    = 270 '8
       Width   = 120
       Height  = 67
       CAPTION = "Scope"
       COLOR   = &HD8E9EC

       CREATE ReplaceGlobal AS QRADIOBUTTON
        Top     = 18
        Left    = 8
        Width   = 110
        Height  = 17
        CAPTION = "Global"
        Checked = True
       END CREATE
       CREATE ReplaceSelectedText AS QRADIOBUTTON
        Top     = 38
        Left    = 8
        Width   = 100
        Height  = 17
        CAPTION = "Selected Text"
       END CREATE
      END CREATE




      CREATE FindReplaceTrackBar AS QTRACKBAR
       Top = GroupBoxReplaceOptions.Top + GroupBoxReplaceOptions.Height -24
       Left = GroupBoxReplaceOptions.Left + GroupBoxReplaceOptions.Width + 48
       Width = 200 'FindReplaceForm.ClientWidth - GroupBoxReplaceOptions.Left - GroupBoxReplaceOptions.Width - 48
       Height = 22
       TickStyle = tsNone
       Max = 255
       Position = 255
       Min = 50                'follow this order!!
       PageSize = 20
       OnChange = FindReplaceTrackBar_Change
      END CREATE


      CREATE FindTransparencyOnLostFocusBox AS QCHECKBOX
       CAPTION = "set on lost focus"
       Left = FindReplaceTrackBar.Left + FindReplaceTrackBar.Width \2
       Top = FindReplaceTrackBar.Top + FindReplaceTrackBar.Height
       Width = FindReplaceTrackBar.Width \2
       Height = 17
       OnClick = FindReplaceTrackBar_Change
      END CREATE


      CREATE ReplaceLabelFind AS QLABEL
       Font.Size = 9
       Top     = 16
       Left    = 64
       Width   = 20
       Height  = 13
       CAPTION = "Find :"
       COLOR   = &HD8E9EC
       Transparent = True
      END CREATE

      CREATE ComboBoxFind AS QCOMBOBOX
       Top     = 12
       Left    = 106
       Width   = 260
       Height  = 23
       Font.Size = 9
       Text    = ""
       COLOR   = &HFFFFFF
       TabOrder = 1
      END CREATE

      CREATE FindCharButton AS QBUTTON
       Top     = 10
       Left    = 372
       Width   = 27
       Height  = 22
       CAPTION = "chr"
       OnClick = FindReplaceForm_AddChar
      END CREATE


      CREATE ReplaceWithCheckBox AS QCHECKBOX
       Font.Size = 9
       Top     = 44
       Left    = 8
       Width   = 89
       Height  = 17
       CAPTION = "Replace With"
       OnClick = FindReplaceForm_Show
       TabOrder = 3
      END CREATE


      CREATE ComboBoxReplaceWith AS QCOMBOBOX
       Top     = 40
       Left    = 106
       Width   = 260
       Height  = 23
       Text    = ""
       Font.Size = 9
       COLOR   = &HFFFFFF
       Enabled = ReplaceWithCheckBox.Checked
       TabOrder = 2
      END CREATE

      CREATE ReplaceCharButton AS QBUTTON
       Top     = 38
       Left    = 372
       Width   = 27
       Height  = 23
       CAPTION = "chr"
       OnClick = FindReplaceForm_AddChar
      END CREATE


      CREATE ReplaceAllButton AS QBUTTON
       Font.Size = 9
       Top     = 190
       Left    = 38
       Width   = 97
       Height  = 24
       CAPTION = "Replace All"
       OnClick = FindReplaceForm_ReplaceAll
      END CREATE

      CREATE ReplaceCancel AS QBUTTON
       Font.Size = 9
       Top     = 190
       Left    = 168
       Width   = 75
       Height  = 25
       CAPTION = "&Close"
       Cancel = True
       OnClick = FindReplaceForm_Close
      END CREATE

      CREATE ReplaceButton AS QBUTTON
       Font.Size = 9
       Top     = 190
       Left    = 248
       Width   = 75
       Height  = 25
       CAPTION = "&Replace"
       ModalResult = 1
       Default = True
       OnClick = FindReplaceForm_Execute
      END CREATE

      CREATE ReplaceNextButton AS QBUTTON
       Font.Size = 9
       Top     = 190
       Left    = ReplaceButton.Left + ReplaceButton.Width + 8
       Width   = 75
       Height  = 25
       CAPTION = "&Next"
       ModalResult = 1
       OnClick = FindReplaceForm_NextExecute
      END CREATE

      CREATE FindRepShowOptions AS QBUTTON
       Font.Size = 9
       CAPTION = "+"
       Top = 170
       Width = 23
       Height = 20
       Left = 4    'FindReplaceForm.ClientWidth - FindRepShowOptions.Width - 8
       OnClick = FindReplaceForm_ShowOptionsClick
      END CREATE



      CREATE ReplaceScopeGroupBox AS QGROUPBOX
       Visible = False
       Font.Size = 9
       Top     = 230 '280
       Left    = 24
       Width   = 353
       Height  = 105
       CAPTION = "Search Scope"
       COLOR   = &HD8E9EC

       CREATE ProjectSearchRadioButton AS QRADIOBUTTON
        Top     = 24
        Left    = 24
        Width   = 113
        Height  = 17
        Checked = False
        CAPTION = "All open files"
        OnClick = DirSearchRadioButton_Clicked        'for toggle
       END CREATE

       CREATE DirSearchRadioButton AS QRADIOBUTTON
        Top     = 52
        Left    = 24
        Width   = 113
        Height  = 17
        Checked = False
        CAPTION = "Directory"
        OnClick = DirSearchRadioButton_Clicked
       END CREATE
       CREATE DirSearchEdit AS QEDIT
        Top     = 48
        Left    = 120
        Width   = 169
        Height  = 21
        Text    = CURDIR$
        COLOR   = &HFFFFFF
       END CREATE
       CREATE DirSearchGetDirButton AS QBUTTON
        Top     = 48
        Left    = 296
        Width   = 43
        Height  = 25
        Tag     = 99      'for signal to ONE QDirTree component in entire project
        CAPTION = "..."
        OnClick = IDE_Conf_FindPathTarget
       END CREATE

       CREATE FindReplaceFilerLabel AS QLABEL
        Top     = 80
        Left    = 64
        Width   = 31
        Height  = 13
        CAPTION = "File Filter"
        COLOR   = &HD8E9EC
       END CREATE
       CREATE FindReplaceFilerEdit AS QEDIT
        Top     = 80
        Left    = 120
        Width   = 121
        Height  = 21
        Text    = "*.*
          Color   = &HFFFFFF
    End Create
END CREATE

END CREATE      'FindReplaceForm



SUB FindReplaceForm_Close
    FindReplaceForm.Close
    re.SetFocus
END SUB



'search replace widgets
' ReplaceCaseSensitive.Checked
' ReplaceWholeWord.Checked
' ReplaceRegularExpression.Checked
' ReplaceBackward.Checked         'forward/backward
' ReplaceSelectedText.Checked     'global versus selected text
' ReplaceGlobal.Checked      'from cursor versus entire text
' ReplaceWithCheckBox.Checked THEN ComboBoxReplaceWith.Enabled = True
' ReplaceAllButton              'replace all
'     SCFIND_MATCHCASE A match only occurs with text that matches the case of the search string.
'     SCFIND_WHOLEWORD A match only occurs if the characters before and after are not word characters.
'     SCFIND_WORDSTART A match only occurs if the character before is not a word character.
'     SCFIND_REGEXP The search string should be interpreted as a regular expression.
'     SCFIND_POSIX Treat regular expression in a more POSIX compatible manner by interpreting bare ( and ) for tagged sections rather than \( and \).

SUB FindReplaceForm_AddLookupItem
    DEFINT i, FndIt = False

    FOR i = 0 TO ComboBoxFind.ItemCount -1
        IF ComboBoxFind.Text = ComboBoxFind.Item(ComboBoxFind.ItemCount -1) THEN FndIt = True : EXIT FOR
    NEXT i
    IF FndIt = False THEN ComboBoxFind.AddItems ComboBoxFind.Text       'add it, no match

    FndIt = False   'reset for next lookup
    FOR i = 0 TO ComboBoxReplaceWith.ItemCount -1
        IF ComboBoxReplaceWith.Text = ComboBoxReplaceWith.Item(ComboBoxReplaceWith.ItemCount -1) THEN FndIt = True : EXIT FOR
    NEXT i
    IF FndIt = False THEN ComboBoxReplaceWith.AddItems ComboBoxReplaceWith.Text       'add it, no match
END SUB


SUB FindReplaceForm_SetFlags
    DEFINT theFlag = 0
    IF ReplaceCaseSensitive.Checked THEN theFlag = SCFIND_MATCHCASE
    IF ReplaceWholeWord.Checked THEN theFlag = theFlag OR SCFIND_WHOLEWORD
    IF ReplaceWordStart.Checked THEN theFlag = theFlag OR SCFIND_WORDSTART
    IF ReplaceRegularExpression.Checked THEN theFlag = theFlag OR SCFIND_REGEXP
    IDE.SearchFlag = theFlag
END SUB


SUB FindReplaceForm_Setup
    FindReplaceForm_SetFlags
    GroupBoxReplaceScope.Visible = True
    DEFSTR tmp = re.SelText
    IF LEN(tmp) > 50 THEN                   'more than 50 chars then probably user selected a block
        ReplaceSelectedText.Checked = True
        ReplaceSelectedText.Caption = "Selected "Text
        ReplaceGlobal.Checked = False
    ELSE
        ReplaceSelectedText.Checked = False
        ReplaceSelectedText.Caption = "From "Cursor
        ReplaceGlobal.Checked = False
        ReplaceSelectedText.Checked = False
        IF tmp <> "" THEN
            ComboBoxFind.Text = tmp
            FindReplaceForm_AddLookupItem                                   'add lookup items in find/replace boxes
        END IF
    END IF
    tmp = ""            'dealloc
END SUB



SUB FindReplaceForm_Search             'hotkey jump from ""search
    FindReplaceForm_Setup
    ReplaceWithCheckBox.Checked = False
    ProjectSearchRadioButton.Checked = False
    DirSearchRadioButton.Checked = False
    DirSearchEdit.Enabled = DirSearchRadioButton.Checked
    FindReplaceForm_SetOptions(False)   'collapse Find Form
    'ReplaceNextButton.Visible = False
    FindReplaceForm_Show
END SUB


SUB FindReplaceForm_Replace             'hotkey jump from ""replace
    FindReplaceForm_Setup
    ReplaceWithCheckBox.Checked = True
    ProjectSearchRadioButton.Checked = False
    DirSearchRadioButton.Checked = False
    DirSearchEdit.Enabled = DirSearchRadioButton.Checked
    FindReplaceForm_SetOptions(False)   'collapse Find Form
    FindReplaceForm_Show
END SUB


SUB FindReplaceForm_Show
    ComboBoxReplaceWith.Enabled = ReplaceWithCheckBox.Checked           'enable replace with options
    ReplaceAllButton.Visible = ReplaceWithCheckBox.Checked
    IF ReplaceWithCheckBox.Checked THEN
        ReplaceButton.Caption = "&"Replace
            ReplaceNextButton.Visible = True
    ELSE
        ReplaceButton.Caption= "&"Find
        ReplaceNextButton.Visible = False
    END IF
    SetFocus (ComboBoxFind.Handle)
    FindReplaceForm.Show
END SUB



SUB FindReplaceForm_NextExecute         'clicked next button or F3
    'read search flags first
    FindReplaceForm_SetFlags
    'go find it, else -1 was not found
    IF -1 = re.Find(ComboBoxFind.Text, IDE.SearchFlag, 0, ReplaceBackward.Checked)  THEN
        IF MessageDlg("no more instances of " + ComboBoxFind.Text + ", search at beginning?", mtInformation,  mbYes OR mbNo, 0) = mrYes THEN
            re.Find(ComboBoxFind.Text, IDE.SearchFlag, 1, ReplaceBackward.Checked)                  'now search at beginning
        END IF
    END IF
END SUB



SUB FindReplaceForm_PrevExecute         'clicked search prev button or Shift-F3
    'read search flags first
    FindReplaceForm_SetFlags
    'go find it, else -1 was not found
    IF -1 = re.Find(ComboBoxFind.Text, IDE.SearchFlag, 0, 1)  THEN
        IF MessageDlg("no more instances of " + ComboBoxFind.Text + ", search at END?", mtInformation,  mbYes OR mbNo, 0) = mrYes THEN
            re.Find(ComboBoxFind.Text, IDE.SearchFlag, 1, 1)                  'now search at end
        END IF
    END IF
END SUB



SUB FindReplaceForm_SelectedExecute
    FindReplaceForm_Close
    DEFINT TheAnchor = re.AnchorPosition, TheCursor = re.Position, FoundIt, TheMBResult
    IF TheAnchor > TheCursor THEN SWAP(TheAnchor, TheCursor)
    DO
        'This will reset the selected text!!!
        FoundIt = re.Find(ComboBoxFind.Text, IDE.SearchFlag, 2, ReplaceBackward.Checked)            'set selected text param, returns -1 on not found

        IF FoundIt <> -1 THEN

            IF ReplaceWithCheckBox.Checked THEN
                TheMBResult = MESSAGEDLG( "Replace this instance?", mtConfirmation, mbYes OR mbNo OR mbCancel, 0)
                IF TheMBResult = mrCancel THEN EXIT DO
                IF TheMBResult = mrNo THEN
                    re.Set_AnchorPosition(re.Position)                                  'restart at end of found word
                    re.Set_Position(TheCursor)
                END IF
                IF TheMBResult = mrYes THEN
                    re.Set_SelText(ComboBoxReplaceWith.Text)                            'replace selected text
                    re.Set_AnchorPosition(re.Position)                                  'start at end of found word
                    TheCursor = TheCursor + LEN(ComboBoxReplaceWith.Text) - LEN(ComboBoxFind.Text)
                    re.Set_Position(TheCursor)
                END IF

            ELSE            'doing simple find here...
                TheMBResult = MESSAGEDLG( "Find NEXT?", mtConfirmation, mbYes OR mbCancel, 0)
                IF TheMBResult = mrCancel THEN EXIT DO
                re.Set_AnchorPosition(re.Position)                                      ' restart at end of found word
                re.Set_Position(TheCursor)
            END IF

        END IF
    LOOP UNTIL (FoundIt = -1) OR (FoundIt > TheCursor)
    'restore selection if needed
    IF TheMBResult <> 9999 THEN                 'did not stop search to selected point, so restore
        re.Set_AnchorPosition(TheAnchor)
        re.Set_Position(TheCursor)
    END IF
END SUB



SUB FindReplaceForm_Execute(Sender AS QButton)

    IF ComboBoxFind.Text = "" THEN
        EXIT SUB                                                 'can't search for null string
    ELSE                                                          'add it to list if not already added
        FindReplaceForm_AddLookupItem                             'add lookup items in find/replace boxes
    END IF

    IF (ComboBoxReplaceWith.Text <> "") AND ReplaceWithCheckBox.Checked THEN
        FindReplaceForm_AddLookupItem                                   'add lookup items in find/replace boxes
    END IF

    'read search flags first
    FindReplaceForm_SetFlags

    IF DirSearchRadioButton.Checked THEN FindReplaceForm_FindInDirectory: EXIT SUB          'search a directory

    IF ReplaceWithCheckBox.Checked AND ProjectSearchRadioButton.Checked THEN                'serially replace in all files
        FindReplaceForm_ReplaceSeriallyInFiles
        EXIT SUB
    END IF

    IF ProjectSearchRadioButton.Checked THEN
        FindReplaceForm_FindSeriallyInFiles                                                 'look across all files
        EXIT SUB
    END IF

    IF ReplaceSelectedText.Checked AND (ReplaceSelectedText.Caption = "Selected "Text) THEN   'search/rep through selected text
        FindReplaceForm_SelectedExecute
        EXIT SUB
    END IF


    DEFINT FoundIt = -1
    IF ReplaceWithCheckBox.Checked THEN                                                                         'doing a replace
        DEFSTR tmp = re.SelText                                                                                 'already is selected?
        IF ReplaceCaseSensitive.Checked THEN
            IF (tmp = ComboBoxFind.Text) THEN FoundIt = 1
        ELSE
            IF(UCASE$(tmp) = UCASE$(ComboBoxFind.Text)) THEN FoundIt = 1                                        'force to return 1 on true (otherwise is -1)
        END IF
        'if not selected then go find it
        IF FoundIt = -1 THEN
            re.Find(ComboBoxFind.Text, IDE.SearchFlag, ReplaceGlobal.Checked, ReplaceBackward.Checked)
            FoundIt = 0                                                                                         'signal first find
        END IF
        IF FoundIt > 0 THEN                                                                                     'found a match
            re.Set_SelText(ComboBoxReplaceWith.Text)                                                            'replace selected text
            FoundIt = re.Find(ComboBoxFind.Text, IDE.SearchFlag, ReplaceGlobal.Checked, ReplaceBackward.Checked)'now find next occurence, returns -1 if not found
        END IF

    ELSE                                                                                                        'else doing a find
        FoundIt = re.Find(ComboBoxFind.Text, IDE.SearchFlag, ReplaceGlobal.Checked, ReplaceBackward.Checked)    'returns -1 on not found
    END IF

    IF FoundIt = -1 THEN
        IF MessageDlg("no more instances of " + ComboBoxFind.Text + ", search at beginning?", mtInformation,  mbYes OR mbNo, 0) = mrYes THEN
            re.Find(ComboBoxFind.Text, IDE.SearchFlag, 1, ReplaceBackward.Checked)                              'now search at beginning
        END IF
    ELSE
        IF ReplaceGlobal.Checked THEN ReplaceGlobal.Checked = False                                             'reset to "From "cursor
    END IF
END SUB




SUB FindReplaceForm_ReplaceAll
    'ReplaceGlobal.Checked = True
    IF ComboBoxFind.Text <> "" THEN                                       'can't search for null string!
        FindReplaceForm_SetFlags
        IF ProjectSearchRadioButton.Checked THEN
            FindReplaceForm_ReplaceAllInFiles                             'replace in all files instead
            EXIT SUB
        END IF
        FindReplaceForm_AddLookupItem                                       'add lookup items in find/replace boxes

        IF ReplaceSelectedText.Checked AND (ReplaceSelectedText.Caption = "Selected "Text) THEN   'search/rep through selected text
            DEFINT TheAnchor = re.AnchorPosition, TheCursor = re.Position, FoundIt
            IF TheAnchor > TheCursor THEN SWAP(TheAnchor, TheCursor)
            DO
                FoundIt = re.Find(ComboBoxFind.Text, IDE.SearchFlag, 2, ReplaceBackward.Checked)            'set selected text param, returns -1 on not found
                IF FoundIt <> -1 THEN
                    re.Set_SelText(ComboBoxReplaceWith.Text)                            'replace selected text
                    re.Set_AnchorPosition(re.Position)                                  'start at end of found word
                    TheCursor = TheCursor + LEN(ComboBoxReplaceWith.Text) - LEN(ComboBoxFind.Text)
                    re.Set_Position(TheCursor)
                END IF
            LOOP UNTIL (FoundIt = -1) OR (FoundIt > TheCursor)
            'restore selection if needed
            re.Set_AnchorPosition(TheAnchor)
            re.Set_Position(TheCursor)

        ELSE
                MFE_GetCursor
                DEFINT cnt = 0, r = -1                                            'set to not found
                DO
                    r = re.Replace(ComboBoxFind.Text, ComboBoxReplaceWith.Text, IDE.SearchFlag, 0, ReplaceBackward.Checked)
                    IF r > -1 THEN cnt++
                LOOP UNTIL r = -1
                Showmessage STR$(cnt) + " replacements "done
                MFE_SetCursor
        END IF
    END IF
END SUB




SUB FindInFiles
    FindReplaceForm_Setup
    ReplaceWithCheckBox.Checked = False
    FindReplaceForm_SetOptions(True)   'expand Find Form
    ProjectSearchRadioButton.Checked = True
    DirSearchRadioButton.Checked = False
    DirSearchEdit.Enabled = DirSearchRadioButton.Checked
    GroupBoxReplaceScope.Visible = False
    FindReplaceForm_Show
END SUB




SUB ReplaceInFiles
    FindReplaceForm_Setup
    FindReplaceForm_SetOptions(True)   'expand Find Form
    ProjectSearchRadioButton.Checked = True
    DirSearchRadioButton.Checked = False
    DirSearchEdit.Enabled = DirSearchRadioButton.Checked
    GroupBoxReplaceScope.Visible = False
    ReplaceWithCheckBox.Checked = True
    FindReplaceForm_Show
END SUB



SUB FindReplaceForm_FindSeriallyInFiles
    IF ComboBoxFind.Text <> "" THEN                         'can't search for null string!
        FindReplaceForm_AddLookupItem                       'add lookup items in find/replace boxes
        DEFINT CurrTabIndx = MFE_Tab.TabIndex
    	MFE_GetCursor
        DEFINT r = -1                              'set to not found
        DEFINT i, NodeCnt = 0, ParentNodeCnt = 0
        DEFINT FoundInFile = False, cntLines = 0, cntFile = 0, ToggleLastFind
        DEFINT TheLineNum


        FindTreeView.Clear
        re.Visible = False
        re.Enabled = False
        FOR i = 0 TO MFE_List.ItemCount-1                                           'need to use this as count of all opened files
            MFE_ChangeToIndexSilent(i)                                              'switch to tab, make it active
'            re.Set_Position(0)
            ToggleLastFind = False
            DO
                r = re.FindLocation(ComboBoxFind.Text, IDE.SearchFlag, ToggleLastFind, 0)                       'if found r = char position
                IF r <> -1 THEN
                    ToggleLastFind = True
                    IF FoundInFile = False THEN                                                                     'new file with a match
                        FindTreeView.AddItems STR$(i) + FileTabDelimitr + " " + StripFileName(MFE_List.Item(i))     'start node with the file
                        FoundInFile = True                                                                          'toggle end of this file
                        cntFile++
                    END IF
'                    FindTreeView.AddChildItems ParentNodeCnt, STR$(re.CurrentLineNumber+1) + "] " + LEFT$(LTRIM$(re.Line(re.CurrentLineNumber+1) - CRLF) , 50)
                    TheLineNum = re.GetEditor(SCI_LINEFROMPOSITION, r, 0)
                    FindTreeView.AddChildItems ParentNodeCnt, STR$(TheLineNum+1) + "] " + LEFT$(LTRIM$(re.Line(TheLineNum+1) - CRLF) , 50)
                    cntLines++
                    NodeCnt++
                END IF
            LOOP UNTIL r < 0                                                        'reached the end of a file
            IF FoundInFile THEN                                                     'for each file found, add a new parent node
                NodeCnt++                                                           'count of children
                ParentNodeCnt = NodeCnt                                             'keep track of single parent nodes to add children
                FoundInFile = False
            END IF
        NEXT i
        re.Visible = True
        re.Enabled = True
        Showmessage STR$(cntLines) + " matches in " + STR$(cntFile) + " "files
        FindReplaceForm.Close
        TabControl3.TabIndex = 2                                                    'show the find panel
        RightTabChange
        FindTreeView.FullExpand
        MFE_ChangeToIndex(CurrTabIndx)                                              'go to next file
        MFE_SetCursor
        re.SetFocus
    END IF
END SUB






SUB FindReplaceForm_ReplaceSeriallyInFiles
    IF ComboBoxFind.Text <> "" THEN                         'can't search for null string!
        FindReplaceForm_AddLookupItem                       'add lookup items in find/replace boxes
        FindReplaceForm_SetFlags                            'set search flags

        DEFINT CurrTabIndx = MFE_Tab.TabIndex
        MFE_GetCursor
        DEFINT r = -1                                       'set to not found
        DEFINT i, Rtn

        FindReplaceForm.Close
        FOR i = 0 TO MFE_List.ItemCount-1                   'count of all opened files
            MFE_ChangeToIndex(i)                            'switch to tab, make it active
            re.Set_Position(0)                              'set to the top of each file
            DO
                r = re.Find(ComboBoxFind.Text, IDE.SearchFlag, 0, ReplaceBackward.Checked)
                IF r <> -1 THEN
                    Rtn = MessageDlg("Replace WITH " + ComboBoxReplaceWith.Text + " ?", mtInformation,  mbYes OR mbNo OR mbCancel, 0)
                    IF Rtn = mrYes THEN
                        re.Set_SelText(ComboBoxReplaceWith.Text)
                        r = r + LEN(ComboBoxFind.Text) - LEN( ComboBoxReplaceWith.Text)
'                    ELSEIF Rtn = mrNo THEN

                    ELSEIF Rtn = mrCancel THEN
                        r = -2
                    END IF
                END IF
            LOOP UNTIL r < 0
            IF r = -2 THEN EXIT FOR
        NEXT i
        MFE_ChangeToIndex(CurrTabIndx)
        MFE_SetCursor
    END IF
END SUB



SUB FindReplaceForm_ReplaceAllInFiles
    IF ComboBoxFind.Text <> "" THEN                                     'can't search for null string!
        FindReplaceForm_AddLookupItem                                   'add lookup items in find/replace boxes
        DEFINT CurrTabIndx = MFE_Tab.TabIndex
        DEFINT cnt = 0, cntFil = 0, cntdelta = 0, r = -1                'set to not found
        DEFINT i
        MFE_GetCursor
        re.Enabled = False
        FOR i = 0 TO MFE_List.ItemCount-1                               'need to use this as count of all opened files
            DEFINT pDoc = re.GetEditor(SCI_GETDOCPOINTER, 0, 0)
            re.SendEditor(SCI_ADDREFDOCUMENT, 0, pDoc)
            re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(i))          'make it our new window, all operations work on new document
            DO
                r = re.Replace(ComboBoxFind.Text, ComboBoxReplaceWith.Text, IDE.SearchFlag, 0, ReplaceBackward.Checked)
                IF r > -1 THEN cnt++
            LOOP UNTIL r = -1
            IF cnt <> cntdelta THEN cntdelta = cnt: cntFil++
        NEXT i
        re.Enabled = True
        pDoc = re.GetEditor(SCI_GETDOCPOINTER, 0, 0)                    'store current (should be last one)
        re.SendEditor(SCI_ADDREFDOCUMENT, 0, pDoc)
        re.SendEditor(SCI_SETDOCPOINTER, 0, IDE.DocPtr(CurrTabIndx))    'restore our window
        Showmessage STR$(cnt) + " replacements done in " + STR$(cntFil) + " "files
        MFE_SetCursor
    END IF
END SUB




SUB FindReplaceForm_FindInDirectory
    IF ComboBoxFind.Text <> "" THEN                                                 'can't search for null string!
        FindReplaceForm_AddLookupItem
        DEFSTR sFile = Dir$(DirSearchEdit.Text + FindReplaceFilerEdit.Text, 0)       '-- Get first file
        DEFINT i, ParentNodeCnt = 0, cnt = 0, FoundInFile = False
        FindTreeView.Tag = True                                                     'signal already loaded ""dirty

        WHILE sFile <> ""
            tmpList.Clear                                                               'use global stringlist
            tmpList.LoadFromFile(sFile)
            FoundInFile = False                                                         'signal for each file with match

            IF INSTR(UCASE$(tmpList.Text), UCASE$(ComboBoxFind.Text)) THEN                   'found a match
                IF FindTreeView.Tag = True THEN FindTreeView.Clear: FindTreeView.Tag = False 'found now clear only once

                IF FoundInFile = False THEN                                                                     'new file with a match
                    FindTreeView.AddItems ("File: " + sFile)  '+ FileTabDelimitr +           'add file to the list
                    FoundInFile = True                                                                          'toggle end of this file
                END IF


                FOR i = 0 TO tmpList.ItemCount -1                                             'now get the line... ugh..
                    IF INSTR(UCASE$(tmpList.Item(i)), UCASE$(ComboBoxFind.Text)) THEN
                        cnt++
                        FindTreeView.AddChildItems ParentNodeCnt, ("line " + STR$(i) + ": " + tmpList.Item(i))   'add to the list
                    END IF
                NEXT i

                IF FoundInFile THEN                                                     'for each file found, add a new parent node
                    cnt++                                                           'count of children
                    ParentNodeCnt = cnt                                                'keep track of single parent nodes to add children
                    FoundInFile = False
                END IF

            END IF
            sFile = Dir$
        WEND

        FindReplaceForm.Close
        ShowMessage "found " + STR$(cnt) + " "matches
        IF FindTreeView.ItemCount > 0 THEN
            TabControl3.TabIndex = 2
            RightTabChange                  'switch to find panel
            FindTreeView.FullExpand         'expand it
        END IF
    END IF
END SUB



SUB FindReplaceForm_ShowOptionsClick
    IF FindReplaceForm.Height = 370 THEN
        FindReplaceForm_SetOptions(False)   'collapse Find Form
    ELSE
        FindReplaceForm_SetOptions(True)   'expand Find Form
    END IF
END SUB


SUB FindReplaceForm_SetOptions(Flag AS INTEGER)
    IF Flag = True THEN                                'flag means expand
        FindReplaceForm.Height = 370
        FindRepShowOptions.Caption = "-"
        ReplaceScopeGroupBox.Visible = True
    ELSE
        FindReplaceForm.Height = 250
        FindRepShowOptions.Caption = "+"
        ReplaceScopeGroupBox.Visible = False
        ProjectSearchRadioButton.Checked = False
        DirSearchRadioButton.Checked = False
        DirSearchEdit.Enabled = DirSearchRadioButton.Checked
    END IF
END SUB



SUB DirSearchRadioButton_Clicked
    DirSearchEdit.Enabled = DirSearchRadioButton.Checked
    DirSearchEdit.Text = DirTree.Directory

    ReplaceWithCheckBox.Checked = False
    ComboBoxReplaceWith.Enabled = ReplaceWithCheckBox.Checked
    ReplaceAllButton.Visible = False
    ReplaceNextButton.Visible = False
    ReplaceGlobal.Checked = True
    ReplaceButton.Caption = "&"Find
END SUB


SUB FindReplaceForm_AddChar(Sender AS QBUTTON)
    gDialogLabel.Caption = "Enter ASCII code (eg 13 = RETURN)"
    gDialogEdit.Text = ""
    gDialogEdit.Width = 150
    gDialogForm.Width = 270
    gDialogOKButton.Left = 160
    gDialogCancelButton.Left = 200
    gDialogForm.ShowModal

    DEFSTR s
    IF Sender.Handle = FindCharButton.Handle THEN
        s = ComboBoxFind.Text + CHR$( VAL(gDialogEdit.Text) )
        ComboBoxFind.Text = s
    ELSE        'ReplaceCharButton.Handle
        s = ComboBoxReplaceWith.Text + CHR$( VAL(gDialogEdit.Text) )
        ComboBoxReplaceWith.Text = s
    END IF

END SUB





'------------  Find in files results -------------------------
SUB FindTreeChange (Sender AS QTREEVIEW)
    DEFINT Node = Sender.ItemIndex              'Level will be 0 for parent, 1 for child
                                                'Sender.Item(Sender.ItemIndex).Count Count will be > 0 For parent, 0 for child


    IF Sender.Item(Node).Level > 0 THEN                                        '0 if a parent, 1, or more if child node
        DEFINT i, TheLineNum, TheFileIndx, st
        st = INSTR(Sender.Item(Node).Text, "]")                                'find the line # of the file by delimiter
        IF st THEN TheLineNum = VAL(LEFT$(Sender.Item(Node).Text, st-1))       'get the line # of the file

        FOR i = Node-1 TO 0 STEP -1
            st = INSTR(Sender.Item(i).Text, FileTabDelimitr)
            IF st THEN
                MFE_ChangeToIndex(VAL(LEFT$(Sender.Item(i).Text, st-1)))       'switch to tab with file
                re.GotoLine(TheLineNum -1)
                re.ActiveLineColor(RGB(241,237,182), 0)             'brighten line that is wanted
                IDE.HiLightTurnOFF = True                           'toggle to turn off compile error line
                re.SetFocus
                'uncomment these lines to select the line
                're.Set_SelStart(re.AnchorPosition)
                're.Set_SelEnd(re.AnchorPosition + re.GetLineLength(re.CurrentLineNumber))
               EXIT FOR                                                        'get out of loop
            END IF
        NEXT i
    END IF
    re.SetFocus
END SUB



SUB FindTreeOpenItem(Sender AS QTREEVIEW)
    DEFSTR s = Sender.Item(Sender.ItemIndex).Text
    DEFINT i = INSTR(s, ": ")
    IF (i > 0) AND (i < LEN(s) -2) THEN i = i + 2
    s = MID$(s, i, LEN(s) - i + 1)            '    FileTabDelimitr
    IF FILEEXISTS(s) = False THEN s = DirSearchEdit.Text + s
    MFE_Load(s)
END SUB


SUB FindTreeHotTrack (X AS INTEGER, Y AS INTEGER, Shift AS INTEGER, Sender AS QTREEVIEW)
    DEFINT I = Sender.GetItemAt(X,Y)
    IF I >= 0 THEN Sender.ItemIndex = I     'causes a jump to OnChange
END SUB

SUB FindReplaceForm_GetFocus
    IF FindTransparencyOnLostFocusBox.Checked = True THEN FindReplaceForm.Transparent = 255
END SUB

SUB FindReplaceForm_LostFocus
    IF FindTransparencyOnLostFocusBox.Checked = True THEN FindReplaceForm.Transparent = FindReplaceTrackBar.Position
END SUB


SUB FindReplaceTrackBar_Change
    IF FindTransparencyOnLostFocusBox.Checked = False THEN
        FindReplaceForm.Transparent = FindReplaceTrackBar.Position
    ELSE
        FindReplaceForm.Transparent = 255
    END IF
END SUB



'----------------Quick IDE search subs--------------------------
SUB IDESearchForward
    IF Poor.Text <> "" THEN
        re.Find(Poor.Text, 0, 0, 0)
        re.SetFocus
    END IF
END SUB

SUB IDESearchBackward
    IF Poor.Text <> "" THEN
        re.Find(Poor.Text, 0, 0, 1)
        re.SetFocus
    END IF
END SUB


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