⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umain.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 4 页
字号:
{Parses data if needed by the parameters of the program.
~result whether the data could be parsed successfully }
function TFormMain.AutoParse: Boolean;
begin
 Result := False;

 FState.StartParsing(False);               //start the parsing
 try

   try
     Result := FState.DoParsing;           //parse the pascal files
     if Result then                        //everything's fine?
      FState.KeepCurrentData;               //keep it, just for fun
   except
     on E: EParseException do              //in case of a parse error
      HandleParsingError(E, 0, FState, ShowSourceCodeCallBack, nil);
     else
      raise;                               //unknown/system error? => handle
   end;

 finally
  FState.FinishParsing;                    //finalize the parsing
 end;
end;




































{Called after the form has been created.
~param Sender the sender of the event, the form }
procedure TFormMain.FormCreate(Sender: TObject);
begin
{$IFDEF DOSOMEPASCALCHECKS}
 TestSay;
{$ENDIF}

 //create state
 FState := TJADDState.Create(ExtractFilePath(ParamStr(0)) + DefaultINIFile);

 CheckGeneratorClasses;                            //make sure generator is set

 ReadDefaultIni;                                   //initialize program

 TreeView.FullExpand;                              //show all frames
 TreeView.Selected := TreeView.Items.GetFirstNode; //select the first frame
{$IFNDEF LINUX}
 TreeView.OnCustomDrawItem := TreeViewCustomDrawItem;
 TreeView.OnDblClick := TreeViewDblClick;
{$ENDIF}

 CheckGeneratorClasses;                            //make sure generator is set

 FShowSource := TFormShowSource.Create(FState);    //create form to show source
 FShowSource.ShowHint := ShowHint;

 CheckGeneratorClasses;                            //make sure generator is set

 Show;           //make sure window is visible, if parsing/compiling takes time

 //assign the progress interface to show it in the form
 FState.Progress := TFormWorkProgress.Create(Self);

 HandleParameters;                                 //handle the parameters
end;

{Called when the form is being deleted.
~param Sender the sender of the event, the form }
procedure TFormMain.FormDestroy(Sender: TObject);
begin
 FShowSource.Free;           //free the window to show the parsed source code

 //free the currently shown page; his is done manually so it can set its
 //options before they are written to the ini file
 FFrame.Free;

 FState.Progress := nil;          //so the ini settings of the progress window
 FState.Generate.Progress := nil; //are written

 WriteDefaultIni;            //save options to ini file

 FState.Free;                //free the state of the program
end;





{Called when the form is resized.
~param Sender the sender of the event, the form }
procedure TFormMain.FormResize(Sender: TObject);
begin                                 //make sure the splitter is still visible
 TreeView.Width := Min(TreeView.Width, ClientWidth - PanelSplitter.Width);
end;



{Called when the user starts to drag the splitter to resize the
 ~[link TreeView].
~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 TFormMain.PanelSplitterMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 PanelSplitter.Tag := X;              //save position of click
end;

{Called when the user drags a splitter to resize the ~[link TreeView].
~param Sender the sender of the event, ~[link PanelSplitter]
~param Shift  state of special modifying keys
~param X, Y   position of the mouse }
procedure TFormMain.PanelSplitterMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
 if Mouse.Capture = PanelSplitter            //currently dragging the splitter?
{$IFNDEF LINUX}
                                 .Handle
{$ENDIF}
                                         then
  //resize the tree view                                       
  TreeView.Width := Max(0, Min(TreeView.Width + X - PanelSplitter.Tag,
                               ClientWidth - PanelSplitter.Width));
end;

{Called when the user double clicks the splitter to resize the
 ~[link TreeView].
~param Sender the sender of the event, ~[link PanelSplitter] }
procedure TFormMain.PanelSplitterDblClick(Sender: TObject);
          //ideal width of the tree view, without horizontal scroll bar;
const     IdealWidth = 141 +     //141 is minimum width without scroll bar;
                       3;        //3 as an additional space
{$IFNDEF LINUX}
var       ScrollInfo    :TScrollInfo;  //options of the scroll bar
{$ENDIF}
begin
 if TreeView.Width =
{$IFNDEF LINUX}
                     0
{$ELSE}
                     1
{$ENDIF}
                       then            //tree view minimized?
  begin
{$IFNDEF LINUX}
   ScrollInfo.cbSize := SizeOf(ScrollInfo);
   ScrollInfo.fMask := SIF_PAGE;
   //scroll bar can be scrolled? this would mean it is visible
   if GetScrollInfo(TreeView.Handle, SB_VERT, ScrollInfo) and
      (ScrollInfo.nPage <> 0) then
    //add the width of the scroll bar to the ideal width
    TreeView.Width := IdealWidth + GetSystemMetrics(SM_CXHTHUMB)
   else
{$ENDIF}
    TreeView.Width := IdealWidth;          //show it with its ideal width
  end
 else
  TreeView.Width := 0;                   //minimize the tree view

 Mouse.Capture :=                      //don't drag the splitter anymore
{$IFDEF LINUX}
                  nil;
{$ELSE}
                  0;
{$ENDIF}
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 TFormMain.TreeViewChange(Sender: TObject; Node: TTreeNode);
begin
 try
   ShowFrame(GetMainFrames(Node));      //show the page of the node
 finally                                //and update the buttons
  BitBtnPrevious.Enabled := Node <> TreeView.Items.GetFirstNode;
  BitBtnNext.Enabled := Assigned(Node.Parent) or
                        Assigned(Node.GetNextSibling());
 end;
end;

{Called when the ~[link TreeView] is double clicked.
~param Sender the sender of the event, ~[link TreeView] }
procedure TFormMain.TreeViewDblClick(Sender: TObject);
{$IFNDEF LINUX}
var       Children :Boolean;          //whether children should be shown/hidden
          Point    :TPoint;           //position of the double click
          Hit      :THitTests;        //what has been double clicked
{$ENDIF}
begin
{$IFNDEF LINUX}

 Children := TreeView.Selected.HasChildren; //only if children available
 if Children then
  begin
   //get position of the double click
   Point := TreeView.ScreenToClient(Mouse.CursorPos);
   //get what has been double clicked
   Hit := TreeView.GetHitTestInfoAt(Point.X, Point.Y);

   Children := not (htOnItem in Hit) ;        //text clicked?
  end;

 if Children then                     //node with children double clicked?
  if TreeView.Selected.Expanded then    //expand/collapse the node
   TreeView.Selected.Collapse(False)
  else
   TreeView.Selected.Expand(False)
 else
{$ENDIF}
  begin
   Assert(Assigned(FFrame));
   FFrame.DefaultAction;                //execute default action of the page
  end;
end;







{Called when the button to go to the previous page is chosen.
~param Sender the sender of the event, ~[link BitBtnPrevious] }
procedure TFormMain.BitBtnPreviousClick(Sender: TObject);
begin
 assert(TreeView.Selected <> TreeView.Items.GetFirstNode);

 //not the first node on a level?
 if assigned(TreeView.Selected.GetPrevSibling()) then
  //got to the previous node and show its page
  SelectOtherNode(TreeView.Selected.GetPrevSibling, False)
 else
  //go to the parent node and show its page
  SelectOtherNode(TreeView.Selected.Parent, False)
end;

{Called when the button to go to the next page is chosen.
~param Sender the sender of the event, ~[link BitBtnNext] }
procedure TFormMain.BitBtnNextClick(Sender: TObject);
begin
 assert(assigned(TreeView.Selected.Parent) or
        assigned(TreeView.Selected.GetNextSibling()));
 //go to the next node and show its page
 SelectOtherNode(TreeView.Items.Item[TreeView.Selected.AbsoluteIndex + 1],
                 True);
end;







{Called when the text of the status bas has to be drawn (or it will truncate it
 after 255 characters).
~param StatusBar the sender of the event, ~[link .StatusBar]
~param Panel     the panel whose text should be drawn, StatusBar.Panel[0]
~param Rect      the rect where to draw the text }
procedure TFormMain.StatusBarDrawPanel(StatusBar: TStatusBar;
                                       Panel: TStatusPanel; const Rect: TRect);
begin                              //just draw the text
 StatusBar.Canvas.TextRect(Rect, Rect.Left, Rect.Top, Panel.Text);
end;



{Called when the menu item to show the options of the program is chosen.
~param Sender the sender of the event, ~[link MenuItemShowOptions] }
procedure TFormMain.MenuItemShowOptionsClick(Sender: TObject);
begin                       //select the last node with the options
 TreeView.Selected := TreeView.Items[TreeView.Items.Count - 1];
end;

{Called when the menu item to show the options of the program is chosen.
~param Sender the sender of the event, ~[link MenuItemClose] }
procedure TFormMain.MenuItemCloseClick(Sender: TObject);
begin
 Close;                     //close the form, end the program
end;



{Called when the menu to toggle the visibility of items pops up.
~param Sender the sender of the event, ~[link MenuItemMenuView] }
procedure TFormMain.MenuItemMenuViewClick(Sender: TObject);
begin
 MenuItemStatusBar.Checked := StatusBar.Visible;  //set state of the menu items
 MenuItemTreeView.Checked := TreeView.Visible;
 MenuItemHints.Checked := ShowHint;
 MenuItemSourceCode.Checked := FShowSource.Visible;
end;

{Called when the menu item to toggle the visibility of the status bar is
 chosen.
~param Sender the sender of the event, ~[link MenuItemStatusBar] }
procedure TFormMain.MenuItemStatusBarClick(Sender: TObject);
begin
 StatusBar.Visible := not StatusBar.Visible;         //toggle the visibility
// MenuItemStatusBar.Checked := StatusBar.Visible;
end;

{Called when the menu item to toggle the visibility of the tree view is chosen.
~param Sender the sender of the event, ~[link MenuItemTreeView] }
procedure TFormMain.MenuItemTreeViewClick(Sender: TObject);
begin
 PanelSplitter.Visible := not PanelSplitter.Visible; //toggle the visibility
 TreeView.Visible := PanelSplitter.Visible;
// MenuItemTreeView.Checked := TreeView.Visible;
end;

{Called when the menu item to toggle the visibility of the hints is chosen.
~param Sender the sender of the event, ~[link MenuItemHints] }
procedure TFormMain.MenuItemHintsClick(Sender: TObject);
var       i        :Integer;
begin
 ShowHint := not ShowHint;                          //toggle the visibility
 for i := 0 to Screen.FormCount - 1 do              //of the hints on all forms
  Screen.Forms[i].ShowHint := ShowHint;
// MenuItemHints.Checked := ShowHint;
end;

{Called when the menu item to toggle the visibility of the form showing the
 parsed source code is chosen.
~param Sender the sender of the event, ~[link MenuItemSourceCode] }
procedure TFormMain.MenuItemSourceCodeClick(Sender: TObject);
begin
 if not FShowSource.Visible then            //toggle the visibility of the form
  FShowSource.Show
 else
  FShowSource.Hide;
// MenuItemSourceCode.Checked := FShowSource.Visible;
end;







{Called when the menu item to show context-sensitive help is chosen.
~param Sender the sender of the event, ~[link MenuItemContext] }
procedure TFormMain.MenuItemContextClick(Sender: TObject);
var       Control  :TWinControl;     //the active control or its parent
begin
 Control := Screen.ActiveControl;    //get the active control
 while assigned(Control) and (Control.HelpContext = 0) do
  Control := Control.Parent;           //search its help context
 assert(assigned(Control));

 if assigned(Control) then           //show help of the active control
{$IFNDEF LINUX}
  Application.HelpContext(Control.HelpContext);
{$ELSE}
  Application.ContextHelp(Control.HelpContext);
{$ENDIF}
end;

{Called when the menu item to show the index of the help is chosen.
~param Sender the sender of the event, ~[link MenuItemIndex] }
procedure TFormMain.MenuItemIndexClick(Sender: TObject);
begin
{$IFNDEF LINUX}
 Application.HelpContext(HelpContext);     //show main topic of the help file
{$ELSE}
 Application.ContextHelp(HelpContext);
{$ENDIF}
end;

{Called when the menu item to show the documentation is chosen.
~param Sender the sender of the event, ~[link MenuItemDocumentation] }
procedure TFormMain.MenuItemDocumentationClick(Sender: TObject);
begin                                      //show the documentation
 ShowDocumentation(MenuItemDocumentation.HelpContext, '');
end;

{Called when the menu item to show the possible parameters of the program is
 chosen.
~param Sender the sender of the event, ~[link MenuItemDocumentation] }
procedure TFormMain.MenuItemCommandLineSwitchesClick(Sender: TObject);
begin                           //show the possible parameters of the program
 TParameterOptions.ShowParametersHelp('');
end;

{Called when the menu item to show the home page of this program is chosen.
~param Sender the sender of the event, ~[link MenuItemVisitHomePage] }
procedure TFormMain.MenuItemVisitHomePageClick(Sender: TObject);
begin                           //show the home page of the program
 ShowDelphiDocProjectPage(MenuItemVisitHomePage.HelpContext);
end;

{Called when the menu item to show information about the program is chosen.
~param Sender the sender of the event, ~[link MenuItemAbout] }
procedure TFormMain.MenuItemAboutClick(Sender: TObject);
begin
 ShowAboutInformation;          //show the information about the program
end;

end.

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -