Commits

code4pay  committed eb728bb Draft

Fixes to work with latest version of Padre , Auto refresh on file save

  • Participants
  • Parent commits 4b958ac

Comments (0)

Files changed (3)

-Revision    history for Padre-Plugin-HG
+Revision     history for Padre-Plugin-HG
 
-0.01    Dadte/time
+0.01    Date/time
         First version, released on an unsuspecting world.
 0.10    2009/11/03:1402
         First release to CPAN,  Added more commands and improved the diffing to be usable. 
 0.15	2010/11/03:17:36 Update the Compatability Version to work with the latest Padre.
 0.16    2010/11/07:20:38 increase Version Number to skip failed upload to cpan
+0.17   2013/05/04  Fixes to work with latest version of Padre, auto refresh on file save

File lib/Padre/Plugin/HG.pm

 use Padre::Plugin::HG::DiffView;
 use Padre::Plugin::HG::LogView;
 my %projects;
-our $VERSION = '0.16';
+our $VERSION = '0.17';
 our @ISA     = 'Padre::Plugin';
 
-my $VCS = "Mercurial";
+my $VCS = "Mercurial"
 # enter the vcs commands here, variables will be evaled in in the sub routines. 
 # was meant as a way to make it more generic.  Not sure it is going to 
 # succeed. 
 # Padre::Plugin Methods
 
 sub padre_interfaces {
-	'Padre::Plugin' => 0.72
+	'Padre::Plugin' => 0.90
 }
 
 sub plugin_name {
   Class::Unload->unload('Padre::Plugin::HG::StatusTree;');
 }
 
+sub padre_hooks
+{
+    my %hooks;
+     $hooks{after_save} =  \&after_save;
+     return \%hooks;
+}
+
 #####################################################################
 # Custom Methods
 
 
 
 
+
+
 # show_statusTree
 #
 # Displays a Project Browser in the side pane. The Browser shows the status of the
 	}
 }
 
+
+
+# close_statusTree
+#
+# Closes the Project Browser and deletes the Status tree object
+
+sub close_statusTree
+{	
+	my ($self) = @_;
+	my $project_root = $self->_project_root(current_filename());
+	if (exists($projects{$project_root}) )
+	{
+		delete $projects{$project_root} ;
+		print "deleted $project_root\n";
+	}
+}
+
+
 #
 #
 #show_commit_list
 	 $self->{project_path} = $self->_project_root(current_filename());
 
 	return $main->error("Not a $VCS Project") if ! $self->{project_path} ;
- 
+	
 	my $obj = Padre::Plugin::HG::LogView->showList($self,current_filename());	
 	$obj = undef;
 
 }	
 
 
+# Event Listner for Save 
+# refresh the dir when done
+#
+
+sub after_save
+{
+	my ( $self ) = @_;
+	my $project_root = $self->_project_root(current_filename());
+	if ($projects{$project_root}){
+		$projects{$project_root}->refresh($projects{$project_root}->{treeCtrl});
+	}
+	print ("saved");
+}	
+
+
 
 
 #
 sub _project_root
 {
 	my ($self, $filename) = @_;
+	if (!$filename){
+		return 0;
+	}
 	my $dir = File::Basename::dirname($filename);
 	my $project_root = $self->vcs_execute($VCSCommand{root}, $dir);
 	#file in not in a HG project.
 #
 # $self->current_filename();
 #  returns the path of the file with the current attention 
-#  in the ide.
-
-
+#  in the ide
 
 
 sub current_filename {
 
 	my $main = Padre->ide->wx->main;
 	my $doc = $main->current->document;
-	
-	my $filename = $doc->filename;
+	my $filename = '';
+	if ($doc){
+	 $filename = $doc->filename;
+	}
 	return $main->error("No document found") if not $filename;
         return ($filename); 
 }

File lib/Padre/Plugin/HG/StatusTree.pm

 
   $self->SetSizer($box);  
   Padre::Current->main->left->show($self);
+  $self->{treeCtrl} = $treectrl;
   $ThisTree = $self;
   return $self;
    
 }
 
 
+
+
+
 =pod
 
 =head2 gettext_label
 =cut
 
 sub gettext_label {
-        
-         my @dirs = File::Spec->splitdir( $project_name );
+        my ($self) = @_;
+        my @dirs = File::Spec->splitdir( $project_name);
         my $name = File::Spec->catdir(('..',$dirs[-2], $dirs[-1]));
          chomp $name;
         return "(HG) ".$name;
                        sub { $HG->show_diff($selected_file, $parent_dir);}
                );  
                #diff to a revision  
-               my $diff = $menu->Append(
+               my $diff2 = $menu->Append(
                          -1,
                        Wx::gettext( 'Diff to Revision' ));
                     
 
 =pod
 
+=head2  view_close
+
+    Called by Padre when the X is clicked on the tree view in the left . 
+ 
+=cut
+sub view_close(){
+   #$HG->close_statusTree();
+   return 1;
+}
+
+sub view_stop(){
+
+}
+
+
+=pod
+
+=head2  view_panel
+
+    Called by Padre when the X is clicked on the tree view in the left . 
+ 
+=cut
+sub view_panel(){
+  return 'left';
+}
+
+=pod
+
 =head2  open_file
 
         open_file($path)
 { 
      	 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);
-	        }
+	        $main->setup_editors($path);
+	        
 }
 
 =pod