source: trunk/UFormMain.pas

Last change on this file was 16, checked in by chronos, 9 years ago
  • Added: Preparation for filtering of non visible nodes.
File size: 8.2 KB
Line 
1unit UFormMain;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
9 ActnList, ComCtrls, StdCtrls, UKConfig, ULastOpenedList, URegistry, MyRegistry,
10 UFindFile;
11
12const
13 RootKey = HKEY_CURRENT_USER;
14 RootPath = '\Software\LinuxBuilder';
15
16type
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
86var
87 FormMain: TFormMain;
88
89implementation
90
91uses
92 UFormList, UFormLog, UFormCompare, UFormSearch;
93
94{$R *.lfm}
95
96{ TFormMain }
97
98procedure TFormMain.FormShow(Sender: TObject);
99begin
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;
106end;
107
108procedure TFormMain.LastOpenedListCompareChange(Sender: TObject);
109begin
110 LastOpenedListOpen.LoadToMenuItem(MenuItemCompareRecent, ACompareExecute);
111 LastOpenedListOpen.LoadToMenuItem(PopupMenuCompareRecent.Items, ACompareExecute);
112end;
113
114procedure TFormMain.LastOpenedListOpenChange(Sender: TObject);
115begin
116 LastOpenedListOpen.LoadToMenuItem(MenuItemOpenRecent, AOpenDirExecute);
117 LastOpenedListOpen.LoadToMenuItem(PopupMenuOpenRecent.Items, AOpenDirExecute);
118end;
119
120procedure TFormMain.TreeView1SelectionChanged(Sender: TObject);
121begin
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;
127end;
128
129procedure TFormMain.DoLog(Text: string);
130begin
131 FormLog.Memo1.Lines.Add(Text);
132end;
133
134procedure TFormMain.OpenDir(Dir: string);
135begin
136 Config.LoadFromDir(Dir);
137 LastOpenedListOpen.AddItem(Dir);
138 Reload;
139 UpdateInterface;
140end;
141
142procedure TFormMain.CompareDir(Dir: string);
143var
144 List1, List2: TStringList;
145 Missing1, Missing2: TStringList;
146 Config2: TConfigMenu;
147begin
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;
174end;
175
176procedure TFormMain.ReloadArch(Dir: string);
177var
178 FindFile: TFindFile;
179 List: TStringList;
180 I: Integer;
181 NewMenuItem: TMenuItem;
182 DirName: string;
183begin
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
205end;
206
207procedure TFormMain.MenuItemArchExecute(Sender: TObject);
208begin
209 if Sender is TMenuItem then begin
210 Config.Arch := TMenuItem(Sender).Caption;
211 Reload;
212 end;
213end;
214
215procedure TFormMain.Reload;
216var
217 Options: TLoadTreeOptions;
218begin
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;
231end;
232
233procedure TFormMain.UpdateInterface;
234begin
235 Caption := Config.BaseDir + ' - ' + Application.Title;
236end;
237
238procedure TFormMain.FocusTreeNode(Node: TMenuNode);
239var
240 TreeNode: TTreeNode;
241begin
242 TreeNode := TreeView1.Items.FindNodeWithData(Node);
243 if Assigned(TreeNode) then begin
244 TreeNode.Selected := True;
245 TreeNode.ExpandParents;
246 end;
247end;
248
249procedure TFormMain.AOpenDirExecute(Sender: TObject);
250var
251 OutDir: string;
252begin
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;
260end;
261
262procedure TFormMain.ASearchExecute(Sender: TObject);
263begin
264 FormSearch.Show;
265end;
266
267procedure TFormMain.ACompareExecute(Sender: TObject);
268var
269 OutDir: string;
270begin
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;
278end;
279
280procedure TFormMain.AExitExecute(Sender: TObject);
281begin
282 FormMain.Close;
283end;
284
285procedure TFormMain.AShowListExecute(Sender: TObject);
286begin
287 FormList.Show;
288end;
289
290procedure TFormMain.AShowLogExecute(Sender: TObject);
291begin
292 FormLog.Show;
293end;
294
295procedure TFormMain.AViemSystemExecute(Sender: TObject);
296begin
297 AViemSystem.Checked := not AViemSystem.Checked;
298 Reload;
299end;
300
301procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
302begin
303 LastOpenedListOpen.SaveToRegistry(RegContext(RootKey, RootPath + '\OpenRecent'));
304 LastOpenedListCompare.SaveToRegistry(RegContext(RootKey, RootPath + '\CompareRecent'));
305end;
306
307procedure TFormMain.FormCreate(Sender: TObject);
308begin
309 Config := TConfigMenu.Create;
310 Config.OnLog := DoLog;
311end;
312
313procedure TFormMain.FormDestroy(Sender: TObject);
314begin
315 FreeAndNil(Config);
316end;
317
318end.
319
Note: See TracBrowser for help on using the repository browser.