Skip to content

Commit f22ad2a

Browse files
committed
UI improvement: ListBox to ListView
1 parent d4303ad commit f22ad2a

File tree

2 files changed

+88
-103
lines changed

2 files changed

+88
-103
lines changed

Source/Unit1.dfm

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,13 @@ object Main: TMain
2121
OnShow = FormShow
2222
PixelsPerInch = 96
2323
TextHeight = 13
24-
object NameAppLbl: TLabel
25-
Left = 9
26-
Top = 8
27-
Width = 50
28-
Height = 13
29-
Caption = #1053#1072#1079#1074#1072#1085#1080#1077
30-
Font.Charset = RUSSIAN_CHARSET
31-
Font.Color = clWindowText
32-
Font.Height = -11
33-
Font.Name = 'MS Sans Serif'
34-
Font.Style = []
35-
ParentFont = False
36-
end
37-
object AppPathLbl: TLabel
38-
Left = 160
39-
Top = 8
40-
Width = 75
41-
Height = 13
42-
Caption = #1056#1072#1089#1087#1086#1083#1086#1078#1077#1085#1080#1077
43-
Font.Charset = RUSSIAN_CHARSET
44-
Font.Color = clWindowText
45-
Font.Height = -11
46-
Font.Name = 'MS Sans Serif'
47-
Font.Style = []
48-
ParentFont = False
49-
end
5024
object AddBtn: TButton
5125
Left = 7
5226
Top = 271
5327
Width = 75
5428
Height = 25
5529
Caption = #1044#1086#1073#1072#1074#1080#1090#1100
56-
TabOrder = 2
30+
TabOrder = 1
5731
OnClick = AddBtnClick
5832
end
5933
object RemBtn: TButton
@@ -62,7 +36,7 @@ object Main: TMain
6236
Width = 75
6337
Height = 25
6438
Caption = #1059#1076#1072#1083#1080#1090#1100
65-
TabOrder = 3
39+
TabOrder = 2
6640
OnClick = RemBtnClick
6741
end
6842
object CheckBtn: TButton
@@ -71,37 +45,16 @@ object Main: TMain
7145
Width = 75
7246
Height = 25
7347
Caption = #1055#1088#1086#1074#1077#1088#1080#1090#1100' '
74-
TabOrder = 4
48+
TabOrder = 3
7549
OnClick = CheckBtnClick
7650
end
77-
object ListBox: TListBox
78-
Left = 8
79-
Top = 24
80-
Width = 393
81-
Height = 217
82-
Font.Charset = RUSSIAN_CHARSET
83-
Font.Color = clWindowText
84-
Font.Height = -11
85-
Font.Name = 'MS Sans Serif'
86-
Font.Style = []
87-
ItemHeight = 13
88-
ParentFont = False
89-
ParentShowHint = False
90-
ShowHint = True
91-
TabOrder = 0
92-
TabWidth = 100
93-
OnDblClick = ListBoxDblClick
94-
OnKeyDown = ListBoxKeyDown
95-
OnKeyUp = ListBoxKeyUp
96-
OnMouseDown = ListBoxMouseDown
97-
end
9851
object FirewallBtn: TButton
9952
Left = 247
10053
Top = 271
10154
Width = 75
10255
Height = 25
10356
Caption = #1041#1088#1072#1085#1076#1084#1072#1091#1101#1088
104-
TabOrder = 5
57+
TabOrder = 4
10558
OnClick = FirewallBtnClick
10659
end
10760
object CloseBtn: TButton
@@ -110,7 +63,7 @@ object Main: TMain
11063
Width = 75
11164
Height = 25
11265
Caption = #1042#1099#1093#1086#1076
113-
TabOrder = 6
66+
TabOrder = 5
11467
OnClick = CloseBtnClick
11568
end
11669
object SearchEdt: TEdit
@@ -124,7 +77,7 @@ object Main: TMain
12477
Font.Name = 'MS Sans Serif'
12578
Font.Style = []
12679
ParentFont = False
127-
TabOrder = 1
80+
TabOrder = 0
12881
Text = #1055#1086#1080#1089#1082'...'
12982
OnChange = SearchEdtChange
13083
OnKeyDown = SearchEdtKeyDown
@@ -139,6 +92,30 @@ object Main: TMain
13992
Panels = <>
14093
SimplePanel = True
14194
end
95+
object ListView: TListView
96+
Left = 8
97+
Top = 8
98+
Width = 393
99+
Height = 233
100+
Columns = <
101+
item
102+
Caption = #1053#1072#1079#1074#1072#1085#1080#1077
103+
Width = 176
104+
end
105+
item
106+
Caption = #1056#1072#1089#1087#1086#1083#1086#1078#1077#1085#1080#1077
107+
Width = 194
108+
end>
109+
HideSelection = False
110+
ReadOnly = True
111+
RowSelect = True
112+
TabOrder = 7
113+
ViewStyle = vsReport
114+
OnDblClick = ListViewDblClick
115+
OnKeyDown = ListViewKeyDown
116+
OnKeyUp = ListViewKeyUp
117+
OnMouseDown = ListViewMouseDown
118+
end
142119
object OpenDialog: TOpenDialog
143120
Filter = '|*.exe'
144121
Left = 48

Source/Unit1.pas

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ TMain = class(TForm)
1111
AddBtn: TButton;
1212
RemBtn: TButton;
1313
CheckBtn: TButton;
14-
ListBox: TListBox;
1514
FirewallBtn: TButton;
1615
CloseBtn: TButton;
1716
OpenDialog: TOpenDialog;
18-
NameAppLbl: TLabel;
19-
AppPathLbl: TLabel;
2017
SearchEdt: TEdit;
2118
StatusBar: TStatusBar;
2219
ImportDialog: TOpenDialog;
@@ -27,6 +24,7 @@ TMain = class(TForm)
2724
ExportBtn: TMenuItem;
2825
HelpItem: TMenuItem;
2926
AboutBtn: TMenuItem;
27+
ListView: TListView;
3028
procedure AddBtnClick(Sender: TObject);
3129
procedure RemBtnClick(Sender: TObject);
3230
procedure FirewallBtnClick(Sender: TObject);
@@ -38,22 +36,22 @@ TMain = class(TForm)
3836
Shift: TShiftState; X, Y: Integer);
3937
procedure SearchEdtChange(Sender: TObject);
4038
procedure FormShow(Sender: TObject);
41-
procedure ListBoxKeyUp(Sender: TObject; var Key: Word;
42-
Shift: TShiftState);
4339
procedure SearchEdtKeyDown(Sender: TObject; var Key: Word;
4440
Shift: TShiftState);
45-
procedure ListBoxKeyDown(Sender: TObject; var Key: Word;
46-
Shift: TShiftState);
4741
procedure FormKeyDown(Sender: TObject; var Key: Word;
4842
Shift: TShiftState);
49-
procedure ListBoxDblClick(Sender: TObject);
50-
procedure ListBoxMouseDown(Sender: TObject; Button: TMouseButton;
51-
Shift: TShiftState; X, Y: Integer);
5243
procedure SearchEdtKeyUp(Sender: TObject; var Key: Word;
5344
Shift: TShiftState);
5445
procedure ImportBtnClick(Sender: TObject);
5546
procedure ExportBtnClick(Sender: TObject);
5647
procedure AboutBtnClick(Sender: TObject);
48+
procedure ListViewMouseDown(Sender: TObject; Button: TMouseButton;
49+
Shift: TShiftState; X, Y: Integer);
50+
procedure ListViewKeyUp(Sender: TObject; var Key: Word;
51+
Shift: TShiftState);
52+
procedure ListViewDblClick(Sender: TObject);
53+
procedure ListViewKeyDown(Sender: TObject; var Key: Word;
54+
Shift: TShiftState);
5755
protected
5856
procedure WMDropFiles (var Msg: TMessage); message WM_DropFiles;
5957
private
@@ -187,9 +185,9 @@ procedure TMain.AddBtnClick(Sender: TObject);
187185

188186
procedure TMain.RemBtnClick(Sender: TObject);
189187
begin
190-
if ListBox.ItemIndex <> - 1 then begin
191-
StatusBar.SimpleText:=' ' + Format(ID_RULE_SUCCESSFULLY_REMOVED, [CutStr(ExtractFileName(RulePaths.Strings[ListBox.ItemIndex]), 22)]); //Ïîñëå óäàëåíèÿ íàçâàíèÿ óæå íå áóäåò, ïîýòîìó ïåðåä óäàëåíèåì
192-
RemoveAppRules(RuleNames.Strings[ListBox.ItemIndex]);
188+
if ListView.ItemIndex <> - 1 then begin
189+
StatusBar.SimpleText:=' ' + Format(ID_RULE_SUCCESSFULLY_REMOVED, [CutStr(ExtractFileName(RulePaths.Strings[ListView.ItemIndex]), 22)]); //Ïîñëå óäàëåíèÿ íàçâàíèÿ óæå íå áóäåò, ïîýòîìó ïåðåä óäàëåíèåì
190+
RemoveAppRules(RuleNames.Strings[ListView.ItemIndex]);
193191
end else StatusBar.SimpleText:=' ' + ID_CHOOSE_RULE;
194192
end;
195193

@@ -239,10 +237,11 @@ procedure TMain.LoadRegRules;
239237
Reg : TRegistry;
240238
SubKeyNames: TStringList;
241239
RegName: string;
240+
Item: TListItem;
242241
begin
243242
RuleNames.Clear;
244243
RulePaths.Clear;
245-
ListBox.Clear;
244+
ListView.Clear;
246245

247246
Rules:=TStringList.Create;
248247
Reg:=TRegistry.Create;
@@ -259,7 +258,9 @@ procedure TMain.LoadRegRules;
259258
RegName:=Copy(RegName, 1, Pos('|', RegName) - 1);
260259
RegName:=Copy(RegName, 1, Pos('_UDP_', RegName) - 1);
261260
RuleNames.Add(RegName);
262-
ListBox.Items.Add(CutStr(ExtractFileName(RulePaths.Strings[RulePaths.Count - 1]), 23) + ^I + CutStr(RulePaths.Strings[RulePaths.Count - 1], 38));
261+
Item:=Main.ListView.Items.Add;
262+
Item.Caption:=ExtractFileName(RulePaths.Strings[RulePaths.Count - 1]);
263+
Item.SubItems.Add(RulePaths.Strings[RulePaths.Count - 1]);
263264
end;
264265
end;
265266
Reg.CloseKey;
@@ -303,9 +304,8 @@ procedure TMain.FormCreate(Sender: TObject);
303304
ID_ABOUT:=Ini.ReadString('Main', 'ID_ABOUT', '');
304305
AboutBtn.Caption:=ID_ABOUT;
305306

306-
307-
NameAppLbl.Caption:=Ini.ReadString('Main', 'ID_APP_NAME', '');
308-
AppPathLbl.Caption:=Ini.ReadString('Main', 'ID_APP_PATH', '');
307+
ListView.Columns[0].Caption:=Ini.ReadString('Main', 'ID_APP_NAME', '');
308+
ListView.Columns[1].Caption:=Ini.ReadString('Main', 'ID_APP_PATH', '');
309309

310310
ID_SEARCH:=Ini.ReadString('Main', 'ID_SEARCH', '');
311311
SearchEdt.Text:=ID_SEARCH;
@@ -390,19 +390,19 @@ procedure TMain.CheckBtnClick(Sender: TObject);
390390

391391
procedure TMain.FormShow(Sender: TObject);
392392
begin
393-
ListBox.SetFocus;
393+
ListView.SetFocus;
394394
if CloseDuplicate then Close;
395395
end;
396396

397-
procedure TMain.ListBoxKeyUp(Sender: TObject; var Key: Word;
397+
procedure TMain.ListViewKeyUp(Sender: TObject; var Key: Word;
398398
Shift: TShiftState);
399399
begin
400-
if ListBox.ItemIndex = -1 then Exit;
401-
StatusBar.SimpleText:=' ' + CutStr(RulePaths.Strings[ListBox.ItemIndex], 62);
400+
if ListView.ItemIndex = -1 then Exit;
401+
StatusBar.SimpleText:=' ' + CutStr(RulePaths.Strings[ListView.ItemIndex], 62);
402402
if Key = VK_DELETE then
403403
RemBtn.Click
404-
else if (Key = VK_RETURN) and (FileExists(RulePaths.Strings[ListBox.ItemIndex])) then
405-
ShellExecute(0, 'open', 'explorer', PChar('/select, "' + RulePaths.Strings[ListBox.ItemIndex] + '"'), nil, SW_SHOW);
404+
else if (Key = VK_RETURN) and (FileExists(RulePaths.Strings[ListView.ItemIndex])) then
405+
ShellExecute(0, 'open', 'explorer', PChar('/select, "' + RulePaths.Strings[ListView.ItemIndex] + '"'), nil, SW_SHOW);
406406
end;
407407

408408
procedure TMain.WMCopyData(var Msg: TWMCopyData);
@@ -415,7 +415,7 @@ procedure TMain.WMCopyData(var Msg: TWMCopyData);
415415
Msg.Result:=Integer(True);
416416
end;
417417

418-
procedure TMain.ListBoxKeyDown(Sender: TObject; var Key: Word;
418+
procedure TMain.ListViewKeyDown(Sender: TObject; var Key: Word;
419419
Shift: TShiftState);
420420
begin
421421
// Óáèðàåì áàã ñêðûòèÿ êîíòðîëîâ
@@ -431,43 +431,37 @@ procedure TMain.FormKeyDown(Sender: TObject; var Key: Word;
431431
Key:=0;
432432
end;
433433

434-
procedure TMain.ListBoxDblClick(Sender: TObject);
434+
procedure TMain.ListViewDblClick(Sender: TObject);
435435
begin
436-
if ListBox.ItemIndex = -1 then Exit;
437-
if FileExists(RulePaths.Strings[ListBox.ItemIndex]) then
438-
ShellExecute(0, 'open', 'explorer', PChar('/select, "' + RulePaths.Strings[ListBox.ItemIndex] + '"'), nil, SW_SHOW);
436+
if ListView.ItemIndex = -1 then Exit;
437+
if FileExists(RulePaths.Strings[ListView.ItemIndex]) then
438+
ShellExecute(0, 'open', 'explorer', PChar('/select, "' + RulePaths.Strings[ListView.ItemIndex] + '"'), nil, SW_SHOW);
439439
end;
440440

441-
procedure TMain.ListBoxMouseDown(Sender: TObject; Button: TMouseButton;
442-
Shift: TShiftState; X, Y: Integer);
441+
procedure ScrollToListViewItem(LV: TListview; ItemIndex: Integer);
442+
var
443+
R: TRect;
443444
begin
444-
// Ñáðàñûâàåì èíäåêñ, åñëè ïîïàäàåì â ïóñòóþ îáëàñòü
445-
ListBox.ItemIndex:=ListBox.ItemAtPos(Point(X, Y), true);
446-
447-
if ListBox.ItemIndex <> -1 then
448-
StatusBar.SimpleText:=' ' + CutStr(RulePaths.Strings[ListBox.ItemIndex], 62)
449-
else
450-
StatusBar.SimpleText:=' ';
451-
452-
if SearchEdt.Text = '' then begin
453-
SearchEdt.Font.Color:=clGray;
454-
SearchEdt.Text:=ID_SEARCH;
455-
end;
445+
R:=LV.Items[ItemIndex].DisplayRect(drBounds);
446+
LV.Scroll(0, R.Top - LV.ClientHeight div 2);
456447
end;
457448

458449
procedure TMain.SearchEdtChange(Sender: TObject);
459450
var
460451
i: integer;
461452
begin
462-
if ListBox.Count = 0 then Exit;
463-
ListBox.ItemIndex:=-1;
453+
if ListView.Items.Count = 0 then Exit;
454+
ListView.ItemIndex:=-1;
464455
for i:=0 to RuleNames.Count - 1 do
465456
if Pos(AnsiLowerCase(SearchEdt.Text), AnsiLowerCase(RuleNames.Strings[i])) > 0 then begin
466-
ListBox.ItemIndex:=i;
457+
458+
ScrollToListViewItem(ListView, i);
459+
//ListView.ItemIndex:=i;
460+
ListView.Items.Item[i].Selected:=true;
467461
Break;
468462
end;
469-
if ListBox.ItemIndex <> -1 then
470-
StatusBar.SimpleText:=' ' + CutStr(RulePaths.Strings[ListBox.ItemIndex], 63)
463+
if ListView.ItemIndex <> -1 then
464+
StatusBar.SimpleText:=' ' + CutStr(RulePaths.Strings[ListView.ItemIndex], 63)
471465
else
472466
StatusBar.SimpleText:=' ';
473467
end;
@@ -533,10 +527,24 @@ procedure TMain.ExportBtnClick(Sender: TObject);
533527

534528
procedure TMain.AboutBtnClick(Sender: TObject);
535529
begin
536-
Application.MessageBox(PChar(Caption + ' 0.7' + #13#10 +
537-
ID_LAST_UPDATE + ' 20.05.2022' + #13#10 +
530+
Application.MessageBox(PChar(Caption + ' 0.7.1' + #13#10 +
531+
ID_LAST_UPDATE + ' 31.03.2024' + #13#10 +
538532
'https://r57zone.github.io' + #13#10 +
539533
'[email protected]'), PChar(ID_ABOUT), MB_ICONINFORMATION);
540534
end;
541535

536+
procedure TMain.ListViewMouseDown(Sender: TObject; Button: TMouseButton;
537+
Shift: TShiftState; X, Y: Integer);
538+
begin
539+
if ListView.ItemIndex <> -1 then
540+
StatusBar.SimpleText:=' ' + CutStr(RulePaths.Strings[ListView.ItemIndex], 62)
541+
else
542+
StatusBar.SimpleText:=' ';
543+
544+
if SearchEdt.Text = '' then begin
545+
SearchEdt.Font.Color:=clGray;
546+
SearchEdt.Text:=ID_SEARCH;
547+
end;
548+
end;
549+
542550
end.

0 commit comments

Comments
 (0)