UPD: ShowInputMultiSelectListBox function

This commit is contained in:
Alexander Koblov 2025-02-09 18:22:15 +03:00
commit 5dcae55b24
3 changed files with 55 additions and 35 deletions

View file

@ -176,7 +176,7 @@ implementation
uses
//Lazarus, Free-Pascal, etc.
IntegerList,
//DC
DCStrUtils, uGlobs, uLng, uSpecialDir, uGlobsPaths, uShowMsg;
@ -709,14 +709,15 @@ end;
{ TfrmOptionsArchivers.miArchiverExportClick }
procedure TfrmOptionsArchivers.miArchiverExportClick(Sender: TObject);
var
slValueList, slOutputIndexSelected: TStringList;
slValueList: TStringList;
slOutputIndexSelected: TIntegerList;
ExportedMultiArcList: TMultiArcList;
iIndex, iExportedIndex: integer;
begin
if MultiArcListTemp.Count > 0 then
begin
slValueList := TStringList.Create;
slOutputIndexSelected := TStringList.Create;
slOutputIndexSelected := TIntegerList.Create;
try
for iIndex := 0 to pred(MultiArcListTemp.Count) do
slValueList.Add(MultiArcListTemp.FList.Strings[iIndex]);
@ -727,7 +728,7 @@ begin
try
for iIndex := 0 to pred(slOutputIndexSelected.Count) do
begin
iExportedIndex := StrToIntDef(slOutputIndexSelected.Strings[iIndex], -1);
iExportedIndex := slOutputIndexSelected[iIndex];
if iExportedIndex <> -1 then
ExportedMultiArcList.Add(MultiArcListTemp.FList.Strings[iExportedIndex], MultiArcListTemp.Items[iExportedIndex].Clone);
end;
@ -758,8 +759,9 @@ end;
{ TfrmOptionsArchivers.miArchiverImportClick }
procedure TfrmOptionsArchivers.miArchiverImportClick(Sender: TObject);
var
slValueList: TStringList;
ImportedMultiArcList: TMultiArcList;
slValueList, slOutputIndexSelected: TStringList;
slOutputIndexSelected: TIntegerList;
iIndex, iImportedIndex, iNbImported: integer;
begin
OpenArchiverDialog.DefaultExt := '*.ini';
@ -773,16 +775,16 @@ begin
if ImportedMultiArcList.Count > 0 then
begin
slValueList := TStringList.Create;
slOutputIndexSelected := TStringList.Create;
slOutputIndexSelected := TIntegerList.Create;
try
for iIndex := 0 to pred(ImportedMultiArcList.Count) do
slValueList.Add(ImportedMultiArcList.FList.Strings[iIndex]);
if ShowInputMultiSelectListBox(rsOptArchiverImportCaption, rsOptArchiverImportPrompt, slValueList, slOutputIndexSelected) then
begin
iNbImported := 0;
for iIndex := 0 to pred(slOutputIndexSelected.Count) do
for iIndex := 0 to Pred(slOutputIndexSelected.Count) do
begin
iImportedIndex := StrToIntDef(slOutputIndexSelected.Strings[iIndex], -1);
iImportedIndex := slOutputIndexSelected[iIndex];
if iImportedIndex <> -1 then
begin
MultiArcListTemp.Add(ImportedMultiArcList.FList.Strings[iImportedIndex], ImportedMultiArcList.Items[iImportedIndex].Clone);

View file

@ -119,7 +119,7 @@ implementation
uses
//Lazarus, Free-Pascal, etc.
StrUtils, LCLProc,
StrUtils, LCLProc, IntegerList,
//DC
DCStrUtils, uShowMsg, uComponentsSignature, fMaskInputDlg, uLng, uGlobs,
@ -544,14 +544,15 @@ end;
{ TfrmOptionsToolTips.miToolTipsFileTypeExportClick }
procedure TfrmOptionsToolTips.miToolTipsFileTypeExportClick(Sender: TObject);
var
slValueList, slOutputIndexSelected: TStringList;
slValueList: TStringList;
slOutputIndexSelected: TIntegerList;
ExportedFileInfoToolTipTemp: TFileInfoToolTip;
iIndex, iExportedIndex: integer;
begin
if FFileInfoToolTipTemp.HintItemList.Count > 0 then
begin
slValueList := TStringList.Create;
slOutputIndexSelected := TStringList.Create;
slOutputIndexSelected := TIntegerList.Create;
try
for iIndex := 0 to pred(FFileInfoToolTipTemp.HintItemList.Count) do
slValueList.Add(FFileInfoToolTipTemp.HintItemList[iIndex].Name);
@ -562,7 +563,7 @@ begin
try
for iIndex := 0 to pred(slOutputIndexSelected.Count) do
begin
iExportedIndex := StrToIntDef(slOutputIndexSelected.Strings[iIndex], -1);
iExportedIndex := slOutputIndexSelected[iIndex];
if iExportedIndex <> -1 then
ExportedFileInfoToolTipTemp.HintItemList.Add(FFileInfoToolTipTemp.HintItemList[iExportedIndex].Clone);
end;
@ -593,9 +594,10 @@ end;
{ TfrmOptionsToolTips.miToolTipsFileTypeImportClick}
procedure TfrmOptionsToolTips.miToolTipsFileTypeImportClick(Sender: TObject);
var
slValueList: TStringList;
slOutputIndexSelected: TIntegerList;
iIndex, iImportedIndex, iNbImported: Integer;
ImportedFileInfoToolTipTemp: TFileInfoToolTip;
slValueList, slOutputIndexSelected: TStringList;
iIndex, iImportedIndex, iNbImported: integer;
begin
OpenTooltipFileTypeDialog.DefaultExt := '*.tooltip';
OpenTooltipFileTypeDialog.FilterIndex := 1;
@ -608,7 +610,7 @@ begin
if ImportedFileInfoToolTipTemp.HintItemList.Count > 0 then
begin
slValueList := TStringList.Create;
slOutputIndexSelected := TStringList.Create;
slOutputIndexSelected := TIntegerList.Create;
try
for iIndex := 0 to pred(ImportedFileInfoToolTipTemp.HintItemList.Count) do
slValueList.Add(ImportedFileInfoToolTipTemp.HintItemList[iIndex].Name);
@ -617,7 +619,7 @@ begin
iNbImported := 0;
for iIndex := 0 to pred(slOutputIndexSelected.Count) do
begin
iImportedIndex := StrToIntDef(slOutputIndexSelected.Strings[iIndex], -1);
iImportedIndex := slOutputIndexSelected[iIndex];
if iImportedIndex <> -1 then
begin
FFileInfoToolTipTemp.HintItemList.Add(ImportedFileInfoToolTipTemp.HintItemList[iImportedIndex].Clone);

View file

@ -40,7 +40,7 @@ unit uShowMsg;
interface
uses
Forms, Classes, DCBasicTypes;
Forms, Classes, IntegerList, DCBasicTypes;
type
TMyMsgResult=(mmrOK, mmrNo, mmrYes, mmrCancel, mmrNone,
@ -131,7 +131,8 @@ function ShowInputQuery(Thread: TThread; const ACaption, APrompt: String; var Va
function ShowInputComboBox(const sCaption, sPrompt : String; slValueList : TStringList; var sValue : String) : Boolean;
function ShowInputListBox(const sCaption, sPrompt : String; slValueList : TStringList; var sValue : String; var SelectedChoice:integer) : Boolean;
function ShowInputMultiSelectListBox(const sCaption, sPrompt : String; slValueList, slOutputIndexSelected : TStringList) : Boolean;
function ShowInputMultiSelectListBox(const sCaption, sPrompt : String; slValueList, slOutputSelected: TStringList) : Boolean; overload;
function ShowInputMultiSelectListBox(const sCaption, sPrompt : String; slValueList: TStringList; slOutputIndexSelected: TIntegerList) : Boolean; overload;
procedure msgLoadLng;
@ -442,7 +443,7 @@ begin
end;
end;
Function MsgTest:TMyMsgResult;
function MsgTest: TMyMsgResult;
begin
Result:= MsgBox('test language of msg subsystem'#10'Second line',[msmbOK, msmbNO, msmbYes, msmbCancel, msmbNone,
msmbAppend, msmbOverwrite, msmbOverwriteAll],msmbOK, msmbNO);
@ -658,7 +659,7 @@ begin
TForm(TComponent(Sender).Owner).ModalResult:=mrOk;
end;
function InnerShowInputListBox(const sCaption, sPrompt: String; bMultiSelect:boolean; slValueList,slOutputIndexSelected:TStringList; var sValue: String; var SelectedChoice:integer) : Boolean;
function InnerShowInputListBox(const sCaption, sPrompt: String; bMultiSelect:boolean; slValueList, slOutputSelected: TStringList; slOutputIndexSelected: TIntegerList; var sValue: String; var SelectedChoice:integer) : Boolean;
var
frmDialog : TForm;
lblPrompt : TLabel;
@ -749,21 +750,27 @@ begin
AnchorToNeighbour(akTop, 18, lbValue);
AnchorToNeighbour(akRight, 6, bbtnCancel);
end;
iModalResult:=ShowModal;
iModalResult:= ShowModal;
Result := (iModalResult = mrOK) AND (lbValue.ItemIndex<>-1);
if (not Result) AND (bMultiSelect) AND (iModalResult = mrAll) then
begin
lbValue.SelectAll;
Result:=True;
end;
if (not Result) AND (bMultiSelect) then
begin
Result:= (iModalResult = mrAll) and (lbValue.Items.Count > 0);
end;
if Result then
begin
sValue:=lbValue.Items.Strings[lbValue.ItemIndex];
SelectedChoice:=lbValue.ItemIndex;
if bMultiSelect then
for iIndex:=0 to pred(lbValue.Items.count) do
if lbValue.Selected[iIndex] then
slOutputIndexSelected.Add(IntToStr(iIndex));
begin
for iIndex:=0 to Pred(lbValue.Items.Count) do
begin
if (iModalResult = mrAll) or lbValue.Selected[iIndex] then
begin
if Assigned(slOutputSelected) then slOutputSelected.Add(lbValue.Items[iIndex]);
if Assigned(slOutputIndexSelected) then slOutputIndexSelected.Add(iIndex);
end;
end;
end;
end;
finally
FreeAndNil(frmDialog);
@ -776,16 +783,25 @@ end;
function ShowInputListBox(const sCaption, sPrompt : String; slValueList : TStringList; var sValue : String; var SelectedChoice:integer) : Boolean;
begin
result := InnerShowInputListBox(sCaption, sPrompt, False, slValueList, nil, sValue, SelectedChoice);
Result := InnerShowInputListBox(sCaption, sPrompt, False, slValueList, nil, nil, sValue, SelectedChoice);
end;
function ShowInputMultiSelectListBox(const sCaption, sPrompt : String; slValueList, slOutputIndexSelected : TStringList) : Boolean;
function ShowInputMultiSelectListBox(const sCaption, sPrompt: String; slValueList, slOutputSelected: TStringList): Boolean;
var
sDummyValue:string;
iDummySelectedChoice:integer;
sDummyValue: String;
iDummySelectedChoice: Integer = 0;
begin
if slValueList.Count>0 then sDummyValue := slValueList.Strings[0];
result := InnerShowInputListBox(sCaption, sPrompt, True, slValueList, slOutputIndexSelected, sDummyValue, iDummySelectedChoice);
if slValueList.Count > 0 then sDummyValue := slValueList.Strings[0];
Result := InnerShowInputListBox(sCaption, sPrompt, True, slValueList, slOutputSelected, nil, sDummyValue, iDummySelectedChoice);
end;
function ShowInputMultiSelectListBox(const sCaption, sPrompt: String; slValueList: TStringList; slOutputIndexSelected: TIntegerList): Boolean;
var
sDummyValue: String;
iDummySelectedChoice: Integer = 0;
begin
if slValueList.Count > 0 then sDummyValue := slValueList.Strings[0];
Result := InnerShowInputListBox(sCaption, sPrompt, True, slValueList, nil, slOutputIndexSelected, sDummyValue, iDummySelectedChoice);
end;
function MsgChoiceBox(const Message: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;