Category : Pascal Source Code
Archive   : TEDIT.ZIP
Filename : MYEDIT.PAS

 
Output of file : MYEDIT.PAS contained in archive : TEDIT.ZIP
Unit MyEdit;
{$X+,S-,D-}

Interface
uses Dos, Objects, Drivers, Memory, Views, Menus, Dialogs,
MStdDlg, MsgBox, App, Editors;

var
ClipWindow: PEditWindow;

type
PEditorView = ^TEditorView;
TEditorView = object(TView)

end;


function ExecDialog(P: PDialog; Data: Pointer): Word;
function CreateFindDialog: PDialog;
function CreateReplaceDialog: PDialog;
function DoEditDialog(Dialog: Integer; Info: Pointer): Word;
function OpenEditor(FileName: PathStr; Visible: Boolean): PEditWindow;
procedure DeleteTheFile(FName: PathStr);

Implementation

function ExecDialog(P: PDialog; Data: Pointer): Word;
var
Result: Word;
begin
Result := cmCancel;
P := PDialog(Application^.ValidView(P));
if P <> nil then
begin
if Data <> nil then P^.SetData(Data^);
Result := DeskTop^.ExecView(P);
if (Result <> cmCancel) and (Data <> nil) then P^.GetData(Data^);
Dispose(P, Done);
end;
ExecDialog := Result;
end;

procedure DeleteTheFile(FName: PathStr);
var
EFile : File;
Begin
FName:=FName;
{$I-}
Assign(EFile, FName);
FileMode := 0;
Reset(EFile);
Close(EFile);
{$I+}
If (IOResult = 0) and (FName <> '') and
(cmOk = MessageBox('Delete File: '#13#10+Fname,
nil, mfConfirmation + mfOkCancel))
then {$I-}Erase(EFile){$I+}
Else
MessageBox('Can''t delete file: '#13#10+Fname, nil, mfError + mfOkButton);
End;

function CreateFindDialog: PDialog;
var
D: PDialog;
Control: PView;
R: TRect;
begin
R.Assign(0, 0, 37, 11);
D := New(PDialog, Init(R, 'Find'));
with D^ do
begin
Options := Options or ofCentered;

R.Assign(2, 3, 32, 4);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(1, 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(7, 5, 35, 7);
Insert(New(PCheckBoxes, Init(R,
NewSItem('~C~ase sensitive',
NewSItem('~W~hole words only', nil)))));

R.Assign(7, 8, 17, 10);
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, 39, 13);
D := New(PDialog, Init(R, 'Replace'));
with D^ do
begin
Options := Options or ofCentered;

R.Assign(2, 3, 34, 4);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(1, 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(2, 5, 34, 6);
Control := New(PInputLine, Init(R, 80));
Insert(Control);
R.Assign(1, 4, 11, 5);
Insert(New(PLabel, Init(R, '~N~ew Text', Control)));
R.Assign(34, 5, 37, 6);
Insert(New(PHistory, Init(R, PInputLine(Control), 11)));

R.Assign(1, 7, 36, 11);
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(27, 8, 37,10);
Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
R.Assign(27,10, 37, 12);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));

SelectNext(False);
end;
CreateReplaceDialog := D;
end;

function DoEditDialog(Dialog: Integer; Info: Pointer): Word;
var
R: TRect;
T: TPoint;
begin
case Dialog of
edOutOfMemory:
DoEditDialog := MessageBox('Not enough memory for this operation.',
nil, mfError + mfOkButton);
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 := ExecDialog(New(PFileDialog, Init('*.*',
'Save file as', '~N~ame', fdOkButton, 101)), Info);
edFind:
DoEditDialog := ExecDialog(CreateFindDialog, Info);
edSearchFailed:
DoEditDialog := MessageBox('Search string not found.',
nil, mfError + mfOkButton);
edReplace:
DoEditDialog := ExecDialog(CreateReplaceDialog, Info);
edReplacePrompt:
begin
{ Avoid placing the dialog on the same line as the cursor }
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 this occurence?',
nil, mfYesNoCancel + mfInformation);
end;
end;
end;

function OpenEditor(FileName: PathStr; Visible: Boolean): PEditWindow;
var
Pw : PEditWindow;
P: PView;
R: TRect;
Rt : TPoint;
begin
P := NIL;
pw := Nil;
DeskTop^.GetExtent(R);
R.B.Y := R.A.Y + 12;
R.B.X := R.A.X + 52;
pw := message(Desktop,evBroadcast,cmUpdateTitle,NIL);
If pw <> NIL then
Begin
Rt := pw^.origin;
If (pw^.Editor)^.Exposed then
Begin
If (Rt.Y >= 22) or (Rt.X >= 78) then
Begin
Rt.X := 1;
Rt.Y := 0;
End;
R.A.X := succ(Rt.X);
R.A.Y := succ(Rt.Y);
R.B.X := R.A.X + 52;
R.B.Y := R.A.Y + 12;
End;
End;
P := Application^.ValidView(New(PEditWindow,
Init(R, FileName, wnNoNumber)));
If P <> NIL then
Begin
if not Visible then P^.Hide;
DeskTop^.Insert(P);
pw := PEditWindow(p);
End;
OpenEditor := pw;
end;



End.


  3 Responses to “Category : Pascal Source Code
Archive   : TEDIT.ZIP
Filename : MYEDIT.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/