📄 ebarmegademomain.pas
字号:
function TEBarMegaDemoMainForm.AskSaveFile: Boolean;
var
Res: Integer;
begin
Result := True;
if Editor.Modified then
begin
Res := Application.MessageBox(PChar(Format('Do you want to save the changes you made to "%s"?',
[FFileName])), PChar(FFileName), MB_ICONQUESTION or MB_YESNOCANCEL);
if Res = ID_CANCEL then
Result := False;
if Res = ID_YES then
Result := SaveFile(False);
end;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonCloseClick(Sender: TObject);
begin
if not AskSaveFile then exit;
Editor.Lines.Clear;
ShowItems(False);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonOpenClick(Sender: TObject);
begin
if not AskSaveFile then exit;
OpenDialog.FileName := '';
if OpenDialog.Execute then
begin
FFileName := OpenDialog.FileName;
Editor.Lines.LoadFromFile(FFileName);
SetModified(False);
ShowItems(True);
end;
end;
procedure TEBarMegaDemoMainForm.EditorChange(Sender: TObject);
begin
if Editor = nil then Exit;
Editor.OnSelectionChange(Editor);
SetModified(Editor.Modified);
dxBarButtonUndo.Caption := '&Undo';
dxBarButtonUndo.Enabled := SendMessage(Editor.Handle, EM_CANUNDO, 0, 0) <> 0;
end;
procedure TEBarMegaDemoMainForm.EditorSelectionChange(Sender: TObject);
var Col, Row : integer;
begin
Row := SendMessage(Editor.Handle, EM_LINEFROMCHAR, Editor.SelStart, 0);
Col := Editor.SelStart - SendMessage(Editor.Handle, EM_LINEINDEX, Row, 0);
with Editor, SelAttributes do
begin
FUpdating := True;
try
dxBSPosition.Caption :=
Format('Line: %3d Col: %3d', [1 + Row, 1 + Col]);
dxBarButtonCopy.Enabled := SelLength > 0;
dxBarButtonCut.Enabled := dxBarButtonCopy.Enabled;
dxBarButtonPaste.Enabled := ((SendMessage(Editor.Handle, EM_CANPASTE, 0, 0) <> 0) and dxBarButtonSave.Enabled);
dxBarButtonClear.Enabled := dxBarButtonCopy.Enabled;
dxBarComboFontSize.Text := IntToStr(Size);
dxBarComboFontName.Text := Name;
dxBarButtonBold.Down := fsBold in Style;
dxBarButtonItalic.Down := fsItalic in Style;
dxBarButtonUnderline.Down := fsUnderline in Style;
dxBarButtonBullets.Down := Boolean(Paragraph.Numbering);
case Ord(Paragraph.Alignment) of
0: dxBarButtonAlignLeft.Down := True;
1: dxBarButtonAlignRight.Down := True;
2: dxBarButtonCenter.Down := True;
end;
dxBarButtonURLDetection.Down := Boolean(SendMessage(Editor.Handle, EM_GETAUTOURLDETECT, 0, 0));
dxBarComboFontColor.Color := Editor.SelAttributes.Color;
finally
FUpdating := False;
end;
end;
end;
function TEBarMegaDemoMainForm.SaveFile(ASaveAs: Boolean): Boolean;
begin
if ASaveAs or (FFileName = '') then
begin
SaveDialog.FileName := FFileName;
Result := SaveDialog.Execute;
if not Result then Exit;
FFileName := SaveDialog.FileName;
end;
Editor.Lines.SaveToFile(FFileName);
SetModified(False);
Result := True;
end;
procedure TEBarMegaDemoMainForm.SetModified(Value: Boolean);
begin
Editor.Modified := Value;
if Value then
dxBSStatus.Caption := 'Modified'
else
dxBSStatus.Caption := '';
if FFileName <> '' then
dxBarButtonSave.Enabled := Value;
end;
procedure TEBarMegaDemoMainForm.ShowItems(AShow: Boolean);
var
AVisible: TdxBarItemVisible;
begin
if not AShow then
begin
dxBSStatus.Caption := '';
dxBSPosition.Caption := '';
end;
BarManager.Groups[0].Enabled := AShow;
if AShow then AVisible := ivAlways
else AVisible := ivInCustomizing;
dxBarSubItemEdit.Visible := AVisible;
dxBarSubItemFormat.Visible := AVisible;
PanelRE.Visible := AShow;
Editor.Repaint;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonExitClick(Sender: TObject);
begin
Close;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonSaveClick(Sender: TObject);
begin
SaveFile(False);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonSaveAsClick(Sender: TObject);
begin
SaveFile(True);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonPrintClick(Sender: TObject);
begin
if PrintDialog.Execute then
Editor.Print(FFileName);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonUndoClick(Sender: TObject);
begin
SendMessage(Editor.Handle, EM_UNDO, 0, 0);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonCutClick(Sender: TObject);
begin
Editor.CutToClipboard;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonCopyClick(Sender: TObject);
begin
Editor.CopyToClipboard;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonPasteClick(Sender: TObject);
begin
Editor.PasteFromClipboard;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonClearClick(Sender: TObject);
begin
Editor.ClearSelection;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonSelectAllClick(Sender: TObject);
begin
Editor.SelectAll;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonFindClick(Sender: TObject);
begin
Editor.SelLength := 0;
FindDialog.Execute;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonReplaceClick(Sender: TObject);
begin
Editor.SelLength := 0;
ReplaceDialog.Execute;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonFontClick(Sender: TObject);
begin
FontDialog.Font.Assign(Editor.SelAttributes);
if FontDialog.Execute then
Editor.SelAttributes.Assign(FontDialog.Font);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonBulletsClick(Sender: TObject);
begin
Editor.Paragraph.Numbering := TNumberingStyle(dxBarButtonBullets.Down);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonProtectedClick(Sender: TObject);
begin
Editor.SelAttributes.Protected := not Editor.SelAttributes.Protected;
end;
procedure TEBarMegaDemoMainForm.dxBarComboFontColorChange(Sender: TObject);
begin
if not FUpdating then
Editor.SelAttributes.Color := dxBarComboFontColor.Color;
end;
procedure TEBarMegaDemoMainForm.dxBarComboFontColorClick(Sender: TObject);
begin
FontDialog.Font.Assign(Editor.SelAttributes);
if FontDialog.Execute then
Editor.SelAttributes.Assign(FontDialog.Font);
end;
procedure TEBarMegaDemoMainForm.dxBarComboHighlightClick(Sender: TObject);
begin
FontDialog.Font.Assign(Editor.SelAttributes);
if FontDialog.Execute then
Editor.SelAttributes.Assign(FontDialog.Font);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonURLDetectionClick(Sender: TObject);
var
URLDetection : Boolean;
begin
URLdetection := Boolean(SendMessage(Editor.Handle, EM_GETAUTOURLDETECT, 0, 0));
URLdetection := not URLdetection;
SendMessage(Editor.Handle, EM_AUTOURLDETECT, Longint(URLdetection), 0);
end;
procedure TEBarMegaDemoMainForm.dxBarComboFontNameChange(Sender: TObject);
begin
if not FUpdating then
Editor.SelAttributes.Name := dxBarComboFontName.Text;
end;
procedure TEBarMegaDemoMainForm.dxBarComboFontNameClick(Sender: TObject);
begin
FontDialog.Font.Assign(Editor.SelAttributes);
if FontDialog.Execute then
Editor.SelAttributes.Assign(FontDialog.Font);
end;
procedure TEBarMegaDemoMainForm.dxBarComboFontSizeChange(Sender: TObject);
begin
if not FUpdating then
Editor.SelAttributes.Size := StrToInt(dxBarComboFontSize.Text);
end;
procedure TEBarMegaDemoMainForm.dxBarComboFontSizeClick(Sender: TObject);
begin
FontDialog.Font.Assign(Editor.SelAttributes);
if FontDialog.Execute then
Editor.SelAttributes.Assign(FontDialog.Font);
end;
procedure TEBarMegaDemoMainForm.dxBarButtonBoldClick(Sender: TObject);
begin
with Editor.SelAttributes do
if dxBarButtonBold.Down then
Style := Style + [fsBold]
else
Style := Style - [fsBold];
end;
procedure TEBarMegaDemoMainForm.dxBarButtonItalicClick(Sender: TObject);
begin
with Editor.SelAttributes do
if dxBarButtonItalic.Down then
Style := Style + [fsItalic]
else
Style := Style - [fsItalic];
end;
procedure TEBarMegaDemoMainForm.dxBarButtonUnderlineClick(Sender: TObject);
begin
with Editor.SelAttributes do
if dxBarButtonUnderline.Down then
Style := Style + [fsUnderline]
else
Style := Style - [fsUnderline];
end;
procedure TEBarMegaDemoMainForm.dxBarButtonAlignLeftClick(Sender: TObject);
begin
if TdxBarLargeButton(Sender).Down then
Editor.Paragraph.Alignment := TAlignment(0)
else
Editor.Paragraph.Alignment := taLeftJustify;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonCenterClick(Sender: TObject);
begin
if TdxBarLargeButton(Sender).Down then
Editor.Paragraph.Alignment := TAlignment(2)
else
Editor.Paragraph.Alignment := taLeftJustify;
end;
procedure TEBarMegaDemoMainForm.dxBarButtonAlignRightClick(Sender: TObject);
begin
if TdxBarLargeButton(Sender).Down then
Editor.Paragraph.Alignment := TAlignment(1)
else
Editor.Paragraph.Alignment := taLeftJustify;
end;
procedure TEBarMegaDemoMainForm.dxAddressComboKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
dxAddressCombo.Items.Insert(0, FAddress);
end;
procedure TEBarMegaDemoMainForm.dxAddressComboDrawItem(Sender: TdxBarCustomCombo;
AIndex: Integer; ARect: TRect; AState: TOwnerDrawState);
var
RectText: TRect;
begin
with Sender,Canvas,ARect do
begin
Brush.Color := clWindow;
FillRect(ARect);
RectText := ARect;
Inc(RectText.Left, 16);
if AIndex >= 0 then
RectText.Right := RectText.Left + TextWidth(Items[AIndex]) + 4;
if odSelected in AState then
begin
Brush.Color := clHighlight;
FillRect(RectText);
end;
if AIndex >= 0 then
begin
Draw(Left + 1, Top + 2, Image.Picture.Bitmap);
TextOut(RectText.Left + 2, Top , Items[AIndex]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -