📄 unotepad.pas
字号:
//[RichEdit]
WriteBool('RichEdit', 'AutoWrap', AutoWrap);
WriteBool('RichEdit', 'AutoAlign', AutoAlign);
WriteBool('RichEdit', 'InsertLine', InsertLine);
WriteBool('RichEdit', 'FreshSelection', FreshSelection);
WriteInteger('RichEdit','TabWidth', TabWidth);
WriteInteger('RichEdit','ReadSpeed',ReadSpeed);
//[Font]
with RichEdit.Font do
begin
WriteString ('Font','Name', Name);
WriteInteger('Font','Country',CharSet);
WriteInteger('Font','Size', Size);
WriteInteger('Font','Height', Height);
end;
//[Color]
WriteInteger('Color','ForeColor',RichEdit.Font.Color);
WriteInteger('Color','BackColor',RichEdit.Color);
WriteInteger('Color','DefForeColor',DefForeColor);
WriteInteger('Color','DefBackColor',DefBackColor);
//[DateTime]
WriteInteger('DateTime','DateMode',DateFormat);
WriteInteger('DateTime','TimeMode',TimeFormat);
WriteInteger('DateTime','DayMode', DayFormat);
//[User]
WriteString('User','UserName',UserName);
WriteString('User','UserCompany',UserCompany);
WriteString('User','UserAddress',UserAddress);
//[Macro]
WriteInteger('Macro','Number',MacroNumber);
for i:=1 to MacroNumber do
WriteString('Macro','Macro'+IntToStr(i),MacroString[i]);
for i:=1 to MacroNumber do
WriteString('Macro','ShortKey'+IntToStr(i),ShortCutToText(MacroShortCut[i]));
//[Other]
WriteBool('Other','CreatBak', CreatBak);
WriteBool('Other','AddToFold',AddToFold);
WriteBool ('Other','LinkMe', LikeMe);
end;
end;
//------------------------------------------------------------------------------
//--------------------------------从Ini文件中读取数据---------------------------
//------------------------------------------------------------------------------
{procedure TNotePadForm.ReadIni(Sender: TObject);
const
IniFileName='NotePad.ini'; //Ini文件名=WinPath+'NotePad.ini'
var
IniFile:TIniFile;
I :Integer;
begin
IniFile:=TIniFile.Create(ExtractFilePath(Application.ExeName)+IniFileName);
with IniFile do
begin
//[Window]
SaveSize:=ReadBool('Window','SaveSize',True);
if SaveSize then
begin
Width :=ReadInteger('Window','Width', Width);
Height:=ReadInteger('Window','Height', Height);
end;
SavePos:=ReadBool('Window','SavePos',True);
if SavePos then
begin
Top :=ReadInteger('Window','Top', (Screen.Height-Height) div 2);
Left:=ReadInteger('Window','Left',(Screen.Width-Width) div 2);
end;
AutoMaxSize:=ReadBool('Window','AutoMaxSize',False);
if AutoMaxSize then
WindowState:=wsMaximized;
//[File]
for i:=1 to 6 do
FileList[i]:=ReadString('File','File'+IntToStr(i),'');
UpdateFileMenu(0);
//[View]
ShowFullPath:= ReadBool('View', 'ShowFullPath', False);
Toolbar1.Visible:=ReadBool('View', 'ShowTool1', True);
Toolbar2.Visible:=ReadBool('View', 'ShowTool2', True);
Statusbar.Visible:=ReadBool('View', 'ShowStatus', True);
MenuWindowShowToolbar.Checked:= Toolbar1.Visible;
MenuWindowShowStatusbar.Checked:= Statusbar.Visible;
ShowAddMenu:=ReadBool('View', 'ShowAddMenu', True);
if ShowAddMenu=False then
MenuFileShowAddMenuClick(Sender);
ShowIcon :=ReadBool('View', 'ShowIcon', True);
if ShowIcon=False then
MainMenu.Images:=NIL;
//[Editor]
AutoWrap :=ReadBool('Editor', 'AutoWrap', True);
AutoAlign :=ReadBool('Editor', 'AutoAlign', False);
InsertLine:=ReadBool('Editor', 'InsertLine', False);
FreshSelection:=ReadBool('Editor', 'FreshSelection', False);
TabWidth :=ReadInteger('Editor','TabWidth', 8);
ReadSpeed :=ReadInteger('Editor','ReadSpeed', 2000);
//[Font]
with EditorFont do
begin
EditorFont:=TFont.Create;
Name :=ReadString ('Font','Name', 'System');
CharSet :=ReadInteger('Font','Country',GB2312_CHARSET);
Size :=ReadInteger('Font','Size', 12);
Height :=ReadInteger('Font','Height', -16);
end;
//[Color]
RichEdit.Font.Color:=ReadInteger('Color','ForeColor',clWindowText);
RichEdit.Color:=ReadInteger('Color','BackColor',clWindow);
DefForeColor:=ReadInteger('Color','DefForeColor',clRed);
DefBackColor:=ReadInteger('Color','DefBackColor',clWindow);
//[DateTime]
DateFormat:=ReadInteger('DateTime','DateMode',0);
TimeFormat:=ReadInteger('DateTime','TimeMode',0);
DayFormat :=ReadInteger('DateTime','DayMode', 0);
//[User]
UserName :=ReadString('User','UserName', '');
UserCompany:=ReadString('User','UserCompany','');
UserAddress:=ReadString('User','UserAddress','');
//[Macro]
MacroNumber:=ReadInteger('Macro','Number',0);
for i:=1 to MacroNumber do
begin
MacroString[i]:=ReadString('Macro','Macro'+IntToStr(i),'');
MacroShortCut[i]:=TextToShortCut(ReadString('Macro','ShortKey'+IntToStr(i),''));
end;
//[Other]
CreatBak :=ReadBool('Other','CreatBak', False);
AddToFold:=ReadBool('Other','AddToFold',True);
LikeMe :=ReadBool('Other','LinkMe', False);
end;
end;
//------------------------------------------------------------------------------
//--------------------------------向INI文件中写入数据---------------------------
//------------------------------------------------------------------------------
procedure TNotePadForm.WriteIni(Sender: TObject);
const
IniFileName='NotePad.ini';
var
IniFile :TIniFile;
i :integer;
begin
IniFile:=TIniFile.Create(ExtractFilePath(Application.ExeName)+IniFileName);
with IniFile do
begin
//[Window]
WriteBool('Window','SaveSize',SaveSize);
if (SaveSize) and (WindowState=wsNormal) then
begin
WriteInteger('Window','Width', Width);
WriteInteger('Window','Height',Height);
end;
WriteBool('Window','SavePos',SavePos);
if SavePos then
begin
WriteInteger('Window','Left', Left);
WriteInteger('Window','Top', Top);
end;
WriteBool('Window','AutoMaxSize',AutoMaxSize);
//WriteInteger('Window','State', ord(WindowState));
//[File]
for i:=1 to 6 do
WriteString('File','File'+IntToStr(i),FileList[i]);
//[View]
WriteBool('View','ShowFullPath',ShowFullPath);
WriteBool('View','ShowTool1', Toolbar1.Visible);
WriteBool('View','ShowTool2', Toolbar2.Visible);
WriteBool('View','ShowStatus', Statusbar.Visible);
WriteBool('View','ShowAddMenu', ShowAddMenu);
WriteBool('View','ShowIcon', ShowIcon);
//[Editor]
WriteBool('Editor', 'AutoWrap', AutoWrap);
WriteBool('Editor', 'AutoAlign', AutoAlign);
WriteBool('Editor', 'InsertLine', InsertLine);
WriteBool('Editor', 'FreshSelection', FreshSelection);
WriteInteger('Editor','TabWidth', TabWidth);
WriteInteger('Editor','ReadSpeed',ReadSpeed);
//[Font]
with RichEdit.Font do
begin
WriteString ('Font','Name', Name);
WriteInteger('Font','Country',CharSet);
WriteInteger('Font','Size', Size);
WriteInteger('Font','Height', Height);
end;
//[Color]
WriteInteger('Color','ForeColor',RichEdit.Font.Color);
WriteInteger('Color','BackColor',RichEdit.Color);
WriteInteger('Color','DefForeColor',DefForeColor);
WriteInteger('Color','DefBackColor',DefBackColor);
//[DateTime]
WriteInteger('DateTime','DateMode',DateFormat);
WriteInteger('DateTime','TimeMode',TimeFormat);
WriteInteger('DateTime','DayMode', DayFormat);
//[User]
WriteString('User','UserName',UserName);
WriteString('User','UserCompany',UserCompany);
WriteString('User','UserAddress',UserAddress);
//[Macro]
WriteInteger('Macro','Number',MacroNumber);
for i:=1 to MacroNumber do
WriteString('Macro','Macro'+IntToStr(i),MacroString[i]);
for i:=1 to MacroNumber do
WriteString('Macro','ShortKey'+IntToStr(i),ShortCutToText(MacroShortCut[i]));
//[Other]
WriteBool('Other','CreatBak', CreatBak);
WriteBool('Other','AddToFold',AddToFold);
WriteBool ('Other','LinkMe', LikeMe);
end;
end; }
//------------------------------------------------------------------------------
procedure TNotePadForm.OpenFile(Sender: TObject; FName: String);
begin
if CheckFileSave(Sender)=IDCANCEL then
Exit;
if FName='' then
begin
OpenDialog.Filter:=DefaultFilter;
OpenDialog.InitialDir:=ExtractFilePath(FileName);
OpenDialog.FileName:='';
if OpenDialog.Execute then
begin
if FileName=OpenDialog.FileName then
begin
Application.MessageBox(Pchar('文件“'+FileName+'”已经打开。'),'错误',MB_ICONEXCLAMATION);
exit;
end
else
FileName:=OpenDialog.FileName;
end
else
Exit;
end
else
if not FileExists(FName) then
begin
Application.MessageBox('此文件不存在!','打开',MB_ICONEXCLAMATION);
Exit;
end
else if FName=FileName then
begin
Application.MessageBox(Pchar('文件“'+FileName+'”已经打开。'),'错误',MB_ICONEXCLAMATION);
Exit;
end
else
FileName:=FName;
try
RichEdit.PlainText:=not (UpperCase(ExtractFileExt(FileName))='.RTF');
Statusbar.Panels[0].Text:='正在读取文件,请稍候……';
Screen.Cursor:=crHourGlass;
Refresh;
RichEdit.Lines.LoadFromFile(FileName);
finally
Screen.Cursor:=crDefault;
Statusbar.Panels[0].Text:='文件读取完毕';
UpdateCaption(Sender);
UpdateFileMenu(1);
//if CreatBak then
// CopyFile(Pchar(FileName),Pchar(FileName+'.bak'),False);
end;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.SaveFile(Sender: TObject; Style: Integer);
var
I:Integer;
TempName:String;
begin
SaveDialog.Filter:=DefaultFilter;
SaveDialog.FileName:=FileName;
TempName:=FileName;
if FileName='' then
begin
SaveDialog.Title:='保存';
SaveDialog.FileName:=Trim(RichEdit.Lines[0]);
if SaveDialog.FileName<>'' then
for I:=1 to Length(SaveDialog.FileName) do
if SaveDialog.FileName[i] in ['/','\','*','?','<','>','|'] then
begin
SaveDialog.FileName:='*.txt';
break;
end;
if SaveDialog.Execute then
try
FileName:=SaveDialog.FileName;
RichEdit.Lines.SaveToFile(FileName);
UpdateCaption(Sender);
except
Application.MessageBox(Pchar(Application.Title+'无法保存文件“'+FileName+'”。'),'错误',MB_ICONEXCLAMATION);
end;
end
else
begin
if Style=1 then //另存为...
begin
SaveDialog.Title:='另存为';
if SaveDialog.Execute then
tempname:=SaveDialog.FileName;
end;
try
RichEdit.Lines.SaveToFile(TempName);
RichEdit.Modified:=False;
except
Application.MessageBox(Pchar(Application.Title+'无法保存文件“'+FileName+'”。'),'错误',MB_ICONEXCLAMATION);
end;
end;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.UpdateCaption(Sender: TObject);
begin
if Length(FileName)<>0 then
// if ShowFullPath then
// Caption:=Application.Title+' - '+FileName
// else
Caption:=Application.Title+' - '+ExtractFileName(FileName)
else
Caption:=Application.Title+' - 未命名';
RichEdit.Modified:=False;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.UpdateFileMenu(Style :Integer);
const
MFIndex=12;
var
I,J:Integer;
begin
if Style=1 then
begin
for J:=1 to 5 do
if FileList[J]=FileName then
break;
if J=6 then J:=5;
for I:=J downto 2 do
FileList[I]:=FileList[I-1];
FileList[1]:=FileName;
end;
with MenuFile do
for I:=MFIndex to MFIndex+4 do //File1's index to File6's index
begin
Items[I].Caption:='&'+IntToStr(I-MFIndex+1)+' '+ExtractFileName(FileList[I-MFIndex+1]);
Items[I].Visible:=FileList[I-MFIndex+1]<>'';
end;
MenuFileLine5.Visible:=MenuFileListFile1.Visible;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.UpdateKeyStatus;
begin
with StatusBar do
begin
if InsertMode then
Panels[3].Text:='插入'
else
Panels[3].Text:='改写';
if (GetKeyState(VK_CAPITAL) and 1)=1 then
Panels[4].Text:='大写'
else
Panels[4].Text:='小写';
if (GetKeyState(VK_NUMLOCK) and 1)=1 then
Panels[5].Text:='NUMLOCK'
else
Panels[5].Text:='NoNUMLOCK';
end;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.FindDialogFind(Sender: TObject);
var
SearchType:TSearchTypes;
begin
with FindDialog do
begin
if frMatchCase in Options then
SearchType:=SearchType+[stMatchCase];
if frWholeWord in Options then
SearchType:=SearchType+[stWholeWord];
PerformFind(Sender,FindText,SearchType);
end;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.ChangeFontSize(Sender: TObject;const Style: integer);
begin
with RichEdit.Font do
begin
if Pitch<>fpFixed then
begin
if Size>1 then
//Font.Size:=Font.Size+Style;
//SelStart:=SelStart;
end
else
Application.MessageBox(Pchar('正在使用的字体('+Font.Name+')是固定字体,不能改变大小!'),'字体',MB_ICONEXCLAMATION);
end;
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function TNotePadForm.CheckFileSave(Sender: TObject):Integer;
var
Response:Integer;
TempName:String;
begin
Response:=-1;
if Length(FileName)<>0 then
TempName:=FileName
else
TempName:='未命名';
if RichEdit.Modified then
Response:=Application.MessageBox(Pchar('文件“'+TempName+
'”的内容已经改变。'+NewLine+'要保存该文件吗?'),
Pchar(Application.Title),MB_ICONQUESTION+MB_YESNOCANCEL+MB_DEFBUTTON1);
if Response=IDYES then
SaveFile(Sender,0);
Result:=Response;
end;
//------------------------------------------------------------------------------
//-------------------------------显示文件菜单项---------------------------------
//------------------------------------------------------------------------------
procedure TNotePadForm.MenuFileShowAddMenuClick(Sender: TObject);
var
I,J:Integer;
begin
with MenuFileShowAddMenu do
Checked:=not Checked;
with MainMenu do
for I:=0 to Items.Count-1 do
if Items[I].tag=1 then
Items[I].Visible:=not Items[I].Visible
else
for J:=0 to Items[I].count-1 do
if Items[I].items[J].tag>=1 then
Items[I].Items[J].Visible:= not Items[I].Items[J].Visible;
UpdateFileMenu(0);
end;
//------------------------------------------------------------------------------
//---------------------------------时间、日期字符转换---------------------------
//------------------------------------------------------------------------------
function TNotePadForm.IntToChi(N:word):String;
var
I:Integer;
T:String;
begin
Result:='';
T:=IntToStr(N);
for I:=1 to Length(T) do
begin
if (I=1) and (T[1]='1') then continue;
if I=2 then
begin
Result:=Result+Number[10];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -