Commits

m...@mm-laptop  committed 13997b0

Prepared for CPAN distribution

  • Participants
  • Parent commits 2152d9a

Comments (0)

Files changed (5)

File HG/ProjectClone.pm

-package Padre::Plugin::HG::ProjectClone;
-
-
-
-
-
-
-=pod
-
-=head1 NAME
-
-Module::Name - My author was too lazy to write an abstract
-
-=head1 SYNOPSIS
-
-  my $object = Module::Name->new(
-      foo  => 'bar',
-      flag => 1,
-  );
-  
-  $object->dummy;
-
-=head1 DESCRIPTION
-
-The author was too lazy to write a description.
-
-=head1 METHODS
-
-=cut
-
-use 5.006;
-use strict;
-use warnings;
-
-our $VERSION = '0.01';
-
-use Wx qw[:everything];
-use base 'Wx::Panel';
-
-=pod
-
-=head2 new
-
-  my $object = Module::Name->new(
-      foo => 'bar',
-  );
-
-The C<new> constructor lets you create a new B<Module::Install> object.
-
-So no big surprises there...
-
-Returns a new B<Module::Install> or dies on error.
-
-=cut
-
-sub new
-{
-    my ($class, $hg) = @_; 
-    my $self       = $class->SUPER::new( Padre::Current->main);
-    $self->{hg} = $hg;
-    $self->enter_repository();
-    if ($self->{project_url})
-    {
-        $self->choose_destination();
-        $self->clone();
-    }
-    
-    
-    return $self;
-}
-
-sub clone
-{
-    my ($self) = @_;
-   if ($self->{project_url}  and $self->{selected_dir})
-   {
-         $self->{hg}->clone_project($self->{project_url},$self->{destination_dir}); 
-   }
-        
-    
-}
-
-sub enter_repository
-{
- my ($self) = @_;
- my $main = Padre->ide->wx->main;
- my $message = $main->prompt("Clone Project", "Enter the Project URL to clone", 'http://');    
- $self->{project_url} = $message ; 
-    
-}
-
-sub choose_destination
-{
-    my ($self) = @_;
-    my $dialog = Wx::DirDialog->new($self, 'Choose a Destination Directory');
-    $dialog->ShowModal();
-    $self->{destination_dir} = $dialog->GetPath();
-}
-=pod
-
-=head2 dummy
-
-This method does something... apparently.
-
-=cut
-
-
-
-1;
-
-=pod
-
-=head1 SUPPORT
-
-No support is available
-
-=head1 AUTHOR
-
-Copyright 2008 Anonymous.
-
-=cut

File HG/ProjectCommit.pm

-package Padre::Plugin::HG::ProjectCommit;
-use strict;
-use Wx qw[:everything];
-use Wx::Event qw( EVT_BUTTON );
-use base 'Wx::Panel';
-
-
-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) = @_;
-	
-	my $self       = $class->SUPER::new( Padre::Current->main);
-	$self->{hg} = $hg;
-	my $frame = Wx::Frame->new( undef, -1, 'Padre Mecurial Commit');
-	my $sizer = Wx::BoxSizer->new(wxVERTICAL);
-	my $sizer2 = Wx::BoxSizer->new(wxHORIZONTAL);
-	my   $listbox1 = Wx::ListCtrl->new($frame, -1, wxDefaultPosition,
-	wxDefaultSize,wxLC_LIST, wxDefaultValidator, 'listbox_1');
-        $listbox1->AssignImageList($images,1);
-        #insert the HG data
-        chdir ($self->{hg}->{project_path});
-        my @hgdata = `hg status`;
-        my @filestatus =  $self->{hg}->_get_hg_files(@hgdata);
-        $self->{file_listbox} = $listbox1;
-	$self->_populate_list( \@filestatus );
-   
-
-	
-
-
-	my $ok_button = Wx::Button->new($frame, 
-						1,                  # id
-						"OK", # label
-						[50,50]             # position
-                                       );
-	my $cancel_button = Wx::Button->new($frame,             # parent
-                                        2,                  # id
-                                        "Cancel", # label
-                                        [50,50]             # position
-                                       );
-
-	#Handle the Button Clicks
-	
-	EVT_BUTTON( $ok_button, 
-             1,         
-             sub{$self->_get_selected_items} 
-             );
-             
-	EVT_BUTTON( $cancel_button, 
-             2,
-              sub{$frame->Destroy(); return} 
-             );
-
-    $sizer->Add($listbox1, 1, wxEXPAND, 10);
-    $sizer2->Add($ok_button, 0, wxALL, 10);
-    $sizer2->Add($cancel_button, 0, wxALL, 10);
-    $sizer->Add($sizer2, 0, wxEXPAND, 10);
-    $frame->SetSizerAndFit($sizer);
-    $frame->Show( 1 ); 
-}
-
-
-sub _get_selected_items
-{
-	my( $self, $event ) = @_; 
-
-	# Change the contents of $self->{txt}
-	print "print the button was clicked\n";
-	my $file_list;
-	#$self->{txt}->SetLabel("The button was clicked!"); 
-	my $item = -1;
-	 while ( 1 ==1 )
-	{
-        $item = $self->{file_listbox}->GetNextItem($item,
-                                     wxLIST_NEXT_ALL,
-                                     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});
-}
-
-sub _populate_list
-{
- my ($self, $filestatus) = @_;
- 
- if (!$filestatus) {return}
- foreach my $file (@$filestatus)
- {
-	my ($status, $path) = @$file;
-	$self->{file_listbox}->InsertImageStringItem(1, $path, $file_types->{$status});
- }	
-	
-}
-
-

File HG/StatusTree.pm

-package Padre::Plugin::HG::StatusTree;
-=pod
-
-=head1 NAME
-
-Padre::Plugin::HG::StatusTree
-Displays the status of the current hg project in a tree format
-
-=head1 SYNOPSIS
- my $object = Padre::Plugin::HG::StatusTree->new($self,$project_root);
-
-=head1 DESCRIPTION
-
-This module diplays a tree in the left panel of the ide that shows
-the mecurial status of each file.  
-Right clicking on a file will give you options to perform actions.  Right clicking the
-project root will give you project wide options. 
-
-=head1 METHODS
-
-=cut
-use strict;
-use warnings;
-
-our $VERSION = '0.01';
-
-use Padre::Wx;
-use lib ("/home/mm/.padre/plugins");
-use Padre::Util qw/_T/;
-use Wx qw/WXK_UP WXK_DOWN wxTR_HAS_BUTTONS  wxTR_HIDE_ROOT  /;
-use base 'Wx::Panel';
-use Padre::Plugin::My;
-use File::Spec;
-use File::Basename;
-my $HG;
-my %dirTree;
-my $project_name;
-my %WxTree;
-my $ThisTree;
-
-  #setup the image list 
-  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 ] ),
-                ),
-          };
-  
-
-
-
-my @root = qw (root root);
-
-=pod
-=head2 new
- Creates and displays the status tree
- $tree = Padre::Plugin::HG::StatusTree->new($self, $project_root);
-=cut
-
-sub new
-{
-  my ($class, $hg, $root) = @_;
-  $project_name = $root;
-  $HG = $hg;
-
-  my $self       = $class->SUPER::new( Padre::Current->main->left );
-  my $box        = Wx::BoxSizer->new(Wx::wxVERTICAL);
-  my $treectrl = Wx::TreeCtrl->new( $self, -1 );
-  $treectrl->AssignImageList($images);
-
-  $self->drawTree($treectrl);
-  Wx::Event::EVT_TREE_ITEM_MENU(
-         $treectrl, $treectrl,
-         \&_on_tree_item_menu,
-  );
-  
-  #Double Click
-  Wx::Event::EVT_TREE_ITEM_ACTIVATED(
-            $treectrl, $treectrl,
-             \&_on_tree_item_activated
-  );
-  
-  $box->Add( $treectrl, 1, Wx::wxGROW );
-
-  $self->SetSizer($box);  
-  Padre::Current->main->left->show($self);
-  $ThisTree = $self;
-  return $self;
-   
-}
-
-
-=pod
-=head2 gettext_label
-        Works out what to name the tab for the project.
-=cut
-
-sub gettext_label {
-        
-         my @dirs = File::Spec->splitdir( $project_name );
-         my $name = File::Spec->catdir(('..',$dirs[-2], $dirs[-1]));
-         chomp $name;
-        return "(HG) ".$name;
-}
-
-=pod
-=head2 getWxNode
-        Add the nodes to the tree. 
-        getWxNode($treectrl,[name,parent,type],path);
-=cut
-
-sub getWxNode
-{
-    my ($treectrl,$node,$path) = @_;
-    
-    my $name = $node->[0];
-    my $parent = $node->[1];
-    my $type = $node->[2];
-    chomp $path;
-    chomp $name;
-    if (exists($WxTree{$path}))
-    {
-      return $WxTree{$path};
-      # $WxTree{$path} = $treectrl->AppendItem( $WxTree{$parent}, $name);
-      
-    }else
-    {
-        $WxTree{$path} = $treectrl->AppendItem( 
-                  getWxNode($treectrl, $dirTree{$parent}, $parent), 
-                            $name, 
-                            $file_types->{$type},
-                             -1,
-                             Wx::TreeItemData->new(
-                                            {   name => $name,
-                                                path  => $path,
-	                                        type => $type,
-	                                }));
-    }
-  
-  
-}
-
-sub parseHgStatus
-{
-      my (@hgstatus) = @_;
-      
-      foreach my $line (@hgstatus)
-      {
-        my ($filestatus, $path) = split(/\s/,$line);
-        chomp $path;
-        my @dir =  split(/\//,$path);
-        createBranch(\@dir,$filestatus);
-               
-      }
-  
-  
-  
-}
-
-sub createBranch
-{
-  
-  my ($dirRef, $status) = @_;
-  my @dir = @$dirRef;
-  my $count = 0;
-  my %parentChild;
-  foreach my $item (@dir)
-  {
-    my $type;
-    my $parent = '';
-    if ($count == 0 ) 
-    { 
-      $parent = $dirTree{root}->[0]; 
-    }
-    else
-    {
-      $parent= join('/',@dir[0..$count -1 ]);
-    }
-    my $node = join('/',@dir[0..$count]);
-    if (!exists($dirTree{$node}))
-    {
-
-	     if ($count < (scalar(@dir) -1))
-	     {
-	       $type = 'dir';
-	     }
-	     else
-	     {
-	       $type = $status;
-	     }
-	     $dirTree{$node} = [$item, $parent, $type];
-    }
-    
-     $count ++;
-  }
-  #return %dirTree;
-}
-
-sub drawTree {
-  my ($self,$treectrl) = @_;
-  
-  %WxTree = ();
-  $WxTree{root} = $treectrl->AddRoot( 
-                        $project_name, 
-                        $file_types->{dir},
-                        -1,
-                        Wx::TreeItemData->new(
-                                            {   name => 'root',
-                                                path  => '',
-	                                        type => 'root',
-	                                })  ); 
-    
- 
-  %dirTree = ();
-  $dirTree{root} = ['root', 'root', 'dir'];
-  chdir ($project_name);
-  my @hgStatus = `hg status --all`;
-  chomp (@hgStatus);
-  parseHgStatus(@hgStatus);
-  foreach my $file  (keys(%dirTree))
-  {
-       my $path = File::Spec->catdir($project_name,$file);
-       my $dir = File::Basename::dirname($path);
-       print $path."\n";
-       getWxNode($treectrl, $dirTree{$file}, $file);      
-  }
-
-
-}
-
-sub _on_tree_item_activated
-{
-	
-	my ( $self, $event,$me ) = @_;
-	my $node      = $event->GetItem;
-        my $node_data = $self->GetPlData($node);
-	my $selected_path  = $node_data->{path};
-        my $selected_file = $node_data->{name};
-        my $selected_type = $node_data->{type};
-        my $full_path = File::Spec->catdir(($project_name,$selected_path));
-
-        if ($selected_type ne 'dir' and $selected_type ne 'root')
-        {
-                open_file($full_path);
-        }
-        
-
-}
-sub _on_tree_item_menu {
-        my ( $self, $event,$me ) = @_;
-        my $node      = $event->GetItem;
-        my $node_data = $self->GetPlData($node);
-        my $menu          = Wx::Menu->new;
-        # Default action - same when the item is activated
-        my $selected_path  = $node_data->{path};
-        my $selected_file = $node_data->{name};
-        my $selected_type = $node_data->{type};
-        my $full_path = File::Spec->catdir(($project_name,$selected_path));
-        print "selected Path = $selected_path\n";
-        my $parent_dir = File::Basename::dirname($full_path);
-        #Commit
-        if ($selected_type eq 'root')
-        {
-               print "ParentDir". $parent_dir ."\n";
-                my $default = $menu->Append(
-                        -1,
-                       Wx::gettext( 'Refresh' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $default,
-                       sub { $ThisTree->refresh($self) }
-               );   
-               my $pull = $menu->Append(
-                        -1,
-                       Wx::gettext( 'Pull & Update' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $pull,
-                        sub {  $HG->pull_update_project($selected_file, $project_name) }
-               );    
-               my $push = $menu->Append(
-                        -1,
-                       Wx::gettext( 'Push' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $push,
-                       sub {  $HG->push_project($selected_file, $project_name) }
-               );   
-        }
-        
-        elsif ($selected_type ne 'dir' and $selected_type ne 'root')
-        {
-                my $default = $menu->Append(
-                        -1,
-                       Wx::gettext( 'Commit' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $default,
-                       sub { $HG->vcs_commit($selected_file, $parent_dir ); $ThisTree->refresh($self)}
-               );
-               
-               #Add
-               my $add = $menu->Append(
-                         -1,
-                       Wx::gettext( 'Add' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $add,
-                       sub { $HG->vcs_add($selected_file, $parent_dir);$ThisTree->refresh($self)}
-               );   
-               
-               #diff (just diffs current file to Tip) 
-               my $diff = $menu->Append(
-                         -1,
-                       Wx::gettext( 'Diff to Tip' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $diff,
-                       sub { $HG->vcs_diff($selected_file, $parent_dir);}
-               );  
-               
-               #open 
-               my $open = $menu->Append(
-                         -1,
-                       Wx::gettext( 'Open' ));
-                    
-                Wx::Event::EVT_MENU(
-                       $self, $open,
-                       sub{open_file($full_path)}
-               ); 
-               
-                 
-       }
-       
-       
-        my $x = $event->GetPoint->x;
-        my $y = $event->GetPoint->y;
-        $self->PopupMenu( $menu, $x, $y );
-        
-
-}
-
-sub open_file
-{ 
-     	 my ($path) = @_;
-     	        my $main = Padre->ide->wx->main;
-	        if ( my $id = $main->find_editor_of_file($path) ) {
-	                my $page = $main->notebook->GetPage($id);
-	                $page->SetFocus;
-	        } else {
-	                $main->setup_editors($path);
-	        }
-}
-
-sub refresh {
-    my ($self, $treeCtrl) = @_;
-        $treeCtrl->DeleteAllItems;
-        $self->drawTree($treeCtrl); 
-    return ();
-}
-1;

File HG/UserPassPrompt.pm

-package Padre::Plugin::HG::UserPassPrompt;
-
-=pod
-
-=head1 NAME
-
-Padre::Plugin::HG::UserPassPrompt 
-provides the username and password prompts for Padre::Plugin::HG
-
-=head1 SYNOPSIS
-
-  my $object = Padre::Plugin::HG::UserPassPrompt->new(
-      title => 'project X',
-      default_username => 'fred',
-      default_password => 'XXXX',
-      
-  );
-  
-  $password = $object->{password};
-  $username = $object->{username};
-
-=head1 DESCRIPTION
-
-This module diplays a username and password prompt for actions like
-pushing in Padre::Plugin::HG
-
-=head1 METHODS
-
-=cut
-
-use 5.006;
-use strict;
-use warnings;
-use Wx qw[:everything];
-use Wx::Event qw( EVT_BUTTON );
-use base 'Wx::Panel';
-our $VERSION = '0.01';
-
-=pod
-
-=head2 new
-
-  my $object = adre::Plugin::HG::UserPassPrompt->new(
-      title => 'project X',
-      default_username => 'fred',
-      default_password => 'XXXX',
-      
-  );
-
-The C<new> constructor is the only method. 
-it will display the username and password prompts  
-
-Access the results via
-$object->{username} and $object->{password}
-
-=cut
-
-sub new
-{
-    my ($class, %params) = @_; 
-    my $self       = $class->SUPER::new( Padre::Current->main);
-    
-    my $user_name = Wx::TextEntryDialog->new(undef, 'Enter your User Name',$params{title},$params{default_username});
-    $user_name->ShowModal();
-    $self->{username} =  $user_name->GetValue();
-    
-    my $user_pass = Wx::PasswordEntryDialog->new(undef, 'Enter your Password',$params{title},$params{default_password},wxOK|wxCANCEL);
-    $user_pass->ShowModal();
-    $self->{password} =  $user_pass->GetValue();
-    
-    return $self;
-}
-
-
-
-1;
-
-=pod
-
-=head1 SUPPORT
-
-http://bitbucket.org/code4pay/padre-plugin-hg/
-
-=head1 AUTHOR
-
-Copyright 2008 Michael Mueller .
-
-=cut

File HG/t/HG.t

-#!/usr/bin/perl
-
-use 5.006;
-use strict;
-use warnings;
-use Test::More tests => 3;
-use FindBin qw ($Bin);
-use lib ("$Bin/../../../../");
-use Padre::Plugin::HG;
-my @hgstatus = ( 'M dir1/test.txt',
-	'? CVS',
-	'? dir2/text1.txt',
-	'? dir2/text2.txt',
-	'? parseStatus.pm',
-	'? status.txt',
-	'? t/padreUtil.t',
-	'? t/parseStatus.t',
-	'? test1.txt');
-
-my @files;
-ok( @files = Padre::Plugin::HG::_get_hg_files(@hgstatus), "Get files from  hg status");
-is ($files[0], 'dir1/test.txt', 'first file');
-is ($files[8], 'test1.txt', 'last file');
-
-print Padre::Plugin::HG::_project_root('','/home/mm/hg/test.pl');
-