App-Codit
view release on metacpan or search on metacpan
lib/App/Codit/Plugins/Git.pm view on Meta::CPAN
=over 4
=item B<git_collapse>
Collapses the git document tree and only opens the current selected document, if it is in
the current selected repository.
=item B<git_command> I<$project>, I<$commandstring>
Executes the git command in $commandstring for repository $project.
=item B<git_expand>
Epxands the git document tree.
=item B<git_open_all>
Opens all files in the current selected repository.
=item B<git_remove> I<?$name?>
If $name is not specified, $name is the selected document.
Closes $name, Removes it from the current selected repository
and deletes the file from disk. Use with care.
=item B<git_remove_dialog>
Same as git_remove but first asks nicely if you really want to do this.
=back
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
return undef unless defined $self;
#load only if git command line is installed
my $git = `git -v`;
return undef unless $git =~/^git\sversion/;
$self->cmdHookAfter('doc_open', 'openDocAfter', $self);
$self->cmdHookAfter('doc_close', 'closeDocAfter', $self);
$self->cmdHookBefore('doc_select', 'selectDocBefore', $self);
$self->cmdConfig(
git_add => ['gitAdd', $self],
git_collapse => ['gitCollapse', $self],
git_command => ['gitCommand', $self],
git_expand => ['gitExpand', $self],
git_open_all => ['gitOpenAll', $self],
git_remove => ['gitRemove', $self],
git_remove_dialog => ['gitRemoveDialog', $self],
);
$self->{PROJECTS} = {};
my $page = $self->ToolLeftPageAdd('Git', 'git-icon', undef, 'Manage your projects', 250);
my $pframe = $page->Frame->pack(-fill => 'x');
$pframe->Label(-text => 'Project:')->pack(-side => 'left');
my $current = '';
$self->{CURRENT} = \$current;
my $mb = $pframe->Menubutton(
-anchor => 'w',
-textvariable => \$current,
)->pack(-side => 'left', -expand => 1, -fill => 'x');
my $menu = $mb->Menu(-tearoff => 0);
$mb->configure(-menu => $menu);
$self->{PMENU} = $menu;
my $nav = $self->extGet('Selector');
my $gtree = $page->DocumentTree(
-entryselect => ['selectInternal', $self],
-diriconcall => ['GetDirIcon', $nav],
-fileiconcall => ['GetFileIcon', $nav],
-saveiconcall => ['GetSaveIcon', $nav],
)->pack(-expand => 1, -fill => 'both');
my $stack =$self->extGet('MenuBar')->menuStack(@contextmenu);
$gtree->configure('-contextmenu', $stack);
$self->{TREE} = $gtree;
$self->after(10, ['doPostConfig', $self]);
return $self;
}
sub closeDocAfter {
my ($self, $file) = @_;
if ($file ne 0) {
#does the file belong to a project?
my $project = $self->fileInAnyProject($file);
if (defined $project) {
#is any other file of this project open?
$self->projectRemove($project) unless $self->filesOpenInProject($project);
}
}
}
sub doPostConfig {
my $self = shift;
my $mdi = $self->mdi;
my @list = $mdi->docFullList;
for (@list) {
my $doc = $_;
my $folder = $self->projectFind($doc);
if (defined $folder) {
my $name = $self->projectName($folder);
$self->projectAdd($name, $folder);
}
}
$self->after(1000, ['navContextMenu', $mdi]);
}
sub fileInAnyProject {
my ($self, $file) = @_;
my @list = $self->projectList;
for (@list) {
my $project = $_;
return $project if $self->fileInProject($project, $file)
}
return undef
}
( run in 0.819 second using v1.01-cache-2.11-cpan-e1769b4cff6 )