summaryrefslogtreecommitdiff
path: root/examples/gui/filegrid/filegrid.lpr
blob: 07af95203d1facfd5d8a043427295c125bd24b03 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
program filegrid;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  SysUtils,
  fpgfx,
  gfxbase,
  gui_form,
  gui_grid,
  gui_checkbox,
  gui_button;

type

  { TMainForm }

  TMainForm = class(TfpgForm)
  private
    FGrid: TfpgFileGrid;
    chkShowHidden: TfpgCheckBox;
    btnQuit: TfpgButton;
    procedure   chkShowHiddenChanged(Sender: TObject);
    procedure   btnQuitClicked(Sender: TObject);
    procedure   GridDblClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
  public
    constructor Create(AOwner: TComponent); override;
  end;

{ TMainForm }

procedure TMainForm.chkShowHiddenChanged(Sender: TObject);
begin
//  FGrid.
  FGrid.FileList.ShowHidden := chkShowHidden.Checked;
  FGrid.FileList.ReadDirectory('');
  fpgSendMessage(self, FGrid, FPGM_PAINT);
end;

procedure TMainForm.btnQuitClicked(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.GridDblClick(Sender: TObject; AButton: TMouseButton;
  AShift: TShiftState; const AMousePos: TPoint);
begin
  if FGrid.CurrentEntry.EntryType = etFile then
//  if (FGrid.CurrentEntry.Attributes and faDirectory) = 0 then
    Exit; //==>
    
  FGrid.FileList.ReadDirectory(FGrid.FileList.DirectoryName + FGrid.CurrentEntry.Name);
  WindowTitle := FGrid.FileList.DirectoryName;
  FGrid.Update;
end;

constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  WindowTitle := 'Filegrid Test';
  SetPosition(100, 100, 620, 400);
  
  FGrid := TfpgFileGrid.Create(self);
  FGrid.SetPosition(8, 8, 600, 360);
  FGrid.FileList.ShowHidden := True;
  FGrid.FileList.ReadDirectory('');
  FGrid.Anchors := [anLeft, anTop, anBottom, anRight];
  FGrid.OnDoubleClick := @GridDblClick;
  
  chkShowHidden := CreateCheckBox(self, 8, Height - 25, 'Show Hidden');
  chkShowHidden.Checked := True;
  chkShowHidden.OnChange := @chkShowHiddenChanged;
  chkShowHidden.Anchors := [anLeft, anBottom];
  
  btnQuit := CreateButton(self, Width - 88, Height - 30, 80, 'Quit', @btnQuitClicked);
  btnQuit.ImageName := 'stdimg.Quit';
  btnQuit.ShowImage := True;
  btnQuit.Anchors := [anRight, anBottom];
end;


procedure MainProc;
var
  frm: TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  frm.Show;
  fpgApplication.Run;
  frm.Free;
end;

begin
  MainProc;
end.