📄 pascalmemo.pas
字号:
{ JADD - Just Another DelphiDoc: Documentation from Delphi Source Code
Copyright (C) 2004-2008 Gerold Veith
This file is part of JADD - Just Another DelphiDoc.
DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
DelphiDoc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}
unit PascalMemo;
{Contains a component to show the pascal code of a parsed file with syntax
highlighting similar to the Delphi code editor. }
interface
uses Classes,
SourceCodeMemo,
UBaseIdents;
type
//the component to show the source code
TPascalMemo = class;
{A simple helper class for ~[link TPascalMemo] to extract the code to show
from a parsed pascal file. }
TTheFileStrings = class(TStrings)
private
//the component, that references the file whose content should be returned
FMemo: TPascalMemo;
protected
//Returns a line of the source code.
function Get(Index: Integer): String; override;
//Returns the number of lines of the source code.
function GetCount: Integer; override;
public
//Raises an exception because this list is read-only.
procedure Clear; override;
//Raises an exception because this list is read-only.
procedure Delete(Index: Integer); override;
//Raises an exception because this list is read-only.
procedure Insert(Index: Integer; const S: String); override;
public
//Creates the object and saves the reference to the component.
constructor Create(Memo: TPascalMemo);
end;
{ * * * *** * * * *** TPascalMemo *** * * * *** * * * }
{The component to show pascal code of a parsed file with syntax highlighting
similar to the Delphi code editor. }
TPascalMemo = class(TSourceCodeMemo)
private
//the file, whose content should be shown
FTheFile: TPascalFile;
//Sets the file, whose content should be shown.
procedure SetTheFile(Value: TPascalFile);
protected
//Draws some text of the source code with syntax highlighting.
procedure DrawText(X, Y: Integer; Line: Integer; First, Last: Integer;
Selected: Boolean);
//Draws the source code with syntax highlighting.
procedure Paint; override;
//Creates the list to access the source code of a parsed file.
function CreateContentList: TStrings; override;
public
//Creates the component and makes it read-only.
constructor Create(AOwner: TComponent); override;
property TheFile: TPascalFile read FTheFile write SetTheFile;
published
//only to check generators, don't use
property SelectedText: String read GetSelectionText;
end;
implementation
uses Windows, Graphics, SysUtils,
SourceFormat;
{ * * * *** * * * *** TTheFileStrings *** * * * *** * * * }
{Creates the object and saves the reference to the component.
~param Memo the component creating this component to access the source code }
constructor TTheFileStrings.Create(Memo: TPascalMemo);
begin
inherited Create; //create the object
FMemo := Memo; //save the reference
end;
{Returns a line of the source code.
~param Index the index of the line to return
~result the text of the specified line }
function TTheFileStrings.Get(Index: Integer): String;
begin
if assigned(FMemo.FTheFile) then //parsed file available?
Result := FMemo.FTheFile.Lines[Index] //return the line
else
Result := ''; //file is complete empty
end;
{Returns the number of lines of the source code.
~result the number of lines of the source code }
function TTheFileStrings.GetCount: Integer;
begin
if assigned(FMemo.FTheFile) then //parsed file available?
Result := FMemo.FTheFile.Lines.Count //return the number of lines
else
Result := 0; //file is complete empty
end;
{Raises an exception because this list is read-only. }
procedure TTheFileStrings.Clear;
begin
raise Exception.Create('Clear on TheFile not allowed (Read-Only!)!');
end;
{Raises an exception because this list is read-only.
~param Index the index of the line to delete }
procedure TTheFileStrings.Delete(Index: Integer);
begin
raise Exception.Create('Delete on TheFile not allowed (Read-Only!)!');
end;
{Raises an exception because this list is read-only.
~param Index the index where to insert the line before
~param S the text to insert as a line }
procedure TTheFileStrings.Insert(Index: Integer; const S: String);
begin
raise Exception.Create('Insert on TheFile not allowed (Read-Only!)!');
end;
{ * * * *** * * * *** TPascalMemo *** * * * *** * * * }
{Creates the component and makes it read-only.
~param AOwner the owner of the component }
constructor TPascalMemo.Create(AOwner: TComponent);
begin
inherited Create(AOwner); //create the component
ReadOnly := True; //can't change the content
end;
{Creates the list to access the source code of a parsed file.
~result the list to access the content }
function TPascalMemo.CreateContentList: TStrings;
begin
Result := TTheFileStrings.Create(Self); //create the list
end;
{Sets the file, whose content should be shown.
~param Value the new file to show }
procedure TPascalMemo.SetTheFile(Value: TPascalFile);
begin
if assigned(Value) or assigned(FTheFile) then //set new file or clear old one?
begin
FTheFile := Value; //set the file
UpdateScrollBar(False); //update the information
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -