Commits

Anonymous committed f9a3b28

Implement Better Diff Viewing

Comments (0)

Files changed (3)

blib/lib/Padre/Plugin/HG.pm

 use Capture::Tiny  qw(capture_merged);
 use File::Basename ();
 use File::Spec;
-use lib ("/home/mm/.padre/plugins");
-use Padre::Plugin::HG::StatusTree;
+
 use Padre::Plugin::HG::ProjectCommit;
 use Padre::Plugin::HG::ProjectClone;
 use Padre::Plugin::HG::UserPassPrompt;
 	];
 }
 
-
+sub plugin_disable
+{
+  require Class::Unload;
+  Class::Unload->unload('Padre::Plugin::HG::StatusTree;');
+}
 
 #####################################################################
 # Custom Methods
 	my $username = $prompt->{username};
 	my $password = $prompt->{password};
 	$path =~ s/\/(.*)@/\/\/$username:$password@/g;
-	print "path $path";
 	my $command = eval "qq\0$VCSCommand{push}\0";
 	my $result = $self->vcs_execute($command, $dir);
 	$main->message( $result, "$VCS Pushing $path" );
 sub vcs_execute
 {
 	my ($self, $command, $dir) = @_;
-	print "\n\nvcs_execute $command $dir\n\n";
 	my $result = capture_merged(sub{chdir($dir);system($command)});
-	print "\n\nresult = $result \n\n";
 	return $result;
 }
 
 sub show_statusTree
 {	
 	my ($self) = @_;
+	require Padre::Plugin::HG::StatusTree;
 	my $main = Padre->ide->wx->main;
 	my $project_root = $self->_project_root(current_filename());
 
 {	
 	my ($self) = @_;
 	my $main = Padre->ide->wx->main;
-	Padre::Plugin::HG::ProjectClone->new($self);	
+	my $clone = Padre::Plugin::HG::ProjectClone->new($self);
+	if ($clone->enter_repository())
+	{
+		$clone->choose_destination();
+	}
+	
+	if ($clone->project_url()  and $clone->destination_dir())
+	{
+		$self->clone_project(
+			$clone->project_url(),
+			$clone->destination_dir()
+			); 
+	}
+        
+    
+}	
 
-}
+
 
 =pod
 
         return ($filename); 
 }
 
+=pod
+
+=head2 object_for_testing
+
+ creates a blessed object so we can run our tests. 
+
+=cut
+
+sub object_for_testing
+{
+	my ($class) = @_;
+	my $self = {};
+	bless $self,$class;
+	
+	
+}
+
 1;
 
 # Copyright 2008-2009 Michael Mueller.

lib/Padre/Plugin/HG/DiffView.pm

+package Padre::Plugin::HG::DiffView;
+use strict;
+use Padre::Wx;
+use Padre::Wx::Icon;
+use Wx::Event qw( EVT_BUTTON );
+our @ISA     = 'Wx::Dialog';
+
+
+my $images = Wx::ImageList->new( 16, 16 );
+        my $file_types = {
+                M => $images->Add(
+	                        Wx::ArtProvider::GetBitmap( 'wxART_TIP', 'wxART_OTHER_C', [ 16, 16 ] ),
+                ),
+                dir => $images->Add(
+                        Wx::ArtProvider::GetBitmap( 'wxART_FOLDER', 'wxART_OTHER_C', [ 16, 16 ] ),
+                ),
+                C => $images->Add(
+                        Wx::ArtProvider::GetBitmap( 'wxART_TICK_MARK', 'wxART_OTHER_C', [ 16, 16 ] ),
+                ),
+                '?' => $images->Add(
+                        Wx::ArtProvider::GetBitmap( 'wxART_MISSING_IMAGE', 'wxART_OTHER_C', [ 16, 16 ] ),
+                ),
+          };
+
+
+sub showList
+{
+	my ($class, $hg, $file) = @_;
+	
+		my $self = $class->SUPER::new(
+		undef,
+		-1,
+		'Padre Mecurial Commit',
+		Wx::wxDefaultPosition,
+		Wx::wxDefaultSize,
+		Wx::wxDEFAULT_FRAME_STYLE | Wx::wxTAB_TRAVERSAL,
+		
+	);
+	$self->{hg} = $hg;
+	$self->SetIcon(Padre::Wx::Icon::PADRE);
+	my $sizer = Wx::BoxSizer->new(Wx::wxVERTICAL);
+	my $sizer2 = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
+	my   $diff_box = Wx::TextCtrl->new($self, -1, ,'',Wx::wxDefaultPosition,
+	Wx::wxDefaultSize,Wx::wxTE_READONLY|Wx::wxTE_MULTILINE, Wx::wxDefaultValidator, 'diffBox');
+    
+        #insert the HG data
+        chdir ($self->{hg}->{project_path});
+        my @hgdata = `hg diff -g $file`;
+        #my @filestatus =  $self->{hg}->_get_hg_files(@hgdata);
+        my $diffString = join("\n",@hgdata);
+        $self->{diff_box} = $diff_box;
+	$self->_populate_list( \@hgdata);
+
+	
+
+
+	my $ok_button = Wx::Button->new($self, 
+						1,                  # id
+						"OK", # label
+						[50,50]             # position
+                                       );
+
+
+	#Handle the Button Clicks
+	
+
+             
+	EVT_BUTTON( $ok_button, 
+             1,
+              sub{$self->Close(); return} 
+             );
+
+    $sizer->Add($diff_box, 1, Wx::wxEXPAND, 10);
+    $sizer2->Add($ok_button, 0, Wx::wxALL, 10);
+    $sizer->Add($sizer2, 0, Wx::wxEXPAND, 10);
+    $self->SetSizer($sizer);
+    $self->SetAutoLayout(1);
+    $self->ShowModal(); 
+}
+
+
+sub _get_selected_items
+{
+	my( $self, $event ) = @_; 
+
+	# Change the contents of $self->{txt}
+	
+	my $file_list;
+	#$self->{txt}->SetLabel("The button was clicked!"); 
+	my $item = -1;
+	 while ( 1 ==1 )
+	{
+        $item = $self->{file_listbox}->GetNextItem($item,
+                                     Wx::wxLIST_NEXT_ALL,
+                                     Wx::wxLIST_STATE_SELECTED);
+        if ( $item == -1 )
+        {
+            last;
+	}
+        # this item is selected - do whatever is needed with it
+        my $itemObj = $self->{file_listbox}->GetItem($item);
+        $file_list .= ' "'.$itemObj->GetText().'" ';
+       
+    }
+    
+    $self->{hg}->vcs_commit($file_list, $self->{hg}->{project_path});
+    $self->Close();
+}
+
+sub _populate_list
+{
+ my ($self, $lines) = @_;
+ 
+ if (!$lines) {return}
+ foreach my $line (@$lines)
+ {
+	if ($line =~ /^\+/)
+	{
+                $self->{diff_box}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('sea green')));
+
+	}
+	elsif ($line =~ /^\-/)
+	{
+		$self->{diff_box}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('red')));
+	}
+	else
+	{
+		$self->{diff_box}->SetDefaultStyle(Wx::TextAttr->new(Wx::Colour->new('black')));
+	}
+	$self->{diff_box}->AppendText($line);
+
+ }	
+	
+}
+
+

lib/Padre/Plugin/HG/StatusTree.pm

 
 sub gettext_label {
         
-       #  my @dirs = File::Spec->splitdir( $project_name );
-        # my $name = File::Spec->catdir(('..',$dirs[-2], $dirs[-1]));
-       #  chomp $name;
-        return "(HG) ".$project_name;
+         my @dirs = File::Spec->splitdir( $project_name );
+        my $name = File::Spec->catdir(('..',$dirs[-2], $dirs[-1]));
+         chomp $name;
+        return "(HG) ".$name;
 }
 
 =pod
                     
                 Wx::Event::EVT_MENU(
                        $self, $diff,
-                       sub { $HG->vcs_diff($selected_file, $parent_dir);}
+                       sub { $HG->show_diff($selected_file, $parent_dir);}
                );  
                
                #open