📄 ffind.class
字号:
' Gambas class file' ---- BM - 29 Mar 2004' Remove *.Frozen = TRUE IN btnFind_Click because Project.ActiveForm IS NOT necessarily an editor' Change button captions if "File list" is checked.PRIVATE $sFind AS StringPRIVATE $sReplace AS StringPRIVATE $bShow AS Boolean'<add FindList ron>PRIVATE $bList AS BooleanPRIVATE $iCline AS IntegerPRIVATE $bForm AS Boolean'</add FindList ron>'<upd 20040401 ronPRIVATE bDoFullScan AS Boolean'</upd>PRIVATE $bCaseSensitive AS BooleanPRIVATE $bWordOnly AS Boolean'PRIVATE $bRegular AS Boolean PRIVATE $bIgnoreComment AS BooleanPRIVATE $iSearch AS IntegerPRIVATE $bReplaceAll AS BooleanPRIVATE $iNbrReplace AS IntegerPRIVATE CONST SEARCH_PROC AS Integer = 1PRIVATE CONST SEARCH_FILE AS Integer = 2PRIVATE CONST SEARCH_PROJECT AS Integer = 3PRIVATE $bTextOnly AS BooleanPUBLIC SUB _new() ME.Center'<add 20040408 bDoFullScan = TRUE'</addENDPUBLIC SUB Find(OPTIONAL sSel AS String) cmbFind.Text = sSel cmbReplace.Text = "" cmbFind.SetFocus btnFind.Default = TRUE ME.ShowENDPUBLIC SUB FindNext() IF NOT cmbFind.Text THEN RETURN Form_Activate btnFind_ClickENDPUBLIC SUB FindPrevious() IF NOT cmbFind.Text THEN RETURN Form_Activate btnFindPrevious_ClickENDPRIVATE FUNCTION TestForm(bReplace AS Boolean) AS Boolean DIM sFind AS String DIM sReplace AS String IF Object.Type(Project.ActiveForm) <> "FEditor" THEN IF Object.Type(Project.ActiveForm) <> "FTextEditor" THEN RETURN TRUE ENDIF ENDIF ReadOption sFind = cmbFind.Text IF NOT sFind THEN RETURN TRUE'<add FindList ron> $iCline = Project.ActiveForm.Editor.Line'</add FindList ron> IF bReplace THEN sReplace = cmbReplace.Text 'IF NOT sReplace THEN RETURN TRUE ENDIF IF sFind <> $sFind THEN $sFind = sFind cmbFind.Add(sFind, 0) ENDIF IF bReplace THEN IF sReplace <> $sReplace THEN $sReplace = sReplace cmbReplace.Add(sReplace, 0) ENDIF ENDIFENDPUBLIC SUB btnFind_Click()'<add FindList ron> DIM sKey AS String DIM hForm AS Object DIM hEdit AS GambasEditor IF $bList THEN IF TestForm(FALSE) THEN RETURN btnFind.Default = TRUE IF cvwFindList.Available THEN sKey=cvwFindlist.item.Key cvwFindlist.MoveBelow() IF cvwFindList.Available THEN sKey=cvwFindlist.item.Key ENDIF ENDIF'<upd 20040401 ron hForm = Project.ActiveForm hEdit = hForm.Editor IF hForm.IsModified() THEN '20040408 ' on empty list object not found IF cvwFindList.Moveto(hForm.path)=FALSE THEN cvwFindList.Item.Delete ENDIF ENDIF IF bDoFullScan THEN cvwFindList.Clear IF hForm.IsModified() OR bDoFullScan THEN hEdit.Frozen= TRUE Search(FALSE, FALSE) ' refresh the FindList hEdit.Frozen= FALSE bDoFullScan = FALSE ENDIF'</upd IF cvwFindList.Exist(sKey) THEN cvwFindList.MoveTo(sKey) cvwFindlist.Item.Selected=TRUE cvwFindList.Item.EnsureVisible cvwFindList_Click ENDIF ELSE ' go on with orginal service'</add FindList ron> IF TestForm(FALSE) THEN RETURN btnFind.Default = TRUE IF Search(FALSE, FALSE) THEN Message(("Search string cannot be found.")) ENDIF'<add FindList ron> ENDIF'</add FindList ron>ENDPUBLIC SUB btnFindPrevious_Click() DIM sFind AS String'<add FindList ron> DIM sKey AS String DIM hForm AS Object DIM hEdit AS GambasEditor IF $bList THEN IF TestForm(FALSE) THEN RETURN btnFindPrevious.Default = TRUE IF cvwFindList.Available THEN sKey=cvwFindlist.item.Key cvwFindlist.MoveAbove() IF cvwFindlist.Available THEN sKey=cvwFindlist.item.Key ENDIF ENDIF'<upd 20040401 ron hForm = Project.ActiveForm hEdit = hForm.Editor IF hForm.IsModified() THEN IF cvwFindList.Moveto(hForm.path)=FALSE THEN '20040408 on empty list object not found cvwFindList.Item.Delete ENDIF ENDIF IF bDoFullScan THEN cvwFindList.Clear IF hForm.IsModified() OR bDoFullScan THEN hEdit.Frozen= TRUE Search(FALSE, FALSE) ' refresh the FindList hEdit.Frozen= FALSE bDoFullScan = FALSE ENDIF'</upd IF cvwFindList.Exist(sKey) THEN cvwFindList.MoveTo(sKey) cvwFindlist.Item.Selected=TRUE cvwFindList.Item.EnsureVisible cvwFindList_Click ENDIF ELSE ' go on with orginal service'</add FindList ron> IF TestForm(FALSE) THEN RETURN btnFindPrevious.Default = TRUE IF Search(FALSE, TRUE) THEN Message(("Search string cannot be found.")) ENDIF'<add FindList ron> ENDIF'</add FindList ron>ENDPUBLIC SUB btnReplace_Click()'<add FindList ron> DIM bOld AS Boolean'</add FindList ron> IF TestForm(TRUE) THEN RETURN btnReplace.Default = TRUE'<add FindList ron> bOld=$bList $bList=FALSE'</add FindList ron> IF Search(TRUE, FALSE) THEN Message(("Search string cannot be found.")) ENDIF'<add FindList ron> $bList=bOld'</add FindList ron>ENDPUBLIC SUB btnReplaceAll_Click()'<add FindList ron> DIM bOld AS Boolean'</add FindList ron> IF TestForm(TRUE) THEN RETURN btnReplace.Default = TRUE $bShow = FALSE $bReplaceAll = TRUE INC Application.Busy'<add FindList ron> bOld=$bList $bList=FALSE'</add FindList ron> Search(TRUE, FALSE)'<add FindList ron> $bList=bOld'</add FindList ron> DEC Application.Busy IF $iNbrReplace = 0 THEN Message(("Search string cannot be found.")) ELSE IF $iNbrReplace = 1 THEN Message(("Search string replaced once.")) ELSE Message(Subst(("Search string replaced &1 times."), $iNbrReplace)) ENDIF $bReplaceAll = FALSEENDPRIVATE FUNCTION Search(bReplace AS Boolean, bBack AS Boolean) AS Boolean DIM bResult AS Boolean INC Application.Busy IF bReplace THEN $iNbrReplace = 0 IF bBack THEN bResult = DoSearchBack() ELSE bResult = DoSearch(bReplace) ENDIF DEC Application.Busy RETURN bResultENDPRIVATE FUNCTION DoSearch(bReplace AS Boolean) AS Boolean DIM sFile AS String DIM iColumn AS Integer DIM iLine AS Integer DIM sLine AS String DIM hForm AS Object DIM hEdit AS GambasEditor DIM iPos AS Integer DIM hFormStop AS Object DIM iLineStop AS Integer DIM iColumnStop AS Integer DIM bStop AS Boolean DIM sNext AS String DIM iNbrReplace AS Integer hForm = Project.ActiveForm WITH hForm sFile = .Path hEdit = .Editor WITH hEdit IF bReplace THEN'<change FindCase ron> IF $bCaseSensitive THEN IF .Selection.Text = $sFind THEN .Selection.Text = $sReplace INC $iNbrReplace ENDIF ELSE IF UCase(.Selection.Text) = UCase($sFind) THEN .Selection.Text = $sReplace INC $iNbrReplace ENDIF ENDIF'</change FindCase ron> ENDIF .Pos = .Selection.Start + .Selection.Length iLine = .Line iColumn = .Column END WITH END WITH hFormStop = hForm iLineStop = iLine iColumnStop = iColumn DO sLine = hEdit.Lines[iLine] iPos = SearchString(sLine, iColumn) IF iPos THEN'<add FindList ron> IF $bList THEN AddToList(hForm, iLine, iPos) hEdit.pos = hEdit.ToPos(iLine, iPos - 1 + Len($sFind)) ELSE'</add FindList ron> hEdit.Pos = hEdit.ToPos(iLine, iPos - 1) hEdit.Select(hEdit.Pos, String.Len($sFind)) IF $bShow THEN 'IF ME.Visible THEN ME.SetFocus 'IF hForm <> hFormStop THEN hForm.Show hForm.Show ENDIF IF bReplace THEN IF NOT $bReplaceAll THEN RETURN hEdit.Selection.Text = $sReplace iColumn = iPos + Len($sReplace) - 1 INC $iNbrReplace CONTINUE ELSE RETURN FALSE ENDIF'<add FindList ron> ENDIF'</add FindList ron> ENDIF IF bStop THEN RETURN TRUE iLine = iLine + 1 iColumn = 0 IF $iSearch = SEARCH_PROC THEN IF FEditor.IsEndProc(sLine) OR iLine >= hEdit.Lines.Count THEN WHILE iLine > 0 iLine = iLine - 1 sLine = hEdit.Lines[iLine] IF FEditor.IsProc(sLine) THEN BREAK WEND ELSE sLine = hEdit.Lines[iLine] IF FEditor.IsProc(sLine) THEN iLine = 0 ENDIF ELSE IF iLine >= hEdit.Lines.Count THEN IF $iSearch = SEARCH_PROJECT THEN sNext = Project.GetNextEditor(hForm.Path) Project.LoadFile(sNext) hForm = Project.Files[sNext]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -