| 1 | package Padre::Plugin::HG::DiffView; | ||
| 2 | use strict; | ||
| 3 | use Padre::Wx; | ||
| 4 | use Padre::Wx::Icon; | ||
| 5 | use Wx::Event qw( EVT_BUTTON ); | ||
| 6 | our @ISA = 'Wx::Dialog'; | ||
| 7 | |||
| 8 | |||
| 9 | my $images = Wx::ImageList->new( 16, 16 ); | ||
| 10 | my $file_types = { | ||
| 11 | M => $images->Add( | ||
| 12 | Wx::ArtProvider::GetBitmap( 'wxART_TIP', 'wxART_OTHER_C', [ 16, 16 ] ), | ||
| 13 | ), | ||
| 14 | dir => $images->Add( | ||
| 15 | Wx::ArtProvider::GetBitmap( 'wxART_FOLDER', 'wxART_OTHER_C', [ 16, 16 ] ), | ||
| 16 | ), | ||
| 17 | C => $images->Add( | ||
| 18 | Wx::ArtProvider::GetBitmap( 'wxART_TICK_MARK', 'wxART_OTHER_C', [ 16, 16 ] ), | ||
| 19 | ), | ||
| 20 | '?' => $images->Add( | ||
| 21 | Wx::ArtProvider::GetBitmap( 'wxART_MISSING_IMAGE', 'wxART_OTHER_C', [ 16, 16 ] ), | ||
| 22 | ), | ||
| 23 | }; | ||
| 24 | |||
| 25 | |||
| 26 | sub showDiff | ||
| 27 | { | ||
| 28 | my ($class, $hg, $diffString) = @_; | ||
| 29 | |||
| 30 | my $self = $class->SUPER::new( | ||
| 31 | undef, | ||
| 32 | -1, | ||
| 33 | 'Padre Mecurial Commit', | ||
| 34 | Wx::wxDefaultPosition, | ||
| 35 | Wx::wxDefaultSize, | ||
| 36 | Wx::wxDEFAULT_FRAME_STYLE | Wx::wxTAB_TRAVERSAL, | ||
| 37 | |||
| 38 | ); | ||
| 39 | $self->{hg} = $hg; | ||
| 40 | $self->SetIcon(Padre::Wx::Icon::PADRE); | ||
| 41 | my $sizer = Wx::BoxSizer->new(Wx::wxVERTICAL); | ||
| 42 | my $sizer2 = Wx::BoxSizer->new(Wx::wxHORIZONTAL); | ||
| 43 | $self->{diff_box} = Wx::TextCtrl->new($self, -1, ,'',Wx::wxDefaultPosition, | ||
| 44 | Wx::wxDefaultSize,Wx::wxTE_READONLY|Wx::wxTE_MULTILINE, Wx::wxDefaultValidator, 'diffBox'); | ||
| 45 | |||
| 46 | #insert the HG data | ||
| 47 | chdir ($self->{hg}->{project_path}); | ||
| 48 | my @hgdata = split(/\n/, $diffString); | ||
| 49 | #my @filestatus = $self->{hg}->_get_hg_files(@hgdata); | ||
| 50 | |||
| 51 | $self->_populate_list( \@hgdata); | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | my $ok_button = Wx::Button->new($self, | ||
| 57 | 1, # id | ||
| 58 | "OK", # label | ||
| 59 | [50,50] # position | ||
| 60 | ); | ||
| 61 | |||
| 62 | |||
| 63 | #Handle the Button Clicks | ||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | EVT_BUTTON( $ok_button, | ||
| 68 | 1, | ||
| 69 | sub{$self->Close(); return} | ||
| 70 | ); | ||
| 71 | |||
| 72 | $sizer->Add($self->{diff_box}, 1, Wx::wxEXPAND, 10); | ||
| 73 | $sizer2->Add($ok_button, 0, Wx::wxALL, 10); | ||
| 74 | $sizer->Add($sizer2, 0, Wx::wxEXPAND, 10); | ||
| 75 | $self->SetSizer($sizer); | ||
| 76 | $self->SetAutoLayout(1); | ||
| 77 | $self->ShowModal(); | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | sub _get_selected_items | ||
| 82 | { | ||
| 83 | my( $self, $event ) = @_; | ||
| 84 | |||
| 85 | # Change the contents of $self->{txt} | ||
| 86 | |||
| 87 | my $file_list; | ||
| 88 | #$self->{txt}->SetLabel("The button was clicked!"); | ||
| 89 | my $item = -1; | ||
| 90 | while ( 1 ==1 ) | ||
| 91 | { | ||
| 92 | $item = $self->{file_listbox}->GetNextItem($item, | ||
| 93 | Wx::wxLIST_NEXT_ALL, | ||
| 94 | Wx::wxLIST_STATE_SELECTED); | ||
| 95 | if ( $item == -1 ) | ||
| 96 | { | ||
| 97 | last; | ||
| 98 | } | ||
| 99 | # this item is selected - do whatever is needed with it | ||
| 100 | my $itemObj = $self->{file_listbox}->GetItem($item); | ||
| 101 | $file_list .= ' "'.$itemObj->GetText().'" '; | ||
| 102 | |||
| 103 | } | ||
| 104 | |||
| 105 | $self->{hg}->vcs_commit($file_list, $self->{hg}->{project_path}); | ||
| 106 | $self->Close(); | ||
| 107 | } | ||
| 108 | |||
| 109 | sub _populate_list | ||
| 110 | { | ||
| 111 | my ($self, $lines) = @_; | ||
| 112 | |||
| 113 | if (!$lines) {return} | ||
| 114 | foreach my $line (@$lines) | ||
| 115 | { | ||
| 116 | if ($line =~ /^\+/) | ||
| 117 | { | ||
| 118 | $self->{diff_box}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('sea green'))); | ||
| 119 | |||
| 120 | } | ||
| 121 | elsif ($line =~ /^\-/) | ||
| 122 | { | ||
| 123 | $self->{diff_box}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('red'))); | ||
| 124 | } | ||
| 125 | else | ||
| 126 | { | ||
| 127 | $self->{diff_box}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('black'))); | ||
| 128 | } | ||
| 129 | $self->{diff_box}->AppendText($line."\n"); | ||
| 130 | |||
| 131 | } | ||
| 132 | |||
| 133 | } | ||
| 134 | |||
| 135 |