| 1 | package Padre::Plugin::HG::ProjectCommit; | ||
| 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 showList | ||
| 27 | { | ||
| 28 | my ($class, $hg) = @_; | ||
| 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 | my $listbox1 = Wx::ListCtrl->new($self, -1, Wx::wxDefaultPosition, | ||
| 44 | Wx::wxDefaultSize,Wx::wxLC_LIST, Wx::wxDefaultValidator, 'listbox_1'); | ||
| 45 | $listbox1->AssignImageList($images,1); | ||
| 46 | #insert the HG data | ||
| 47 | chdir ($self->{hg}->{project_path}); | ||
| 48 | my @hgdata = `hg status`; | ||
| 49 | my @filestatus = $self->{hg}->_get_hg_files(@hgdata); | ||
| 50 | $self->{file_listbox} = $listbox1; | ||
| 51 | $self->_populate_list( \@filestatus ); | ||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | my $ok_button = Wx::Button->new($self, | ||
| 58 | 1, # id | ||
| 59 | "OK", # label | ||
| 60 | [50,50] # position | ||
| 61 | ); | ||
| 62 | my $cancel_button = Wx::Button->new($self, # parent | ||
| 63 | 2, # id | ||
| 64 | "Cancel", # label | ||
| 65 | [50,50] # position | ||
| 66 | ); | ||
| 67 | |||
| 68 | #Handle the Button Clicks | ||
| 69 | |||
| 70 | EVT_BUTTON( $ok_button, | ||
| 71 | 1, | ||
| 72 | sub{$self->_get_selected_items} | ||
| 73 | ); | ||
| 74 | |||
| 75 | EVT_BUTTON( $cancel_button, | ||
| 76 | 2, | ||
| 77 | sub{$self->Close(); return} | ||
| 78 | ); | ||
| 79 | |||
| 80 | $sizer->Add($listbox1, 1, Wx::wxEXPAND, 10); | ||
| 81 | $sizer2->Add($ok_button, 0, Wx::wxALL, 10); | ||
| 82 | $sizer2->Add($cancel_button, 0, Wx::wxALL, 10); | ||
| 83 | $sizer->Add($sizer2, 0, Wx::wxEXPAND, 10); | ||
| 84 | $self->SetSizer($sizer); | ||
| 85 | $self->SetAutoLayout(1); | ||
| 86 | $self->ShowModal(); | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | sub _get_selected_items | ||
| 91 | { | ||
| 92 | my( $self, $event ) = @_; | ||
| 93 | |||
| 94 | # Change the contents of $self->{txt} | ||
| 95 | |||
| 96 | my $file_list; | ||
| 97 | #$self->{txt}->SetLabel("The button was clicked!"); | ||
| 98 | my $item = -1; | ||
| 99 | while ( 1 ==1 ) | ||
| 100 | { | ||
| 101 | $item = $self->{file_listbox}->GetNextItem($item, | ||
| 102 | Wx::wxLIST_NEXT_ALL, | ||
| 103 | Wx::wxLIST_STATE_SELECTED); | ||
| 104 | if ( $item == -1 ) | ||
| 105 | { | ||
| 106 | last; | ||
| 107 | } | ||
| 108 | # this item is selected - do whatever is needed with it | ||
| 109 | my $itemObj = $self->{file_listbox}->GetItem($item); | ||
| 110 | $file_list .= ' "'.$itemObj->GetText().'" '; | ||
| 111 | |||
| 112 | } | ||
| 113 | |||
| 114 | $self->{hg}->vcs_commit($file_list, $self->{hg}->{project_path}); | ||
| 115 | $self->Close(); | ||
| 116 | } | ||
| 117 | |||
| 118 | sub _populate_list | ||
| 119 | { | ||
| 120 | my ($self, $filestatus) = @_; | ||
| 121 | |||
| 122 | if (!$filestatus) {return} | ||
| 123 | foreach my $file (@$filestatus) | ||
| 124 | { | ||
| 125 | my ($status, $path) = @$file; | ||
| 126 | $self->{file_listbox}->InsertImageStringItem(1, $path, $file_types->{$status}); | ||
| 127 | } | ||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 131 |