unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, Grids, StdCtrls, Mask, Menus, ExtCtrls, Buttons, Spin,
  Outlook8, OleServer, ImgList, ToolWin;

type   Parametr=Record
       FontA:Tfont;
       FontB:Tfont;
       Left:integer;
       top:integer;
       width:integer;
       hight:integer;
       colorA:Tcolor;
       colorB:Tcolor;
       end;

  TForm1 = class(TForm)
    Status1: TStatusBar;
    Panel1: TPanel;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    Open1: TOpenDialog;
    save1: TSaveDialog;
    N4: TMenuItem;
    N5: TMenuItem;
    txt1: TMenuItem;
    RTF1: TMenuItem;
    RTF2: TMenuItem;
    N6: TMenuItem;
    C1: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    Memo1: TMemo;
    Open2: TOpenDialog;
    RichEdit1: TRichEdit;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    N15: TMenuItem;
    N16: TMenuItem;
    Font1: TFontDialog;
    N22: TMenuItem;
    N23: TMenuItem;
    N24: TMenuItem;
    Find1: TFindDialog;
    Replace1: TReplaceDialog;
    N30: TMenuItem;
    Panel2: TPanel;
    ListBox1: TListBox;
    Bevel1: TBevel;
    SpinButton1: TSpinButton;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    N9: TMenuItem;
    N19: TMenuItem;
    N32: TMenuItem;
    N34: TMenuItem;
    N25: TMenuItem;
    N26: TMenuItem;
    N27: TMenuItem;
    N28: TMenuItem;
    N35: TMenuItem;
    N36: TMenuItem;
    Status2: TStatusBar;
    BitBtn3: TBitBtn;
    Color2: TColorDialog;
    PopupMenu1: TPopupMenu;
    N17: TMenuItem;
    N20: TMenuItem;
    N21: TMenuItem;
    N29: TMenuItem;
    N37: TMenuItem;
    N38: TMenuItem;
    Font2: TFontDialog;
    Color1: TColorDialog;
    Chat1: TMenuItem;
    Timer1: TTimer;
    Timer2: TTimer;
    N39: TMenuItem;
    N40: TMenuItem;
    N41: TMenuItem;
    N42: TMenuItem;
    N43: TMenuItem;
    N44: TMenuItem;
    N45: TMenuItem;
    Panel3: TPanel;
    Edit1: TEdit;
    N47: TMenuItem;
    N31: TMenuItem;
    Tool1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    ImageList1: TImageList;
    N18: TMenuItem;
    N33: TMenuItem;
    N46: TMenuItem;
    N48: TMenuItem;
    N49: TMenuItem;
    N50: TMenuItem;
    N51: TMenuItem;
    N52: TMenuItem;
    N53: TMenuItem;
    N54: TMenuItem;
    s1: TMenuItem;
    ImageList2: TImageList;
    DostoWindows1: TMenuItem;
    procedure txt1Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure RTF2Click(Sender: TObject);
    procedure C1Click(Sender: TObject);
    procedure N19Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N22Click(Sender: TObject);
    procedure N24Click(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Find1Find(Sender: TObject);
    procedure N10Click(Sender: TObject);
    procedure N12Click(Sender: TObject);
    procedure N13Click(Sender: TObject);
    procedure N14Click(Sender: TObject);
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
    procedure ListBox1Click(Sender: TObject);
    procedure N9Click(Sender: TObject);
    procedure N30Click(Sender: TObject);
    procedure N26Click(Sender: TObject);
    procedure N27Click(Sender: TObject);
   procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure SpinButton1UpClick(Sender: TObject);
    procedure SpinButton1DownClick(Sender: TObject);
    procedure N35Click(Sender: TObject);
    procedure N38Click(Sender: TObject);
    procedure N28Click(Sender: TObject);
    procedure SAVE;
    procedure N37Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure N36Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure N17Click(Sender: TObject);
    procedure N20Click(Sender: TObject);
    procedure N21Click(Sender: TObject);
    procedure N40Click(Sender: TObject);
    procedure N41Click(Sender: TObject);
    procedure N42Click(Sender: TObject);
    procedure N44Click(Sender: TObject);
    procedure N45Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Chat1Click(Sender: TObject);
    procedure Panel3Resize(Sender: TObject);
    procedure N34Click(Sender: TObject);
    procedure N15Click(Sender: TObject);
    procedure N32Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N47Click(Sender: TObject);
    procedure save1TypeChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure N33Click(Sender: TObject);
    procedure N50Click(Sender: TObject);
    procedure N52Click(Sender: TObject);
    procedure N54Click(Sender: TObject);
    procedure s1Click(Sender: TObject);
    procedure DostoWindows1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const FF='Ваш рабочий файл ';
var
  Form1: TForm1;

implementation
uses unit2, unit3,Unit4,Unit5,Unit6,Unit7, Unit55,Unit88;
{$R *.DFM}

procedure tform1.SAVE;
begin
save1.Execute;
save1.Tag:=1;
memo1.Lines.SaveToFile(save1.filename);
end;

procedure TForm1.txt1Click(Sender: TObject);
var s:string;
    r:integer;
begin
n32.Enabled:=true; // Закрыть
with form1 do begin
c1.Enabled:=true;
n7.Enabled:=true;
n27.Enabled:=true;
richedit1.hide;
n9.Enabled:=true;

if memo1.Visible=true then
R:=Application.MessageBox('Cохранить изменения в тексте ?','Сообщение от EDITOR',
Mb_iconQuestion+mb_yesNoCancel);
Case r of
6: C1Click(nil);
7: begin memo1.Clear end;
2: exit;
end;

memo1.Clear;
if Open1.execute and FileExists(open1.fileName) then begin
memo1.Show;
memo1.Lines.LoadFromFile(open1.FileName);

form8.show;
form8.Panel1.Update;
form8.Label1.Update;
form8.Label2.Update;
listbox1.Items.LoadFromFile(open1.filename);
form8.Hide;
save1.filename:=open1.FileName;
s:=ff+Open1.FileName;
Status1.Panels[0].text:=s;//ff+'open1.filename;
end;
end;
end;

procedure TForm1.N4Click(Sender: TObject);
var result:integer;
begin

//===Сохранение когода нажимаем на новый===========

if (memo1.tag=1)or (memo1.Visible=true) then
result:=Application.MessageBox('Cохранить изменения в тексте?','Сообщение от EDITOR',
mb_IconQuestion+mb_yesnoCancel);//=idyes then c1click(nil);

case result of
6: c1click(nil);
2: Exit;
end;

status1.Panels[0].Text:=ff+'Безымянный.txt';

memo1.tag:=0;
//=======Конец====================================

n32.Enabled:=true; // Закрыть

c1.Enabled:=true;
n7.Enabled:=true;

n27.Enabled:=true;
memo1.Clear;
n9.Enabled:=true;
richedit1.Hide;

memo1.Clear;
Memo1.Show;
memo1.SetFocus;
end;

procedure TForm1.RTF2Click(Sender: TObject);
begin
n12.Enabled:=false;
n14.Enabled:=true;
n15.Enabled:=false;


n27.Enabled:=false;
memo1.hide;
richedit1.visible:=true;
richedit1.Clear;
n9.Enabled:=true;
open2.Execute;
richedit1.Lines.LoadFromFile(open2.FileName);
end;

procedure zacr;
begin
with form1 do begin
n12.Enabled:=false;
n14.Enabled:=false;
n15.Enabled:=false;

c1.Enabled:=false;
n7.Enabled:=false;
end;
if form1.richedit1.Visible=true then
 begin
 form1.richedit1.hide;
 exit;
 end;
if Application.MessageBox('Cохранить изменения в тексте','Закрытие',
Mb_iconQuestion+mb_yesNo)=idYes then form1.memo1.lines.SaveToFile(form1.save1.FileName);


if form1. memo1.Visible=true then form1.memo1.Visible:=false;
if form1.richedit1.Visible=true then form1.richedit1.Visible:=false;
form1.n9.Enabled:=false;
end;


procedure TForm1.Chat1Click(Sender: TObject);
begin

if   form1.Chat1.Checked=false then begin
chat1.checked:=true;
panel3.visible:=true;
edit1.SetFocus;
end else
begin
chat1.checked:=false;
panel3.visible:=false;
memo1.SetFocus;
end;

end;


procedure TForm1.C1Click(Sender: TObject);
begin
if save1.Tag=0 then save
else
memo1.Lines.SaveToFile(save1.filename);
end;

procedure TForm1.N19Click(Sender: TObject);
var  i:integer;
begin
with freport do begin
qrMemo1.Lines.Assign(form1.memo1.lines);
//for i:=0 to form1.memo1.lines.count-1 do
//qrMemo1.lines[i]:=form1.Memo1.Lines[i];
qrmemo1.font:=form1.Memo1.font;
QuickRep1.preview;
end;
end;

procedure TForm1.N7Click(Sender: TObject);
var s:string;
begin
save;
s:=ff+save1.filename;
status1.Panels[0].text:=s;
end;

procedure TForm1.N22Click(Sender: TObject);
begin
Find1.Execute;
end;

procedure TForm1.N24Click(Sender: TObject);
begin
Replace1.Execute;
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
memo1.Tag:=1;

n12.Enabled:=true;
n14.Enabled:=true;
n15.Enabled:=true;

status2.SimpleText:='Всего строк: '+inttostr(form1.memo1.Lines.count);

{memo1.ClearSelection
memo1.CopyToClipboard
memo1.CutToClipboard
memo1.Undo
memo1.ClearUndo
memo1.SelectAll}

end;

procedure TForm1.Find1Find(Sender: TObject);
var selpos:integer;
s:string;
begin

with Tfinddialog(sender) do
begin
selpos:=pos(findText,Memo1.lines.text);
if selpos>0 then
begin
memo1.SelStart:=selpos-1;
memo1.SelLength:=length(findText);
end else
//s:='Текст "'+FindText+'" не найден';
//Application.MessageBox(s,'j',mb_iconHand+mb_ok);
end;
end;
procedure TForm1.N10Click(Sender: TObject);
begin
memo1.Undo;
end;

procedure TForm1.N12Click(Sender: TObject);
begin

n10.Enabled:=true;
n13.Enabled:=true;

memo1.CutToClipboard;
end;

procedure TForm1.N13Click(Sender: TObject);
begin
n10.Enabled:=true;
memo1.PasteFromClipboard;
end;

procedure TForm1.N14Click(Sender: TObject);
begin
n10.Enabled:=true;
n13.Enabled:=true;
memo1.CopyToClipboard;
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
if memo1.Lines[memo1.Lines.Count-1]<>'' then
listbox1.Items.Add( memo1.Lines[memo1.Lines.Count-1]);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var k:integer;
begin


with memo1 do
begin
k:=pos(listbox1.items[form1.ListBox1.itemindex],text);
selstart:=k-1;
sellength:=length(listbox1.items[listbox1.itemindex]);
end;

end;

procedure TForm1.N9Click(Sender: TObject);
var s:string;
 f:textfile;
begin

c1.Enabled:=true; //Сохранить
n7.Enabled:=true; //сохранить как


n32.Enabled:=true;//"Закрыть"
memo1.show;

open1.Title:='Добавление файла';
if  Open1.Execute and FileExists(open1.fileName) then
BEGIN
AssignFile(F,open1.filename);
reset(f);
while not eof(f) do
begin
readln(f,s);
memo1.Lines.Add(s);
listbox1.Items.Add(s);
end;
open1.Title:='Открытие файла';

closefile(f);
end;
END;
procedure TForm1.N30Click(Sender: TObject);
begin
n10.Enabled:=true;
memo1.SelectAll;

end;

procedure TForm1.N26Click(Sender: TObject);
begin
Font1.Execute;
memo1.Font:=font1.Font;

end;

procedure TForm1.N27Click(Sender: TObject);
begin
if n27.Checked=True then n27.Checked:=false
else n27.Checked:=true;

if n27.Checked=true then  memo1.ScrollBars:=ssVertical
else memo1.ScrollBars:=ssBoth;

end;


procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
begin
form1.ListBox1.Clear;
listbox1.Items.Assign(memo1.lines);
//for i:=0 to memo1.Lines.Count-1 do
//listbox1.Items.Add(memo1.lines[i]);

end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
form1.ListBox1.Clear;
end;

procedure TForm1.SpinButton1UpClick(Sender: TObject);
begin
form1.ListBox1.ItemIndex:=0;

end;

procedure TForm1.SpinButton1DownClick(Sender: TObject);
begin
form1.ListBox1.ItemIndex:=listbox1.Items.Count-1;

end;

procedure TForm1.N35Click(Sender: TObject);
begin

if n35.Checked=false then begin
 n35.Checked:=true;
 panel2.Visible:=true;
 n39.Visible:=true;
 end
else  begin
n35.Checked:=false;
panel2.Visible:=false;
n39.Visible:=false;
end;



end;

procedure TForm1.N38Click(Sender: TObject);
begin
form1.color2.execute;
form1.ListBox1.Color:=color2.Color;
end;

procedure TForm1.N28Click(Sender: TObject);
begin
color1.Execute;
memo1.Color:=color1.Color;
end;

procedure TForm1.N37Click(Sender: TObject);
begin
font2.Execute;
listbox1.Font:=font2.Font;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
var i:integer;
begin
memo1.Clear;

{for i:=0 to listbox1.items.count-1 do
memo1.Lines.Add(listbox1.Items[i]); }
memo1.Clear;
memo1.Lines.assign(listbox1.items);
end;


procedure TForm1.FormCreate(Sender: TObject);
var result:integer;
begin

font1.Font:=memo1.Font;

bitbtn3.hint:='Заменяет содержимое основного'+#13+'поля содержимым редактора';
spinButton1.hint:='Перемещение по редактору:'+#13+'либо в начало, либо в конец';


c1.Enabled:=false; //Сохранить
n7.Enabled:=false; //сохранить как
n32.Enabled:=false;//Закрыть

n10.Enabled:=false; //Отменить
n12.Enabled:=false; //вырезать
//n13.Enabled:=false;//вставить
n14.Enabled:=false;//копировать
n15.Enabled:=false;//Удалить

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var k:TDateTime;
begin

k:=time;
status1.Panels[1].Text:=datetimetostr(k);

end;

procedure TForm1.N36Click(Sender: TObject);
begin


if n36.Checked=true then
begin n36.Checked:=False;
timer2.Enabled:=false;;
timer2.tag:=0;
end
else
Fsave.ShowModal;
//n36.Checked:=true;
//timer2.Enabled:=true;
//end;

end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
timer2.tag:=Timer2.Tag+1;
if timer2.tag=Fsave.SpinEdit1.Value*60
 then begin
timer2.Enabled:=false;
SAVE;
timer2.Tag:=0;
timer2.Enabled:=true;
end;
end;

procedure TForm1.N17Click(Sender: TObject);
begin
listbox1.Items.Delete(listbox1.itemindex);
end;

procedure TForm1.N20Click(Sender: TObject);
begin
form2.showModal;
end;

procedure TForm1.N21Click(Sender: TObject);
begin
form3.showmodal;

end;

procedure TForm1.N40Click(Sender: TObject);
begin
n17click(nil);
end;

procedure TForm1.N41Click(Sender: TObject);
begin
n20click(nil);
end;

procedure TForm1.N42Click(Sender: TObject);
begin
N21click(nil);
end;

procedure TForm1.N44Click(Sender: TObject);
begin
n37click(nil);
end;

procedure TForm1.N45Click(Sender: TObject);
begin
n28click(nil);
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then begin
memo1.Lines.add(edit1.text);
listbox1.Items.Add(edit1.text);
edit1.clear;
end;
end;

procedure TForm1.Panel3Resize(Sender: TObject);
begin
edit1.Width:=panel3.width-1;
end;

procedure TForm1.N34Click(Sender: TObject);
begin
close;
end;

procedure TForm1.N15Click(Sender: TObject);
begin
memo1.ClearSelection;
end;

procedure TForm1.N32Click(Sender: TObject);
var r:integer;
begin
R:=Application.MessageBox('Cохранить изменения в тексте ?','Сообщение от EDITOR',
Mb_iconQuestion+mb_yesNoCancel);
Case r of
6: C1Click(nil);
7: begin memo1.Clear end;
2: exit;
end;
memo1.hide;
n32.Enabled:=false;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var r:integer;
begin

if save1.Tag=0 then

if memo1.Visible=true then BEGIN

R:=Application.MessageBox('Cохранить изменения в тексте ?','Завершение программы',
Mb_iconQuestion+mb_yesNoCancel);
Case r of
6: C1Click(nil);
2: Action:=caNone;
end;

{fexit.ShowModal;
if Fexit.tag=3 then action:=caNone else action:=caFree;}

END;
end;

procedure TForm1.N47Click(Sender: TObject);
begin
color1.Execute;
memo1.Color:=color1.color;
listbox1.Color:=color1.Color;
edit1.color:=color1.Color;
end;

procedure TForm1.save1TypeChange(Sender: TObject);
begin

case Save1.FilterIndex of
1: save1.DefaultExt:='txt';
2: Begin save1.DefaultExt:='pas'; save1.FileName:='qqqq';end;
3: save1.DefaultExt:='dpr';
4: save1.DefaultExt:='cfg';
5: save1.DefaultExt:='bat';
end;

end;
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
N4click(nil);
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
txt1click(nil);
end;

procedure TForm1.ToolButton3Click(Sender: TObject);
begin
C1click(nil);
end;

procedure TForm1.ToolButton7Click(Sender: TObject);
begin
N9Click(nil);
end;

procedure TForm1.ToolButton8Click(Sender: TObject);
begin
N19click(nil);
end;

procedure TForm1.N33Click(Sender: TObject);
begin
if n33.Checked=True then begin
n33.Checked:=false;
tool1.Visible:=false;
end
else begin
 n33.Checked:=true;
tool1.Visible:=true;;
end;
end;

procedure TForm1.N50Click(Sender: TObject);
begin
Fabout.showModal;
end;

procedure TForm1.N52Click(Sender: TObject);
var i:integer;
begin
listbox1.Items.clear;
for i:=0 to memo1.Lines.Count-1 do
if memo1.Lines[i]<>'' then listbox1.Items.Add(memo1.lines[i]);

end;

procedure TForm1.N54Click(Sender: TObject);
begin
n52click(nil);

end;

procedure TForm1.s1Click(Sender: TObject);
var
    s1,ss:string;
    i,k,cod,col,d:integer;

begin
ListBox1.Clear;
col:=memo1.Lines.Count;//кол-во сторк в тексте
d:=col;//Счётчик. сколько осталось

//красивое оформление
Form5.show;
Form5.Panel1.Caption:='Ждите. Идёт преобразование текста...';
form5.Panel1.Update;
form5.Bevel1.Update;


form5.Label1.Caption:='Всего сторк:'+Inttostr(col);
form5.Label1.Update;

form5.G1.MinValue:=0;
form5.G1.MaxValue:=col-1;
form5.G1.Progress:=0;
//Преобразование символов

for i:=0 to memo1.lines.count-1 do
        Begin
        s1:=memo1.Lines[i];
        ss:='';
        form5.G1.Progress:=form5.G1.Progress+1;

                FOR K:=1 TO LENGTH(S1)DO
                BEGIN
                cod:=ord(s1[k]);
                CASE cod of
                169:S1[k]:='й'; 137:S1[K]:='Й';
                230:S1[k]:='ц'; 150:S1[K]:='Ц';
                227:S1[k]:='у'; 147:S1[K]:='У';
                170:S1[k]:='к'; 138:S1[K]:='К';
                165:S1[k]:='е'; 133:S1[K]:='Е';
                173:S1[k]:='н'; 141:S1[K]:='Н';
                163:S1[k]:='г'; 131:S1[K]:='Г';
                232:S1[k]:='ш'; 152:S1[K]:='Ш';
                233:S1[k]:='щ'; 153:S1[K]:='Щ';
                167:S1[k]:='з'; 135:S1[K]:='З';
                229:S1[k]:='х'; 149:S1[K]:='Х';
                234:S1[k]:='ъ'; 154:S1[K]:='Ъ';
                228:S1[k]:='ф'; 148:S1[K]:='Ф';
                235:S1[k]:='ы'; 155:S1[K]:='Ы';
                162:S1[k]:='в'; 130:S1[K]:='В';
                160:S1[k]:='а';
                175:S1[k]:='п'; 128:S1[K]:='А';
                224:S1[k]:='р'; 143:S1[K]:='П';
                174:S1[k]:='о'; 144:S1[K]:='Р';
                171:S1[k]:='л'; 142:S1[K]:='О';
                164:S1[k]:='д'; 139:S1[K]:='Л';
                166:S1[k]:='ж'; 132:S1[K]:='Д';
                237:S1[k]:='э'; 134:S1[K]:='Ж';
                239:S1[k]:='я'; 157:S1[K]:='Э';
                231:S1[k]:='ч'; 159:S1[K]:='Я';
                225:S1[k]:='с'; 151:S1[K]:='Ч';
                172:S1[k]:='м'; 145:S1[K]:='С';
                168:S1[k]:='и'; 140:S1[K]:='М';
                226:S1[k]:='т'; 136:S1[K]:='И';
                236:S1[k]:='ь'; 146:S1[K]:='Т';
                161:S1[k]:='б'; 156:S1[K]:='Ь';
                238:S1[k]:='ю'; 129:S1[K]:='Б';
                241:S1[k]:='ё'; 158:S1[K]:='Ю';
                                240:S1[K]:='Ё';
                END;
               ss:=ss+s1[k];
               END;
         ListBox1.Items.add(ss);
        End;
form5.Hide;
end;

procedure TForm1.DostoWindows1Click(Sender: TObject);
begin
s1click(nil);
end;


end.
