Скачиваний:
43
Добавлен:
10.12.2013
Размер:
9.2 Кб
Скачать
{$X+,S-}
{$M 16384,8192,655360}
uses
Dos, Objects, Drivers, Memory, Views, Menus, Dialogs, StdDlg, HistList,
MsgBox, App, DemoCmds,Gadgets,
Editors;
const
HeapSize = 48 * (1024 div 16);
var
ClipWindow: PEditWindow;
type
Pproga = ^Tproga;
Tproga = object(TApplication)
Clock: PClockView;
Heap: PHeapView;
constructor Init;
procedure FileOpen(WildCard: PathStr);
function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
procedure GetEvent(var Event: TEvent); virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure InitMenuBar; virtual;
procedure InitStatusLine; virtual;
procedure OutOfMemory; virtual;
end;
function CreateFindDialog: PDialog;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 38, 12);
D := New(PDialog, Init(R, 'Find'));
with D^ do
begin
Options := Options or ofCentered;
R.Assign(3, 3, 32, 4);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(2, 2, 15, 3);
Insert(New(PLabel, Init(R, '~T~ext to find', Control)));
R.Assign(32, 3, 35, 4);
Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
R.Assign(3, 5, 35, 7);
Insert(New(PCheckBoxes, Init(R,
NewSItem('~C~ase sensitive',
NewSItem('~W~hole words only', nil)))));
R.Assign(14, 9, 24, 11);
Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
Inc(R.A.X, 12); Inc(R.B.X, 12);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
SelectNext(False);
end;
CreateFindDialog := D;
end;

function CreateReplaceDialog: PDialog;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 40, 16);
D := New(PDialog, Init(R, 'Replace'));
with D^ do
begin
Options := Options or ofCentered;
R.Assign(3, 3, 34, 4);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(2, 2, 15, 3);
Insert(New(PLabel, Init(R, '~T~ext to find', Control)));
R.Assign(34, 3, 37, 4);
Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
R.Assign(3, 6, 34, 7);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(2, 5, 12, 6);
Insert(New(PLabel, Init(R, '~N~ew text', Control)));
R.Assign(34, 6, 37, 7);
Insert(New(PHistory, Init(R, PInputLine(Control), 11)));
R.Assign(3, 8, 37, 12);
Insert(New(PCheckBoxes, Init(R,
NewSItem('~C~ase sensitive',
NewSItem('~W~hole words only',
NewSItem('~P~rompt on replace',
NewSItem('~R~eplace all', nil)))))));
R.Assign(17, 13, 27, 15);
Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
R.Assign(28, 13, 38, 15);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
SelectNext(False);
end;
CreateReplaceDialog := D;
end;

function DoEditDialog(Dialog: Integer; Info: Pointer): Word; far;
var
R: TRect;
T: TPoint;
begin
case Dialog of
edReadError:
DoEditDialog := MessageBox('Error reading file %s.',
@Info, mfError + mfOkButton);
edWriteError:
DoEditDialog := MessageBox('Error writing file %s.',
@Info, mfError + mfOkButton);
edCreateError:
DoEditDialog := MessageBox('Error creating file %s.',
@Info, mfError + mfOkButton);
edSaveModify:
DoEditDialog := MessageBox('%s has been modified. Save?',
@Info, mfInformation + mfYesNoCancel);
edSaveUntitled:
DoEditDialog := MessageBox('Save untitled file?',
nil, mfInformation + mfYesNoCancel);
edSaveAs:
DoEditDialog := Application^.ExecuteDialog(New(PFileDialog, Init('*.*',
'Save file as', '~N~ame', fdOkButton, 101)), Info);
edFind:
DoEditDialog := Application^.ExecuteDialog(CreateFindDialog, Info);
edSearchFailed:
DoEditDialog := MessageBox('Search string not found.',
nil, mfError + mfOkButton);
edReplace:
DoEditDialog := Application^.ExecuteDialog(CreateReplaceDialog, Info);
edReplacePrompt:
begin
R.Assign(0, 1, 40, 8);
R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
Desktop^.MakeGlobal(R.B, T);
Inc(T.Y);
if TPoint(Info).Y <= T.Y then
R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
DoEditDialog := MessageBoxRect(R, 'Replace?',
nil, mfYesNoCancel + mfInformation);
end;
end;
end;

constructor Tproga.Init;
var
R: TRect;
I: Integer;
FileName: PathStr;
begin
MaxHeapSize := HeapSize;
inherited Init;
RegisterObjects;
RegisterViews;
RegisterMenus;
RegisterDialogs;
RegisterApp;
RegisterEditors;
GetExtent(R);
R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
Clock := New(PClockView, Init(R));
Insert(Clock);
GetExtent(R);
Dec(R.B.X);
R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
Heap := New(PHeapView, Init(R));
Insert(Heap);
DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste, cmClear,
cmUndo, cmFind, cmReplace, cmSearchAgain, cmCloseAll]);
EditorDialog := DoEditDialog;
ClipWindow := OpenEditor('', False);
if ClipWindow <> nil then
begin
Clipboard := ClipWindow^.Editor;
Clipboard^.CanUndo := False;
end;
for I := 1 to ParamCount do
begin
FileName := ParamStr(I);
if FileName[Length(FileName)] = '\' then
FileName := FileName + '*.*';
if (Pos('?', FileName) = 0) and (Pos('*', FileName) = 0) then
OpenEditor(FExpand(FileName), True)
else FileOpen(FileName);
end;
end;

function Tproga.OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
var
P: PView;
R: TRect;
begin
DeskTop^.GetExtent(R);
P := Application^.ValidView(New(PEditWindow,
Init(R, FileName, wnNoNumber)));
if not Visible then P^.Hide;
DeskTop^.Insert(P);
OpenEditor := PEditWindow(P);
end;

procedure Tproga.FileOpen(WildCard: PathStr);
var
FileName: FNameStr;
begin
FileName := '*.*';
if ExecuteDialog(New(PFileDialog, Init(WildCard, 'Open a file',
'~N~ame', fdOpenButton + fdHelpButton, 100)), @FileName) <> cmCancel then
OpenEditor(FileName, True);
end;

procedure Tproga.GetEvent(var Event: TEvent);
var
W: PWindow;
begin
inherited GetEvent(Event);
case Event.What of
evCommand:;
evMouseDown:
if Event.Buttons <> 1 then Event.What := evNothing;
end;
end;
procedure Tproga.HandleEvent(var Event: TEvent);
procedure ChangeDir;
var
D: PChDirDialog;
begin
D := New(PChDirDialog, Init(cdNormal + cdHelpButton, 101));
ExecuteDialog(D, nil);
end;

procedure About;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 40, 11);
D := New(PDialog, Init(R, 'About'));
with D^ do
begin
Options := Options or ofCentered;
R.Grow(-1, -1);
Dec(R.B.Y, 3);
Insert(New(PStaticText, Init(R,
#13 +
^C'Text Editor'#13 +
#13 +
^C''#13 +
#13 +
^C'VTAU internation')));
R.Assign(15, 8, 25, 10);
Insert(New(PButton, Init(R, 'O~K', cmOk, bfDefault)));
end;
if ValidView(D) <> nil then
begin
Desktop^.ExecView(D);
Dispose(D, Done);
end;
end;

procedure FileNew;
begin
OpenEditor('', True);
end;

procedure ShowClip;
begin
ClipWindow^.Select;
ClipWindow^.Show;
end;

begin
inherited HandleEvent(Event);
case Event.What of
evCommand:
begin
case Event.Command of
cmOpen: FileOpen('*.*');
cmNew: FileNew;
cmShowClip: ShowClip;
cmChangeDir: ChangeDir;
cmAbout: About;
else
Exit;
end;
ClearEvent(Event);
end;
end;
end;

procedure Tproga.InitMenuBar;
var
R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y+1;
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~'#240'~', hcnocontext, NewMenu(
NewItem('~A~bout', '', kbNoKey, cmAbout, hcnocontext,nil)),
NewSubMenu('~F~ile', hcnocontext, NewMenu(
StdFileMenuItems(nil)),
NewSubMenu('~E~dit', hcnocontext, NewMenu(
StdEditMenuItems(
NewLine(
NewItem('~S~how clipboard', '', kbNoKey, cmShowClip, hcnocontext,
nil)))),
NewSubMenu('~S~earch', hcnocontext, NewMenu(
NewItem('~F~ind...', '', kbNoKey, cmFind, hcnocontext,
NewItem('~R~eplace...', '', kbNoKey, cmReplace, hcnocontext,
NewItem('~S~earch again', '', kbNoKey, cmSearchAgain, hcnocontext,
nil)))),
nil)))))));
end;

procedure Tproga.InitStatusLine;
var
R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PStatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~F3~ Open', kbF3, cmOpen,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
NewStatusKey('~F10~ Menu', kbF10, cmMenu,
nil)))),
nil)));
end;

procedure Tproga.OutOfMemory;
begin
MessageBox('Not enough memory.',
nil, mfError + mfOkButton);
end;

var
Proga: Tproga;

begin
proga.Init;
proga.Run;
proga.Done;
end.