1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
---|
9 | ActnList, ComCtrls, StdCtrls, UKConfig, ULastOpenedList, URegistry, MyRegistry,
|
---|
10 | UFindFile;
|
---|
11 |
|
---|
12 | const
|
---|
13 | RootKey = HKEY_CURRENT_USER;
|
---|
14 | RootPath = '\Software\LinuxBuilder';
|
---|
15 |
|
---|
16 | type
|
---|
17 |
|
---|
18 | { TFormMain }
|
---|
19 |
|
---|
20 | TFormMain = class(TForm)
|
---|
21 | ACompare: TAction;
|
---|
22 | AExit: TAction;
|
---|
23 | ASearch: TAction;
|
---|
24 | AShowList: TAction;
|
---|
25 | AShowLog: TAction;
|
---|
26 | AViemSystem: TAction;
|
---|
27 | AOpenDir: TAction;
|
---|
28 | ActionList1: TActionList;
|
---|
29 | ImageList1: TImageList;
|
---|
30 | LastOpenedListOpen: TLastOpenedList;
|
---|
31 | LastOpenedListCompare: TLastOpenedList;
|
---|
32 | MainMenu1: TMainMenu;
|
---|
33 | Memo1: TMemo;
|
---|
34 | MenuItem1: TMenuItem;
|
---|
35 | MenuItem10: TMenuItem;
|
---|
36 | MenuItemArch: TMenuItem;
|
---|
37 | MenuItemCompareRecent: TMenuItem;
|
---|
38 | MenuItem2: TMenuItem;
|
---|
39 | MenuItem3: TMenuItem;
|
---|
40 | MenuItem4: TMenuItem;
|
---|
41 | MenuItem5: TMenuItem;
|
---|
42 | MenuItem6: TMenuItem;
|
---|
43 | MenuItem7: TMenuItem;
|
---|
44 | MenuItem8: TMenuItem;
|
---|
45 | MenuItem9: TMenuItem;
|
---|
46 | MenuItemOpenRecent: TMenuItem;
|
---|
47 | PopupMenuCompareRecent: TPopupMenu;
|
---|
48 | PopupMenuOpenRecent: TPopupMenu;
|
---|
49 | StatusBar1: TStatusBar;
|
---|
50 | ToolBar1: TToolBar;
|
---|
51 | ToolButton1: TToolButton;
|
---|
52 | ToolButton2: TToolButton;
|
---|
53 | ToolButton3: TToolButton;
|
---|
54 | ToolButton4: TToolButton;
|
---|
55 | ToolButton5: TToolButton;
|
---|
56 | ToolButton6: TToolButton;
|
---|
57 | TreeView1: TTreeView;
|
---|
58 | procedure ACompareExecute(Sender: TObject);
|
---|
59 | procedure AExitExecute(Sender: TObject);
|
---|
60 | procedure AOpenDirExecute(Sender: TObject);
|
---|
61 | procedure ASearchExecute(Sender: TObject);
|
---|
62 | procedure AShowListExecute(Sender: TObject);
|
---|
63 | procedure AShowLogExecute(Sender: TObject);
|
---|
64 | procedure AViemSystemExecute(Sender: TObject);
|
---|
65 | procedure FormCreate(Sender: TObject);
|
---|
66 | procedure FormDestroy(Sender: TObject);
|
---|
67 | procedure FormShow(Sender: TObject);
|
---|
68 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
69 | procedure LastOpenedListCompareChange(Sender: TObject);
|
---|
70 | procedure LastOpenedListOpenChange(Sender: TObject);
|
---|
71 | procedure TreeView1SelectionChanged(Sender: TObject);
|
---|
72 | private
|
---|
73 | procedure DoLog(Text: string);
|
---|
74 | procedure OpenDir(Dir: string);
|
---|
75 | procedure CompareDir(Dir: string);
|
---|
76 | procedure ReloadArch(Dir: string);
|
---|
77 | procedure MenuItemArchExecute(Sender: TObject);
|
---|
78 | public
|
---|
79 | AutoOpen: Boolean;
|
---|
80 | Config: TConfigMenu;
|
---|
81 | procedure Reload;
|
---|
82 | procedure UpdateInterface;
|
---|
83 | procedure FocusTreeNode(Node: TMenuNode);
|
---|
84 | end;
|
---|
85 |
|
---|
86 | var
|
---|
87 | FormMain: TFormMain;
|
---|
88 |
|
---|
89 | implementation
|
---|
90 |
|
---|
91 | uses
|
---|
92 | UFormList, UFormLog, UFormCompare, UFormSearch;
|
---|
93 |
|
---|
94 | {$R *.lfm}
|
---|
95 |
|
---|
96 | { TFormMain }
|
---|
97 |
|
---|
98 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
99 | begin
|
---|
100 | AutoOpen := True;
|
---|
101 | LastOpenedListOpen.LoadFromRegistry(RegContext(RootKey, RootPath + '\OpenRecent'));
|
---|
102 | LastOpenedListCompare.LoadFromRegistry(RegContext(RootKey, RootPath + '\CompareRecent'));
|
---|
103 | if AutoOpen and (LastOpenedListOpen.Items.Count > 0) then
|
---|
104 | OpenDir(LastOpenedListOpen.Items[0])
|
---|
105 | else Reload;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TFormMain.LastOpenedListCompareChange(Sender: TObject);
|
---|
109 | begin
|
---|
110 | LastOpenedListOpen.LoadToMenuItem(MenuItemCompareRecent, ACompareExecute);
|
---|
111 | LastOpenedListOpen.LoadToMenuItem(PopupMenuCompareRecent.Items, ACompareExecute);
|
---|
112 | end;
|
---|
113 |
|
---|
114 | procedure TFormMain.LastOpenedListOpenChange(Sender: TObject);
|
---|
115 | begin
|
---|
116 | LastOpenedListOpen.LoadToMenuItem(MenuItemOpenRecent, AOpenDirExecute);
|
---|
117 | LastOpenedListOpen.LoadToMenuItem(PopupMenuOpenRecent.Items, AOpenDirExecute);
|
---|
118 | end;
|
---|
119 |
|
---|
120 | procedure TFormMain.TreeView1SelectionChanged(Sender: TObject);
|
---|
121 | begin
|
---|
122 | if Assigned(TreeView1.Selected) then begin
|
---|
123 | if Assigned(TreeView1.Selected.Data) then
|
---|
124 | TMenuNode(TreeView1.Selected.Data).LoadStats(Memo1.Lines)
|
---|
125 | else Memo1.Lines.Clear;
|
---|
126 | end;
|
---|
127 | end;
|
---|
128 |
|
---|
129 | procedure TFormMain.DoLog(Text: string);
|
---|
130 | begin
|
---|
131 | FormLog.Memo1.Lines.Add(Text);
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TFormMain.OpenDir(Dir: string);
|
---|
135 | begin
|
---|
136 | Config.LoadFromDir(Dir);
|
---|
137 | LastOpenedListOpen.AddItem(Dir);
|
---|
138 | Reload;
|
---|
139 | UpdateInterface;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TFormMain.CompareDir(Dir: string);
|
---|
143 | var
|
---|
144 | List1, List2: TStringList;
|
---|
145 | Missing1, Missing2: TStringList;
|
---|
146 | Config2: TConfigMenu;
|
---|
147 | begin
|
---|
148 | try
|
---|
149 | List1 := TStringList.Create;
|
---|
150 | List2 := TStringList.Create;
|
---|
151 | Missing1 := TStringList.Create;
|
---|
152 | Missing2 := TStringList.Create;
|
---|
153 | Config2 := TConfigMenu.Create;
|
---|
154 | Config.TopNode.SaveToList(List1);
|
---|
155 | Config2.LoadFromDir(Dir);
|
---|
156 | Config2.TopNode.SaveToList(List2);
|
---|
157 | Config.CompareStringLists(List1, List2, Missing1, Missing2);
|
---|
158 | Config2.OptionListNames(Missing1);
|
---|
159 | Config.OptionListNames(Missing2);
|
---|
160 | Missing1.Sort;
|
---|
161 | Missing2.Sort;
|
---|
162 | FormCompare.Memo1.Lines.Assign(Missing1);
|
---|
163 | FormCompare.Memo2.Lines.Assign(Missing2);
|
---|
164 | FormCompare.Memo3.Lines.Assign(List1);
|
---|
165 | FormCompare.Memo4.Lines.Assign(List2);
|
---|
166 | FormCompare.Show;
|
---|
167 | finally
|
---|
168 | Config2.Free;
|
---|
169 | Missing1.Free;
|
---|
170 | Missing2.Free;
|
---|
171 | List1.Free;
|
---|
172 | List2.Free;
|
---|
173 | end;
|
---|
174 | end;
|
---|
175 |
|
---|
176 | procedure TFormMain.ReloadArch(Dir: string);
|
---|
177 | var
|
---|
178 | FindFile: TFindFile;
|
---|
179 | List: TStringList;
|
---|
180 | I: Integer;
|
---|
181 | NewMenuItem: TMenuItem;
|
---|
182 | DirName: string;
|
---|
183 | begin
|
---|
184 | try
|
---|
185 | FindFile := TFindFile.Create(nil);
|
---|
186 | FindFile.FileAttr := [ffaDirectory];
|
---|
187 | FindFile.Path := Dir;
|
---|
188 | FindFile.FileMask := '*';
|
---|
189 | List := FindFile.SearchForFiles;
|
---|
190 | MenuItemArch.Clear;
|
---|
191 | for I := 0 to List.Count - 1 do begin
|
---|
192 | DirName := ExtractFileName(List[I]);
|
---|
193 | if (DirName <> '..') and (DirName <> '.') and
|
---|
194 | FileExists(List[I] + DirectorySeparator + 'Kconfig') then begin
|
---|
195 | NewMenuItem := TMenuItem.Create(MenuItemArch);
|
---|
196 | NewMenuItem.Caption := DirName;
|
---|
197 | NewMenuItem.OnClick := MenuItemArchExecute;
|
---|
198 | if Config.Arch = DirName then NewMenuItem.Checked := True;
|
---|
199 | MenuItemArch.Add(NewMenuItem);
|
---|
200 | end;
|
---|
201 | end;
|
---|
202 | finally
|
---|
203 | FindFile.Free;
|
---|
204 | end
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TFormMain.MenuItemArchExecute(Sender: TObject);
|
---|
208 | begin
|
---|
209 | if Sender is TMenuItem then begin
|
---|
210 | Config.Arch := TMenuItem(Sender).Caption;
|
---|
211 | Reload;
|
---|
212 | end;
|
---|
213 | end;
|
---|
214 |
|
---|
215 | procedure TFormMain.Reload;
|
---|
216 | var
|
---|
217 | Options: TLoadTreeOptions;
|
---|
218 | begin
|
---|
219 | TreeView1.Items.Clear;
|
---|
220 | if Assigned(Config.TopNode) then begin
|
---|
221 | TreeView1.Items.AddChild(nil, Config.TopNode.GetName);
|
---|
222 | Options := [];
|
---|
223 | if AViemSystem.Checked then Include(Options, toShowSystem);
|
---|
224 | Config.TopNode.LoadTreeNode(TreeView1.TopItem, Options);
|
---|
225 | TreeView1.TopItem.Expanded := True;
|
---|
226 | StatusBar1.Panels[0].Text := 'Count: ' + IntToStr(Config.TopNode.GetCount);
|
---|
227 | ReloadArch(Config.BaseDir + DirectorySeparator + 'arch');
|
---|
228 | end else begin
|
---|
229 | StatusBar1.Panels[0].Text := '';
|
---|
230 | end;
|
---|
231 | end;
|
---|
232 |
|
---|
233 | procedure TFormMain.UpdateInterface;
|
---|
234 | begin
|
---|
235 | Caption := Config.BaseDir + ' - ' + Application.Title;
|
---|
236 | end;
|
---|
237 |
|
---|
238 | procedure TFormMain.FocusTreeNode(Node: TMenuNode);
|
---|
239 | var
|
---|
240 | TreeNode: TTreeNode;
|
---|
241 | begin
|
---|
242 | TreeNode := TreeView1.Items.FindNodeWithData(Node);
|
---|
243 | if Assigned(TreeNode) then begin
|
---|
244 | TreeNode.Selected := True;
|
---|
245 | TreeNode.ExpandParents;
|
---|
246 | end;
|
---|
247 | end;
|
---|
248 |
|
---|
249 | procedure TFormMain.AOpenDirExecute(Sender: TObject);
|
---|
250 | var
|
---|
251 | OutDir: string;
|
---|
252 | begin
|
---|
253 | if Sender is TMenuItem then begin
|
---|
254 | OpenDir(TMenuItem(Sender).Caption);
|
---|
255 | end else begin
|
---|
256 | if SelectDirectory('Select Linux source directory', Config.BaseDir, OutDir) then begin
|
---|
257 | OpenDir(OutDir);
|
---|
258 | end;
|
---|
259 | end;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | procedure TFormMain.ASearchExecute(Sender: TObject);
|
---|
263 | begin
|
---|
264 | FormSearch.Show;
|
---|
265 | end;
|
---|
266 |
|
---|
267 | procedure TFormMain.ACompareExecute(Sender: TObject);
|
---|
268 | var
|
---|
269 | OutDir: string;
|
---|
270 | begin
|
---|
271 | if Sender is TMenuItem then begin
|
---|
272 | CompareDir(TMenuItem(Sender).Caption);
|
---|
273 | end else begin
|
---|
274 | if SelectDirectory('Select Linux source directory for compare', Config.BaseDir, OutDir) then begin
|
---|
275 | CompareDir(OutDir);
|
---|
276 | end;
|
---|
277 | end;
|
---|
278 | end;
|
---|
279 |
|
---|
280 | procedure TFormMain.AExitExecute(Sender: TObject);
|
---|
281 | begin
|
---|
282 | FormMain.Close;
|
---|
283 | end;
|
---|
284 |
|
---|
285 | procedure TFormMain.AShowListExecute(Sender: TObject);
|
---|
286 | begin
|
---|
287 | FormList.Show;
|
---|
288 | end;
|
---|
289 |
|
---|
290 | procedure TFormMain.AShowLogExecute(Sender: TObject);
|
---|
291 | begin
|
---|
292 | FormLog.Show;
|
---|
293 | end;
|
---|
294 |
|
---|
295 | procedure TFormMain.AViemSystemExecute(Sender: TObject);
|
---|
296 | begin
|
---|
297 | AViemSystem.Checked := not AViemSystem.Checked;
|
---|
298 | Reload;
|
---|
299 | end;
|
---|
300 |
|
---|
301 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
302 | begin
|
---|
303 | LastOpenedListOpen.SaveToRegistry(RegContext(RootKey, RootPath + '\OpenRecent'));
|
---|
304 | LastOpenedListCompare.SaveToRegistry(RegContext(RootKey, RootPath + '\CompareRecent'));
|
---|
305 | end;
|
---|
306 |
|
---|
307 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
308 | begin
|
---|
309 | Config := TConfigMenu.Create;
|
---|
310 | Config.OnLog := DoLog;
|
---|
311 | end;
|
---|
312 |
|
---|
313 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
314 | begin
|
---|
315 | FreeAndNil(Config);
|
---|
316 | end;
|
---|
317 |
|
---|
318 | end.
|
---|
319 |
|
---|