📄 ushowsourceform.pas
字号:
NotIncluded; //it was not included
end;
end;
{Called when the form is resized.
~param Sender the sender of the event, the form }
procedure TFormShowSource.FormResize(Sender: TObject);
begin
ListBox.Height := Min(ListBox.Height, //make sure, the window doesn't scroll
ClientHeight - PanelSplitter.Height -
PanelNavigate.Height);
end;
{Called when a key is pressed.
~param Sender the sender of the event, the form
~param Key the code of the pressed key
~param Shift the state of the special control keys }
procedure TFormShowSource.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Shift = []) and //ESC pressed?
{$IFNDEF LINUX}
(Key = VK_ESCAPE)
{$ELSE}
(Key = Key_Escape)
{$ENDIF}
then
Hide; //hide the form
end;
{Called when the user starts to drag the splitter to resize the
~[link ListBox].
~param Sender the sender of the event, ~[link PanelSplitter]
~param Button the pressed mouse button
~param Shift state of special modifying keys
~param X, Y position of the mouse }
procedure TFormShowSource.PanelSplitterMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
PanelSplitter.Tag := Y;
end;
{Called when the user drags the splitter to resize the list of identifiers in a
file.
~param Sender the sender of the event, ~[link PanelSplitter]
~param Shift state of special modifying keys
~param X, Y position of the mouse }
procedure TFormShowSource.PanelSplitterMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if Mouse.Capture = PanelSplitter //currently dragging the splitter?
{$IFNDEF LINUX}
.Handle
{$ENDIF}
then
//adjust size of list box and source view
ListBox.Height := Min(ListBox.Height + PanelSplitter.Tag - Y,
ClientHeight - PanelSplitter.Height -
PanelNavigate.Height);
end;
{Called when the user double clicks the splitter to resize the
~[link ListBox].
~param Sender the sender of the event, ~[link PanelSplitter] }
procedure TFormShowSource.PanelSplitterDblClick(Sender: TObject);
begin
if ListBox.Height = 0 then //list of identifiers minimized?
ListBox.Height := 6 * ListBox.ItemHeight + //show it with a good height
2 * Ord(ListBox.BorderStyle = bsSingle)
{$IFNDEF LINUX}
+ 2 * Ord(ListBox.Ctl3D)
{$ENDIF}
else
ListBox.Height := 0; //minimize it
Mouse.Capture := //don't drag the splitter anymore
{$IFDEF LINUX}
nil;
{$ELSE}
0;
{$ENDIF}
end;
{Called when the file to show the declared identifiers and the source code of
is changed.
~param Sender the sender of the event, ~[link ComboBox] }
procedure TFormShowSource.ComboBoxChange(Sender: TObject);
var FileD :TPascalFile; //the selected file
{Adds all identifiers of the selected file to the list box. }
procedure ShowIdents;
{Adds all identifiers in the given list to the list box.
~param List the list of the identifiers to add
~param PreIdent prefix to add before the name of the identifiers
(for members) }
procedure AddIdentList(List: TIdentifierList; PreIdent: String = '');
{Returns the position as a string.
~param Pos the position of an identifier
~result the position as a string }
function GetPosString(Pos: TPosition): String;
begin
Result := Format('%d:%d', [Pos.Row, Pos.Column]); //return it as a string
end;
var TextFormat :TTextFormat; //to get declaration of the identifier
Ident :TIdentifier; //each identifier in the list
i :Integer; //counter through the list
Text :String; //text to use for the identifier
Decl :String; //declaration of the identifier
begin
//create object to get the deaclaration of the identifiers as a string
TextFormat := TTextFormat.Create;
try
for i := 0 to List.Count - 1 do //for each identifier in the list
begin
Ident := List[i]; //get it
Text := GetPosString(Ident.ForwardDefPos); //add position of identifier
//has a forward-declaration?
if (Ident.ForwardDefPos.Row <> Ident.Position.Row) or
(Ident.ForwardDefPos.Column <> Ident.Position.Column) then
//also add positon of the real declaration of the identifier
Text := Text + ':' + GetPosString(Ident.Position);
//get the declaration of the identifier
if (PreIdent = '') and (Ident is TRecordType) then
Decl := RecordKindNames[TRecordType(Ident).Kind]
else
Decl := Ident.GetDescriptionString(TextFormat, Ident);
//add the identifier to the list
ListBox.Items.AddObject(Format('%s: %s%s: ',
[Text, PreIdent, Ident.Name]) + Decl,
Ident);
Text := Ident.Name; //use the name of the identifier as prefix
if Ident is TField then //for fields use their types
Ident := TField(Ident).FieldType;
if Ident is TRecordType then //is a record (with further identifiers)
//add also the members as list of identifiers
AddIdentList(TRecordType(Ident).IdentList, PreIdent + Text + '.')
end; //for i := 0 to List.Count - 1
finally
TextFormat.Free; //free the object to get declarations
end;
end;
begin
AddIdentList(FileD.Idents); //add all identifiers directly in the file
end;
begin
//files available?
if Assigned(FState.FileList) and not FState.FileList.IsEmpty then
begin
FileD := TPascalFile(ComboBox.Items.Objects[ComboBox.ItemIndex]); //get file
if FPascalMemo.TheFile <> FileD then
begin
if FileD.Lines.Count > 0 then //file not empty?
FPascalMemo.TheFile := FileD //assign the file to show the source code
else
FPascalMemo.TheFile := nil; //no code to show
{$IFNDEF USESOURCECODEGRID}
FPascalMemo.Invalidate; //and show the source code
{$ENDIF}
ListBox.Clear; //clear the list of identifiers of the file
try
ShowIdents; //fill list with identifiers of the file
except
MessageDlg('Can''t show all identifiers in the file: ' +
ExceptObject.ClassName + ':' + LineDelimiter +
Exception(ExceptObject).Message,
mtWarning, [mbOK], ListBox.HelpContext);
end;
end;
end
else
begin
FPascalMemo.TheFile := nil; //clear the file
{$IFNDEF USESOURCECODEGRID}
FPascalMemo.Invalidate; //and show the empty component
{$ENDIF}
ListBox.Clear; //clear the list of identifiers of the file
end;
NotIncluded; //file chosen, not included
end;
{Called when the button to go to the including file is chosen.
~param Sender the sender of the event, ~[link ButtonGoInluded] }
procedure TFormShowSource.ButtonGoInludedClick(Sender: TObject);
begin
ShowSourceCode(nil, FIncludingFile, FIncludingPosition, //go to the position
FIncludingFile, FIncludingPosition);
if FPascalMemo.Enabled then //and focus if
FPascalMemo.SetFocus;
end;
{Called when an identifier in the list is selected.
~param Sender the sender of the event, ~[link ListBox] }
procedure TFormShowSource.ListBoxClick(Sender: TObject);
begin
if ListBox.ItemIndex > -1 then //valid item selected?
//show the first declaration of the selected identifier
ShowSourceCodeOfIdentifier(TIdentifier(ListBox.Items.Objects[
ListBox.ItemIndex]),
False);
end;
{Called when the list of identifiers is double clicked.
~param Sender the sender of the event, ~[link ListBox] }
procedure TFormShowSource.ListBoxDblClick(Sender: TObject);
begin
if ListBox.ItemIndex > -1 then //valid item selected?
//show declaration/implementation of the selected identifier
ShowSourceCodeOfIdentifier(TIdentifier(ListBox.Items.Objects[
ListBox.ItemIndex]),
True);
end;
{Called when the button to show the statistics about the file is chosen.
~param Sender the sender of the event, ~[link ButtonFileStatistics] }
procedure TFormShowSource.ButtonFileStatisticsClick(Sender: TObject);
begin
if Assigned(FPascalMemo.TheFile) then //a file selected?
//show the statistics
ShowStatistics('Statistic for ' + FPascalMemo.TheFile.InternalFileName + ':',
FPascalMemo.TheFile.Statistic,
ButtonFileStatistics.HelpContext);
end;
{Called when the button to show the summed up statistics about all parsed file
is chosen.
~param Sender the sender of the event, ~[link ButtonAllStatistics] }
procedure TFormShowSource.ButtonAllStatisticsClick(Sender: TObject);
var Statistics :TStatisticOfPascalFile; //summed up statistics
Count :Integer; //number of valid statistics
i :Integer; //counter through files
begin
//files available?
if Assigned(FState.FileList) and not FState.FileList.IsEmpty then
begin
Statistics := TStatisticOfPascalFile.Create; //create empty statistics
try
Count := 0; //no valid statistic so far
for i := 0 to FState.FileList.Count - 1 do //sum up all statistics
//the file has valid statistics?
if FState.FileList[i].Statistic.Numbers[psfLines] <> -1 then
begin
Statistics.SumStatistics(FState.FileList[i].Statistic); //add it
Inc(Count);
end;
//show the statistics
ShowStatistics(Format('Summed up Statistics on all %d of %d parsed Files:',
[Count, FState.FileList.Count]),
Statistics, ButtonAllStatistics.HelpContext);
finally
Statistics.Free; //free statistics
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -