Ver código fonte

Cleanup & improve.

Martijn Laan 1 ano atrás
pai
commit
90311954ea
3 arquivos alterados com 24 adições e 12 exclusões
  1. 6 6
      Components/ScintEdit.pas
  2. 6 6
      Projects/Src/CompForm.pas
  3. 12 0
      Projects/Src/CompFunc.pas

+ 6 - 6
Components/ScintEdit.pas

@@ -253,8 +253,8 @@ type
     procedure RestyleLine(const Line: Integer);
     procedure RestyleLine(const Line: Integer);
     procedure ScrollCaretIntoView;
     procedure ScrollCaretIntoView;
     procedure SelectAll;
     procedure SelectAll;
-    procedure SelectAllOccurrences(const MatchCase: Boolean);
-    procedure SelectNextOccurrence(const MatchCase: Boolean);
+    procedure SelectAllOccurrences(const Options: TScintFindOptions);
+    procedure SelectNextOccurrence(const Options: TScintFindOptions);
     function SelEmpty: Boolean;
     function SelEmpty: Boolean;
     function SelNotEmpty(out Sel: TScintRange): Boolean;
     function SelNotEmpty(out Sel: TScintRange): Boolean;
     function SelTextEquals(const S: String; const MatchCase: Boolean): Boolean;
     function SelTextEquals(const S: String; const MatchCase: Boolean): Boolean;
@@ -1225,17 +1225,17 @@ begin
 end;
 end;
 
 
 
 
-procedure TScintEdit.SelectAllOccurrences(const MatchCase: Boolean);
+procedure TScintEdit.SelectAllOccurrences(const Options: TScintFindOptions);
 begin
 begin
   Call(SCI_TARGETWHOLEDOCUMENT, 0, 0);
   Call(SCI_TARGETWHOLEDOCUMENT, 0, 0);
-  Call(SCI_SETSEARCHFLAGS, GetSearchFlags(MatchCase), 0);
+  Call(SCI_SETSEARCHFLAGS, GetSearchFlags(Options), 0);
   Call(SCI_MULTIPLESELECTADDEACH, 0, 0);
   Call(SCI_MULTIPLESELECTADDEACH, 0, 0);
 end;
 end;
 
 
-procedure TScintEdit.SelectNextOccurrence(const MatchCase: Boolean);
+procedure TScintEdit.SelectNextOccurrence(const Options: TScintFindOptions);
 begin
 begin
   Call(SCI_TARGETWHOLEDOCUMENT, 0, 0);
   Call(SCI_TARGETWHOLEDOCUMENT, 0, 0);
-  Call(SCI_SETSEARCHFLAGS, GetSearchFlags(MatchCase), 0);
+  Call(SCI_SETSEARCHFLAGS, GetSearchFlags(Options), 0);
   Call(SCI_MULTIPLESELECTADDNEXT, 0, 0);
   Call(SCI_MULTIPLESELECTADDNEXT, 0, 0);
 end;
 end;
 
 

+ 6 - 6
Projects/Src/CompForm.pas

@@ -2509,20 +2509,20 @@ end;
 
 
 procedure TCompileForm.ESelectAllOccurrencesClick(Sender: TObject);
 procedure TCompileForm.ESelectAllOccurrencesClick(Sender: TObject);
 begin
 begin
-  var MatchCase := False;
+  var Options := GetSelTextOccurrenceFindOptions;
   if FActiveMemo.SelEmpty then begin
   if FActiveMemo.SelEmpty then begin
     var Range := FActiveMemo.WordAtCursorRange;
     var Range := FActiveMemo.WordAtCursorRange;
     if Range.StartPos <> Range.EndPos then begin
     if Range.StartPos <> Range.EndPos then begin
       FActiveMemo.SetSingleSelection(Range.EndPos, Range.StartPos);
       FActiveMemo.SetSingleSelection(Range.EndPos, Range.StartPos);
-      MatchCase := True;
+      Options := GetWordOccurrenceFindOptions;
     end;
     end;
   end;
   end;
-  FActiveMemo.SelectAllOccurrences(MatchCase);
+  FActiveMemo.SelectAllOccurrences(Options);
 end;
 end;
 
 
 procedure TCompileForm.ESelectNextOccurrenceClick(Sender: TObject);
 procedure TCompileForm.ESelectNextOccurrenceClick(Sender: TObject);
 begin
 begin
-  FActiveMemo.SelectNextOccurrence(True);
+  FActiveMemo.SelectNextOccurrence(GetWordOccurrenceFindOptions);
 end;
 end;
 
 
 procedure TCompileForm.ECompleteWordClick(Sender: TObject);
 procedure TCompileForm.ECompleteWordClick(Sender: TObject);
@@ -3331,7 +3331,7 @@ begin
       var Word := AMemo.WordAtCursorRange;
       var Word := AMemo.WordAtCursorRange;
       if (Word.StartPos <> Word.EndPos) and Selection.Within(Word) then begin
       if (Word.StartPos <> Word.EndPos) and Selection.Within(Word) then begin
         var TextToIndicate := AMemo.GetRawTextRange(Word.StartPos, Word.EndPos);
         var TextToIndicate := AMemo.GetRawTextRange(Word.StartPos, Word.EndPos);
-        FindTextAndAddRanges(AMemo, TextToIndicate, [sfoMatchCase, sfoWholeWord], SelNotEmpty, Selection, RangeList);
+        FindTextAndAddRanges(AMemo, TextToIndicate, GetWordOccurrenceFindOptions, SelNotEmpty, Selection, RangeList);
       end;
       end;
     end;
     end;
     AMemo.UpdateIndicators(RangeList, inWordAtCursorOccurrence);
     AMemo.UpdateIndicators(RangeList, inWordAtCursorOccurrence);
@@ -3339,7 +3339,7 @@ begin
     RangeList.Clear;
     RangeList.Clear;
     if FOptions.HighlightSelTextOccurrences and SelNotEmpty and SelSingleLine then begin
     if FOptions.HighlightSelTextOccurrences and SelNotEmpty and SelSingleLine then begin
       var TextToIndicate := AMemo.RawSelText;
       var TextToIndicate := AMemo.RawSelText;
-      FindTextAndAddRanges(AMemo, TextToIndicate, [], SelNotEmpty, Selection, RangeList);
+      FindTextAndAddRanges(AMemo, TextToIndicate, GetSelTextOccurrenceFindOptions, SelNotEmpty, Selection, RangeList);
     end;
     end;
     AMemo.UpdateIndicators(RangeList, inSelTextOccurrence);
     AMemo.UpdateIndicators(RangeList, inSelTextOccurrence);
   finally
   finally

+ 12 - 0
Projects/Src/CompFunc.pas

@@ -69,6 +69,8 @@ function GetSourcePath(const AFilename: String): String;
 function ReadScriptLines(const ALines: TStringList; const ReadFromFile: Boolean;
 function ReadScriptLines(const ALines: TStringList; const ReadFromFile: Boolean;
   const ReadFromFileFilename: String; const NotReadFromFileMemo: TScintEdit): Integer;
   const ReadFromFileFilename: String; const NotReadFromFileMemo: TScintEdit): Integer;
 function CreateBitmapInfo(const Width, Height, BitCount: Integer): TBitmapInfo;
 function CreateBitmapInfo(const Width, Height, BitCount: Integer): TBitmapInfo;
+function GetWordOccurrenceFindOptions: TScintFindOptions;
+function GetSelTextOccurrenceFindOptions: TScintFindOptions;
 
 
 implementation
 implementation
 
 
@@ -709,6 +711,16 @@ begin
   Result.bmiHeader.biCompression := BI_RGB;
   Result.bmiHeader.biCompression := BI_RGB;
 end;
 end;
 
 
+function GetWordOccurrenceFindOptions: TScintFindOptions;
+begin
+  Result := [sfoMatchCase, sfoWholeWord];
+end;
+
+function GetSelTextOccurrenceFindOptions: TScintFindOptions;
+begin
+  Result := [];
+end;
+
 initialization
 initialization
   var OSVersionInfo: TOSVersionInfo;
   var OSVersionInfo: TOSVersionInfo;
   OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
   OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);