frmMain.pas
上传用户:youjie821
上传日期:2013-01-27
资源大小:459k
文件大小:6k
- unit frmMain;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, hxUpdate, ActnList, StdCtrls, ComCtrls, RzButton, ImgList,
- RzListVw, ExtCtrls, RzPanel, RzTreeVw, Mask, RzEdit, RzBtnEdt, FileCtrl,
- Menus, RzTray, IniFiles;
- type
- TMainForm = class(TForm)
- ActionList1: TActionList;
- actStart: TAction;
- actStop: TAction;
- RzToolbar1: TRzToolbar;
- lvProjects: TRzListView;
- ImageList1: TImageList;
- actQuit: TAction;
- BtnPlay: TRzToolButton;
- BtnStop: TRzToolButton;
- BtnInsertRecord: TRzToolButton;
- BtnDeleteRecord: TRzToolButton;
- RzSpacer1: TRzSpacer;
- actAdd: TAction;
- actDelete: TAction;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- N7: TMenuItem;
- N8: TMenuItem;
- actConfig: TAction;
- BtnUtilities: TRzToolButton;
- N9: TMenuItem;
- PopupMenu1: TPopupMenu;
- N10: TMenuItem;
- N11: TMenuItem;
- actModify: TAction;
- RzToolButton1: TRzToolButton;
- N12: TMenuItem;
- N13: TMenuItem;
- TrayIcon: TRzTrayIcon;
- ImageList2: TImageList;
- PopupMenu2: TPopupMenu;
- N14: TMenuItem;
- N15: TMenuItem;
- actShow: TAction;
- actHide: TAction;
- RzToolButton2: TRzToolButton;
- N16: TMenuItem;
- N17: TMenuItem;
- RzSpacer2: TRzSpacer;
- N18: TMenuItem;
- N19: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure actStartUpdate(Sender: TObject);
- procedure actStopUpdate(Sender: TObject);
- procedure actStartExecute(Sender: TObject);
- procedure actStopExecute(Sender: TObject);
- procedure actQuitExecute(Sender: TObject);
- procedure actAddExecute(Sender: TObject);
- procedure actModifyExecute(Sender: TObject);
- procedure actDeleteExecute(Sender: TObject);
- procedure actDeleteUpdate(Sender: TObject);
- procedure actConfigExecute(Sender: TObject);
- procedure actModifyUpdate(Sender: TObject);
- procedure actShowExecute(Sender: TObject);
- procedure actHideExecute(Sender: TObject);
- private
- { Private declarations }
- FUpdateServer: ThxUpdateServer;
- procedure RefreshProjects;
- public
- { Public declarations }
- end;
- var
- MainForm: TMainForm;
- implementation
- uses Types, frmConfig, hxSysUtils, ConvUtils, frmInfo;
- {$R *.dfm}
- procedure TMainForm.FormCreate(Sender: TObject);
- var
- Ini: TIniFile;
- Port: Integer;
- begin
- RefreshProjects;
- Ini:= TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'main.ini');
- try
- Port:= Ini.ReadInteger('Server', 'Port', 9901);
- finally
- Ini.Free;
- end;
- FUpdateServer:= ThxUpdateServer.Create(Port);
- end;
- procedure TMainForm.FormDestroy(Sender: TObject);
- begin
- FUpdateServer.Free;
- GetProjectCollection.Free;
- end;
- procedure TMainForm.actStartUpdate(Sender: TObject);
- begin
- (Sender as TAction).Enabled:= not FUpdateServer.Active;
- end;
- procedure TMainForm.actStopUpdate(Sender: TObject);
- begin
- (Sender as TAction).Enabled:= FUpdateServer.Active;
- end;
- procedure TMainForm.actStartExecute(Sender: TObject);
- begin
- FUpdateServer.StartService;
- end;
- procedure TMainForm.actStopExecute(Sender: TObject);
- begin
- FUpdateServer.StopServerice;
- end;
- procedure TMainForm.actQuitExecute(Sender: TObject);
- begin
- Close;
- end;
- procedure TMainForm.actModifyExecute(Sender: TObject);
- var
- szProjectName, szRootDir, szDescription: string;
- begin
- with lvProjects.Selected do
- begin
- szProjectName:= Caption;
- szRootDir:= SubItems[0];
- szDescription:= SubItems[1];
- end;
- if ShowInfoForm(szProjectName, szRootDir, szDescription) then
- begin
- with lvProjects.Selected do
- begin
- Caption:= szProjectName;
- SubItems[0]:= szRootDir;
- SubItems[1]:= szDescription;
- end;
- end;
- end;
- procedure TMainForm.actDeleteUpdate(Sender: TObject);
- begin
- (Sender as TAction).Enabled:= lvProjects.Selected <> nil;
- end;
- procedure TMainForm.actDeleteExecute(Sender: TObject);
- var
- Index: Integer;
- begin
- if MessageBox(0, '是否删除选择的项目?', '提示', MB_YESNO + MB_ICONWARNING) = IDYES then
- begin
- Index:= GetProjectCollection.IndexOf(lvProjects.Selected.Caption);
- if Index <> -1 then
- begin
- GetProjectCollection.Items[Index].RemoveResTree;
- GetProjectCollection.Delete(Index);
- lvProjects.DeleteSelected;
- end;
- end;
- end;
- procedure TMainForm.actAddExecute(Sender: TObject);
- var
- szProjectName, szRootDir, szDescription: string;
- begin
- szProjectName:= '';
- szRootDir:= '';
- szDescription:= '';
- if ShowInfoForm(szProjectName, szRootDir, szDescription) then
- begin
- with lvProjects.Items.Add do
- begin
- Caption:= szProjectName;
- SubItems.Add(szRootDir);
- SubItems.Add(szDescription);
- end;
- end;
- end;
- procedure TMainForm.actConfigExecute(Sender: TObject);
- begin
- ShowConfigForm;
- end;
- { TProjectMgr }
- procedure TMainForm.RefreshProjects;
- var
- I: Integer;
- AItem: TProjectItem;
- begin
- lvProjects.Clear;
- for I:= 0 to GetProjectCollection.Count - 1 do
- begin
- AItem:= TProjectItem(GetProjectCollection[I]);
- with lvProjects.Items.Add do
- begin
- Caption:= AItem.ProjectName;
- SubItems.Add(AItem.RootDir);
- SubItems.Add(AItem.Description);
- ImageIndex:= -1;
- end;
- end;
- end;
- procedure TMainForm.actModifyUpdate(Sender: TObject);
- begin
- (Sender as TAction).Enabled:= lvProjects.Selected <> nil;
- end;
- procedure TMainForm.actShowExecute(Sender: TObject);
- begin
- TrayIcon.RestoreApp;
- end;
- procedure TMainForm.actHideExecute(Sender: TObject);
- begin
- TrayIcon.MinimizeApp;
- end;
- end.