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

📄 ueditguitopics.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 4 页
字号:

         //move the entry accordingly
         Entry.Parent.UnlinkEntry(Entry.ParentIndex);
         try
           InsertAt.Parent.InsertEntry(InsertAt.ParentIndex, Entry);
         except
           Entry.Free;
           raise;
         end;
        end; //else MoveBelow
     except                                      //in case of error
       SetEditing(False);                          //cancel everything
       ReloadTree;                                 //refill the tree
       raise;                                      //and show the error
     end;

     SetOverlays(AtNode, OldParent);             //recalculate changed overlays
     if IsExpanded then                          //if it was expanded
      Selected.Expand(True);                       //expand it again
     UpdateButtonState;                          //and update the buttons
    end; //if assigned Selected and AtNode and not AtNode.HasAsParent(Selected)
  end; //if Sender = TreeView and Source = TreeView
end;




{Called when the button to move the selected node "left", below its parent
 node, is clicked.
~param Sender the sender of the event, ~[link ButtonLeft] }
procedure TFormGUITopics.ButtonLeftClick(Sender: TObject);
var       Selected      :TTreeNode;           //the node to be moved
          OldParent     :TTreeNode;           //the parent of the node
          Entry         :TGUIMainIndexEntry;  //the entry of the moved node
          InsertAfter   :TGUIMainIndexEntry;  //the entry to move it to
begin
 Selected := TreeView.Selected;               //get the current node
 //a node selected, and can be moved to the same level as its parent
 if assigned(Selected) and assigned(Selected.Parent) then //(i.e. has one)
  begin
   OldParent := Selected.Parent;                //get the parent node
   if assigned(OldParent.GetNextSibling()) then //parent not the last node?
    Selected.MoveTo(OldParent.GetNextSibling(), naInsert)  //move after it
   else
    Selected.MoveTo(OldParent, naAdd);            //append as last child node

   Entry := Selected.Data;                      //entry represented by the node
   InsertAfter := Entry.Parent;                 //entry of the old parent node

   //move the entry after the parent's entry
   Entry.Parent.UnlinkEntry(Entry.ParentIndex);
   try
     InsertAfter.Parent.InsertEntryAfter(InsertAfter, Entry);
   except                                       //in case of error
     Entry.Free;                                  //remove the entry
     SetEditing(False);                           //cancel everything
     ReloadTree;                                  //refill the tree
     raise;                                       //and show the error
   end;

   SetOverlays(OldParent, nil);                 //recalculate changed overlays
   UpdateButtonState;                           //and update the buttons
  end;
end;

{Called when the button to move the selected node "right", as a child node of
 its preceding node, is clicked.
~param Sender the sender of the event, ~[link ButtonRight] }
procedure TFormGUITopics.ButtonRightClick(Sender: TObject);
var       Selected      :TTreeNode;           //the node to be moved
          Entry         :TGUIMainIndexEntry;  //the entry of the moved node
          InsertIn      :TGUIMainIndexEntry;  //the entry to move it to
begin
 Selected := TreeView.Selected;               //get the current node
 //a node selected, and can be moved right, i.e. has a preceding node?
 if assigned(Selected) and assigned(Selected.GetPrevSibling()) then
  begin
   Selected.MoveTo(Selected.GetPrevSibling, naAddChild); //add as child node
   Entry := Selected.Data;                               //get the node's entry

   InsertIn := Entry.Parent.SubTopics[Entry.ParentIndex - 1]; //preceding entry

   //make the entry a child entry of its preceding entry
   Entry.Parent.UnlinkEntry(Entry.ParentIndex);
   try
     InsertIn.AppendEntry(Entry);
   except                                       //in case of error
     Entry.Free;                                  //remove the entry
     SetEditing(False);                           //cancel everything
     ReloadTree;                                  //refill the tree
     raise;                                       //and show the error
   end;

   SetOverlays(Selected, nil);                  //recalculate changed overlays
   UpdateButtonState;                           //and update the buttons
  end;
end;

{Called when the button to move the selected node "up" is clicked.
~param Sender the sender of the event, ~[link ButtonUp] }
procedure TFormGUITopics.ButtonUpClick(Sender: TObject);
var       Selected      :TTreeNode;          //the node to be moved
          Entry         :TGUIMainIndexEntry; //and its entry
begin
 Selected := TreeView.Selected;              //get the current node
 //a node selected and is not the first node, i.e. can be moved upward?
 if assigned(Selected) and assigned(Selected.GetPrevSibling()) then
  begin
   //not the second node?
   if assigned(Selected.GetPrevSibling.GetPrevSibling()) then
    Selected.MoveTo(Selected.GetPrevSibling, naInsert)    //move upward
   else
    Selected.MoveTo(Selected.GetPrevSibling, naAddFirst); //make it first one

   Entry := Selected.Data;                     //get its entry
   Entry.Parent.SwapSubTopics(Entry.ParentIndex - 1);  //and move it upward

   UpdateButtonState;                          //update the buttons
  end;
end;

{Called when the button to move the selected node "down" is clicked.
~param Sender the sender of the event, ~[link ButtonDown] }
procedure TFormGUITopics.ButtonDownClick(Sender: TObject);
var       Selected      :TTreeNode;               //the node to be moved
          Entry         :TGUIMainIndexEntry;      //and its entry
begin
 Selected := TreeView.Selected;                   //get the current node
 //a node selected and is not the last node, i.e. can be moved downward?
 if assigned(Selected) and assigned(Selected.GetNextSibling()) then
  begin
   //not the last but one node?
   if assigned(Selected.GetNextSibling.GetNextSibling()) then
    Selected.MoveTo(Selected.GetNextSibling.GetNextSibling, naInsert) //mode it
   else
    Selected.MoveTo(Selected.GetNextSibling, naAdd);  //make it the last node

   Entry := Selected.Data;                        //get its entry
   Entry.Parent.SwapSubTopics(Entry.ParentIndex); //and move it downward

   UpdateButtonState;                             //update the buttons
  end;
end;









{Called when the button to create a new entry is clicked.
~param Sender the sender of the event, ~[link ButtonNew] }
procedure TFormGUITopics.ButtonNewClick(Sender: TObject);
var       Selected      :TTreeNode;          //the currently selected node
          New           :TGUIMainIndexEntry; //the newly created entry
          NewNode       :TTreeNode;
begin
 Selected := TreeView.Selected;              //get the currently selected node

 New := TGUIMainIndexEntry.Create;           //create a new entry
 try
   if assigned(Selected) then                //tree is not empty? add after it
    TGUIMainIndexEntry(Selected.Data).Parent.InsertEntry(Selected.Index + 1,
                                                         New)
   else
    FGUIMainIndexRoot.AppendEntry(New);        //add the first node
 except
   New.Free;
   raise;
 end;

 if assigned(Selected) then                  //a node is selected?
  if assigned(Selected.GetNextSibling()) then  //not the last node?
   //add the node after the selected node
   NewNode := TreeView.Items.InsertObject(Selected.GetNextSibling, '', New)
  else
   NewNode := TreeView.Items.AddObject(Selected, '', New) //add as last node
 else
  NewNode := TreeView.Items.AddObject(nil, '', New); //create the first node

 NewNode.ImageIndex := Ord(iText);           //by default a simple text node
 NewNode.SelectedIndex := Ord(iText);

 TreeView.Selected := NewNode;               //select the new node

 EditText.SetFocus;                          //text has probably to be edited
end;

{Called when the button to delete an entry is clicked.
~param Sender the sender of the event, ~[link ButtonRemove] }
procedure TFormGUITopics.ButtonRemoveClick(Sender: TObject);
var       Selected      :TTreeNode;          //the selected node to be deleted
          Parent        :TTreeNode;          //its parent node
          Entry         :TGUIMainIndexEntry; //the entry o be deleted
begin
 Selected := TreeView.Selected;              //get the currently selected node
 if assigned(Selected) then                  //a node is selected?
  begin
   SetEditing(False);                          //stop editing it
   ButtonRemove.Enabled := False;              //can't be removed again

   Parent := Selected.Parent;                  //get its parent node

   Entry := Selected.Data;                     //get the represented entry
   Entry.Free;                                 //and free it
   Selected.Free;                              //free also the node

   SetOverlays(Parent, nil);                   //recalculate changed overlays
  end;
end;

{Called when the button to clear the alternative content of the main index
 completely is clicked.
~param Sender the sender of the event, ~[link ButtonClearTree] }
procedure TFormGUITopics.ButtonClearTreeClick(Sender: TObject);
var       i             :Integer;       //counter through all top-level entries
begin
 //the user has to confirm this action
 if MessageDlg('Are you sure you want delete the whole content of the index?',
               mtConfirmation, [mbOK, mbCancel],
               ButtonClearTree.HelpContext) = mrOK then
  begin
   SetEditing(False);                     //stop editing the current node

   for i := 0 to FGUIMainIndexRoot.SubTopicCount - 1 do //clear all entries
    FGUIMainIndexRoot.SubTopics[0].Free;

   ReloadTree;                            //reload, to show the empty tree
   SetEditing(False);                     //make sure, no node is edited
   UpdateButtonState;                     //and only a new node can be created
  end;
end;



{Called when another kind of link is selected for the current entry with the
 radio group.
~param Sender the sender of the event, ~[link RadioGroupLinkType] }
procedure TFormGUITopics.RadioGroupLinkTypeClick(Sender: TObject);
var       Index         :Integer;    //the index of the selected kind of link
          VisTarget     :Boolean;    //whether a link is selected with a target
          //whether the comment inside as GUI has to be selected
          VisComment    :Boolean;
begin
 Index := RadioGroupLinkType.ItemIndex; //get the selected kind
 VisTarget := Index <> 0;               //not only simple text?
 VisComment := Index = 1;               //a link inside the help on a GUI?
 case Index of                          //handle the kind of the link
   0: ;                                   //nothing to be done
   1: begin
       LoadGUIBaseNames(ComboBoxLinkTarget.Items); //load all known GUI's names
       ComboBoxComment.Items.Clear;                //no comments so far
      end;
   2: begin
       LoadUserDocPages(ComboBoxLinkTarget.Items); //load all pages of user doc
      end;
   3: ComboBoxLinkTarget.Items.Clear;              //no choices available
 else
  assert(False);
 end;

 //only show component to set link target when it is a link
 LabelLinkTarget.Visible := VisTarget;
 ComboBoxLinkTarget.Visible := VisTarget;

 //only show component to set comment inside a GUI when it is a link into the
 LabelComment.Visible := VisComment;    //help on a GUI
 ComboBoxComment.Visible := VisComment;

 SaveData;                              //save the new link kind
end;

{Called when the target of the link is changed.
~param Sender the sender of the event, ~[link ComboBoxLinkTarget] }
procedure TFormGUITopics.ComboBoxLinkTargetChange(Sender: TObject);
var       Index         :Integer;          //index of select GUI
begin
 if RadioGroupLinkType.ItemIndex = 1 then  //is a link inside help on a GUI?
  begin
   ComboBoxComment.Items.Clear;              //clear list of comments
   Index := ComboBoxLinkTarget.ItemIndex;    //get index of selected GUI
   if Index = -1 then                        //not selected?
    //then search manually with the entered name of the GUI
    Index := ComboBoxLinkTarget.Items.IndexOf(ComboBoxLinkTarget.Text);
   if Index <> -1 then                       //a valid GUI selected
    //load the comments of the selected GUI into the other combo box
    LoadGUIComments(ComboBoxComment.Items, ComboBoxLinkTarget.Text);
  end;

 SaveData;                                 //save the new target of the link
end;


{Called when a value of the currently edited entry is changed.
~param Sender the sender of the event, either ~[link EditText] or
              ~[link ComboBoxComment] }
procedure TFormGUITopics.EntryValuesChanged(Sender: TObject);
begin
 SaveData;                                 //save the newly edited data
end;


end.

⌨️ 快捷键说明

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