1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Abstract:
Useful functions for IDE add ons.
}
unit IDEUtils;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, StdCtrls, LazUTF8, LazFileUtils;
type
TCmpStrType = (
cstCaseSensitive,
cstCaseInsensitive,
cstFilename
);
function IndexInStringList(List: TStrings; Cmp: TCmpStrType; s: string): integer;
procedure SetComboBoxText(AComboBox: TComboBox; const AText: String;
Cmp: TCmpStrType; MaxCount: integer = 1000);
implementation
function IndexInStringList(List: TStrings; Cmp: TCmpStrType; s: string): integer;
var
i: Integer;
begin
for i:=0 to List.Count-1 do begin
case Cmp of
cstCaseSensitive: if List[i]=s then exit(i);
cstCaseInsensitive: if UTF8CompareText(List[i],s)=0 then exit(i);
cstFilename: if CompareFilenames(List[i],s)=0 then exit(i);
end;
end;
Result:=-1;
end;
procedure SetComboBoxText(AComboBox:TComboBox; const AText: String;
Cmp: TCmpStrType; MaxCount: integer);
var
a: integer;
begin
a := IndexInStringList(AComboBox.Items,Cmp,AText);
if a >= 0 then
AComboBox.ItemIndex := a
else
begin
AComboBox.Items.Insert(0,AText);
AComboBox.ItemIndex:=IndexInStringList(AComboBox.Items,Cmp,AText);
if MaxCount<2 then MaxCount:=2;
while AComboBox.Items.Count>MaxCount do
AComboBox.Items.Delete(AComboBox.Items.Count-1);
end;
AComboBox.Text := AText;
end;
end.
|