Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Also keep current branch and workdir status cached. |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
8f789ae9fc7264419999c0f49e54a4d6 |
User & Date: | tinus 2015-11-19 12:32:45.200 |
Context
2015-11-19
| ||
13:00 | Differentiate between caption and hint for branch button. Also, just launch Tortoise when clicking on sync status. check-in: b4108802da user: tinus tags: trunk | |
12:32 | Also keep current branch and workdir status cached. check-in: 8f789ae9fc user: tinus tags: trunk | |
10:28 | Added buttons for branches and for sync info, but their actions' update method has nefarious side effects (the drop-down button loses its caption and its drop-down arrow). Added convenience functions to get the current file or project's repo info. check-in: a9f098e96c user: tinus tags: trunk | |
Changes
Changes to src/VCSInfoMenuWzrd.pas.
1 2 3 4 5 6 7 8 9 10 11 12 | unit VCSInfoMenuWzrd; interface uses System.Generics.Collections, ToolsAPI, Vcl.ComCtrls, Vcl.Controls; type TRepoInfo = record Root: string; IsRepo: Boolean; | > > | | > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | unit VCSInfoMenuWzrd; interface uses System.Generics.Collections, ToolsAPI, Vcl.ComCtrls, Vcl.Controls; type TRepoInfo = record Root: string; IsRepo: Boolean; Branch: string; Pending: Integer; Incoming: Integer; Outgoing: Integer; LastUpdated: TDateTime; end; // TODO: implement IOTAEditorNotifier and/or IOTAIDENotifier so we know which file is active TVCSInfoWizard = class(TNotifierObject, IOTAWizard, IOTAMenuWizard) private FRepos: TDictionary<string,TRepoInfo>; FToolbar: TToolBar; FButtonBranch: TToolButton; FButtonSync: TToolButton; FImgUnknown: integer; FImgNoSync: integer; FImgIn: integer; FImgOut: integer; FImgInOut: integer; FImgClean: integer; FImgPending: integer; FImgExtra: integer; |
︙ | ︙ | |||
376 377 378 379 380 381 382 383 | actSync: TAction; actBranch: TAction; begin Supports(ToolsAPI.BorlandIDEServices, INTAServices, Services); Services.MenuBeginUpdate; try FToolbar := Services.NewToolbar('tlbVCSInfo', 'VCS Info'); | > | > | | | | | | < < < < < < < < < < < < < | > > > > > > > > > > > > > > > > > > > < > > > | > | < | < | | > | 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | actSync: TAction; actBranch: TAction; begin Supports(ToolsAPI.BorlandIDEServices, INTAServices, Services); Services.MenuBeginUpdate; try FToolbar := Services.NewToolbar('tlbVCSInfo', 'VCS Info'); FToolbar.AutoSize := True; FImgUnknown := AddButtonImage(clBtnShadow); FImgNoSync := AddButtonImage(clGreen); FImgIn := AddButtonImage(clRed); FImgOut := AddButtonImage(clYellow); FImgInOut := AddButtonImage(clWebOrange); FImgClean := AddButtonImage(clLime); FImgPending := AddButtonImage(clBlue); FImgExtra := AddButtonImage(clFuchsia, 0); actSync := TAction.Create(FToolbar); actSync.Caption := '(nothing to sync)'; actSync.Hint := actSync.Caption; actSync.Enabled := True; actSync.ImageIndex := FImgUnknown; actSync.OnExecute := actSyncExecute; actSync.OnUpdate := actSyncUpdate; FButtonSync := Services.AddToolButton(FToolbar.Name, 'btnSync', actSync) as TToolButton; FButtonSync.Style := tbsButton; actBranch := TAction.Create(FToolbar); actBranch.Caption := '(branch name)'; actBranch.Enabled := True; actBranch.ImageIndex := FImgUnknown; actBranch.OnExecute := actBranchExecute; actBranch.OnUpdate := actBranchUpdate; FButtonBranch := Services.AddToolButton(FToolbar.Name, 'btnBranch', actBranch) as TToolButton; FButtonBranch.Style := tbsTextButton; FButtonBranch.DropdownMenu := TPopupMenu.Create(FButtonBranch); FButtonBranch.DropdownMenu.AutoHotkeys := maManual; FButtonBranch.DropdownMenu.OnPopup := actBranchMenuPopup; FButtonBranch.DropdownMenu.AutoPopup := True; FToolbar.Left := Application.MainForm.Width - FToolbar.Width; FToolbar.Visible := True; // Services.ReadToolbar(FToolbar.Owner, FToolbar.Parent, FToolbar.Name, TWinControl(FToolbar)); Services.ToolbarModified(FToolbar); finally Services.MenuEndUpdate; end; end {TVCSInfoWizard.Create}; { ------------------------------------------------------------------------------------------------ } destructor TVCSInfoWizard.Destroy; var Services: INTAServices; Button: TToolButton; begin Supports(ToolsAPI.BorlandIDEServices, INTAServices, Services); // Services.WriteToolbar(FToolbar); // FButtonIn.Action.Free; for Button in FToolbar do begin FToolbar.Perform(CM_CONTROLCHANGE, WPARAM(Button), 0); end; Services.MenuBeginUpdate; try Services.ToolbarModified(FToolbar); FToolbar.Free; finally Services.MenuEndUpdate; end; FRepos.Free; inherited; end; procedure TVCSInfoWizard.actBranchUpdate(Sender: TObject); var actBranch: TAction; Repo: TRepoInfo; NewImageIndex: Integer; NewCaption: string; NewEnabled: boolean; Services: INTAServices; begin actBranch := TAction(Sender); Repo := GetActiveFileRepo; NewEnabled := Repo.IsRepo; if Repo.IsRepo then begin NewCaption := Repo.Branch; case Repo.Pending of -1: NewImageIndex := FImgUnknown; 0: NewImageIndex := FImgClean; else NewImageIndex := FImgPending; end; end else begin NewImageIndex := -1; // FImgNeutral; if Repo.Root = '' then begin NewCaption := '(no project)'; end else begin NewCaption := '(not Mercurial)'; end; end; if (actBranch.ImageIndex <> NewImageIndex) or (actBranch.Caption <> NewCaption) or (actBranch.Enabled <> NewEnabled) then begin actBranch.Enabled := NewEnabled; actBranch.ImageIndex := NewImageIndex; actBranch.Caption := NewCaption; actBranch.Hint := actBranch.Caption; Supports(ToolsAPI.BorlandIDEServices, INTAServices, Services); Services.ToolbarModified(FToolbar); LogMessage(Format('actBranchUpdate: IsRepo=%d, In: %d, Out: %d; Caption="%s", Img=%d', |
︙ | ︙ | |||
490 491 492 493 494 495 496 497 498 499 500 501 502 503 | procedure TVCSInfoWizard.actBranchMenuClick(Sender: TObject); var Item: TMenuItem; Repo: TRepoInfo; Output: string; MsgType: TMsgDlgType; ModuleServices: IOTAModuleServices; begin Item := Sender as TMenuItem; Repo := GetActiveFileRepo; if Repo.IsRepo then begin Supports(ToolsAPI.BorlandIDEServices, IOTAModuleServices, ModuleServices); if not ModuleServices.SaveAll then Exit; | > | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | procedure TVCSInfoWizard.actBranchMenuClick(Sender: TObject); var Item: TMenuItem; Repo: TRepoInfo; Output: string; MsgType: TMsgDlgType; ModuleServices: IOTAModuleServices; i: Integer; begin Item := Sender as TMenuItem; Repo := GetActiveFileRepo; if Repo.IsRepo then begin Supports(ToolsAPI.BorlandIDEServices, IOTAModuleServices, ModuleServices); if not ModuleServices.SaveAll then Exit; |
︙ | ︙ | |||
513 514 515 516 517 518 519 | {$MESSAGE WARN 'HINT: perhaps close the project?'} Output := ''; if ExecuteCmd('hg -y update "' + Item.Caption + '"', Output, False, nil, Repo.Root) = 0 then begin TaskMessageDlg(Repo.Root, Output, mtInformation, [mbOK], 0); end else begin TaskMessageDlg(Repo.Root, Output, mtError, [mbOK], 0); end; | | > > > | | < < > | | < | | > | > > > > > > > > | | | | | < | | | | | | | < | | > > > > | > > > > > > | > | 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | {$MESSAGE WARN 'HINT: perhaps close the project?'} Output := ''; if ExecuteCmd('hg -y update "' + Item.Caption + '"', Output, False, nil, Repo.Root) = 0 then begin TaskMessageDlg(Repo.Root, Output, mtInformation, [mbOK], 0); end else begin TaskMessageDlg(Repo.Root, Output, mtError, [mbOK], 0); end; {$MESSAGE WARN 'TODO: reopen the project if we closed it'} for i := ModuleServices.ModuleCount - 1 downto 0 do begin ModuleServices.Modules[i].Refresh(False); end; end; end; procedure TVCSInfoWizard.actBranchMenuPopup(Sender: TObject); var Menu: TPopupMenu; Repo: TRepoInfo; Branches: TStringList; Branch: string; mi: TMenuItem; begin Menu := Sender as TPopupMenu; Menu.Items.Clear; Repo := GetActiveFileRepo(True); if Repo.IsRepo then begin Branches := TStringList.Create; try ExecuteCmd('hg -yq branches', Branches.Append, False, nil, Repo.Root); Branches.Sort; for Branch in Branches do begin if Branch <> Repo.Branch then begin mi := TMenuItem.Create(Menu); mi.Caption := Branch; mi.OnClick := actBranchMenuClick; Menu.Items.Add(mi); end; end; finally Branches.Free; end; end; end {TVCSInfoWizard.actBranchMenuPopup}; procedure TVCSInfoWizard.actSyncExecute(Sender: TObject); begin Self.Execute; end; procedure TVCSInfoWizard.actSyncUpdate(Sender: TObject); var actSync: TAction; Repo: TRepoInfo; NewImageIndex: Integer; NewCaption: string; NewEnabled: boolean; Services: INTAServices; begin actSync := Sender as TAction; Repo := GetActiveFileRepo; NewEnabled := Repo.IsRepo; if Repo.IsRepo then begin if (Repo.Incoming < 0) and (Repo.Outgoing < 0) then begin NewImageIndex := FImgUnknown; NewCaption := 'Error while checking remote repository'; end else if Repo.Incoming > 0 then begin if Repo.Outgoing > 0 then begin NewImageIndex := FImgInOut; NewCaption := Format('%d pull(s), %d push(es)', [Repo.Incoming, Repo.Outgoing]); end else begin NewImageIndex := FImgIn; NewCaption := Format('%d pull(s)', [Repo.Incoming]); end; end else if Repo.Outgoing > 0 then begin NewImageIndex := FImgOut; NewCaption := Format('%d push(es)', [Repo.Outgoing]); end else begin NewImageIndex := FImgNoSync; NewCaption := 'nothing to sync'; end; end else begin NewImageIndex := FImgUnknown; NewCaption := '(not a repo)'; end; if (NewImageIndex <> actSync.ImageIndex) or (NewCaption <> actSync.Caption) or (NewEnabled <> actSync.Enabled) then begin actSync.ImageIndex := NewImageIndex; actSync.Caption := NewCaption; actSync.Hint := actSync.Caption; actSync.Enabled := NewEnabled; Supports(ToolsAPI.BorlandIDEServices, INTAServices, Services); Services.ToolbarModified(FToolbar); LogMessage(Format('actSyncUpdate: IsRepo=%d, In: %d, Out: %d; Caption="%s", Img=%d', [Ord(Repo.IsRepo), Repo.Incoming, Repo.Outgoing, NewCaption, NewImageIndex])); end; end {TVCSInfoWizard.actSyncUpdate}; { ------------------------------------------------------------------------------------------------ } function TVCSInfoWizard.GetMenuText: string; var Project: IOTAProject; Repo: TRepoInfo; begin |
︙ | ︙ | |||
698 699 700 701 702 703 704 705 | end; function TVCSInfoWizard.GetActiveFileRepo(const AForceUpdate: Boolean): TRepoInfo; var Modules: IOTAModuleServices; Module: IOTAModule; Editor: IOTAEditor; begin | > < | < | | < | | > > | | > > > > > > | 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | end; function TVCSInfoWizard.GetActiveFileRepo(const AForceUpdate: Boolean): TRepoInfo; var Modules: IOTAModuleServices; Module: IOTAModule; Editor: IOTAEditor; FileName: string; begin if Supports(ToolsAPI.BorlandIDEServices, IOTAModuleServices, Modules) then begin Module := Modules.CurrentModule; if Assigned(Module) then begin Editor := Module.CurrentEditor; if Assigned(Editor) then FileName := Editor.FileName; end; if FileExists(FileName) then begin Result := GetRepoInfo(FileName, AForceUpdate); end else begin Result := GetProjectRepo(AForceUpdate); end; end else begin Result := Default(TRepoInfo); end; end {TVCSInfoWizard.GetActiveFileRepo}; function TVCSInfoWizard.GetProjectRepo(const AForceUpdate: Boolean): TRepoInfo; var Project: IOTAProject; begin Project := ToolsAPI.GetActiveProject; |
︙ | ︙ | |||
750 751 752 753 754 755 756 757 758 | RootPath := RootPath.Trim; FinalRootPath := GetFinalPathName(RootPath); if AForceUpdate or (not FRepos.TryGetValue(FinalRootPath, Result)) or (Now - Result.LastUpdated > 5 / SecsPerDay) then begin Result.Root := RootPath; Result.IsRepo := True; Lines := TStringList.Create; try iRes := ExecuteCmd('hg -yq incoming --newest-first --template "{rev}\t{node|short}\t{node}\t{parents}\t{date|isodatesec}\t{author}\t{branches}\t{desc|firstline}\t{tags}\n"', Lines.Append, False, nil, FilePath); | > > > > > > > > > > > > > > > | > > | > > | 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 | RootPath := RootPath.Trim; FinalRootPath := GetFinalPathName(RootPath); if AForceUpdate or (not FRepos.TryGetValue(FinalRootPath, Result)) or (Now - Result.LastUpdated > 5 / SecsPerDay) then begin Result.Root := RootPath; Result.IsRepo := True; Lines := TStringList.Create; try Lines.Clear; iRes := ExecuteCmd('hg -yq branch', Lines.Append, False, nil, FilePath); if iRes = 0 then begin Result.Branch := Lines.Text.Trim; end; Lines.Clear; iRes := ExecuteCmd('hg -yq status', Lines.Append, False, nil, FilePath); if iRes = 0 then begin Result.Pending := Lines.Count; end else begin Result.Pending := -1; end; Lines.Clear; iRes := ExecuteCmd('hg -yq incoming --newest-first --template "{rev}\t{node|short}\t{node}\t{parents}\t{date|isodatesec}\t{author}\t{branches}\t{desc|firstline}\t{tags}\n"', Lines.Append, False, nil, FilePath); if iRes < 255 then begin Result.Incoming := Lines.Count; end else begin Result.Incoming := -1; end; Lines.Clear; iRes := ExecuteCmd('hg -yq outgoing --newest-first --template "{rev}\t{node}\t{parents}\t{date|isodatesec}\t{author}\t{branches}\t{desc|firstline}\t{tags}.\n"', Lines.Append, False, nil, FilePath); if iRes < 255 then begin Result.Outgoing := Lines.Count; end else begin Result.Outgoing := -1; end; finally Lines.Free; end; Result.LastUpdated := Now; end; end; |
︙ | ︙ |