📄 umfgenerator.pas
字号:
Node.ImageIndex := 2 + Ord(assigned(HighlightClass) and
AClass.InheritsFrom(HighlightClass));
if AClass.ClassNameIs(SelectedClass) then //is currently selected class?
Selected := Node; //save it
end;
TreeView.OnChange := nil;
TreeView.Selected := Selected; //select the node of the selected class
TreeView.OnChange := TreeViewChange;
end;
{Selects the node in the tree representing the specified class.
~param ClassName the name of the class to select
~result if the class has been found and selected }
function TMFGenerator.SelectByClassName(ClassName: String): Boolean;
var Count :Integer; //number of nodes in the tree
i :Integer; //counter through all nodes
begin
Count := TreeView.Items.Count; //get number of nodes in the tree
i := 0;
while (i < Count) and //search the node of the class
not TClass(TreeView.Items[i].Data).ClassNameIs(ClassName) do
Inc(i);
Result := i < Count;
if Result then //node of the class found?
begin
Assert(TreeView.Items[i].ImageIndex > 1);
TreeView.Selected := TreeView.Items[i]; //select the node
end;
end;
{Initializes the tree view. }
procedure TMFGenerator.Init;
var Name :String; //name of the currently selected generator
i :Integer; //counter through all nodes
begin
if State.Generate.GeneratorAvailable then //get the name of the generator
Name := State.Generate.GeneratorClassName
else
Name := '';
//fill all classes of the generators in the tree view
FillTreeView(GeneratorClasses, TMakeDoc, TICCommentDoc, Name);
//change the caption of the generators
for i := 0 to TreeView.Items.Count - 1 do //for each node
with TreeView.Items[i] do
if ImageIndex > 1 then //if it is a generator
Text := TMakeDocClass(Data).GetDescription.Name; //use its name instead
TreeView.SortType := stText; //and now sort by the names
end;
{Checks whether an object of the class is curently used.
~param AClass the class to check if it is currently selected
~result if the class is currently selected }
function TMFGenerator.IsCurrentClass(AClass: TClass): Boolean;
begin
Result := State.Generate.GeneratorAvailable and
AClass.ClassNameIs(State.Generate.GeneratorClassName);
end;
{Called to select the class.
~param AClass the class to select }
procedure TMFGenerator.SetClass(AClass: TClass);
begin
Assert(GeneratorClasses.IndexOfObject(TObject(AClass)) <> -1);
State.Generate.ChangeGeneratorByName(AClass.ClassName); //set the generator
with State.Generate.GeneratorDescription do
begin
Memo.Text := ''; //show its description
Memo.Lines.Append('Name: ' + Name);
Memo.Lines.Append('Identification: ' + Identification);
Memo.Lines.Append('Class Name: ' + State.Generate.GeneratorClassName);
Memo.Lines.Append('');
Memo.Lines.Append(Description);
end;
end;
{Returns an object to edit the options of the current object.
~result an object to edit the options }
function TMFGenerator.GetOptions: TOptionWrapper;
begin
Result := State.Generate.GeneratorOptions;
end;
{Resets the current object. }
procedure TMFGenerator.ResetOptions;
begin
State.Generate.ResetGenerator;
end;
{$IFNDEF LINUX}
{Called whenever a node in the ~[link TreeView] has to be drawn.
~param Sender the sender of the event, ~[link TreeView]
~param Node the node to be drawn
~param State the state of the node
~param DefaultDraw out: if the node should be drawn by the tree view }
procedure TMFGenerator.TreeViewCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode;
State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
with TreeView.Canvas do //draw on the tree view
begin
//no +/- there so indicate expandable nodes with an underlined caption
if Node.HasChildren and not Node.Expanded then
Font.Style := Font.Style + [fsUnderline];
{$ELSE}
{Called whenever a node in the ~[link TreeView] has to be drawn.
~param Sender the sender of the event, ~[link TreeView]
~param Item the node to be drawn
~param Canvas the canvas od the tree view to draw on
~param Rect the rectangle of the node on the canvas
~param State the state of the node
~param Stage the current while drawing the tree view
~param DefaultDraw out: if the node should be drawn by the tree view }
procedure TMFGenerator.TreeViewCustomDrawItem(Sender: TCustomViewControl;
Item: TCustomViewItem;
Canvas: TCanvas;
const Rect: TRect;
State: TCustomDrawState;
Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
var Node :TTreeNode; //the node to be drawn
begin
Assert(Item is TTreeNode);
Node := TTreeNode(Item);
with Canvas do //draw on the specified canvas
begin
{$ENDIF}
if not CheckBoxMonochrome.Checked then
if Node.ImageIndex <= 1 then //an ancestor class?
Brush.Color := $3030D0 //a dirty red as background
else
if Node.ImageIndex = 2 then //not a highlighted class?
Brush.Color := $00A080 //darker yellow as background
else
Brush.Color := $00A000 //darker green as background
else
if Node.ImageIndex <= 1 then //an ancestor class?
Brush.Color := $404040 //a dark gray as background
else
if Node.ImageIndex = 2 then //not a highlighted class?
Brush.Color := $808080 //darker gray as background
else
Brush.Color := $A0A0A0; //lighter gray as background
if IsCurrentClass(Node.Data) then //is the current class?
begin
Font.Style := Font.Style + [fsBold]; //use a bold font and
if not CheckBoxMonochrome.Checked then
Font.Color := $B03030 //highlight with a dirty blue
else
Font.Color := $F0F0F0 //highlight with dirty white
end
else
if cdsSelected in State then //make sure the text can be read
Font.Color := clWhite
else
Font.Color := clBlack;
{$IFDEF LINUX}
DefaultDraw := False; //we are drawing manually
if Stage = cdPostPaint then //draw on only one paint event
begin
FillRect(Rect); //fill colored background
TextOut(Rect.Left, Rect.Top, Node.Text); //and draw the text
end;
{$ENDIF}
end;
end;
{Called when another node is selected in the ~[link TreeView].
~param Sender the sender of the event, ~[link TreeView]
~param Node the newly selected node }
procedure TMFGenerator.TreeViewChange(Sender: TObject; Node: TTreeNode);
begin
if Node.ImageIndex > 1 then //a valid class selected (not an ancestor)?
begin
SetClass(Node.Data); //set the class
TreeView.Invalidate; //and show the new selection
end;
end;
{Called when the ~[link TreeView] is double clicked.
~param Sender the sender of the event, ~[link TreeView] }
procedure TMFGenerator.TreeViewDblClick(Sender: TObject);
var Point :TPoint; //position of the double click
{$IFNDEF LINUX}
Hit :THitTests; //what has been double clicked
{$ENDIF}
begin
//get position of the double click
Point := TreeView.ScreenToClient(Mouse.CursorPos);
{$IFNDEF LINUX}
//get what has been double clicked
Hit := TreeView.GetHitTestInfoAt(Point.X, Point.Y);
if ([htOnItem, htOnIndent, htOnRight] * Hit <> []) and //on a node clicked and
{$ELSE}
if assigned(TreeView.GetNodeAt(Point.X, Point.Y)) and //on a node clicked and
{$ENDIF}
IsCurrentClass(TreeView.Selected.Data) then //current object clicked?
EditOptionsByCategory(GetOptions) //edit its options
{$IFNDEF LINUX}
else
//a node has been double clicked outside its label?
if [htOnItem, htNowhere] * Hit = [] then
if TreeView.Selected.Expanded then //expand/collapse the node
TreeView.Selected.Collapse(False)
else
TreeView.Selected.Expand(False)
{$ENDIF}
;
end;
{Called when the mouse is moved inside the ~[link TreeView].
~param Sender the sender of the event, ~[link TreeView]
~param Shift the state of the special keys
~param X, Y position of the mouse in the tree view }
procedure TMFGenerator.TreeViewMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var NodeUnder :TTreeNode; //the node under the mouse pointer
begin
NodeUnder := TreeView.GetNodeAt(X, Y);
if Assigned(NodeUnder) and (NodeUnder.ImageIndex > 1) then
TreeView.Cursor := crHandPoint
else
TreeView.Cursor := crDefault;
end;
{Called when the check box to select whether the ~[link TreeView] should be
drawn monochrome is changed.
~param Sender the sender of the event, ~[link CheckBoxMonochrome] }
procedure TMFGenerator.CheckBoxMonochromeClick(Sender: TObject);
begin
{$IFNDEF LINUX}
TreeView.Invalidate;
{$ELSE}
TreeView.Refresh;
{$ENDIF}
end;
{Called when the button to edit the options of the current object sorted by
their category is chosen.
~param Sender the sender of the event, ~[link ButtonEditOptionsCategory] }
procedure TMFGenerator.ButtonEditOptionsCategoryClick(Sender: TObject);
var Options :TOptionWrapper; //the options to edit
begin
Options := GetOptions; //get the options to be edited
if assigned(Options) then
EditOptionsByCategory(Options) //edit the options
else
MessageDlg('No object available whose options could be edited.', mtError,
[mbOk], TButton(Sender).HelpContext);
end;
{Called when the button to edit the options of the current object as a list is
chosen.
~param Sender the sender of the event, ~[link ButtonEditOptionsAsList] }
procedure TMFGenerator.ButtonEditOptionsAsListClick(Sender: TObject);
var Options :TOptionWrapper; //the options to edit
begin
Options := GetOptions; //get the options to be edited
if assigned(Options) then
EditOptions(Options) //edit the options
else
MessageDlg('No object available whose options could be edited.', mtError,
[mbOk], TButton(Sender).HelpContext);
end;
{Called when the button to reset the options of the current object is clicked.
~param Sender the sender of the event, ~[link ButtonResetOptions] }
procedure TMFGenerator.ButtonResetOptionsClick(Sender: TObject);
begin
ResetOptions; //reset the options
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -