|
From: Peter T. <pe...@us...> - 2003-08-23 23:26:32
|
Update of /cvsroot/jvcl/dev/JVCL3/examples/JvChangeNotify
In directory sc8-pr-cvs1:/tmp/cvs-serv4702/JVCL3/examples/JvChangeNotify
Added Files:
ChangeNotificationDirDlgU.dfm ChangeNotificationDirDlgU.pas
ChangeNotificationMainFormU.dfm
ChangeNotificationMainFormU.pas ChangeNotifyDemo.dof
ChangeNotifyDemo.dpr ChangeNotifyDemo.res
Log Message:
- Copied jvcl/devtools and jvcl/examples dev/JVCL3
- Copied JVCLConvert *.dat files to dev/JVCL3/converter
--- NEW FILE: ChangeNotificationDirDlgU.dfm ---
object ChangeNotificationDirDlg: TChangeNotificationDirDlg
Left = 242
Top = 168
BorderStyle = bsDialog
Caption = 'Add directory to watch'
ClientHeight = 245
ClientWidth = 390
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 8
Width = 45
Height = 13
Caption = 'Directory:'
end
object Edit1: TEdit
Left = 16
Top = 32
Width = 233
Height = 21
TabOrder = 0
end
object Button1: TButton
Left = 264
Top = 32
Width = 75
Height = 25
Caption = '&Browse...'
TabOrder = 1
OnClick = Button1Click
end
object GroupBox1: TGroupBox
Left = 8
Top = 72
Width = 353
Height = 105
Caption = ' Watch for: '
TabOrder = 2
object cbAttributes: TCheckBox
Left = 16
Top = 72
Width = 126
Height = 17
Caption = '&Attributes change'
TabOrder = 0
end
object cbDirNames: TCheckBox
Left = 16
Top = 48
Width = 126
Height = 17
Caption = '&Directory change'
Checked = True
State = cbChecked
TabOrder = 1
end
object cbFileNames: TCheckBox
Left = 16
Top = 24
Width = 126
Height = 17
Caption = '&File change'
Checked = True
State = cbChecked
TabOrder = 2
end
object cbSize: TCheckBox
Left = 182
Top = 24
Width = 126
Height = 17
Caption = '&Size change'
TabOrder = 3
end
object cbWrite: TCheckBox
Left = 182
Top = 48
Width = 126
Height = 17
Caption = '&Write time change'
TabOrder = 4
end
object cbSubTrees: TCheckBox
Left = 182
Top = 72
Width = 142
Height = 17
Caption = '&Include subtrees'
Checked = True
State = cbChecked
TabOrder = 5
end
end
object btnOK: TButton
Left = 200
Top = 208
Width = 75
Height = 25
Caption = 'OK'
Default = True
ModalResult = 1
TabOrder = 3
end
object Button3: TButton
Left = 288
Top = 208
Width = 75
Height = 25
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 4
end
end
--- NEW FILE: ChangeNotificationDirDlgU.pas ---
unit ChangeNotificationDirDlgU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, JvChangeNotify;
type
TChangeNotificationDirDlg = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
GroupBox1: TGroupBox;
cbAttributes: TCheckBox;
cbDirNames: TCheckBox;
cbFileNames: TCheckBox;
cbSize: TCheckBox;
cbWrite: TCheckBox;
cbSubTrees: TCheckBox;
btnOK: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
public
class function Execute(var Directory: string; var Options: TJvChangeActions; var IncludeSubDirs: boolean): boolean;
end;
implementation
uses
FileCtrl;
{$R *.DFM}
procedure TChangeNotificationDirDlg.Button1Click(Sender: TObject);
var S: string;
begin
S := GetCurrentDir;
if SelectDirectory(S, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
Edit1.Text := S;
end;
class function TChangeNotificationDirDlg.Execute(var Directory: string;
var Options: TJvChangeActions; var IncludeSubDirs: boolean): boolean;
var f: TChangeNotificationDirDlg;
begin
f := self.Create(Application);
with f do
try
Edit1.Text := Directory;
cbFileNames.Checked := caChangeFileName in Options;
cbAttributes.Checked := caChangeAttributes in Options;
cbDirNames.Checked := caChangeDirName in Options;
cbSize.Checked := caChangeSize in Options;
cbWrite.Checked := caChangeLastWrite in Options;
cbSubTrees.Checked := IncludeSubDirs;
Result := ShowModal = mrOK;
if Result then
begin
Directory := Edit1.Text;
Options := [];
if cbFileNames.Checked then
Include(Options, caChangeFileName);
if cbAttributes.Checked then
Include(Options, caChangeAttributes);
if cbDirNames.Checked then
Include(Options, caChangeDirName);
if cbSize.Checked then
Include(Options, caChangeSize);
if cbWrite.Checked then
Include(Options, caChangeLastWrite);
IncludeSubDirs := cbSubTrees.Checked;
end;
finally
f.Free;
end;
end;
end.
--- NEW FILE: ChangeNotificationMainFormU.dfm ---
object ChangeNotificationMainForm: TChangeNotificationMainForm
Left = 283
Top = 166
AutoScroll = False
Caption = 'TJvChangeNotify demo'
ClientHeight = 333
ClientWidth = 384
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = True
Position = poScreenCenter
OnCloseQuery = FormCloseQuery
PixelsPerInch = 96
TextHeight = 13
object Label3: TLabel
Left = 0
Top = 132
Width = 384
Height = 13
Align = alTop
Caption = ' Detected changes:'
end
object ListBox2: TListBox
Left = 0
Top = 145
Width = 384
Height = 105
Align = alClient
ItemHeight = 13
TabOrder = 0
end
object ListView1: TListView
Left = 0
Top = 0
Width = 384
Height = 132
Align = alTop
Columns = <
item
Caption = 'Directory'
Width = 100
end
item
Caption = 'Subtrees'
Width = 80
end
item
Caption = 'Actions'
Width = 200
end>
ReadOnly = True
RowSelect = True
TabOrder = 1
ViewStyle = vsReport
OnDblClick = ListView1DblClick
end
object Panel1: TPanel
Left = 0
Top = 250
Width = 384
Height = 83
Align = alBottom
BevelOuter = bvNone
TabOrder = 2
object btnStart: TSpeedButton
Left = 294
Top = 46
Width = 75
Height = 25
AllowAllUp = True
GroupIndex = 1
Caption = 'Start'
OnClick = btnStartClick
end
object Label2: TLabel
Left = 10
Top = 13
Width = 78
Height = 13
Caption = 'Timeout interval:'
end
object Label4: TLabel
Left = 152
Top = 12
Width = 30
Height = 13
Caption = 'msecs'
end
object btnAdd: TButton
Left = 110
Top = 46
Width = 75
Height = 25
Caption = 'Add...'
TabOrder = 0
OnClick = btnAddClick
end
object btnDelete: TButton
Left = 190
Top = 46
Width = 75
Height = 25
Caption = 'Delete'
TabOrder = 1
OnClick = btnDeleteClick
end
object Edit1: TEdit
Left = 96
Top = 10
Width = 33
Height = 21
TabOrder = 2
Text = '100'
end
object udInterval: TUpDown
Left = 129
Top = 10
Width = 15
Height = 21
Associate = Edit1
Max = 1000
Increment = 50
Position = 100
TabOrder = 3
end
object btnClear: TButton
Left = 14
Top = 46
Width = 75
Height = 25
Caption = 'Clear'
TabOrder = 4
OnClick = btnClearClick
end
end
object CN1: TJvChangeNotify
Notifications = <>
OnChangeNotify = CN1ChangeNotify
Left = 192
Top = 256
end
end
--- NEW FILE: ChangeNotificationMainFormU.pas ---
unit ChangeNotificationMainFormU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
JvChangeNotify, Buttons, StdCtrls, ComCtrls, ExtCtrls, JvComponent;
type
TChangeNotificationMainForm = class(TForm)
CN1: TJvChangeNotify;
ListBox2: TListBox;
Label3: TLabel;
ListView1: TListView;
Panel1: TPanel;
btnStart: TSpeedButton;
Label2: TLabel;
btnAdd: TButton;
btnDelete: TButton;
Edit1: TEdit;
udInterval: TUpDown;
btnClear: TButton;
Label4: TLabel;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure btnDeleteClick(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnStartClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure CN1ChangeNotify(Sender: TObject; Dir: string; Actions: TJvChangeActions);
procedure EditItem(li: TListItem);
procedure DeleteItem(li: TListItem);
procedure ListView1DblClick(Sender: TObject);
private
{ Private declarations }
procedure ResetCaptions(Invert: boolean);
procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
end;
var
ChangeNotificationMainForm: TChangeNotificationMainForm;
implementation
uses ChangeNotificationDirDlgU;
{$R *.DFM}
procedure TChangeNotificationMainForm.ResetCaptions(Invert: boolean);
const
aCap: array[boolean] of string = ('TJvChangeNotification demo', 'Checking...');
begin
if Invert then
Caption := aCap[not CN1.Active]
else
Caption := aCap[CN1.Active];
Application.Title := Caption;
end;
procedure TChangeNotificationMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CN1.Active := false;
end;
procedure TChangeNotificationMainForm.btnDeleteClick(Sender: TObject);
begin
DeleteItem(ListView1.Selected);
end;
function OptionsToStr(Options: TJvChangeActions): string;
begin
Result := '';
if caChangeFileName in Options then
Result := Result + 'Rename Files,';
if caChangeDirName in Options then
Result := Result + 'Rename Folders,';
if caChangeAttributes in Options then
Result := Result + 'Change Attributes,';
if caChangeSize in Options then
Result := Result + 'Change Size,';
if caChangeLastWrite in Options then
Result := Result + 'Change Content,';
if caChangeSecurity in Options then
Result := Result + 'Change Security,';
if Length(Result) > 0 then
begin
SetLength(Result, Length(Result) - 1);
Result := '(' + Result + ')';
end;
end;
procedure TChangeNotificationMainForm.btnAddClick(Sender: TObject);
begin
EditItem(nil);
end;
procedure TChangeNotificationMainForm.btnStartClick(Sender: TObject);
var b: boolean;
begin
if CN1.Notifications.Count = 0 then
begin
ShowMessage('No notifications to monitor!');
btnStart.Down := false;
Exit;
end;
b := btnStart.Down;
btnAdd.Enabled := not b;
btnDelete.Enabled := not b;
ResetCaptions(true);
{ do this *after* setting buttons }
CN1.Active := b;
end;
procedure TChangeNotificationMainForm.btnClearClick(Sender: TObject);
begin
ListBox2.Clear;
ResetCaptions(false);
end;
procedure TChangeNotificationMainForm.CN1ChangeNotify(Sender: TObject; Dir: string;
Actions: TJvChangeActions);
begin
Application.Title := Format('Change in %s (%s)', [Dir, ActionsToString(Actions)]);
ListBox2.Items.Add(Application.Title);
FlashWindow(ChangeNotificationMainForm.Handle, true);
MessageBeep(DWORD(-1));
end;
procedure TChangeNotificationMainForm.WMGetMinMaxINfo(var Msg: TWMGetMinMaxInfo);
begin
with Msg.MinMaxInfo^.ptMinTrackSize do
begin
X := 392;
Y := 295;
end;
Msg.Result := 0;
end;
procedure TChangeNotificationMainForm.EditItem(li: TListItem);
var ADirectory: string;
AOptions: TJvChangeActions;
AIncludeSubDirs: boolean;
begin
if (li = nil) or (li.Data = nil) then
begin
ADirectory := GetCurrentDir;
AIncludeSubDirs := true;
AOptions := [caChangeFileName, caChangeDirName];
end
else
with TJvChangeItem(li.Data) do
begin
ADirectory := Directory;
AIncludeSubDirs := IncludeSubTrees;
AOptions := Actions;
end;
if TChangeNotificationDirDlg.Execute(ADirectory, AOptions, AIncludeSubDirs) then
begin
if li = nil then
begin
li := ListView1.Items.Add;
li.Caption := ADirectory;
if AIncludeSubDirs and (Win32Platform = VER_PLATFORM_WIN32_NT) then
li.SubItems.Add('Yes')
else
li.SubItems.Add('No');
li.SubItems.Add(OptionsToStr(AOptions));
end
else
begin
li.Caption := ADirectory;
if AIncludeSubDirs and (Win32Platform = VER_PLATFORM_WIN32_NT) then
li.SubItems[0] := 'Yes'
else
li.SubItems[0] := 'No';
li.SubItems[1] := OptionsToStr(AOptions);
end;
if li.Data = nil then
li.Data := CN1.Notifications.Add;
with TJvChangeItem(li.Data) do
begin
IncludeSubTrees := AIncludeSubDirs and (Win32Platform = VER_PLATFORM_WIN32_NT);
Directory := ADirectory;
Actions := AOptions;
end;
end;
end;
procedure TChangeNotificationMainForm.DeleteItem(li: TListItem);
begin
if li = nil then
Exit;
if li.Data <> nil then
CN1.Notifications.Delete(li.Index);
li.Delete;
end;
procedure TChangeNotificationMainForm.ListView1DblClick(Sender: TObject);
begin
EditItem(ListView1.Selected);
end;
end.
--- NEW FILE: ChangeNotifyDemo.dof ---
[Directories]
OutputDir=..\..\Bin
UnitOutputDir=..\..\Dcu
SearchPath=..\..\Source;..\..\Common
--- NEW FILE: ChangeNotifyDemo.dpr ---
program ChangeNotifyDemo;
uses
Forms,
ChangeNotificationMainFormU in 'ChangeNotificationMainFormU.pas' {ChangeNotificationMainForm},
ChangeNotificationDirDlgU in 'ChangeNotificationDirDlgU.pas' {ChangeNotificationDirDlg};
{$R *.RES}
begin
Application.Initialize;
Application.Title := 'TChangeNotification Demo';
Application.CreateForm(TChangeNotificationMainForm, ChangeNotificationMainForm);
Application.CreateForm(TChangeNotificationMainForm, ChangeNotificationMainForm);
Application.Run;
end.
--- NEW FILE: ChangeNotifyDemo.res ---
(This appears to be a binary file; contents omitted.)
|