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

📄 addrbk_frm.pas

📁 siMail, siMail, siMail, siMail
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    if (sel = nodePublicBook) then begin
      node := trBooks.AddChild(sel);
      trBooks.Expanded[sel] := True;
    end
    else begin
      node := trBooks.AddChild(sel.Parent);
      trBooks.Expanded[sel.Parent] := True;
    end;
    trBooks.EditNode(node, -1);
  end;
end;

procedure TfrmAddrBk.trBooksGetPopupMenu(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
  var AskParent: Boolean; var PopupMenu: TPopupMenu);
begin
  if Mode = abkNormal then
    PopupMenu := popAddrBkNormal
  //else
  //  PopupMenu := popAddrBkSelect;
end;

procedure TfrmAddrBk.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;

procedure TfrmAddrBk.actBookNewUpdate(Sender: TObject);
begin

  if (trBooks.GetFirstSelected <> nil) and (trBooks.GetFirstSelected <> nodeRemoteBook) and
    (trBooks.GetFirstSelected.Parent <> nodeRemoteBook) and not trBooks.IsEditing then begin
    actBookNew.Enabled := True;
    actBookRename.Enabled := True;
    actBookDelete.Enabled := True;
  end
  else begin
    actBookNew.Enabled := False;
    actBookRename.Enabled := False;
    actBookDelete.Enabled := False;
  end;

end;

procedure TfrmAddrBk.trBooksCreateEditor(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
begin
  editor.LinkEditor(EditLink, TAddressBook(
    PTreeAddrBk(trBooks.GetNodeData(Node))^.obj).BookName);
end;

procedure TfrmAddrBk.trBooksEdited(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex);
var no: Integer;
begin
  with PTreeAddrBk(trBooks.GetNodeData(Node))^ do begin
    if Trim(txtName.Text) = TAddressBook(obj).BookName then exit;
    case id of
      abtPrivate:
        no := frmMailbox.Profile.AddressBook.GetNoForName(Trim(txtName.Text));
      abtPublic:
        no := frmMailbox.PublicAddressBook.GetNoForName(Trim(txtName.Text));
    end;
    if no = 0 then begin
      TAddressBook(obj).BookName := Trim(txtName.Text);
      { TODO : when ldap will be implemented you have to fix next line. }
      frmAddressBook.UpdateBookInMenu(Node.Index, PTreeAddrBk(trBooks.GetNodeData(Node.Parent))^.id = abtPrivateRoot);
    end
    else begin
      MessageDlg(Format(_('Address book with name: ''%s'' already exists.' +
        #10#13 + 'Please write diffrent name.'), [Trim(txtName.Text)]), mtError, [mbOK], 0);
            //txtName.Text:=Trim(txtName.Text)  + '-' + IntToHex(i,4));
      trBooks.CancelEditNode;
      trBooks.ClearSelection;
      trBooks.FocusedNode := Node;
      //trBooks.EditNode(Node,-1);
    end;
  end;
  (FSelectedAddressBook.Collection as TAddressBooks).Dirty := True;
end;

procedure TfrmAddrBk.trBooksEditCancelled(Sender: TBaseVirtualTree;
  Column: TColumnIndex);
var Node: PVirtualNode;
begin
  if newBook then begin
    Node := trBooks.FocusedNode;

    if PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^.id = abtPrivate then
      frmMailbox.Profile.AddressBook.Delete(frmMailbox.Profile.AddressBook.FindItem(
        TAddressBook(PTreeAddrBk(trBooks.GetNodeData(Node))^.obj)))
    else
      frmMailbox.PublicAddressBook.Delete(frmMailbox.PublicAddressBook.FindItem(
        TAddressBook(PTreeAddrBk(trBooks.GetNodeData(Node))^.obj)));

    newBook := False;
    trBooks.DeleteNode(Node);
  end;
end;

procedure TfrmAddrBk.txtNameExit(Sender: TObject);
begin
  trBooks.CancelEditNode;
end;

procedure TfrmAddrBk.actFileCloseExecute(Sender: TObject);
begin
  Self.Close;
end;

procedure TfrmAddrBk.trBooksInitChildren(Sender: TBaseVirtualTree;
  Node: PVirtualNode; var ChildCount: Cardinal);
begin
  with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
    case id of
      abtPrivateRoot:
        ChildCount := frmMailbox.Profile.AddressBook.Count;
      abtPublicRoot:
        ChildCount := frmMailbox.PublicAddressBook.Count;
      abtPublic, abtPrivate: ChildCount := TAddressBook(obj).Persons.Count;
      abtContact: ChildCount := TPerson(obj).Emails.Count;
    end;
  end;
end;

procedure TfrmAddrBk.trBooksInitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var i: Integer;
begin
  if ParentNode = nil then exit;
  case PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(ParentNode))^.id of
    abtPrivateRoot: begin
      with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
        id := abtPrivate;
        if NewBook then begin
          frmMailbox.Profile.AddressBook.Dirty := True;
          i := frmMailbox.Profile.AddressBook.GetNoForName(_('New address book'));
          if i <> 0 then
            frmMailbox.Profile.AddressBook.Add(
              _('New address book' + '-' + IntToHex(i, 4)))
          else
            frmMailbox.Profile.AddressBook.Add(_('New address book'));

          frmAddressBook.AddBookToMenu(Node.Index, True);
        end;
        obj := frmMailbox.Profile.AddressBook.Items[Node.Index];
        if (Mode = abkSelect) and (TAddressBook(obj).Persons.Count > 0) then
          InitialStates := [ivsHasChildren];
        text := '';
        default := False;
      end;
    end;
    abtPublicRoot: begin
      with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
        id := abtPublic;
        if NewBook then begin
          frmMailbox.PublicAddressBook.Dirty := True;
          i := frmMailbox.PublicAddressBook.GetNoForName(_('New address book'));
          if i <> 0 then
            frmMailbox.PublicAddressBook.Add(
              _('New address book' + '-' + IntToHex(i, 4)))
          else
            frmMailbox.PublicAddressBook.Add(_('New address book'));

          frmAddressBook.AddBookToMenu(Node.Index, False);
        end;
        obj := frmMailbox.PublicAddressBook.Items[Node.Index];
        if (Mode = abkSelect) and (TAddressBook(obj).Persons.Count > 0) then
          InitialStates := [ivsHasChildren];
        text := '';
        default := False;
      end;
    end;
    abtPrivate, abtPublic: begin
      with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
        id := abtContact;
        obj := TAddressBook(PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node.Parent))^.obj).Persons.Persons[Node.Index];
        text := '';
        if (Mode = abkSelect) and (TPerson(obj).Emails.Count > 0) then
          InitialStates := [ivsHasChildren];
        default := False;
      end;
    end;
    abtContact: begin
      with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
        id := abtEmail;
        obj := TPerson(PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node.Parent))^.obj).Emails.Emails[Node.Index];
        text := '';
        if Node.Index = 0 then
          default := True
        else
          default := False;
      end;
    end;
  end;
end;

procedure TfrmAddrBk.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  newBook := False;
  SaveAddressBook;
end;

procedure TfrmAddrBk.trBooksGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
begin
    //return correct folder image
  with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
    if (Kind in [ikNormal, ikSelected]) then begin
      case id of
        abtPrivateRoot:
          ImageIndex := 0;
        abtPublicRoot:
          ImageIndex := 1;
        abtRemoteRoot:
          ImageIndex := 2;
        abtPrivate, abtPublic:
          ImageIndex := 3;
        abtGroup:
          ImageIndex := 4;
        abtContact:
          ImageIndex := 5;
        abtEmail:
          ImageIndex := 6;
      end;
    end;
  end;
end;

procedure TfrmAddrBk.trBooksEditing(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean);
begin
  if Mode = abkSelect then begin
    Allowed := False;
    exit;
  end;
  
  case PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^.id of
    abtPrivate, abtPublic, abtGroup:
      Allowed := True;
    else
      Allowed := False;
  end;
end;

procedure TfrmAddrBk.actBookRenameExecute(Sender: TObject);
begin
  if trBooks.FocusedNode = nil then exit;
  trBooks.EditNode(trBooks.FocusedNode, -1);
end;

procedure TfrmAddrBk.actBookDeleteExecute(Sender: TObject);
var Node: PVirtualNode;
var addrBk: TAddressBook;
var idx: Integer;
begin
  if trBooks.SelectedCount = 0 then exit;

  Node := trBooks.GetFirstSelected;
  addrBk := TAddressBook(PTreeAddrBk(trBooks.GetNodeData(Node))^.obj);
  if MessageDlg(Format(_('Are you sure you want to delete address book ''%s''?'),
      [addrBk.BookName]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
    (FSelectedAddressBook.Collection as TAddressBooks).Dirty := True;
    idx := addrBk.Index;
    { TODO : when ldap will be implemented you have to fix next line. }
    frmAddressBook.DeleteBookFromMenu(idx, PTreeAddrBk(trBooks.GetNodeData(Node.Parent))^.id = abtPrivateRoot);
    addrBk.Delete;
    lstContacts.Clear;
    trBooks.DeleteNode(Node);
  end;
end;

procedure TfrmAddrBk.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
    (*if msg.CharCode = 27 then begin
        Self.Close;
        Handled:=True;
    end
    else*)if msg.CharCode = 46 then begin //delete
    Handled := False;
    actDelete.Execute;
  end;
end;

procedure TfrmAddrBk.actDeleteExecute(Sender: TObject);
begin
  if Mode = abkSelect then begin
    if (GetFocus = lstTo.Handle) and (lstTo.SelCount > 0) then begin
      if MessageDlg(_('Are you sure you want to remove selected contacts from list?'),
       mtConfirmation, [mbYes, mbNo], 0 ) = mrYes then
        imgTrashDragDrop(imgTrash, lstTo, 1, 1);
    end;
    if (GetFocus = lstCC.Handle) and (lstCC.SelCount > 0) then begin
      if MessageDlg(_('Are you sure you want to remove selected contacts from list?'),
       mtConfirmation, [mbYes, mbNo], 0 ) = mrYes then
        imgTrashDragDrop(imgTrash, lstCC, 1, 1);
    end;
    if (GetFocus = lstBCC.Handle) and (lstBCC.SelCount > 0) then begin
      if MessageDlg(_('Are you sure you want to remove selected contacts from list?'),
       mtConfirmation, [mbYes, mbNo], 0 ) = mrYes then
        imgTrashDragDrop(imgTrash, lstBCC, 1, 1);
    end;
    Exit;
  end;

  if GetFocus = trBooks.Handle then begin
    actBookDelete.Execute;
    exit;
  end;

  if GetFocus = lstContacts.Handle then begin
    actContactDelete.Execute;
    exit;
  end;

end;

procedure TfrmAddrBk.FormHide(Sender: TObject);
begin
  //write self position & size
  frmMailbox.Profile.Config.WriteControlSettings(Self);
end;

procedure TfrmAddrBk.pnlSelectResize(Sender: TObject);
begin
  lstTo.Top := 8;
  lstTo.Left := cmdTo.Left + cmdTo.Width + 16;
  lstTo.Width := pnlSelect.Width - lstTo.Left - 16;
  lstTo.Height := -12 + (pnlSelect.Height) div 3;
  cmdTo.Top := ((lstTo.Height - 24) div 2) + lstTo.Top;

  lstCC.Top := lstTo.Top + lstTo.Height + 8;
  lstCC.Left := lstTo.Left;
  lstCC.Width := lstTo.Width;;
  lstCC.Height := lstTo.Height;
  cmdCC.Top := ((lstCC.Height - 24) div 2) + lstCC.Top;

  lstBCC.Top := lstCC.Top + lstCC.Height + 8;
  lstBCC.Left := lstTo.Left;
  lstBCC.Width := lstTo.Width;;
  lstBCC.Height := lstTo.Height;
  cmdBCC.Top := ((lstBCC.Height - 24) div 2) + lstBCC.Top;

end;

procedure TfrmAddrBk.actContactNewExecute(Sender: TObject);
begin
  frmContact.ScheduleAsNew := True;
  frmContact.AddressBook := FSelectedAddressBook;
  frmContact.ShowModal;

  //add person to current address book's lstContacts
  lstContacts.RootNodeCount := FSelectedAddressBook.Persons.Count;
  //update address book if necessary
  if FSelectedAddressBook = frmAddressBook.SelectedAddressBook then
    frmAddressBook.ReloadBook(rbmNewContact);
end;

procedure TfrmAddrBk.actContactNewUpdate(Sender: TObject);
begin
  if trBooks.GetFirstSelected = nil then exit;

  case PTreeAddrBk(trBooks.GetNodeData(trBooks.GetFirstSelected))^.id of
    abtPrivate, abtPublic:
      actContactNew.Enabled := True;
    else actContactNew.Enabled := False;
  end;

end;

procedure TfrmAddrBk.trBooksChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin
  lstContacts.Clear;
  if (Node = nil) or (Mode = abkSelect) then
    Exit;
  if not (vsSelected in Node.States) then
    Exit;

   with PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
     case id of
     abtPrivateRoot, abtPublicRoot, abtRemoteRoot: Exit;
     end;
   end;

  FSelectedAddressBook := TAddressBook(PTreeAddrBk((Sender as TVirtualStringTree).GetNodeData(Node))^.obj);
  lstContacts.RootNodeCount := FSelectedAddressBook.Persons.Count;
  
  //gettext: number of contacts in selected address book
  sb.Panels[0].Caption := Format(_('''%s'' has %d contacts.'), [FSelectedAddressBook.BookName, lstContacts.RootNodeCount]);
end;

procedure TfrmAddrBk.lstContactsGetNodeDataSize(Sender: TBaseVirtualTree;
  var NodeDataSize: Integer);
begin
  NodeDataSize := sizeOf(TTreeContacts);
end;

procedure TfrmAddrBk.lstContactsGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var i:Integer;
begin
  CellText := '';
  with PTreeContacts((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
    case Column of
    0: CellText := frmAddressBook.GetFullName(obj);

⌨️ 快捷键说明

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