mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-04 04:18:22 +01:00
Examples: Added SynEdit search example. Issue #33554
git-svn-id: trunk@58298 -
This commit is contained in:
parent
c9007b6741
commit
19f92d6a42
6
.gitattributes
vendored
6
.gitattributes
vendored
@ -5872,6 +5872,12 @@ examples/SynEdit/NewHighlighterTutorial/foldhl.pas svneol=native#text/pascal
|
||||
examples/SynEdit/NewHighlighterTutorial/simplehl.pas svneol=native#text/pascal
|
||||
examples/SynEdit/NewHighlighterTutorial/unit1.lfm svneol=native#text/pascal
|
||||
examples/SynEdit/NewHighlighterTutorial/unit1.pas svneol=native#text/pascal
|
||||
examples/SynEdit/SearchAndReplace/SynEditSearchExample.lpi svneol=native#text/pascal
|
||||
examples/SynEdit/SearchAndReplace/SynEditSearchExample.lpr svneol=native#text/pascal
|
||||
examples/SynEdit/SearchAndReplace/UfrmMain.lfm svneol=native#text/pascal
|
||||
examples/SynEdit/SearchAndReplace/UfrmMain.pas svneol=native#text/pascal
|
||||
examples/SynEdit/SearchAndReplace/uFrameSearch.lfm svneol=native#text/pascal
|
||||
examples/SynEdit/SearchAndReplace/uFrameSearch.pas svneol=native#text/pascal
|
||||
examples/SynEdit/SynAnyHighlighter/README.txt svneol=native#text/plain
|
||||
examples/SynEdit/SynAnyHighlighter/synanysynhighlighter.lpi svneol=native#text/plain
|
||||
examples/SynEdit/SynAnyHighlighter/synanysynhighlighter.lpr svneol=native#text/plain
|
||||
|
||||
95
examples/SynEdit/SearchAndReplace/SynEditSearchExample.lpi
Normal file
95
examples/SynEdit/SearchAndReplace/SynEditSearchExample.lpi
Normal file
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="SynEditSearchExample"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="1">
|
||||
<Mode0 Name="default"/>
|
||||
</Modes>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="SynEdit"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Unit0>
|
||||
<Filename Value="SynEditSearchExample.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="UfrmMain.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="uFrameSearch.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Frame1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Frame"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="SynEditSearchExample"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<SyntaxMode Value="Delphi"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<IgnoredMessages idx4105="True"/>
|
||||
</CompilerMessages>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
||||
21
examples/SynEdit/SearchAndReplace/SynEditSearchExample.lpr
Normal file
21
examples/SynEdit/SearchAndReplace/SynEditSearchExample.lpr
Normal file
@ -0,0 +1,21 @@
|
||||
program SynEditSearchExample;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, UfrmMain
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource :=True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
||||
667
examples/SynEdit/SearchAndReplace/UfrmMain.lfm
Normal file
667
examples/SynEdit/SearchAndReplace/UfrmMain.lfm
Normal file
@ -0,0 +1,667 @@
|
||||
object Form1: TForm1
|
||||
Left = 349
|
||||
Height = 644
|
||||
Top = 60
|
||||
Width = 820
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 644
|
||||
ClientWidth = 820
|
||||
LCLVersion = '1.9.0.0'
|
||||
object ToolBar1: TToolBar
|
||||
Left = 0
|
||||
Height = 26
|
||||
Top = 0
|
||||
Width = 820
|
||||
Caption = 'ToolBar1'
|
||||
ShowCaptions = True
|
||||
TabOrder = 0
|
||||
object ToolButton1: TToolButton
|
||||
Left = 1
|
||||
Top = 2
|
||||
Action = ActLoad
|
||||
end
|
||||
object ToolButton2: TToolButton
|
||||
Left = 50
|
||||
Top = 2
|
||||
Action = actSaveAs
|
||||
end
|
||||
object ToolButton3: TToolButton
|
||||
Left = 115
|
||||
Top = 2
|
||||
Action = actSearch
|
||||
Caption = '&Search'
|
||||
end
|
||||
object ToolButton4: TToolButton
|
||||
Left = 163
|
||||
Top = 2
|
||||
Action = actExit
|
||||
end
|
||||
object ToolButton5: TToolButton
|
||||
Left = 158
|
||||
Height = 22
|
||||
Top = 2
|
||||
Caption = 'ToolButton5'
|
||||
Style = tbsDivider
|
||||
end
|
||||
object ToolButton6: TToolButton
|
||||
Left = 110
|
||||
Height = 22
|
||||
Top = 2
|
||||
Caption = 'ToolButton6'
|
||||
Style = tbsDivider
|
||||
end
|
||||
end
|
||||
object StatusBar1: TStatusBar
|
||||
Left = 0
|
||||
Height = 23
|
||||
Top = 621
|
||||
Width = 820
|
||||
Panels = <
|
||||
item
|
||||
Width = 50
|
||||
end>
|
||||
SimplePanel = False
|
||||
end
|
||||
inline SynEdit1: TSynEdit
|
||||
Left = 0
|
||||
Height = 465
|
||||
Top = 26
|
||||
Width = 820
|
||||
Align = alClient
|
||||
Font.Height = -13
|
||||
Font.Name = 'Courier New'
|
||||
Font.Pitch = fpFixed
|
||||
Font.Quality = fqNonAntialiased
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
TabOrder = 2
|
||||
Gutter.Width = 57
|
||||
Gutter.MouseActions = <>
|
||||
RightGutter.Width = 0
|
||||
RightGutter.MouseActions = <>
|
||||
Keystrokes = <
|
||||
item
|
||||
Command = ecUp
|
||||
ShortCut = 38
|
||||
end
|
||||
item
|
||||
Command = ecSelUp
|
||||
ShortCut = 8230
|
||||
end
|
||||
item
|
||||
Command = ecScrollUp
|
||||
ShortCut = 16422
|
||||
end
|
||||
item
|
||||
Command = ecDown
|
||||
ShortCut = 40
|
||||
end
|
||||
item
|
||||
Command = ecSelDown
|
||||
ShortCut = 8232
|
||||
end
|
||||
item
|
||||
Command = ecScrollDown
|
||||
ShortCut = 16424
|
||||
end
|
||||
item
|
||||
Command = ecLeft
|
||||
ShortCut = 37
|
||||
end
|
||||
item
|
||||
Command = ecSelLeft
|
||||
ShortCut = 8229
|
||||
end
|
||||
item
|
||||
Command = ecWordLeft
|
||||
ShortCut = 16421
|
||||
end
|
||||
item
|
||||
Command = ecSelWordLeft
|
||||
ShortCut = 24613
|
||||
end
|
||||
item
|
||||
Command = ecRight
|
||||
ShortCut = 39
|
||||
end
|
||||
item
|
||||
Command = ecSelRight
|
||||
ShortCut = 8231
|
||||
end
|
||||
item
|
||||
Command = ecWordRight
|
||||
ShortCut = 16423
|
||||
end
|
||||
item
|
||||
Command = ecSelWordRight
|
||||
ShortCut = 24615
|
||||
end
|
||||
item
|
||||
Command = ecPageDown
|
||||
ShortCut = 34
|
||||
end
|
||||
item
|
||||
Command = ecSelPageDown
|
||||
ShortCut = 8226
|
||||
end
|
||||
item
|
||||
Command = ecPageBottom
|
||||
ShortCut = 16418
|
||||
end
|
||||
item
|
||||
Command = ecSelPageBottom
|
||||
ShortCut = 24610
|
||||
end
|
||||
item
|
||||
Command = ecPageUp
|
||||
ShortCut = 33
|
||||
end
|
||||
item
|
||||
Command = ecSelPageUp
|
||||
ShortCut = 8225
|
||||
end
|
||||
item
|
||||
Command = ecPageTop
|
||||
ShortCut = 16417
|
||||
end
|
||||
item
|
||||
Command = ecSelPageTop
|
||||
ShortCut = 24609
|
||||
end
|
||||
item
|
||||
Command = ecLineStart
|
||||
ShortCut = 36
|
||||
end
|
||||
item
|
||||
Command = ecSelLineStart
|
||||
ShortCut = 8228
|
||||
end
|
||||
item
|
||||
Command = ecEditorTop
|
||||
ShortCut = 16420
|
||||
end
|
||||
item
|
||||
Command = ecSelEditorTop
|
||||
ShortCut = 24612
|
||||
end
|
||||
item
|
||||
Command = ecLineEnd
|
||||
ShortCut = 35
|
||||
end
|
||||
item
|
||||
Command = ecSelLineEnd
|
||||
ShortCut = 8227
|
||||
end
|
||||
item
|
||||
Command = ecEditorBottom
|
||||
ShortCut = 16419
|
||||
end
|
||||
item
|
||||
Command = ecSelEditorBottom
|
||||
ShortCut = 24611
|
||||
end
|
||||
item
|
||||
Command = ecToggleMode
|
||||
ShortCut = 45
|
||||
end
|
||||
item
|
||||
Command = ecCopy
|
||||
ShortCut = 16429
|
||||
end
|
||||
item
|
||||
Command = ecPaste
|
||||
ShortCut = 8237
|
||||
end
|
||||
item
|
||||
Command = ecDeleteChar
|
||||
ShortCut = 46
|
||||
end
|
||||
item
|
||||
Command = ecCut
|
||||
ShortCut = 8238
|
||||
end
|
||||
item
|
||||
Command = ecDeleteLastChar
|
||||
ShortCut = 8
|
||||
end
|
||||
item
|
||||
Command = ecDeleteLastChar
|
||||
ShortCut = 8200
|
||||
end
|
||||
item
|
||||
Command = ecDeleteLastWord
|
||||
ShortCut = 16392
|
||||
end
|
||||
item
|
||||
Command = ecUndo
|
||||
ShortCut = 32776
|
||||
end
|
||||
item
|
||||
Command = ecRedo
|
||||
ShortCut = 40968
|
||||
end
|
||||
item
|
||||
Command = ecLineBreak
|
||||
ShortCut = 13
|
||||
end
|
||||
item
|
||||
Command = ecSelectAll
|
||||
ShortCut = 16449
|
||||
end
|
||||
item
|
||||
Command = ecCopy
|
||||
ShortCut = 16451
|
||||
end
|
||||
item
|
||||
Command = ecBlockIndent
|
||||
ShortCut = 24649
|
||||
end
|
||||
item
|
||||
Command = ecLineBreak
|
||||
ShortCut = 16461
|
||||
end
|
||||
item
|
||||
Command = ecInsertLine
|
||||
ShortCut = 16462
|
||||
end
|
||||
item
|
||||
Command = ecDeleteWord
|
||||
ShortCut = 16468
|
||||
end
|
||||
item
|
||||
Command = ecBlockUnindent
|
||||
ShortCut = 24661
|
||||
end
|
||||
item
|
||||
Command = ecPaste
|
||||
ShortCut = 16470
|
||||
end
|
||||
item
|
||||
Command = ecCut
|
||||
ShortCut = 16472
|
||||
end
|
||||
item
|
||||
Command = ecDeleteLine
|
||||
ShortCut = 16473
|
||||
end
|
||||
item
|
||||
Command = ecDeleteEOL
|
||||
ShortCut = 24665
|
||||
end
|
||||
item
|
||||
Command = ecUndo
|
||||
ShortCut = 16474
|
||||
end
|
||||
item
|
||||
Command = ecRedo
|
||||
ShortCut = 24666
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker0
|
||||
ShortCut = 16432
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker1
|
||||
ShortCut = 16433
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker2
|
||||
ShortCut = 16434
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker3
|
||||
ShortCut = 16435
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker4
|
||||
ShortCut = 16436
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker5
|
||||
ShortCut = 16437
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker6
|
||||
ShortCut = 16438
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker7
|
||||
ShortCut = 16439
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker8
|
||||
ShortCut = 16440
|
||||
end
|
||||
item
|
||||
Command = ecGotoMarker9
|
||||
ShortCut = 16441
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker0
|
||||
ShortCut = 24624
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker1
|
||||
ShortCut = 24625
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker2
|
||||
ShortCut = 24626
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker3
|
||||
ShortCut = 24627
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker4
|
||||
ShortCut = 24628
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker5
|
||||
ShortCut = 24629
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker6
|
||||
ShortCut = 24630
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker7
|
||||
ShortCut = 24631
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker8
|
||||
ShortCut = 24632
|
||||
end
|
||||
item
|
||||
Command = ecSetMarker9
|
||||
ShortCut = 24633
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel1
|
||||
ShortCut = 41009
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel2
|
||||
ShortCut = 41010
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel3
|
||||
ShortCut = 41011
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel4
|
||||
ShortCut = 41012
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel5
|
||||
ShortCut = 41013
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel6
|
||||
ShortCut = 41014
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel7
|
||||
ShortCut = 41015
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel8
|
||||
ShortCut = 41016
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel9
|
||||
ShortCut = 41017
|
||||
end
|
||||
item
|
||||
Command = EcFoldLevel0
|
||||
ShortCut = 41008
|
||||
end
|
||||
item
|
||||
Command = EcFoldCurrent
|
||||
ShortCut = 41005
|
||||
end
|
||||
item
|
||||
Command = EcUnFoldCurrent
|
||||
ShortCut = 41003
|
||||
end
|
||||
item
|
||||
Command = EcToggleMarkupWord
|
||||
ShortCut = 32845
|
||||
end
|
||||
item
|
||||
Command = ecNormalSelect
|
||||
ShortCut = 24654
|
||||
end
|
||||
item
|
||||
Command = ecColumnSelect
|
||||
ShortCut = 24643
|
||||
end
|
||||
item
|
||||
Command = ecLineSelect
|
||||
ShortCut = 24652
|
||||
end
|
||||
item
|
||||
Command = ecTab
|
||||
ShortCut = 9
|
||||
end
|
||||
item
|
||||
Command = ecShiftTab
|
||||
ShortCut = 8201
|
||||
end
|
||||
item
|
||||
Command = ecMatchBracket
|
||||
ShortCut = 24642
|
||||
end
|
||||
item
|
||||
Command = ecColSelUp
|
||||
ShortCut = 40998
|
||||
end
|
||||
item
|
||||
Command = ecColSelDown
|
||||
ShortCut = 41000
|
||||
end
|
||||
item
|
||||
Command = ecColSelLeft
|
||||
ShortCut = 40997
|
||||
end
|
||||
item
|
||||
Command = ecColSelRight
|
||||
ShortCut = 40999
|
||||
end
|
||||
item
|
||||
Command = ecColSelPageDown
|
||||
ShortCut = 40994
|
||||
end
|
||||
item
|
||||
Command = ecColSelPageBottom
|
||||
ShortCut = 57378
|
||||
end
|
||||
item
|
||||
Command = ecColSelPageUp
|
||||
ShortCut = 40993
|
||||
end
|
||||
item
|
||||
Command = ecColSelPageTop
|
||||
ShortCut = 57377
|
||||
end
|
||||
item
|
||||
Command = ecColSelLineStart
|
||||
ShortCut = 40996
|
||||
end
|
||||
item
|
||||
Command = ecColSelLineEnd
|
||||
ShortCut = 40995
|
||||
end
|
||||
item
|
||||
Command = ecColSelEditorTop
|
||||
ShortCut = 57380
|
||||
end
|
||||
item
|
||||
Command = ecColSelEditorBottom
|
||||
ShortCut = 57379
|
||||
end>
|
||||
MouseActions = <>
|
||||
MouseTextActions = <>
|
||||
MouseSelActions = <>
|
||||
Lines.Strings = (
|
||||
'The example calls '
|
||||
' SynEdit.SearchReplace(SearchTerm, OptionalReplaceTerm, Options)'
|
||||
'with the options you selected.'
|
||||
''
|
||||
'Options are'
|
||||
' ssoMatchCase, // find only matches with matching upper/lower-case'
|
||||
' ssoWholeWord, // find only matches wich are whole words (word boundary at start and end of found text)'
|
||||
' ssoBackwards, // search backwards from current caret pos'
|
||||
' ssoEntireScope, // search from top of file (or end of file, if ssoBackwards)'
|
||||
' ssoSelectedOnly, // search only in selection. Search starts at boundary of selection instead of caret'
|
||||
' ssoReplace, // replace the first found match (after prompt) and stop searching'
|
||||
' ssoReplaceAll, // replace all matches (after prompt)'
|
||||
' ssoPrompt, // Show the prompt before replacing. The prompt function must be set to SynEdit.OnReplaceText'
|
||||
' ssoSearchInReplacement, // with ssoReplaceAll: continue search-replace in replacement // replace recursive'
|
||||
' ssoRegExpr, ssoRegExprMultiLine, // use regexpr'
|
||||
' ssoFindContinue // Assume the current selection is the last match, and start search behind selection'
|
||||
''
|
||||
'The result of the function is the amount of matches found.'
|
||||
'For a search this is either 0 or 1. A search will stop at the first match found, so there can never be more matches found.'
|
||||
'For a replace this can be 0 or any positive number. It indicates the number of matches found, even if they where not replaced (skipped in prompt)'
|
||||
''
|
||||
'The function will set the "selection" to the found match (or the last replaced text).'
|
||||
'When working with the results of the selection note that SynEdit specifies the selection in "Logical" coordinates.'
|
||||
'The Caret on the other hand has "Physical" coordinates. But you can use LogicalCaret for "Logical" coordinates.'
|
||||
''
|
||||
'Logical/Physical position'
|
||||
' Physical X/Y: Corresponds to visual (canvas) position,'
|
||||
' Logical X/Y: Corresponds to byte offset of the text.'
|
||||
'Both are 1-based. Currently Y coordinates are always the same. This may change in future.'
|
||||
''
|
||||
'The Physical coordinate'
|
||||
' is the position in the display grid (ignoring any scrolling). That is: '
|
||||
' the letter "a" and "â" take both ONE cell on the grid, increasing physical x by 1. Even though in utf8 encoding "a" takes one byte, and "â" takes several bytes. '
|
||||
' however the tab char (#9), besides being just one byte and one char, can take several cells in the grid, increasing the physical x by more than one. There are also some chars in Chinese and eastern languages, that take 2 grid positions (google full-width vs half-width char) '
|
||||
' The physical X is always counted from the left of the text, even if this is scrolled out.'
|
||||
''
|
||||
'The Logical coordinate'
|
||||
' is the byte offset in the string holding the line. '
|
||||
' the letter "a" has 1 byte and increases by 1 '
|
||||
' the letter "â" has 2 (or 3) bytes, and increases by that '
|
||||
' tab has 1 byte and increases by that. '
|
||||
''
|
||||
'Neither of the 2 give the position in UTF8 chars/code-points (e.g. for Utf8Copy or Utf8Length).'
|
||||
)
|
||||
VisibleSpecialChars = [vscSpace, vscTabAtLast]
|
||||
SelectedColor.BackPriority = 50
|
||||
SelectedColor.ForePriority = 50
|
||||
SelectedColor.FramePriority = 50
|
||||
SelectedColor.BoldPriority = 50
|
||||
SelectedColor.ItalicPriority = 50
|
||||
SelectedColor.UnderlinePriority = 50
|
||||
SelectedColor.StrikeOutPriority = 50
|
||||
BracketHighlightStyle = sbhsBoth
|
||||
BracketMatchColor.Background = clNone
|
||||
BracketMatchColor.Foreground = clNone
|
||||
BracketMatchColor.Style = [fsBold]
|
||||
FoldedCodeColor.Background = clNone
|
||||
FoldedCodeColor.Foreground = clGray
|
||||
FoldedCodeColor.FrameColor = clGray
|
||||
MouseLinkColor.Background = clNone
|
||||
MouseLinkColor.Foreground = clBlue
|
||||
LineHighlightColor.Background = clNone
|
||||
LineHighlightColor.Foreground = clNone
|
||||
OnReplaceText = SynEdit1ReplaceText
|
||||
inline SynLeftGutterPartList1: TSynGutterPartList
|
||||
object SynGutterMarks1: TSynGutterMarks
|
||||
Width = 24
|
||||
MouseActions = <>
|
||||
end
|
||||
object SynGutterLineNumber1: TSynGutterLineNumber
|
||||
Width = 17
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clBtnFace
|
||||
MarkupInfo.Foreground = clNone
|
||||
DigitCount = 2
|
||||
ShowOnlyLineNumbersMultiplesOf = 1
|
||||
ZeroStart = False
|
||||
LeadingZeros = False
|
||||
end
|
||||
object SynGutterChanges1: TSynGutterChanges
|
||||
Width = 4
|
||||
MouseActions = <>
|
||||
ModifiedColor = 59900
|
||||
SavedColor = clGreen
|
||||
end
|
||||
object SynGutterSeparator1: TSynGutterSeparator
|
||||
Width = 2
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clWhite
|
||||
MarkupInfo.Foreground = clGray
|
||||
end
|
||||
object SynGutterCodeFolding1: TSynGutterCodeFolding
|
||||
AutoSize = False
|
||||
MouseActions = <>
|
||||
MarkupInfo.Background = clNone
|
||||
MarkupInfo.Foreground = clGray
|
||||
MouseActionsExpanded = <>
|
||||
MouseActionsCollapsed = <>
|
||||
end
|
||||
end
|
||||
end
|
||||
inline frSearch: TFrame1
|
||||
Left = 6
|
||||
Top = 497
|
||||
Width = 808
|
||||
Align = alBottom
|
||||
ClientWidth = 808
|
||||
TabOrder = 3
|
||||
inherited SpeedButtonSearchFwd: TSpeedButton
|
||||
Flat = True
|
||||
end
|
||||
inherited SpeedButtonSearchBack: TSpeedButton
|
||||
Flat = True
|
||||
end
|
||||
inherited SpeedButtonClose: TSpeedButton
|
||||
AnchorSideRight.Control = frSearch
|
||||
Left = 781
|
||||
end
|
||||
inherited EditInfoCallParams: TEdit
|
||||
Width = 800
|
||||
end
|
||||
inherited LabelInfoCallParams: TLabel
|
||||
Width = 800
|
||||
end
|
||||
end
|
||||
object ActionList1: TActionList
|
||||
left = 304
|
||||
top = 200
|
||||
object ActLoad: TFileOpen
|
||||
Category = 'File'
|
||||
Caption = '&Open ...'
|
||||
Hint = 'Open'
|
||||
ImageIndex = 1
|
||||
ShortCut = 16463
|
||||
OnAccept = ActLoadAccept
|
||||
end
|
||||
object actSaveAs: TFileSaveAs
|
||||
Category = 'File'
|
||||
Caption = 'Save &As ...'
|
||||
Hint = 'Save As'
|
||||
ImageIndex = 5
|
||||
ShortCut = 24659
|
||||
OnAccept = actSaveAsAccept
|
||||
end
|
||||
object actExit: TFileExit
|
||||
Category = 'File'
|
||||
Caption = 'E&xit'
|
||||
Hint = 'Exit'
|
||||
ImageIndex = 3
|
||||
ShortCut = 32856
|
||||
end
|
||||
object actSearch: TAction
|
||||
Category = 'Edit'
|
||||
Caption = 'actSearch'
|
||||
ImageIndex = 6
|
||||
OnExecute = actSearchExecute
|
||||
OnUpdate = actSearchUpdate
|
||||
ShortCut = 16454
|
||||
end
|
||||
end
|
||||
end
|
||||
128
examples/SynEdit/SearchAndReplace/UfrmMain.pas
Normal file
128
examples/SynEdit/SearchAndReplace/UfrmMain.pas
Normal file
@ -0,0 +1,128 @@
|
||||
unit UfrmMain;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, SynEdit, SynHighlighterPas, Forms,
|
||||
Controls, Graphics, Dialogs, ComCtrls, ActnList, StdActns, LCLType,
|
||||
uFrameSearch;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
actSearch :TAction;
|
||||
ActionList1 :TActionList;
|
||||
actExit :TFileExit;
|
||||
ActLoad :TFileOpen;
|
||||
actSaveAs :TFileSaveAs;
|
||||
frSearch: TFrame1;
|
||||
ImageList1 :TImageList;
|
||||
StatusBar1 :TStatusBar;
|
||||
SynEdit1 :TSynEdit;
|
||||
ToolBar1 :TToolBar;
|
||||
ToolButton1 :TToolButton;
|
||||
ToolButton2 :TToolButton;
|
||||
ToolButton3 :TToolButton;
|
||||
ToolButton4 :TToolButton;
|
||||
ToolButton5 :TToolButton;
|
||||
ToolButton6 :TToolButton;
|
||||
procedure ActLoadAccept(Sender :TObject);
|
||||
procedure actSaveAsAccept(Sender :TObject);
|
||||
procedure actSearchExecute(Sender :TObject);
|
||||
procedure actSearchUpdate(Sender :TObject);
|
||||
procedure SpeedButton4Click(Sender :TObject);
|
||||
procedure SynEdit1ReplaceText(Sender: TObject; const ASearch,
|
||||
AReplace: string; Line, Column: integer;
|
||||
var ReplaceAction: TSynReplaceAction);
|
||||
private
|
||||
procedure CloseFrame(Sender:TObject);
|
||||
procedure AfterSearch(Sender:TObject; cnt: Integer);
|
||||
public
|
||||
constructor Create(aOwner :TComponent); override;
|
||||
end;
|
||||
|
||||
var
|
||||
Form1 : TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
const
|
||||
cDefaultFiles = 'Known Files (*.txt,*.pas,*.dpr,*.dpk,*.inc,*.C,*.cpp)|*.txt,*.pas;*.dpr;*.dpk;*.inc;*.C;*.cpp';
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.actSearchExecute(Sender :TObject);
|
||||
begin
|
||||
frSearch.Visible := True;
|
||||
frSearch.EditSearch.SetFocus;
|
||||
end;
|
||||
|
||||
procedure TForm1.actSearchUpdate(Sender :TObject);
|
||||
begin
|
||||
actSearch.Enabled := SynEdit1.Lines.Count > 0;
|
||||
end;
|
||||
|
||||
procedure TForm1.SpeedButton4Click(Sender :TObject);
|
||||
begin
|
||||
frSearch.Visible := False;
|
||||
end;
|
||||
|
||||
procedure TForm1.SynEdit1ReplaceText(Sender: TObject; const ASearch,
|
||||
AReplace: string; Line, Column: integer; var ReplaceAction: TSynReplaceAction
|
||||
);
|
||||
var
|
||||
a: TModalResult;
|
||||
p: TPoint;
|
||||
begin
|
||||
p := SynEdit1.RowColumnToPixels(Point(Column,Line));
|
||||
a:=MessageDlgPos('Replace "'+ASearch+'" with "'+AReplace+'"?',mtconfirmation,
|
||||
[mbYes,mbYesToAll,mbNo,mbCancel],0,Left+50+p.x,Top+100+p.y);
|
||||
|
||||
case a of
|
||||
mrYes:ReplaceAction:=raReplace;
|
||||
mrNo :ReplaceAction:=raSkip;
|
||||
mrAll,mrYesToAll:ReplaceAction:=raReplaceAll;
|
||||
else
|
||||
ReplaceAction:=raCancel;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.CloseFrame(Sender :TObject);
|
||||
begin
|
||||
frSearch.Hide;
|
||||
SynEdit1.SetFocus;
|
||||
end;
|
||||
|
||||
procedure TForm1.AfterSearch(Sender: TObject; cnt: Integer);
|
||||
begin
|
||||
StatusBar1.Panels[0].Text := 'Last search : "'+frSearch.EditSearch.Text+'" matched: '+inttostr(cnt);
|
||||
end;
|
||||
|
||||
procedure TForm1.ActLoadAccept(Sender :TObject);
|
||||
begin
|
||||
SynEdit1.Lines.LoadFromFile(ActLoad.Dialog.FileName);
|
||||
end;
|
||||
|
||||
procedure TForm1.actSaveAsAccept(Sender :TObject);
|
||||
begin
|
||||
SynEdit1.Lines.SaveToFile(actSaveAs.Dialog.FileName);
|
||||
end;
|
||||
|
||||
constructor TForm1.Create(aOwner :TComponent);
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
ActLoad.Dialog.Filter := cDefaultFiles;
|
||||
actSaveAs.Dialog.Filter := cDefaultFiles;
|
||||
frSearch.Editor := SynEdit1;
|
||||
frSearch.OnCloseFrame := @CloseFrame;
|
||||
frSearch.OnAfterSearch := @AfterSearch;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
|
||||
298
examples/SynEdit/SearchAndReplace/uFrameSearch.lfm
Normal file
298
examples/SynEdit/SearchAndReplace/uFrameSearch.lfm
Normal file
@ -0,0 +1,298 @@
|
||||
object Frame1: TFrame1
|
||||
Left = 0
|
||||
Height = 140
|
||||
Top = 0
|
||||
Width = 663
|
||||
BorderSpacing.Around = 6
|
||||
ChildSizing.LeftRightSpacing = 4
|
||||
ChildSizing.TopBottomSpacing = 4
|
||||
ChildSizing.VerticalSpacing = 2
|
||||
ClientHeight = 140
|
||||
ClientWidth = 663
|
||||
TabOrder = 0
|
||||
DesignLeft = 352
|
||||
DesignTop = 779
|
||||
object EditSearch: TEdit
|
||||
Left = 16
|
||||
Height = 23
|
||||
Top = 9
|
||||
Width = 171
|
||||
OnKeyDown = EditKeyDown
|
||||
TabOrder = 0
|
||||
end
|
||||
object cbReplace: TCheckBox
|
||||
AnchorSideLeft.Control = EditSearch
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = EditReplace
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 207
|
||||
Height = 19
|
||||
Top = 11
|
||||
Width = 87
|
||||
Action = actReplace
|
||||
BorderSpacing.Left = 14
|
||||
BorderSpacing.Around = 6
|
||||
OnChange = cbReplaceChange
|
||||
TabOrder = 1
|
||||
end
|
||||
object EditReplace: TEdit
|
||||
AnchorSideLeft.Control = cbReplace
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = EditSearch
|
||||
Left = 300
|
||||
Height = 23
|
||||
Top = 9
|
||||
Width = 224
|
||||
BorderSpacing.Left = 6
|
||||
Enabled = False
|
||||
OnKeyDown = EditKeyDown
|
||||
TabOrder = 2
|
||||
end
|
||||
object SpeedButtonSearchFwd: TSpeedButton
|
||||
Left = 525
|
||||
Height = 24
|
||||
Top = 4
|
||||
Width = 25
|
||||
Action = actFindNext
|
||||
Flat = True
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000000000000000
|
||||
000000000000000000000000000000000000FF000001995F307699602FB4945E
|
||||
2813000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000925B370E985F2FA999602FFA99602FFA995F
|
||||
2FDE9B5F2D330000000000000000000000000000000000000000000000000000
|
||||
000000000000000000009A603030995F2FD999602FFA99602FFA99602FFA9960
|
||||
2FFA99602FF298612F5C00000000000000000000000000000000000000000000
|
||||
00000000000098612F5C99602FF199602FFA99602FFA99602FFA99602FFA9960
|
||||
2FFA99602FFA99602FFA995F2F8EAA5555030000000000000000000000008E55
|
||||
390999612F9999602FFA99602FFA99602FFA99602FFA99602FFA99602FFA9960
|
||||
2FFA99602FFA99602FFA99602FFA99602FB4965A2D110000000098603025995F
|
||||
2FCE99602FFA99602FFA99602FFA99602FFA99602FFA99602FFA99602FFA9960
|
||||
2FFA99602FFA99602FFA99602FFA99602FFA98602FD89A5F2F2B99602FE69960
|
||||
2FFA99602FFA99602FFA99602FFA99602FF999602FF899602FFA99602FFA9960
|
||||
2FFA99602FF899602FFA99602FFA99602FFA99602FFA99602FEE995F2FF39960
|
||||
2FFA99602FFA99602FFA995F2FEB98602F529A602FE599602FFA99602FFA9960
|
||||
2FFA9B613154995F2FD999602FFA99602FFA99602FFA99602FFA99602FF59960
|
||||
2FFA99602FFA98602FC79B642E210000000099602FE499602FFA99602FFA9960
|
||||
2FFA995F2C23925B370E985F2FA999602FFA99602FFA99602FFA99602EF79960
|
||||
2FF9995F2F8EAA552B06000000000000000099612FE399602FFA99602FFA9960
|
||||
2FFA995F2C2300000000FF00000198602F6D99602FF599602FFA995F2FEB9A5F
|
||||
2E530000000000000000000000000000000099602FE299602FFA99602FFA9960
|
||||
2FFA995F2C2300000000000000000000000096602E3D99602EE19C63311F0000
|
||||
000000000000000000000000000000000000995F2EE199602FFA99602FFA9960
|
||||
2FFA995F2C2300000000000000000000000000000000995C3319000000000000
|
||||
00000000000000000000000000000000000099602FE099602FFA99602FFA9960
|
||||
2FFA995F2C230000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000099602FDF99602FFA99602FFA9960
|
||||
2FFA995F2C230000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000995F2FDE99602FFA99602FFA9960
|
||||
2FFA995F2C230000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000099602EDC99602FFA99602FFA9960
|
||||
2FFA995F2C230000000000000000000000000000000000000000
|
||||
}
|
||||
ShowCaption = False
|
||||
end
|
||||
object SpeedButtonSearchBack: TSpeedButton
|
||||
Left = 551
|
||||
Height = 24
|
||||
Top = 4
|
||||
Width = 25
|
||||
Action = actFindPrevious
|
||||
Flat = True
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000000000000000
|
||||
0000000000000000000000000000995F2C2399602FFA99602FFA99602FFA9960
|
||||
2EDC000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000995F2C2399602FFA99602FFA99602FFA9860
|
||||
2FDD000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000995F2C2399602FFA99602FFA99602FFA995F
|
||||
2FDE000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000995F2C2399602FFA99602FFA99602FFA9960
|
||||
2FDF000000000000000000000000000000000000000000000000995C33190000
|
||||
0000000000000000000000000000995F2C2399602FFA99602FFA99602FFA995F
|
||||
2EE100000000000000000000000000000000000000009C63311F9A602FE59A5E
|
||||
2D44000000000000000000000000995F2C2399602FFA99602FFA99602FFA9960
|
||||
2EE100000000000000000000000000000000995F304B99602FE699602FFA9960
|
||||
2EF799602F7D8080000200000000995F2C2399602FFA99602FFA99602FFA9960
|
||||
2FE200000000000000008040400499602F7D99602FF899602FF699602FFA9960
|
||||
2FFA99602FFA9A602EB09C632B12995F2C2399602FFA99602FFA99602FFA9961
|
||||
2FE3000000009B642E1C996030C199602FFA99602FFA99602FF499602FFA9960
|
||||
2FFA99602FFA99602FFA98602FDD9B612E5999602FFA99602FFA99602FFA9960
|
||||
2FE4995F304B99602FE899602FFA99602FFA99602FFA99602FF299602FEE9960
|
||||
2FFA99602FFA99602FFA99602FFA99602FF899602FFA99602FFA99602FFA9960
|
||||
2FF899602FF999602FFA99602FFA99602FFA99602FFA99602FE69A5E2F26985F
|
||||
2FD399602FFA99602FFA99602FFA99602FFA99602FFA99602FFA99602FFA9960
|
||||
2FFA99602FFA99602FFA99602FFA99602FFA985F2FD39861312A00000000925B
|
||||
370E99602FAF99602FFA99602FFA99602FFA99602FFA99602FFA99602FFA9960
|
||||
2FFA99602FFA99602FFA99602FFA985F30A18B5D2E0B00000000000000000000
|
||||
0000AA5555039960308599602FF999602FFA99602FFA99602FFA99602FFA9960
|
||||
2FFA99602FFA995F2FF398602F6D000000000000000000000000000000000000
|
||||
00000000000000000000996030559A602FEF99602FFA99602FFA99602FFA9960
|
||||
2FFA98602FDD975E2F3600000000000000000000000000000000000000000000
|
||||
000000000000000000000000000099602D2D99602FDA99602FFA99602FFA9A60
|
||||
2EB09C632B120000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000945E28139A5F2FB399602F7D8080
|
||||
0002000000000000000000000000000000000000000000000000
|
||||
}
|
||||
ShowCaption = False
|
||||
end
|
||||
object SpeedButtonClose: TSpeedButton
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 636
|
||||
Height = 22
|
||||
Top = 7
|
||||
Width = 23
|
||||
Anchors = [akTop, akRight]
|
||||
Flat = True
|
||||
Glyph.Data = {
|
||||
46020000424D460200000000000036000000280000000C0000000B0000000100
|
||||
2000000000001002000064000000640000000000000000000000FFFFFF00FFFF
|
||||
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
|
||||
FF00FFFFFF00FFFFFF00FFFFFF00000000610000006600000066000000660000
|
||||
0061FFFFFF000000006100000066000000660000006600000061FFFFFF000000
|
||||
0066FFFFFFB3FFFFFFB3FFFFFFB30000004C000000660000004CFFFFFFB3FFFF
|
||||
FFB3FFFFFFB300000066FFFFFF000000006100000066FFFFFFB3FFFFFFB3FFFF
|
||||
FFB30000004CFFFFFFB3FFFFFFB3FFFFFFB30000006600000061FFFFFF00FFFF
|
||||
FF000000006100000066FFFFFFB3FFFFFFB3FFFFFFB3FFFFFFB3FFFFFFB30000
|
||||
006600000061FFFFFF00FFFFFF00FFFFFF00FFFFFF00000000660000004CFFFF
|
||||
FFB3FFFFFFB3FFFFFFB30000004C00000066FFFFFF00FFFFFF00FFFFFF00FFFF
|
||||
FF00000000610000004CFFFFFFB3FFFFFFB3FFFFFFB3FFFFFFB3FFFFFFB30000
|
||||
004C00000061FFFFFF00FFFFFF00000000610000004CFFFFFFB3FFFFFFB3FFFF
|
||||
FFB300000066FFFFFFB3FFFFFFB3FFFFFFB30000004C00000061FFFFFF000000
|
||||
0066FFFFFFB3FFFFFFB3FFFFFFB3000000660000006600000066FFFFFFB3FFFF
|
||||
FFB3FFFFFFB300000066FFFFFF00000000610000006600000066000000660000
|
||||
0061FFFFFF000000006100000066000000660000006600000061FFFFFF00FFFF
|
||||
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
|
||||
FF00FFFFFF00FFFFFF00
|
||||
}
|
||||
OnClick = SpeedButtonCloseClick
|
||||
end
|
||||
object cbWholeWords: TCheckBox
|
||||
Left = 16
|
||||
Height = 19
|
||||
Top = 40
|
||||
Width = 91
|
||||
Action = actWholeWords
|
||||
TabOrder = 3
|
||||
end
|
||||
object CheckBox2: TCheckBox
|
||||
Left = 300
|
||||
Height = 19
|
||||
Top = 40
|
||||
Width = 123
|
||||
Action = actPromptOnReplace
|
||||
TabOrder = 4
|
||||
end
|
||||
object CheckBox3: TCheckBox
|
||||
Left = 120
|
||||
Height = 19
|
||||
Top = 40
|
||||
Width = 94
|
||||
Action = actCaseSensitive
|
||||
TabOrder = 5
|
||||
end
|
||||
object CheckBox4: TCheckBox
|
||||
Left = 440
|
||||
Height = 19
|
||||
Top = 40
|
||||
Width = 78
|
||||
Action = actReplaceAll
|
||||
TabOrder = 6
|
||||
end
|
||||
object EditInfoCallParams: TEdit
|
||||
Left = 4
|
||||
Height = 23
|
||||
Top = 113
|
||||
Width = 655
|
||||
Align = alBottom
|
||||
TabOrder = 7
|
||||
end
|
||||
object LabelInfoCallParams: TLabel
|
||||
Left = 4
|
||||
Height = 15
|
||||
Top = 96
|
||||
Width = 655
|
||||
Align = alBottom
|
||||
Caption = 'Search will call:'
|
||||
ParentColor = False
|
||||
end
|
||||
object cbWholeScope: TCheckBox
|
||||
Left = 16
|
||||
Height = 19
|
||||
Top = 64
|
||||
Width = 89
|
||||
Action = actWholeScope
|
||||
OnChange = cbWholeScopeChange
|
||||
TabOrder = 8
|
||||
end
|
||||
object cbSelectionOnly: TCheckBox
|
||||
Left = 120
|
||||
Height = 19
|
||||
Top = 64
|
||||
Width = 96
|
||||
Action = actSelectOnly
|
||||
OnChange = cbSelectionOnlyChange
|
||||
TabOrder = 9
|
||||
end
|
||||
object ActionList1: TActionList
|
||||
OnUpdate = ActionList1Update
|
||||
left = 584
|
||||
top = 64
|
||||
object actFindNext: TAction
|
||||
Caption = 'Find &Next'
|
||||
OnExecute = actFindNextExecute
|
||||
OnUpdate = ActUpdateFindButtons
|
||||
ShortCut = 114
|
||||
end
|
||||
object actFindPrevious: TAction
|
||||
Caption = 'Find &Previous'
|
||||
OnExecute = actFindPreviousExecute
|
||||
OnUpdate = ActUpdateFindButtons
|
||||
ShortCut = 8306
|
||||
end
|
||||
object actWholeWords: TAction
|
||||
AutoCheck = True
|
||||
Caption = 'Whole &Words'
|
||||
OnUpdate = ActionUpdateOptions
|
||||
ShortCut = 32855
|
||||
end
|
||||
object actCaseSensitive: TAction
|
||||
AutoCheck = True
|
||||
Caption = '&Case Sensitive'
|
||||
OnUpdate = ActionUpdateOptions
|
||||
ShortCut = 32835
|
||||
end
|
||||
object actPromptOnReplace: TAction
|
||||
AutoCheck = True
|
||||
Caption = 'Prompt &On Replace'
|
||||
OnUpdate = ActionUpdateReplaceOptions
|
||||
ShortCut = 32847
|
||||
end
|
||||
object actReplaceAll: TAction
|
||||
AutoCheck = True
|
||||
Caption = 'Replace &All'
|
||||
OnUpdate = ActionUpdateReplaceOptions
|
||||
ShortCut = 32833
|
||||
end
|
||||
object actReplace: TAction
|
||||
AutoCheck = True
|
||||
Caption = '&Replace with'
|
||||
OnUpdate = ActionUpdateOptions
|
||||
ShortCut = 32850
|
||||
end
|
||||
object actWholeScope: TAction
|
||||
AutoCheck = True
|
||||
Caption = '&Whole Scope'
|
||||
OnUpdate = ActionUpdateOptions
|
||||
ShortCut = 32855
|
||||
end
|
||||
object actSelectOnly: TAction
|
||||
AutoCheck = True
|
||||
Caption = '&Selection Only'
|
||||
OnUpdate = ActionUpdateOptions
|
||||
end
|
||||
end
|
||||
end
|
||||
213
examples/SynEdit/SearchAndReplace/uFrameSearch.pas
Normal file
213
examples/SynEdit/SearchAndReplace/uFrameSearch.pas
Normal file
@ -0,0 +1,213 @@
|
||||
unit uFrameSearch;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, SynEdit, SynEditSearch, SynEditTypes, Forms, Controls, StdCtrls,
|
||||
Buttons, Menus, ActnList, ExtCtrls, LCLType;
|
||||
|
||||
type
|
||||
|
||||
TOnAfterSearch = procedure (Sender:TObject; cnt: Integer) of object;
|
||||
|
||||
{ TFrame1 }
|
||||
|
||||
TFrame1 = class(TFrame)
|
||||
actFindNext :TAction;
|
||||
actFindPrevious :TAction;
|
||||
actCaseSensitive :TAction;
|
||||
actSelectOnly: TAction;
|
||||
actWholeScope: TAction;
|
||||
actReplace :TAction;
|
||||
actReplaceAll :TAction;
|
||||
actPromptOnReplace :TAction;
|
||||
actWholeWords :TAction;
|
||||
ActionList1 :TActionList;
|
||||
cbReplace :TCheckBox;
|
||||
cbWholeWords :TCheckBox;
|
||||
cbWholeScope: TCheckBox;
|
||||
cbSelectionOnly: TCheckBox;
|
||||
CheckBox2 :TCheckBox;
|
||||
CheckBox3 :TCheckBox;
|
||||
CheckBox4 :TCheckBox;
|
||||
EditInfoCallParams: TEdit;
|
||||
EditSearch :TEdit;
|
||||
EditReplace :TEdit;
|
||||
LabelInfoCallParams: TLabel;
|
||||
mniReplaceAll :TMenuItem;
|
||||
mniWholeWords :TMenuItem;
|
||||
mniCaseSensitive :TMenuItem;
|
||||
mniPromptOnReplace :TMenuItem;
|
||||
SpeedButtonSearchFwd :TSpeedButton;
|
||||
SpeedButtonSearchBack :TSpeedButton;
|
||||
SpeedButtonClose :TSpeedButton;
|
||||
procedure actFindNextExecute(Sender :TObject);
|
||||
procedure actFindPreviousExecute(Sender :TObject);
|
||||
procedure ActionList1Update(AAction: TBasicAction; var Handled: Boolean);
|
||||
procedure ActionUpdateOptions(Sender:TObject);
|
||||
procedure ActionUpdateReplaceOptions(Sender :TObject);
|
||||
procedure ActUpdateFindButtons(Sender :TObject);
|
||||
procedure cbReplaceChange(Sender :TObject);
|
||||
procedure cbWholeScopeChange(Sender: TObject);
|
||||
procedure cbSelectionOnlyChange(Sender: TObject);
|
||||
procedure EditKeyDown(Sender :TObject; var Key :Word; Shift :TShiftState);
|
||||
procedure SpeedButtonCloseClick(Sender :TObject);
|
||||
private
|
||||
FBackwards :Boolean;
|
||||
FOnCloseFrame :TNotifyEvent;
|
||||
FOnAfterSearch :TOnAfterSearch;
|
||||
FSynedit :TSynEdit;
|
||||
FInCheckBoxChange :Boolean;
|
||||
function GetOptions:TSynSearchOptions;
|
||||
procedure DoSearch;
|
||||
protected
|
||||
procedure DoCloseFrame;
|
||||
public
|
||||
constructor Create(aOwner :TComponent); override;
|
||||
property Editor :TSynEdit read FSynedit write FSynedit;
|
||||
property OnAfterSearch :TOnAfterSearch read FOnAfterSearch write FOnAfterSearch;
|
||||
property OnCloseFrame :TNotifyEvent read FOnCloseFrame write FOnCloseFrame;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
procedure TFrame1.SpeedButtonCloseClick(Sender :TObject);
|
||||
begin
|
||||
DoCloseFrame;
|
||||
end;
|
||||
|
||||
procedure TFrame1.ActUpdateFindButtons(Sender :TObject);
|
||||
begin
|
||||
if Sender is TAction then TAction(Sender).Enabled := (EditSearch.Text <> '') and Assigned(FSynedit);
|
||||
end;
|
||||
|
||||
procedure TFrame1.ActionUpdateOptions(Sender :TObject);
|
||||
begin
|
||||
if Sender is TAction then TAction(Sender).Enabled := Assigned(FSynedit);
|
||||
end;
|
||||
|
||||
procedure TFrame1.ActionUpdateReplaceOptions(Sender :TObject);
|
||||
begin
|
||||
if Sender is TAction then TAction(Sender).Enabled := Assigned(FSynedit) and cbReplace.Checked;
|
||||
end;
|
||||
|
||||
function TFrame1.GetOptions :TSynSearchOptions;
|
||||
begin
|
||||
Result := [ssoFindContinue];
|
||||
if actWholeScope.Checked then Result := [ssoEntireScope];
|
||||
if actSelectOnly.Checked then Result := [ssoSelectedOnly];
|
||||
|
||||
if actCaseSensitive.Checked then Result := Result+[ssoMatchCase];
|
||||
if actWholeWords.Checked then Result := Result+[ssoWholeWord];
|
||||
if FBackwards then Result := Result+[ssoBackwards];
|
||||
if cbReplace.Checked then begin
|
||||
Result := Result+[ssoReplace];
|
||||
if actReplaceAll.Checked then Result := Result+[ssoReplaceAll];
|
||||
if actPromptOnReplace.Checked then Result := Result+[ssoPrompt];
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFrame1.DoSearch;
|
||||
var
|
||||
cnt: Integer;
|
||||
begin
|
||||
if cbReplace.Checked then
|
||||
cnt := FSynedit.SearchReplace(EditSearch.Text, EditReplace.Text, GetOptions)
|
||||
else
|
||||
cnt := FSynedit.SearchReplace(EditSearch.Text, '', GetOptions);
|
||||
|
||||
actWholeScope.Checked := False;
|
||||
actSelectOnly.Checked := False;
|
||||
|
||||
if Assigned(FOnAfterSearch) then FOnAfterSearch(FSynedit, cnt);
|
||||
end;
|
||||
|
||||
procedure TFrame1.DoCloseFrame;
|
||||
begin
|
||||
if Assigned(FOnCloseFrame) then FOnCloseFrame(Self);
|
||||
end;
|
||||
|
||||
constructor TFrame1.Create(aOwner :TComponent);
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
FBackwards := False;
|
||||
FSynedit := Nil;
|
||||
end;
|
||||
|
||||
procedure TFrame1.cbReplaceChange(Sender :TObject);
|
||||
begin
|
||||
EditReplace.Enabled := cbReplace.Checked;
|
||||
end;
|
||||
|
||||
procedure TFrame1.cbWholeScopeChange(Sender: TObject);
|
||||
begin
|
||||
if FInCheckBoxChange then exit;
|
||||
FInCheckBoxChange := True;
|
||||
if not actWholeScope.Checked then
|
||||
actSelectOnly.Checked := False;
|
||||
FInCheckBoxChange := False;
|
||||
end;
|
||||
|
||||
procedure TFrame1.cbSelectionOnlyChange(Sender: TObject);
|
||||
begin
|
||||
if FInCheckBoxChange then exit;
|
||||
FInCheckBoxChange := True;
|
||||
if not actSelectOnly.Checked then
|
||||
actWholeScope.Checked := False;
|
||||
FInCheckBoxChange := False;
|
||||
end;
|
||||
|
||||
procedure TFrame1.EditKeyDown(Sender :TObject; var Key :Word; Shift :TShiftState);
|
||||
begin
|
||||
if Key = VK_RETURN then begin
|
||||
Key := 0;
|
||||
if ssShift in Shift then
|
||||
actFindPreviousExecute(actFindPrevious)
|
||||
else
|
||||
actFindNextExecute(actFindNext);
|
||||
end;
|
||||
|
||||
if Key = VK_ESCAPE then begin
|
||||
Key := 0;
|
||||
DoCloseFrame;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFrame1.actFindNextExecute(Sender :TObject);
|
||||
begin
|
||||
FBackwards := False;
|
||||
DoSearch;
|
||||
end;
|
||||
|
||||
procedure TFrame1.actFindPreviousExecute(Sender :TObject);
|
||||
begin
|
||||
FBackwards := True;
|
||||
DoSearch;
|
||||
end;
|
||||
|
||||
procedure TFrame1.ActionList1Update(AAction: TBasicAction; var Handled: Boolean
|
||||
);
|
||||
var
|
||||
opts: TSynSearchOptions;
|
||||
i: TSynSearchOption;
|
||||
s, tmp: String;
|
||||
begin
|
||||
opts := GetOptions;
|
||||
for i := low(opts) to high(opts) do
|
||||
if i in opts then begin
|
||||
WriteStr(tmp, i);
|
||||
if s <> '' then s := s + ', ';
|
||||
s := s + tmp;
|
||||
end;
|
||||
if cbReplace.Checked then
|
||||
EditInfoCallParams.Text := 'Synedit.SearchReplace('''+EditSearch.Text+''', '''+EditReplace.Text+''', ['+s+'])'
|
||||
else
|
||||
EditInfoCallParams.Text := 'Synedit.SearchReplace('''+EditSearch.Text+''', '''', ['+s+'])';
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user