📄 formfamtree.cpp
字号:
DeleteNode(node, true, false);
if (siblingnode)
siblingnode->Selected = true;
else if (parentnode)
parentnode->Selected = true; // select the parent
else
{
ActionNodeDeleteHard->Enabled = false;
ActionNodeDeleteSoft->Enabled = false;
}
TreeViewFamilyClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionNodeDeleteSoftExecute(TObject *Sender)
{
TTreeNode* node;
TTreeNode* parentnode;
TTreeNode* siblingnode;
node = TreeViewFamily->Selected;
parentnode = TreeViewFamily->Selected->Parent;
siblingnode = TreeViewFamily->Selected->getNextSibling();
ActionEditUndo->Enabled = DeleteNode(node, true, true, TreeViewUndo->Items);
if (siblingnode)
siblingnode->Selected = true;
else if (parentnode)
parentnode->Selected = true; // select the parent
else
{
ActionNodeDeleteHard->Enabled = false;
ActionNodeDeleteSoft->Enabled = false;
}
TreeViewFamilyClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionFileSaveAsExecute(TObject *Sender)
{
SaveDialog1->DefaultExt = "FAM";
SaveDialog1->FileName = "*.fam";
if (SaveDialog1->Execute())
{
TreeViewFamily->SaveToFile(SaveDialog1->FileName);
}
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionFileOpenExecute(TObject *Sender)
{
OpenDialog1->DefaultExt = "FAM";
OpenDialog1->FileName = "*.fam";
if (OpenDialog1->Execute())
{
TreeViewFamily->LoadFromFile(OpenDialog1->FileName);
if (!PageControlEditEntry->Visible)
PageControlEditEntry->Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionNodeMoveUpExecute(TObject *Sender)
{
// move the item up.
MoveUpTree(TreeViewFamily->Selected);
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionNodeMoveDownExecute(TObject *Sender)
{
// move the item down.
if (!TreeViewFamily->Selected)
{
MessageBeep(MB_OK);
return;
}
// move up the item below it..
TTreeNode *pItem = TreeViewFamily->Selected->getNextSibling();
if (pItem != NULL)
MoveUpTree(pItem);
else
MessageBeep(MB_OK);
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionNodeFindLabelExecute(TObject *Sender)
{
// let's call a routine that will build the text label for the node we want to search for
AnsiString search = CreateLabel(EditFirstName->Text,EditLastName->Text);
int absindex = FindTreeNodeBasedOnLabel(TreeViewFamily->Items,search);
if (absindex != -1)
{
// found it
TreeViewFamily->Items->Item[absindex]->Selected = true;
ReflectNodeLabel(TreeViewFamily->Selected);
}
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionNodeAddLabelExecute(TObject *Sender)
{
// add node label to the tree
AnsiString temptext = AnsiString("Person" +
AnsiString(TreeViewFamily->Items->Count));
ClearEntryPanel(); // clear the edit display.
if (TreeViewFamily->Selected)
{
TPersonalInfo *ParentData;
ParentData = (TPersonalInfo*)( TreeViewFamily->Selected->Data);
EditLastName->Text = ParentData->LastName;
EditFirstName->Text = temptext;
}
else // no parent
EditLastName->Text = temptext;
// let's call a routine that will build the text label for the new tree node
AnsiString text = CreateLabel(EditFirstName->Text,EditLastName->Text);
// let's add the node to the tree
TTreeNode* tempnode = TreeViewFamily->Items->AddChild(TreeViewFamily->Selected,text);
tempnode->Selected = true; // select the node we just added
// let's provide the user the ability to modify and delete the new node
ActionNodeDeleteHard->Enabled = true;
ActionNodeDeleteSoft->Enabled = true;
TreeViewFamilyClick(Sender); // to refresh
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionNodeAddDataExecute(TObject *Sender)
{
// first save any information that was just modifed
ActionNodeModifyExecute(Sender);
if (!PageControlEditEntry->Visible)
PageControlEditEntry->Visible = true;
PanelEditEntry->Enabled = true;
AnsiString temptext = AnsiString("Person" + AnsiString(TreeViewFamily->Items->Count));
if (!TreeViewFamily->Selected)
ClearEntryPanel(); // clear the edit display.
// Here's where we add the information to the tree
TPersonalInfo * PersonalInfo = new TPersonalInfo;
PersonalInfo->ID = GetNewID(); // get a unique id
PersonalInfo->LastName = temptext;
TPersonalInfo *ParentData;
TTreeNode* node = TreeViewFamily->Selected;
if (node)
if (node->Data)
{
PersonalInfo->FirstName = temptext;
// TPersonalInfo *ParentData;
ParentData = (TPersonalInfo*)( node->Data);
PersonalInfo->DetermineParent(ParentData);
if (ParentData->deleted) // node selected is "soft" deleted
node = NULL;
}
// let's call a routine that will build the text label for the new tree node
AnsiString text = CreateLabel(PersonalInfo->FirstName,PersonalInfo->LastName);
PersonalInfo->Name = text;
TTreeNode* tempnode = TreeViewFamily->Items->AddChildObject(node,text,PersonalInfo);
if (PersonalInfo->Gender)
{
tempnode->ImageIndex = gPersonMale;
tempnode->SelectedIndex = gPersonMaleSelected;
}
else
{
tempnode->ImageIndex = gPersonFemale;
tempnode->SelectedIndex = gPersonFemaleSelected;
}
AddCountToNode(TreeViewFamily->Items);
// provide the user the ability to modify and delete the new node
ActionNodeDeleteHard->Enabled = true;
ActionNodeDeleteSoft->Enabled = true;
TreeViewFamilyClick(Sender); // to refresh
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionEditUndoExecute(TObject *Sender)
{
// take top item of undo tree and set it's delete flag to false.
TTreeNode *undonode = TreeViewUndo->Items->GetFirstNode();
if (!undonode)
{
MessageBeep(MB_OK);
return;
}
TInfo* info = PInfo(undonode->Data);
int absindex = FindTreeNodeBasedOnID(TreeViewFamily->Items,info->ID);
if (absindex != -1)
{
TTreeNode * node = TreeViewFamily->Items->Item[absindex];
// put it on top of redo tree view
ActionEditRedo->Enabled = AddToUndoRedoList(TreeViewRedo->Items,info->ID,info, node->ImageIndex,false);
UndeleteNode(node); // need to turn off the overlayindex... this takes care of children too.
undonode->Delete(); // remove it out of the undo tree
// refresh everything
TreeViewFamilyClick(Sender);
}
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionEditRedoExecute(TObject *Sender)
{
// take top item of redo tree and set it's delete flag to true.
TTreeNode *redonode = TreeViewRedo->Items->GetFirstNode();
if (!redonode)
{
MessageBeep(MB_OK);
return;
}
TInfo* info = PInfo(redonode->Data);
int absindex = FindTreeNodeBasedOnID(TreeViewFamily->Items,info->ID);
if (absindex != -1)
{
TTreeNode * node = TreeViewFamily->Items->Item[absindex];
ActionEditRedo->Enabled = DeleteNode(node, true, true, TreeViewUndo->Items);
redonode->Delete(); // remove it out of the redo tree
TreeViewFamilyClick(Sender); // refresh everything
}
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionFileClearExecute(TObject *Sender)
{
ClearAll(TreeViewFamily->Items);
TreeViewUndo->Items->Clear();
TreeViewRedo->Items->Clear();
// clear the edit entry panel
ClearEntryPanel();
//disable the edit entiry panel
PageControlEditEntry->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::Exit1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionEditRefreshExecute(TObject *Sender)
{
// this routine will refresh the tree view
// causing any "soft" deleted nodes to be permanetly deleted
if (TreeViewUndo->Items->Count > 0)
TreeViewUndo->Items->Clear();
if (TreeViewRedo->Items->Count > 0)
TreeViewRedo->Items->Clear();
ClearDeletedItems(TreeViewFamily->Items);
TreeViewFamilyClick(Sender); // refresh everything
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionOtherChangeExecute(TObject *Sender)
{
bool modified = false;
TCustomEdit *edit = dynamic_cast<TCustomEdit*>(Sender);
if (edit)
if (edit->Modified)
modified = true;
TRadioButton *rbutton = dynamic_cast<TRadioButton*>(Sender);
if (rbutton)
modified = true;
if (modified)
{
ActionNodeModify->Enabled = true;
ActionOtherRestore->Enabled = true;
// remember node
nodetoremember = TreeViewFamily->Selected;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionOtherRestoreExecute(TObject *Sender)
{
// restore settings
if (nodetoremember) // make sure changes were made
ReflectNodeLabel(nodetoremember);
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionTreeExpandExecute(TObject *Sender)
{
TreeViewFamily->FullExpand();
}
//---------------------------------------------------------------------------
void __fastcall TFormFamilyTree::ActionTreeCollapseExecute(TObject *Sender)
{
TreeViewFamily->FullCollapse();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -