| 1 | =pod | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Padre::Plugin::HG::LogView | ||
| 6 | Displays a list of commits for the passed file. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | my $changeset = Padre::Plugin::HG::LogView->showList($self, $file); | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | This module displays the list of commits that have occured for the passed file. | ||
| 15 | it returns the changeset number. | ||
| 16 | =head1 METHODS | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | package Padre::Plugin::HG::LogView; | ||
| 22 | use strict; | ||
| 23 | use Padre::Wx; | ||
| 24 | use Padre::Wx::Icon; | ||
| 25 | use Wx::Event qw( EVT_BUTTON ); | ||
| 26 | our @ISA = 'Wx::Dialog'; | ||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | sub showList | ||
| 31 | { | ||
| 32 | my ($class, $hg, $file) = @_; | ||
| 33 | |||
| 34 | my $self = $class->SUPER::new( | ||
| 35 | undef, | ||
| 36 | -1, | ||
| 37 | 'Padre Diff to Revision', | ||
| 38 | Wx::wxDefaultPosition, | ||
| 39 | Wx::wxDefaultSize, | ||
| 40 | Wx::wxDEFAULT_FRAME_STYLE | Wx::wxTAB_TRAVERSAL, | ||
| 41 | |||
| 42 | ); | ||
| 43 | $self->{hg} = $hg; | ||
| 44 | $self->SetIcon(Padre::Wx::Icon::PADRE); | ||
| 45 | my $sizer = Wx::BoxSizer->new(Wx::wxVERTICAL); | ||
| 46 | my $sizer2 = Wx::BoxSizer->new(Wx::wxHORIZONTAL); | ||
| 47 | $self->{list_box} = Wx::ListCtrl->new($self, -1, Wx::wxDefaultPosition, | ||
| 48 | Wx::wxDefaultSize,Wx::wxLC_REPORT|Wx::wxLC_SINGLE_SEL, Wx::wxDefaultValidator, 'listbox_1'); | ||
| 49 | #insert the HG data | ||
| 50 | chdir ($self->{hg}->{project_path}); | ||
| 51 | my $hgdata = $self->{hg}->vcs_log($file, $self->{hg}->{project_path}); | ||
| 52 | |||
| 53 | $self->_populate_list( $hgdata); | ||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | my $ok_button = Wx::Button->new($self, | ||
| 59 | 1, # id | ||
| 60 | "OK", # label | ||
| 61 | [50,50] # position | ||
| 62 | ); | ||
| 63 | |||
| 64 | |||
| 65 | #Handle the Button Clicks | ||
| 66 | |||
| 67 | my $changeset; | ||
| 68 | |||
| 69 | EVT_BUTTON( $ok_button, | ||
| 70 | 1, | ||
| 71 | sub{$changeset = $self->_get_selected_item(); | ||
| 72 | $self->Close(); | ||
| 73 | return $changeset; | ||
| 74 | |||
| 75 | } | ||
| 76 | ); | ||
| 77 | |||
| 78 | $sizer->Add($self->{list_box}, 1, Wx::wxEXPAND, 10); | ||
| 79 | $sizer2->Add($ok_button, 0, Wx::wxALL, 10); | ||
| 80 | $sizer->Add($sizer2, 0, Wx::wxEXPAND, 10); | ||
| 81 | $self->SetSizer($sizer); | ||
| 82 | $self->SetAutoLayout(1); | ||
| 83 | $self->ShowModal(); | ||
| 84 | return $changeset; | ||
| 85 | |||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | sub _get_selected_item | ||
| 90 | { | ||
| 91 | my( $self, $event ) = @_; | ||
| 92 | |||
| 93 | # Change the contents of $self->{txt} | ||
| 94 | |||
| 95 | my $changeset; | ||
| 96 | |||
| 97 | my $item = -1; | ||
| 98 | while ( 1 ==1 ) | ||
| 99 | { | ||
| 100 | $item = $self->{list_box}->GetNextItem($item, | ||
| 101 | Wx::wxLIST_NEXT_ALL, | ||
| 102 | Wx::wxLIST_STATE_SELECTED); | ||
| 103 | if ( $item == -1 ) | ||
| 104 | { | ||
| 105 | last; | ||
| 106 | } | ||
| 107 | # this item is selected - do whatever is needed with it | ||
| 108 | my $itemObj = $self->{list_box}->GetItem($item); | ||
| 109 | $changeset .= $itemObj->GetText(); | ||
| 110 | |||
| 111 | } | ||
| 112 | $changeset =~ s/^.*://; | ||
| 113 | return $changeset; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub _populate_list | ||
| 117 | { | ||
| 118 | my ($self, $log) = @_; | ||
| 119 | my @commits = $self->{hg}->parse_log($log); | ||
| 120 | |||
| 121 | if (!$log) {return} | ||
| 122 | #build the list headers | ||
| 123 | $self->{list_box}->InsertColumn(0,'changeset'); | ||
| 124 | $self->{list_box}->InsertColumn(1,'user'); | ||
| 125 | $self->{list_box}->InsertColumn(2,'date'); | ||
| 126 | $self->{list_box}->InsertColumn(3,'summary'); | ||
| 127 | |||
| 128 | for (my $i = (scalar(@commits)-1); $i >= 0; $i--) | ||
| 129 | { | ||
| 130 | |||
| 131 | my $item = $self->{list_box}->InsertStringItem(0,$commits[$i]->{changeset}); | ||
| 132 | $self->{list_box}->SetItem($item,1, $commits[$i]->{user}); | ||
| 133 | $self->{list_box}->SetItem($item,2, $commits[$i]->{date}); | ||
| 134 | $self->{list_box}->SetItem($item,3, $commits[$i]->{summary}); | ||
| 135 | |||
| 136 | } | ||
| 137 | |||
| 138 | } | ||
| 139 | |||
| 140 |