📄 umain.pas
字号:
else
FShowSource.BringToFront; //just bring it to the front
end;
{Initializes the program from its ini file. }
procedure TFormMain.ReadDefaultIni;
var FileName :String; //the name of the ini file
Settings :TMainFormSettings; //to read ini settings of the form
Ini :TIniFile; //the ini file of the program
Localize :TOptionWrapper; //to load the current language texts
begin
//calculate name of the ini file
FileName := ExtractFilePath(ParamStr(0)) + DefaultINIFile;
//set name for general settings
TSettingsKeeper.SetIniFileName(FileName);
//get object to load the settings from
Settings := TMainFormSettings(TMainFormSettings.
GetSettings(TFormMainIniSection));
if not Assigned(Settings) then //no object initialized?
begin //create a new object
Settings := TMainFormSettings.Create(TFormMainIniSection);
Settings.ReadValues(Self); //initialize with the default values
Settings.Initialize; //and read from the ini file
end;
Settings.SetValuesToForm(Self); //initialize form with read values
ShowHint := Settings.ShowHint;
StatusBar.Visible := Settings.StatusBar;
PanelSplitter.Visible := Settings.TreeView;
TreeView.Visible := Settings.TreeView;
TreeView.Width := Settings.TreeViewWidth;
//open the ini file
Ini := TIniFile.Create(FileName);
try
//load the language strings from the default ini file
Localize := TDocumentationTextOptionWrapper.Create;
try
Localize.LoadIniOptions(Ini);
finally
Localize.Free;
end;
FState.ReadIni(Ini); //read state of the state of the program
finally
Ini.Free; //close the ini file
end;
end;
{Writes the options of the program to its ini file. }
procedure TFormMain.WriteDefaultIni;
var Settings :TMainFormSettings; //to save the settings of the form
Ini :TIniFile; //the ini file of the program
begin
//get object to save the settings in
Settings := TMainFormSettings(TMainFormSettings.
GetSettings(TFormMainIniSection));
if Assigned(Settings) then
Settings.ReadValues(Self); //save current settings
//open the ini file
Ini := TIniFile.Create(ExtractFilePath(ParamStr(0)) + DefaultINIFile);
try
FState.WriteIni(Ini); //write state of the state of the program
finally
Ini.Free; //close the ini file
end;
TSettingsKeeper.SaveSettings; //save all settings
end;
{Makes sure generator, extractor and evaluator of comments are assigned. }
procedure TFormMain.CheckGeneratorClasses;
var i :Integer; //index of the classes
begin
if not FState.Generate.GeneratorAvailable and //no generator set but
(GeneratorClasses.Count <> 0) then //generators available?
begin
i := GeneratorClasses.IndexOf( //search default generator
{$IFNDEF LINUX}
'TICWinHelpDoc'
{$ELSE}
'TICHTMLDoc'
{$ENDIF}
);
if i = -1 then
i := GeneratorClasses.IndexOf('TPDFDoc'); //fall back to PDF output
if i = -1 then
i := 0; //or the first available one
//set the generator
FState.Generate.ChangeGeneratorByName(
TMakeDocClass(GeneratorClasses.Objects[i]).
GetDescription.Identification);
end;
if (FState.Generate.ExtractorClassName = '') and //no extractor set but
(ExtractorClasses.Count <> 0) then //extractors available?
begin
i := ExtractorClasses.IndexOf('TSourceCommentExtractor'); //search default
if i = -1 then //if not found, fall back
i := 0; //to first available one
//set the extractor of comments
FState.Generate.ChangeExtractorByName(
TCommentExtractorClass(ExtractorClasses.Objects[i]).
GetDescription.Identification);
end;
if (FState.Generate.EvaluatorClassName = '') and //no evaluator set but
(EvaluatorClasses.Count <> 0) then //but evaluators available?
begin
i := EvaluatorClasses.IndexOf('TJADDCommentEvaluator'); //search default
if i = -1 then //if not found, fall back
i := 0; //to first available one
//set the evaluators of texts for the documentation
FState.Generate.ChangeEvaluatorByName(
TCommentEvaluatorClass(EvaluatorClasses.Objects[i]).
GetDescription.Identification);
end;
end;
{Handles the program parameters. }
procedure TFormMain.HandleParameters;
var Parameters :TGUIParameterOptions; //parsed parameter values
begin
Parameters := TGUIParameterOptions.Create; //create list for parameters
try
Parameters.Form := Self; //set back-reference
Parameters.JADDState := FState; //set state of the program
Parameters.HandleAllParameters; //and handle them
finally
Parameters.Free; //free list of parameters
end;
end;
{Create a new page of the selected class and shows it.
~param FrameClass the class of the page to create and show }
procedure TFormMain.ShowFrame(FrameClass: TMainFormFrameClass);
begin
Assert(Assigned(FrameClass));
if Assigned(FFrame) then //not the first frame?
try
FFrame.Free //free old frame
finally
FFrame := nil;
end;
if Assigned(TreeView.Selected) then //show name of the page
GroupBox.Caption := TreeView.Selected.Text
else
GroupBox.Caption := '';
//create and show the frame
FFrame := FrameClass.Create(GroupBox, FState);
//set call back handler to show source code
FFrame.ShowSourceCode := ShowSourceCodeCallBack;
{$IFNDEF LINUX}
//(un-)register to accept dragging of files
DragAcceptFiles(Handle, mffpAcceptsFileDrop in FFrame.Properties);
{$ENDIF}
end;
{Returns the class of page to be shown for the selected node.
~param Node the node to return the page for
~result the class of the page to show for the node }
function TFormMain.GetMainFrames(Node: TTreeNode): TMainFormFrameClass;
var Parent :TTreeNode; //the top-level parent node of the node
begin
Parent := Node;
while Assigned(Parent.Parent) do //the top-level parent node
Parent := Parent.Parent;
Result := nil;
case Parent.Index of //get the corresponding page
0: begin //Welcome!
Assert(Parent = Node);
Result := TMFWelcome;
end;
1: begin //Acquire Parsed Date
if Parent = Node then //the main node itself?
Result := TMFAcquireParsedData
else
Result := GetParseFrames(Node); //get the page of the sub-node
end;
2: begin //Generate Documentation
if Parent = Node then //the main node itself?
Result := TMFGenerateMain
else
Result := GetGenerateFrames(Node); //get the page of the sub-node
end;
3: begin //Diagrams
Assert(Parent = Node);
Result := TMFDiagrams;
end;
4: begin //Compare
Assert(Parent = Node);
Result := TMFCompare;
end;
5: begin //Options
Assert(Parent = Node);
Result := TMFProgramOptions;
end;
else
Assert(False);
end;
end;
{Returns the class of page to be shown for the selected node to acquire parsed
data.
~param Node the node to return the page for
~result the class of the page to show for the node }
function TFormMain.GetParseFrames(Node: TTreeNode): TMainFormFrameClass;
var Parent :TTreeNode; //the parent node of the node
begin
Parent := Node;
Assert(Assigned(Parent.Parent));
if Assigned(Parent.Parent.Parent) then //get the parent node
Parent := Parent.Parent;
Result := nil;
case Parent.Index of //get the corresponding page
0: begin //Load/Save Parsed Data
Assert(Parent = Node);
Result := TMFLoadParsedData;
end;
1: begin //Parse
if Parent = Node then //the main node itself?
Result := TMFParseMain
else
Result := GetParseSubFrames(Node); //get the page of the sub-sub-node
end;
2: begin //Keep/Select
Assert(Parent = Node);
Result := TMFKeepSelectData;
end;
else
Assert(False);
end;
end;
{Returns the class of page to be shown for the selected node to parse source
code files.
~param Node the node to return the page for
~result the class of the page to show for the node }
function TFormMain.GetParseSubFrames(Node: TTreeNode): TMainFormFrameClass;
begin
Result := nil;
case Node.Index of //get the corresponding page
0: begin //Select Files
Result := TMFSelectFiles;
end;
1: begin //Exclude from Parsing
Result := TMFExcludeFromParsing;
end;
2: begin //Select Library Files
Result := TMFSelectLibraryFiles
end;
3: begin //Compiler Options
Result := TMFCompilerOptions;
end;
4: begin //Load Save Project
Result := TMFLoadProject;
end;
5: begin //Parse
Result := TMFParse;
end;
6: begin //Parsing Messages
Result := TMFParseMessages;
end;
7: begin //Unknown Identifiers
Result := TMFUnknownIdents;
end;
8: begin //View Source Code
Result := TMFShowSource;
end;
else
Assert(False);
end;
end;
{Returns the class of page to be shown for the selected node to generate
documentation.
~param Node the node to return the page for
~result the class of the page to show for the node }
function TFormMain.GetGenerateFrames(Node: TTreeNode): TMainFormFrameClass;
begin
Result := nil;
case Node.Index of //get the corresponding page
0: begin //Select Generator
Result := TMFGenerator;
end;
1: begin //Select Extractor
Result := TMFExtractor;
end;
2: begin //Select Evaluator
Result := TMFEvaluator;
end;
3: begin //Localization
Result := TMFLocalization;
end;
4: begin //User Documentation
Result := TMFUserDoc;
end;
5: begin //Generate
Result := TMFGenerate;
end;
6: begin //Status Text
Result := TMFStatusText;
end;
7: begin //Parsing Mesages
{$IFDEF DONT_USE_MESSAGEGRID}
Result := TMFGenerateMessagesKylix;
{$ELSE}
Result := TMFGenerateMessages;
{$ENDIF}
end;
8: begin //GUIHelp Log Files
Result := TMFGUIHelpFiles;
end;
9: begin //GUIHelp
Result := TMFGUIHelp;
end;
else
Assert(False);
end;
end;
{Shows the page of the selcted node unless overridden by the current page.
~param NewNode the node whose page should be shown
~param IsNext if the next page should is selected, instead of the previous }
procedure TFormMain.SelectOtherNode(NewNode: TTreeNode; IsNext: Boolean);
var OrgFrame :TMainFormFrameClass; //the page of the node
Frame :TMainFormFrameClass; //the page to be shown
Count :Integer; //number of all nodes
i :Integer; //counter through all nodes
begin
Frame := GetMainFrames(NewNode); //get the page of the node
Assert(Assigned(Frame));
if Assigned(FFrame) then //not the first page?
begin
OrgFrame := Frame; //save the class of the page
FFrame.SelectNextFrame(Frame, IsNext); //query the current page
if Frame <> OrgFrame then //page wants another page?
begin
Count := TreeView.Items.Count; //search node of the other page
i := 0;
while (i < Count) and (GetMainFrames(TreeView.Items[i]) <> Frame) do
Inc(i);
if i < Count then //node of the page found?
NewNode := TreeView.Items[i]; //select the node
end;
end;
if Assigned(Frame) then //new page selected?
TreeView.Selected := NewNode; //select the corresponding node
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -