1 | unit UFormModuleList;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
---|
9 | ComCtrls, ExtCtrls, Menus, ActnList, SpecializedList, UModularSystem;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormModuleList }
|
---|
14 |
|
---|
15 | TFormModuleList = class(TForm)
|
---|
16 | AInstall: TAction;
|
---|
17 | AUninstall: TAction;
|
---|
18 | AModuleUnregister: TAction;
|
---|
19 | ActionList1: TActionList;
|
---|
20 | ListViewModules: TListView;
|
---|
21 | MenuItem1: TMenuItem;
|
---|
22 | MenuItem2: TMenuItem;
|
---|
23 | MenuItem3: TMenuItem;
|
---|
24 | PopupMenu1: TPopupMenu;
|
---|
25 | TimerRedraw: TTimer;
|
---|
26 | ToolBar1: TToolBar;
|
---|
27 | ToolButton1: TToolButton;
|
---|
28 | ToolButton2: TToolButton;
|
---|
29 | ToolButton3: TToolButton;
|
---|
30 | procedure AInstallExecute(Sender: TObject);
|
---|
31 | procedure AModuleUnregisterExecute(Sender: TObject);
|
---|
32 | procedure AUninstallExecute(Sender: TObject);
|
---|
33 | procedure FormCreate(Sender: TObject);
|
---|
34 | procedure FormHide(Sender: TObject);
|
---|
35 | procedure FormShow(Sender: TObject);
|
---|
36 | procedure ListViewModulesData(Sender: TObject; Item: TListItem);
|
---|
37 | procedure ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
|
---|
38 | Selected: Boolean);
|
---|
39 | procedure TimerRedrawTimer(Sender: TObject);
|
---|
40 | private
|
---|
41 | FModuleManager: TModuleManager;
|
---|
42 | procedure SetModuleManager(AValue: TModuleManager);
|
---|
43 | { private declarations }
|
---|
44 | public
|
---|
45 | property ModuleManager: TModuleManager read FModuleManager
|
---|
46 | write SetModuleManager;
|
---|
47 | procedure Reload;
|
---|
48 | procedure UpdateInterface;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | var
|
---|
52 | FormModuleList: TFormModuleList;
|
---|
53 |
|
---|
54 | implementation
|
---|
55 |
|
---|
56 | resourcestring
|
---|
57 | SNotInstalled = 'Not installed';
|
---|
58 | SInstalled = 'Installed';
|
---|
59 |
|
---|
60 | { TFormModuleList }
|
---|
61 |
|
---|
62 | procedure TFormModuleList.ListViewModulesData(Sender: TObject; Item: TListItem);
|
---|
63 | begin
|
---|
64 | if (Item.Index >= 0) and (Item.Index < FModuleManager.Modules.Count) then
|
---|
65 | with TModule(FModuleManager.Modules[Item.Index]) do begin
|
---|
66 | Item.Caption := Identification;
|
---|
67 | Item.Data := FModuleManager.Modules[Item.Index];
|
---|
68 | Item.SubItems.Add(Title);
|
---|
69 | if Installed then Item.SubItems.Add(SInstalled)
|
---|
70 | else Item.SubItems.Add(SNotInstalled);
|
---|
71 | Item.SubItems.Add(Author);
|
---|
72 | Item.SubItems.Add(License);
|
---|
73 | Item.SubItems.Add(Version);
|
---|
74 | Item.SubItems.Add(StringReplace(Dependencies.Text, LineEnding, ', ', [rfReplaceAll]));
|
---|
75 | end;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TFormModuleList.ListViewModulesSelectItem(Sender: TObject;
|
---|
79 | Item: TListItem; Selected: Boolean);
|
---|
80 | begin
|
---|
81 | UpdateInterface;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | procedure TFormModuleList.FormCreate(Sender: TObject);
|
---|
85 | begin
|
---|
86 | DoubleBuffered := True;
|
---|
87 | ControlStyle := ControlStyle + [csOpaque];
|
---|
88 | ListViewModules.DoubleBuffered := True;
|
---|
89 | ListViewModules.ControlStyle := ListViewModules.ControlStyle + [csOpaque];
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TFormModuleList.AModuleUnregisterExecute(Sender: TObject);
|
---|
93 | begin
|
---|
94 | if Assigned(ListViewModules.Selected) then begin
|
---|
95 | FModuleManager.UnregisterModule(TModule(ListViewModules.Selected.Data));
|
---|
96 | UpdateInterface;
|
---|
97 | end;
|
---|
98 | end;
|
---|
99 |
|
---|
100 | procedure TFormModuleList.AUninstallExecute(Sender: TObject);
|
---|
101 | begin
|
---|
102 | if Assigned(ListViewModules.Selected) then begin
|
---|
103 | TModule(ListViewModules.Selected.Data).Uninstall;
|
---|
104 | UpdateInterface;
|
---|
105 | end;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TFormModuleList.AInstallExecute(Sender: TObject);
|
---|
109 | begin
|
---|
110 | if Assigned(ListViewModules.Selected) then begin
|
---|
111 | TModule(ListViewModules.Selected.Data).Install;
|
---|
112 | UpdateInterface;
|
---|
113 | end
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TFormModuleList.FormHide(Sender: TObject);
|
---|
117 | begin
|
---|
118 | TimerRedraw.Enabled := False;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TFormModuleList.FormShow(Sender: TObject);
|
---|
122 | begin
|
---|
123 | Reload;
|
---|
124 | UpdateInterface;
|
---|
125 | TimerRedraw.Enabled := True;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TFormModuleList.TimerRedrawTimer(Sender: TObject);
|
---|
129 | begin
|
---|
130 | Reload;
|
---|
131 | end;
|
---|
132 |
|
---|
133 | procedure TFormModuleList.SetModuleManager(AValue: TModuleManager);
|
---|
134 | begin
|
---|
135 | if FModuleManager = AValue then Exit;
|
---|
136 | FModuleManager := AValue;
|
---|
137 | Reload;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | procedure TFormModuleList.Reload;
|
---|
141 | begin
|
---|
142 | ListViewModules.Items.Count := FModuleManager.Modules.Count;
|
---|
143 | ListViewModules.Refresh;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TFormModuleList.UpdateInterface;
|
---|
147 | begin
|
---|
148 | AModuleUnregister.Enabled := Assigned(ListViewModules.Selected);
|
---|
149 | AInstall.Enabled := Assigned(ListViewModules.Selected) and
|
---|
150 | not TModule(ListViewModules.Selected.Data).Installed;
|
---|
151 | AUninstall.Enabled := Assigned(ListViewModules.Selected) and
|
---|
152 | TModule(ListViewModules.Selected.Data).Installed;
|
---|
153 | end;
|
---|
154 |
|
---|
155 | initialization
|
---|
156 | {$I UFormModuleList.lrs}
|
---|
157 |
|
---|
158 | end.
|
---|
159 |
|
---|