source: trunk/Packages/ModularSystem/Demo/UMainForm.pas

Last change on this file was 18, checked in by chronos, 12 years ago
  • Used external packages are now stored in uncompressed form rather in zipped files. This allow better package version synchronisation.
File size: 5.0 KB
Line 
1unit UMainForm;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 StdCtrls, Menus, ActnList, UModularSystem;
10
11type
12
13 { TMainForm }
14
15 TMainForm = class(TForm)
16 published
17 AModuleInstall: TAction;
18 AModuleUninstall: TAction;
19 AModuleUpdate: TAction;
20 ActionList1: TActionList;
21 ButtonUpdate: TButton;
22 ButtonUninstall: TButton;
23 ButtonInstall: TButton;
24 ListViewModules: TListView;
25 MenuItem1: TMenuItem;
26 MenuItem2: TMenuItem;
27 MenuItem3: TMenuItem;
28 PopupMenu1: TPopupMenu;
29 procedure ButtonInstallClick(Sender: TObject);
30 procedure ButtonUninstallClick(Sender: TObject);
31 procedure ButtonUpdateClick(Sender: TObject);
32 procedure FormCreate(Sender: TObject);
33 procedure FormDestroy(Sender: TObject);
34 procedure FormShow(Sender: TObject);
35 procedure ListViewModulesData(Sender: TObject; Item: TListItem);
36 procedure ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
37 Selected: Boolean);
38 private
39 procedure RegisterModules;
40 public
41 ModuleManager: TModuleManager;
42 procedure RefreshList;
43 end;
44
45const
46 InstalledText: array[Boolean] of string = ('Not installed', 'Installed');
47
48var
49 MainForm: TMainForm;
50
51
52implementation
53
54{$R *.lfm}
55
56uses
57 UModuleUser, UModuleBase, UModuleACL;
58
59
60{ TMainForm }
61
62procedure TMainForm.ListViewModulesData(Sender: TObject; Item: TListItem);
63begin
64 if (Item.Index >= 0) and (Item.Index < ModuleManager.Modules.Count) then
65 with TModule(ModuleManager.Modules[Item.Index]) do begin
66 Item.Caption := Title;
67 Item.Data := ModuleManager.Modules[Item.Index];
68 Item.SubItems.Add(Name);
69 Item.SubItems.Add(Version);
70 Item.SubItems.Add(InstalledText[Installed]);
71 Item.SubItems.Add(License);
72 Item.SubItems.Add(StringReplace(Dependencies.Text, LineEnding, ', ', [rfReplaceAll]));
73 Item.SubItems.Add(StringReplace(Description.Text, LineEnding, ', ', [rfReplaceAll]));
74 end;
75end;
76
77procedure TMainForm.ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
78 Selected: Boolean);
79var
80 Installed: Boolean;
81begin
82 if Assigned(ListViewModules.Selected) then Installed := TModule(ListViewModules.Selected.Data).Installed;
83 AModuleInstall.Enabled := Assigned(ListViewModules.Selected) and not Installed;
84 AModuleUninstall.Enabled := Assigned(ListViewModules.Selected) and Installed;
85 AModuleUpdate.Enabled := Assigned(ListViewModules.Selected) and Installed;
86end;
87
88procedure TMainForm.RegisterModules;
89begin
90 ModuleManager.RegisterModule(TModuleUser.Create);
91 ModuleManager.RegisterModule(TModuleBase.Create);
92 ModuleManager.RegisterModule(TModuleACL.Create);
93end;
94
95procedure TMainForm.RefreshList;
96begin
97 ListViewModules.Items.Count := ModuleManager.Modules.Count;
98 ListViewModules.Refresh;
99 ListViewModulesSelectItem(ListViewModules, ListViewModules.Selected,
100 Assigned(ListViewModules.Selected));
101end;
102
103procedure TMainForm.FormCreate(Sender: TObject);
104begin
105 ModuleManager := TModuleManager.Create(nil);
106 RegisterModules;
107end;
108
109procedure TMainForm.ButtonInstallClick(Sender: TObject);
110var
111 ModuleList: TStringList;
112begin
113 if Assigned(ListViewModules.Selected) then begin
114 try
115 ModuleList := TStringList.Create;
116 TModule(ListViewModules.Selected.Data).EnumModulesInstall(ModuleList);
117 if ModuleList.Count > 0 then begin
118 if MessageDlg('These modules will be installed in addition to ' +
119 TModule(ListViewModules.Selected.Data).Name + ': ' +
120 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
121 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
122 TModule(ListViewModules.Selected.Data).Install;
123 end else TModule(ListViewModules.Selected.Data).Install;
124 finally
125 ModuleList.Free;
126 end;
127 RefreshList;
128 end;
129end;
130
131procedure TMainForm.ButtonUninstallClick(Sender: TObject);
132var
133 ModuleList: TStringList;
134begin
135 if Assigned(ListViewModules.Selected) then begin
136 try
137 ModuleList := TStringList.Create;
138 TModule(ListViewModules.Selected.Data).EnumModulesUninstall(ModuleList);
139 if ModuleList.Count > 0 then begin
140 if MessageDlg('These modules will be uninstalled in addition to ' +
141 TModule(ListViewModules.Selected.Data).Name + ': ' +
142 StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
143 mtConfirmation, [mbYes, mbNo], 0) = mrYes then
144 TModule(ListViewModules.Selected.Data).Uninstall;
145 end else TModule(ListViewModules.Selected.Data).Uninstall;
146 finally
147 ModuleList.Free;
148 end;
149
150 RefreshList;
151 end;
152end;
153
154procedure TMainForm.ButtonUpdateClick(Sender: TObject);
155begin
156 if Assigned(ListViewModules.Selected) then begin
157 TModule(ListViewModules.Selected.Data).Update;
158 RefreshList;
159 end;
160end;
161
162procedure TMainForm.FormDestroy(Sender: TObject);
163begin
164 ModuleManager.Free;
165end;
166
167procedure TMainForm.FormShow(Sender: TObject);
168begin
169 RefreshList;
170end;
171
172end.
173
Note: See TracBrowser for help on using the repository browser.