| 1 | package App::Codit::Plugins::FileBrowser; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | App::Codit::Plugins::FileBrowser - plugin for App::Codit | ||
| 6 | |||
| 7 | =cut | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | use vars qw( $VERSION ); | ||
| 12 | $VERSION = '0.22'; | ||
| 13 | |||
| 14 | use base qw( Tk::AppWindow::BaseClasses::Plugin ); | ||
| 15 | |||
| 16 | require Tk::FileManager; | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | Browse your file system. | ||
| 21 | |||
| 22 | =head1 DETAILS | ||
| 23 | |||
| 24 | The FileBrowser plugin lets you browse and manage your harddrive. | ||
| 25 | |||
| 26 | Double clicking a file will open it in Codit if it is a text file. | ||
| 27 | Otherwise it will open in the appropriate application of your desktop. | ||
| 28 | |||
| 29 | Clicking the right mouse button will open a context menu with options for opening, copy, cut, paste and delete selected files. | ||
| 30 | |||
| 31 | All columns are sortable and sizable. If you left-click the header it will give you options to display hidden files (that start with a dot), Sort case dependant or not and directories first. | ||
| 32 | |||
| 33 | The following keyboard shortcuts are available when the file list has the focus: | ||
| 34 | |||
| 35 | =over 4 | ||
| 36 | |||
| 37 | =item CTRL+C Copy selected files to the file clipboard. | ||
| 38 | |||
| 39 | =item CTRL+X Copy selected files to the file clipboard. Delete them after paste. | ||
| 40 | |||
| 41 | =item CTRL+V Paste files in the file clipboard into the main folder. | ||
| 42 | |||
| 43 | =item CTRL+F Pop the filter entry. | ||
| 44 | |||
| 45 | =back | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | my @contextmenu = ( | ||
| 50 | [ 'menu_normal', undef, 'Open', 'fb_open', 'document-open', 'CTRL+SHIFT+I'], | ||
| 51 | [ 'menu_separator', undef, 'f1'], | ||
| 52 | [ 'menu_normal', undef, 'Copy', 'fb_copy', 'edit-copy', '*CTRL+C'], | ||
| 53 | [ 'menu_normal', undef, 'Cut', 'fb_cut', 'edit-cut', '*CTRL+X'], | ||
| 54 | [ 'menu_normal', undef, 'Paste', 'fb_paste', 'edit-paste', '*CTRL+V'], | ||
| 55 | [ 'menu_separator', undef, 'f2'], | ||
| 56 | [ 'menu_normal', undef, 'Delete', 'fb_delete', 'edit-delete', '*SHIFT+DELETE'], | ||
| 57 | [ 'menu_separator', undef, 'f3'], | ||
| 58 | [ 'menu_normal', undef, 'Properties', 'fb_properties', 'document-properties', '*CTRL+P'], | ||
| 59 | ); | ||
| 60 | |||
| 61 | sub new { | ||
| 62 | my $class = shift; | ||
| 63 | my $self = $class->SUPER::new(@_); | ||
| 64 | return undef unless defined $self; | ||
| 65 | |||
| 66 | |||
| 67 | my $page = $self->ToolLeftPageAdd('FileBrowser', 'folder', undef, 'Browse your file system', 400); | ||
| 68 | my $b = $page->FileManager( | ||
| 69 | -invokefile => ['fbInvoke', $self], | ||
| 70 | -listmenu => $self->extGet('MenuBar')->menuStack(@contextmenu), | ||
| 71 | -diriconcall => ['getDirIcon', $self], | ||
| 72 | -fileiconcall => ['getFileIcon', $self], | ||
| 73 | -linkiconcall => ['getLinkIcon', $self], | ||
| 74 | -selectmode => 'extended', | ||
| 75 | )->pack(-expand => 1, -fill => 'both'); | ||
| 76 | $self->cmdConfig( | ||
| 77 | 'fb_copy' => ['clipboardCopy', $b], | ||
| 78 | 'fb_cut' => ['clipboardCut', $b], | ||
| 79 | 'fb_delete' => ['delete', $b], | ||
| 80 | 'fb_open' => ['fbOpen', $self], | ||
| 81 | 'fb_paste' => ['clipboardPaste', $b], | ||
| 82 | 'fb_properties' => ['propertiesPop', $b], | ||
| 83 | ); | ||
| 84 | $self->after(1000, ['load', $b]); | ||
| 85 | $self->{BROWSER} = $b; | ||
| 86 | |||
| 87 | $self->ReConfigure; | ||
| 88 | return $self; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub browser { return $_[0]->{BROWSER} } | ||
| 92 | |||
| 93 | sub fbDir { | ||
| 94 | } | ||
| 95 | |||
| 96 | sub fbInvoke { | ||
| 97 | my ($self, $file) = @_; | ||
| 98 | if (-T $file) { | ||
| 99 | $self->cmdExecute('doc_open', $file); | ||
| 100 | } else { | ||
| 101 | $self->openURL($file) | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | sub fbOpen { | ||
| 106 | my $self = shift; | ||
| 107 | my $b = $self->browser; | ||
| 108 | my $mdi = $self->extGet('CoditMDI'); | ||
| 109 | $mdi->silentMode(1); | ||
| 110 | my @sel = $b->infoSelection; | ||
| 111 | for (@sel) { | ||
| 112 | my $d = $b->get($_); | ||
| 113 | $b->Invoke($_) unless $d->isDir; | ||
| 114 | } | ||
| 115 | $mdi->silentMode(0); | ||
| 116 | $mdi->docSelectFirst; | ||
| 117 | } | ||
| 118 | |||
| 119 | sub ReConfigure { | ||
| 120 | my $self = shift; | ||
| 121 | my $b = $self->{BROWSER}; | ||
| 122 | my $size = $self->configGet('-tooliconsize'); | ||
| 123 | my @images = ( | ||
| 124 | ['-compactimage', 'view-list-details', $size], | ||
| 125 | ['-detailsimage', 'view-list-tree', $size], | ||
| 126 | ['-iconviewimage', 'view-list-icons', $size], | ||
| 127 | ['-msgimage', 'dialog-information', 32], | ||
| 128 | ['-newfolderimage', 'folder-new', $size], | ||
| 129 | ['-reloadimage', 'appointment-recurring', $size], | ||
| 130 | ['-warnimage', 'dialog-warning', 32], | ||
| 131 | ); | ||
| 132 | for (@images) { | ||
| 133 | my ($opt, $icon, $size) = @$_; | ||
| 134 | my $img = $self->getArt($icon, $size); | ||
| 135 | $b->configure($opt, $img) if defined $img; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | sub Unload { | ||
| 140 | my $self = shift; | ||
| 141 | $self->cmdRemove('fb_copy'); | ||
| 142 | $self->cmdRemove('fb_cut'); | ||
| 143 | $self->cmdRemove('fb_delete'); | ||
| 144 | $self->cmdRemove('fb_open'); | ||
| 145 | $self->cmdRemove('fb_paste'); | ||
| 146 | $self->cmdRemove('fb_properties'); | ||
| 147 | $self->ToolLeftPageRemove('FileBrowser'); | ||
| 148 | return $self->SUPER::Unload | ||
| 149 | } | ||
| 150 | |||
| 151 | =head1 LICENSE | ||
| 152 | |||
| 153 | Same as Perl. | ||
| 154 | |||
| 155 | =head1 AUTHOR | ||
| 156 | |||
| 157 | Hans Jeuken (hanje at cpan dot org) | ||
| 158 | |||
| 159 | =head1 TODO | ||
| 160 | |||
| 161 | =over 4 | ||
| 162 | |||
| 163 | =back | ||
| 164 | |||
| 165 | =head1 BUGS AND CAVEATS | ||
| 166 | |||
| 167 | If you find any bugs, please report them here L<https://github.com/haje61/App-Codit/issues>. | ||
| 168 | |||
| 169 | =head1 SEE ALSO | ||
| 170 | |||
| 171 | =over 4 | ||
| 172 | |||
| 173 | =back | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | 1; | ||
| 180 | |||
| 181 | |||
| 182 | |||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 |