📄 mainform.pas
字号:
with ActivePasEditor do
if CanUndo then Undo;
EditorForm.Show;
end;
procedure TFMainForm.SearchGotoItemClick(Sender: TObject);
var
ret:boolean;
SLine:string;
CurLine,NewLine:integer;
begin
// 漂沥茄 青 锅龋肺 捞悼茄促.
ret:=InputQuery('Go to Line Number','Enter New Line Number:!',SLine);
if ret then
begin
CurLine:= 0;
ActivePasEditor.SetFocus;
NewLine:=StrToIntDef(SLine,CurLine);
ActivePasEditor.CaretY:= NewLine;
end;
end;
procedure TFMainForm.ViewObjectInspectorItemClick(Sender: TObject);
begin
ObjectInspector.Show;
end;
procedure TFMainForm.ViewNewEditorItemClick(Sender: TObject);
begin
with EditorForm.Create(self) do Show;
end;
procedure TFMainForm.ViewSpeedBarItemClick(Sender: TObject);
begin
SpeedBar.Visible:=not SpeedBar.Visible;
ViewSpeedBarItem.Checked:=not ViewSpeedBarItem.Checked;
end;
procedure TFMainForm.ViewPaletteItemClick(Sender: TObject);
begin
PageControl1.Visible:=not PageControl1.Visible;
ViewPaletteItem.Checked:=not ViewPaletteItem.Checked;
end;
procedure TFMainForm.FileNewFormItemClick(Sender: TObject);
begin
NewForm;
end;
procedure TFMainForm.SearchFindItemClick(Sender: TObject);
begin
// searching text
with TSearch.Create(self) do
begin
if IniFile.ReadBool('EDITOR','FindTextCursor',True) then
cbSearch.Text:= EditorForm.GetCursorWord;
if ShowModal <> mrCancel then
begin
SearchOption:= [];
SearchText:= cbSearch.Text;
if (chkWholeWord.Checked) then Include(SearchOption, mwsoWholeWord);
if (chkMatchCase.Checked) then Include(SearchOption, mwsoMatchCase);
if not chkDown.Checked then Include(SearchOption, mwsoBackwards);
if chkEntire.Checked then Include(SearchOption, mwsoEntireScope)
else Include(SearchOption, mwsoSelectedOnly);
SearchingText(SearchText,SearchOption);
end;
end;
end;
procedure TFMainForm.FindDialog1Find(Sender: TObject);
var
FindOption:TSearchTypes;
LinePos:integer;
begin
FindOption:=[];
if Sender=FindDialog1 then
begin
SearchText:=(Sender as TFindDialog).FindText;
if (frWholeWord in (Sender as TFindDialog).Options) then
Include(FindOption,stWholeWord);
if (frMatchCase in (Sender as TFindDialog).Options) then
Include(FindOption,stMatchCase);
end;
//// MatchPos:=ActivePasEditor.FindText(SearchText,EndPos,ActivePasEditor.GetTextlen,FindOption);
if MatchPos<>-1 then
begin
EndPos:=MatchPos+Length(SearchText);
SendMessage(ActivePasEditor.Handle,EM_SETSEL, MatchPos, EndPos);
LinePos:=SendMessage(ActivePasEditor.Handle,EM_LINEFROMCHAR, -1,0);
SendMessage(ActivePasEditor.Handle,EM_LINESCROLL, 0,LinePos-OldLine);
OldLine:=LinePos;
ActivePasEditor.SetFocus;
end
else
begin
MessageDlg('Search String Not Found!', mtInformation , [mbOK], 0);
EndPos:= 0;
end;
end;
procedure TFMainForm.SearchReplaceItemClick(Sender: TObject);
var
ReplaceText:string;
begin
// 巩磊凯 八祸 拳搁俊辑 可记阑 搬沥茄促.
with TReplace.Create(self) do
begin
cbSearch.Text:=Trim(ActivePasEditor.SelText);
if ShowModal <> mrCancel then
begin
SearchText:= cbSearch.Text;
ReplaceText:= cbReplace.Text;
SearchOption:= [mwsoReplace];
if (chkWholeWord.Checked) then Include(SearchOption, mwsoWholeWord);
if (chkMatchCase.Checked) then Include(SearchOption, mwsoMatchCase);
if not chkDown.Checked then Include(SearchOption, mwsoBackwards);
if chkPrompt.Checked then Include(SearchOption, mwsoPrompt);
if ReplaceAll then Include(SearchOption, mwsoReplaceAll);
// if chkCursor.Checked then SearchOption.Origin:= foCursor
// else SearchOption.Origin:= foEntire;
if chkEntire.Checked then Include(SearchOption, mwsoEntireScope)
else Include(SearchOption, mwsoSelectedOnly);
ReplacingText(SearchText,ReplaceText,SearchOption);
end;
end;
end;
procedure TFMainForm.ReplaceDialog1Replace(Sender: TObject);
begin
if (frReplaceAll in ReplaceDialog1.Options) then
begin
while MatchPos<>-1 do
begin
SendMessage(ActivePasEditor.Handle,EM_REPLACESEL, 0,Longint(PChar(ReplaceDialog1.ReplaceText)));
FindDialog1Find(ReplaceDialog1);
end;
end
else
begin
SendMessage(ActivePasEditor.Handle,EM_REPLACESEL, 0,Longint(PChar(ReplaceDialog1.ReplaceText)));
FindDialog1Find(ReplaceDialog1);
end;
end;
procedure TFMainForm.FileNewApplicationItemClick(Sender: TObject);
begin
NewProject;
end;
procedure TFMainForm.FileCloseAllItemClick(Sender: TObject);
var
I,SaveResp:Integer;
begin
if (ProjectInfo.ProjectState= psChange) then
begin
SaveResp := MessageDlg(Format('Save Changes to project %s?',
[ExtractFileName(ProjectInfo.ProjectName)]), mtWarning, mbYesNoCancel, 0);
if SaveResp = idYes then SaveProject(ProjectInfo.ProjectName);
end;
// Close all forms except mainform, object inspector
for I:= Screen.FormCount-1 downto 0 do
begin
if (not (Screen.Forms[I] is TFMainForm)) and (not (Screen.Forms[I] is TObjectInspector)) then
Screen.Forms[I].Close;
end;
// Close all editor's tab sheets
with EditorForm.PageControl1 do
for I:= PageCount - 1 downto 0 do
Pages[I].Free;
CloseProject;
end;
function TFMainForm.OpenProject(const ProjName:string):Boolean;
// Open Delphi Project
var
UnitName:string;
begin
Result:= True;
FileCloseAllItemClick(self);
ProjectInfo.ProjectName:= ProjName;
Caption:= Application.Title + ' - '+ProjName;
if FileExistOnPath(ProjName) then
begin
UnitName:= GetUnitName(ProjectInfo.MainForm);
OpenFile(UnitName);
SaveProjectHistory(ProjName);
end
else NewProject;
UpdateControl(psOpen);
end;
function TFMainForm.SaveProject(const ProjName:string):Boolean;
// Save project
var
I:Integer;
Path:string;
begin
Result:= False;
sbSaveAll.Enabled:= False;
for I:= 0 to ProjectInfo.UnitItems.Count - 1 do
begin
ActiveUnit:= ProjectInfo.UnitItems[I]; // 橇肺璃飘俊 乐绰 蜡聪飘甫 瞒肥肺 急琶茄促.
SaveFile(ActiveUnit);
end;
if (ProjectInfo.ProjectState = psNew) or (not FileExistOnPath(ProjName)) then
begin
SaveDialog1.FileName:= ExtractFileName(ProjName);
if SaveDialog1.Execute then
begin
ProjectInfo.ProjectSource.SaveToFile(SaveDialog1.FileName);
Path:= ExtractFilePath(SaveDialog1.FileName);
if (Path <> ProjectInfo.ProjectPath) then
ProjectInfo.ProjectPath:= Path;
ProjectInfo.ProjectName:= SaveDialog1.FileName;
end;
end
else ProjectInfo.ProjectSource.SaveToFile(ProjName);
ProjectInfo.ProjectState:= psSave;
if ProjName<>'' then Result:=True;
UpdateControl(psSave);
end;
procedure TFMainForm.sbSaveAllClick(Sender: TObject);
begin
SaveProject(ProjectInfo.ProjectName);
end;
procedure TFMainForm.SaveFile(const FileName:string);
var
SaveResp:integer;
SaveName:string;
LinkForm:TForm;
begin
SaveName:= FileName;
if FileName='Project1' then
begin
// new project
SaveDialog1.FileName:='Project1.dpr';
SaveDialog1.FilterIndex:=1;
if SaveDialog1.Execute then
begin
ProjectInfo.ProjectSource.SaveToFile(SaveDialog1.FileName);
ProjectInfo.ProjectPath:= ExtractFilePath(SaveDialog1.FileName);
end;
Exit;
end
else if ExtractFileExt(FileName)='.pas' then // save form file
begin
LinkForm:= GetLinkForm;
if LinkForm = nil then Exit;
SaveName:= FileName;
if (not FileExistOnPath(FileName)) then
begin
SaveDialog1.FileName := FileName;
SaveDialog1.FilterIndex:= 2;
if SaveDialog1.Execute then SaveName:= SaveDialog1.FileName;
end;
if (SaveName <> '') and (not IniFile.ReadBool('SYSTEM','UnitOnly', False)) then
SaveForm(LinkForm,Copy(SaveName,1,Length(SaveName)-4)+'.dfm');
end;
if (FileExistOnPath(SaveName)) and (FileName <> SaveName) then
begin
SaveResp := MessageDlg(Format('Same filename exists already!' +#10#13 +' Save changes to %s?',
[ExtractFileName(SaveName)]), mtWarning, mbYesNoCancel, 0);
case SaveResp of
idYes:
EditorForm.GetLinkEditor.Lines.SaveToFile(SaveName);
idNo: Exit;
idCancel: Abort;
end;
end
else if FileName <> SaveName then
begin
RenameUnit(FileName, SaveName);
EditorForm.GetLinkWithFile(FileName).Lines.SaveToFile(SaveName);
end
else EditorForm.GetLinkWithFile(FileName).Lines.SaveToFile(SaveName);
end;
procedure TFMainForm.sbToggleUnitClick(Sender: TObject);
// 汽苞 蜡聪飘甫 配臂窍搁辑 劝己拳茄促.
begin
ToggleFormAndUnit;
end;
procedure TFMainForm.NHideClick(Sender: TObject);
begin
SpeedBar.Visible:=False;
ViewSpeedBarItem.Checked:=False;
end;
procedure TFMainForm.ToolsOptionsItemClick(Sender: TObject);
begin
CreateShowModal(TOptions);
end;
procedure TFMainForm.ToolsImageEditItemClick(Sender: TObject);
var
ret:integer;
begin
Screen.Cursor:=crHourGlass;
ret:=WinExec(PChar(CompilerPath+'IMAGEDIT.EXE'),SW_SHOWNORMAL);
if ret<31 then
MessageDlg('Cannot Execute Program !', mtError, [mbOK], 0);
Screen.Cursor:=crDefault;
end;
procedure TFMainForm.ToolsDatabaseItemClick(Sender: TObject);
var
ret:integer;
begin
Screen.Cursor:=crHourGlass;
ret:=WinExec(PChar(DESKTOP+'DBD32.EXE'),SW_SHOWNORMAL);
if ret < 31 then
MessageDlg('Cannot Execute Program!', mtError, [mbOK], 0);
Screen.Cursor:=crDefault;
end;
procedure TFMainForm.ProjectOptionsItemClick(Sender: TObject);
begin
CreateShowModal(TProjOption);
end;
procedure TFMainForm.OpenForm(const FileName:string);
// Open form file
var
Input,Output:TMemoryStream;
Form:TForm;
I, Left, Top:Integer;
procedure DeleteEventHandler;
var
I:Integer;
begin
for I:= SourceList.Count - 1 downto 0 do
if Copy(Trim(SourceList[I]),1,2) = 'On' then
SourceList.Delete(I);
end;
begin
if not FileExistOnPath(FileName) then Exit;
Form:= ReadDFM(FileName);
if Form = nil then Exit;
ProxyDesigner.SetProxyForm(Form);
if ProxyDesigner <> nil then ProxyDesigner.GetComponentList;
ActiveUnit:= GetLinkUnit(FileName);
TProxyForm(Form).FileName:= ActiveUnit;
Form.Show;
ActiveForm:= Form;
ObjectInspector.SelectComponent:= nil;
for I:= 0 to Form.ComponentCount - 1 do
begin
if (Form.Components[I] is TMainMenu) then
ProxyDesigner.CreateMenuItemComponent(Form.Components[I]);
if not (Form.Components[I] is TControl) then
begin
// Set Left, Top property for non-visual component
Left:= LongRec(Form.Components[I].DesignInfo).Lo;
Top := LongRec(Form.Components[I].DesignInfo).Hi;
if not (Form.Components[I] is TMenuItem) then
ProxyDesigner.CreateWrapperComponent(Form.Components[I], Left, Top);
end;
end;
end;
procedure TFMainForm.OpenFormAsText(const FileName:string);
// Open from as text file
var
Input,Output:TMemoryStream;
begin
if not FileExistOnPath(FileName) then Exit;
Input:=TMemoryStream.Create;
Input.LoadFromFile(FileName);
Output:=TMemoryStream.Create;
ObjectResourceToText(Input,Output);
Output.Position:= 0;
Output.SaveToFile(FilePath+TempFile);
CreateSheetAsStream(FileName , Output);
ActivePasEditor.HighLighter:= EditorForm.PasSyn;
end;
procedure TFMainForm.NewProject;
begin
FileCloseAllItemClick(self);
with ProjectInfo do
begin
ProjectPath:= '';
ProjectName:= 'Project1.dpr';
end;
FileNewFormItemClick(self);
ProjectInfo.ProjectState:= psNew;
Caption:= Application.Title + ' - Project1';
end;
function TFMainForm.GetSelectComponent:TComponentClass;
var
SelectClass:TComponentClass;
begin
SelectClass:= nil;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -