Skip to content

Commit 28182e5

Browse files
committed
refact update layout
1 parent 228abbf commit 28182e5

7 files changed

+127
-106
lines changed

src/Common/RipGrepper.Common.SimpleTypes.pas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ TErrorCounters = record
5858

5959
TNullableString = Nullable<string>;
6060

61+
EMemoTextFormat = (mtfOneLine, mtfSeparateLines);
62+
ESearchFormLayout = (sflReplace, sflExtension, sflExpert);
63+
64+
TSearchFormLayout = set of ESearchFormLayout;
65+
6166
const
6267
GUI_SEARCH_PARAMS : TArray<EGuiOption> = [
6368
{ } EGuiOption.soMatchCase,

src/UI/RipGrepper.UI.CustomCheckOptions.pas

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface
1414
Winapi.Windows,
1515
Winapi.Messages,
1616
RipGrepper.Settings.RipGrepperSettings,
17-
RipGrepper.Settings.SettingVariant;
17+
RipGrepper.Settings.SettingVariant,
18+
RipGrepper.Common.SimpleTypes;
1819

1920
type
2021

@@ -222,6 +223,7 @@ TCustomOptionsBase = class(TCustomPanel)
222223
procedure setColumns(const _value : Integer);
223224

224225
protected
226+
FSearchFormLayout : TSearchFormLayout;
225227
procedure Resize; override;
226228

227229
public
@@ -271,8 +273,8 @@ TCustomCheckOptions = class(TCustomOptionsBase)
271273
procedure CalculateActualWidths(const _itemWidth, _firstControlWidth : Integer;
272274
out _actualFirstWidth, _actualSecondWidth : Integer);
273275
procedure PositionItemPanel(const _item : TCustomCheckItem; const _itemIndex, _itemWidth, _itemHeight : Integer);
274-
procedure PositionItemControls(const _item : TCustomCheckItem; const
275-
_itemIndex, _actualFirstWidth, _actualSecondWidth : Integer);
276+
procedure PositionItemControls(const _item : TCustomCheckItem;
277+
const _itemIndex, _actualFirstWidth, _actualSecondWidth : Integer);
276278
// Helper methods for positioning different control types
277279
procedure PositionCheckBoxOnly(const _item : TCustomCheckItem; const _itemIndex, _actualFirstWidth, _itemHeight : Integer);
278280
procedure PositionCheckBoxWithCombo(const _item : TCustomCheckItem; const _itemIndex, _actualFirstWidth, _actualSecondWidth,
@@ -306,7 +308,7 @@ TCustomCheckOptions = class(TCustomOptionsBase)
306308
function GetItemByCaption(const _caption : string) : TCustomCheckItem;
307309
procedure SetItemControlEnabled(_itemIdx : Integer; _controlIdx : ESubItemIndex; _enabled : Boolean);
308310
function GetMinimumWidth() : Integer;
309-
procedure ShowExpertItems(const _bShow : Boolean = True);
311+
procedure UpdateLayout(const _layout : TSearchFormLayout);
310312
procedure SetDefaultValues();
311313
property EventsEnabled : Boolean read FEventsEnabled write FEventsEnabled;
312314
property SelectedItems : TArray<TCustomCheckItem> read getSelectedItems;
@@ -322,9 +324,10 @@ implementation
322324
uses
323325
Math,
324326
RipGrepper.Common.IDEContextValues,
325-
RipGrepper.Common.SimpleTypes,
327+
326328
Spring,
327-
RipGrepper.Tools.DebugUtils;
329+
RipGrepper.Tools.DebugUtils,
330+
RipGrepper.Common.Constants;
328331

329332
{ TCustomCheckItemsEnumerator }
330333

@@ -1221,7 +1224,8 @@ procedure TCustomCheckOptions.CalculateActualWidths(const _itemWidth, _firstCont
12211224
end;
12221225

12231226
procedure TCustomCheckOptions.PositionItemPanel(const _item : TCustomCheckItem; const _itemIndex, _itemWidth, _itemHeight : Integer);
1224-
var col, row : Integer;
1227+
var
1228+
col, row : Integer;
12251229
baseLeft, itemHeight : Integer;
12261230
begin
12271231
col := _itemIndex mod Columns;
@@ -1260,7 +1264,8 @@ procedure TCustomCheckOptions.PositionCheckBoxOnly(const _item : TCustomCheckIte
12601264
iTextWidth := Canvas.TextWidth(_item.CheckBox.Caption) + CHECKBOX_MARGIN;
12611265
if UseFlowLayout then begin
12621266
// Flow layout: calculate width based on caption text width using parent's canvas
1263-
var checkboxWidth : integer := Canvas.TextWidth(_item.CheckBox.Caption) + CHECKBOX_MARGIN;
1267+
var
1268+
checkboxWidth : integer := Canvas.TextWidth(_item.CheckBox.Caption) + CHECKBOX_MARGIN;
12641269
if (FItems.Count = 1) then begin
12651270
_item.CheckBox.Width := Max(checkboxWidth, iTextWidth);
12661271
end else begin
@@ -1854,11 +1859,13 @@ procedure TCustomCheckOptions.SetSettings(const Value : TRipGrepperSettings);
18541859
FSettings := Value;
18551860
end;
18561861

1857-
procedure TCustomCheckOptions.ShowExpertItems(const _bShow : Boolean = True);
1862+
procedure TCustomCheckOptions.UpdateLayout(const _layout : TSearchFormLayout);
18581863
begin
1859-
for var item in Items do begin
1860-
if item.ShowInExpertModeOnly then begin
1861-
item.ParentPanel.Visible := _bShow;
1864+
if FSearchFormLayout = _layout then begin
1865+
for var item in Items do begin
1866+
if item.ShowInExpertModeOnly then begin
1867+
item.ParentPanel.Visible := sflExpert in FSearchFormLayout;
1868+
end;
18621869
end;
18631870
end;
18641871
end;
@@ -1874,7 +1881,7 @@ procedure TCustomCheckOptions.SetDefaultValues();
18741881

18751882
procedure Register;
18761883
begin
1877-
RegisterComponents('Custom', [TCustomCheckOptions]);
1884+
RegisterComponents(DRIPGREPPER_APPNAME, [TCustomCheckOptions]);
18781885
end;
18791886

18801887
class function TAutoSetReset.New(var _bValue : Boolean; const _bInitValue : Boolean = True) : TAutoSetReset;

src/UI/RipGrepper.UI.CustomRadioOptions.pas

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ interface
1111
Vcl.StdCtrls,
1212
Vcl.ExtCtrls,
1313
Winapi.Windows,
14-
RipGrepper.UI.CustomCheckOptions;
14+
RipGrepper.UI.CustomCheckOptions,
15+
RipGrepper.Common.SimpleTypes;
1516

1617
type
1718
// Forward declarations
@@ -64,7 +65,8 @@ TCustomRadioItems = class(TCollection)
6465
// Custom radio options control
6566
TCustomRadioOptions = class(TCustomOptionsBase)
6667

67-
private
68+
strict private
69+
FSearchFormLayout: TSearchFormLayout;
6870
FCollection : TCustomRadioItems;
6971
FItemIndex : Integer;
7072
FOnRadioItemSelect : TRadioItemSelectEvent;
@@ -81,7 +83,7 @@ TCustomRadioOptions = class(TCustomOptionsBase)
8183
procedure Clear; override;
8284
function AddRadioButton(const _caption, _hint : string; _orderIndex : Integer; _obj : IInterface = nil) : TCustomRadioItem;
8385
procedure AlignControlItems(); override;
84-
procedure ShowExpertItems(const _bShow : Boolean = True);
86+
procedure UpdateLayout(const _layout: TSearchFormLayout);
8587
procedure SetDefaultValues();
8688

8789
published
@@ -97,8 +99,7 @@ implementation
9799

98100
uses
99101
Math,
100-
RipGrepper.Common.IDEContextValues,
101-
RipGrepper.Common.SimpleTypes;
102+
RipGrepper.Common.IDEContextValues, RipGrepper.Common.Constants;
102103

103104
{ TCustomRadioItem }
104105

@@ -386,13 +387,13 @@ function TCustomRadioOptions.getSelectedItem : TCustomRadioItem;
386387
end;
387388
end;
388389

389-
procedure TCustomRadioOptions.ShowExpertItems(const _bShow : Boolean = True);
390+
procedure TCustomRadioOptions.UpdateLayout(const _layout: TSearchFormLayout);
390391
begin
391392
for var ci in Collection do begin
392393
var
393394
item := ci as TCustomRadioItem;
394395
if item.ShowInExpertModeOnly and Assigned(item.RadioButton) then begin
395-
item.RadioButton.Visible := _bShow;
396+
item.RadioButton.Visible := sflExpert in _layout;
396397
end;
397398
end;
398399
end;
@@ -404,7 +405,7 @@ procedure TCustomRadioOptions.SetDefaultValues();
404405

405406
procedure Register;
406407
begin
407-
RegisterComponents('Custom', [TCustomRadioOptions]);
408+
RegisterComponents(DRIPGREPPER_APPNAME, [TCustomRadioOptions]);
408409
end;
409410

410411
end.

0 commit comments

Comments
 (0)