File Coverage

blib/lib/App/Editor/GVip.pm
Criterion Covered Total %
statement 26 28 92.8
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 36 38 94.7


line stmt bran cond sub pod time code
1              
2             package App::Editor::GVip ;
3              
4 1     1   57782 use strict;
  1         2  
  1         32  
5 1     1   4 use warnings ;
  1         2  
  1         26  
6 1     1   7 use Carp qw(carp croak confess) ;
  1         7  
  1         96  
7              
8             BEGIN
9             {
10 1         9 use Sub::Exporter -setup =>
11             {
12             exports => [ qw() ],
13             groups =>
14             {
15             all => [ qw() ],
16             }
17 1     1   903 };
  1         23421  
18            
19 1     1   379 use vars qw ($VERSION);
  1         4  
  1         47  
20 1     1   19 $VERSION = '0.01_01';
21             }
22              
23             #-------------------------------------------------------------------------------
24              
25 1     1   918 use English qw( -no_match_vars ) ;
  1         4718  
  1         6  
26              
27 1     1   1235 use Readonly ;
  1         3343  
  1         60  
28             Readonly my $EMPTY_STRING => q{} ;
29              
30 1     1   935 use Time::HiRes qw(gettimeofday tv_interval) ;
  1         1816  
  1         5  
31 1     1   679 use Data::TreeDumper ;
  0            
  0            
32             use File::Spec ;
33             use File::Basename ;
34              
35             use Glib ':constants';
36             use Gtk2 -init;
37             use Gtk2::Pango;
38              
39             use base 'Gtk2::Window' ;
40              
41             #-------------------------------------------------------------------------------
42              
43             =head1 NAME
44              
45             App::Editor::GVip - gnome interface to Text::Editor::Vip
46              
47             =head1 SYNOPSIS
48              
49             use Gtk2 -init ;
50             my $editor_app = App::Editor::GVip->new(SETUP_PATH => $setup_path) ;
51            
52             #~ $editor_app->AddView('gvip.pl') ; # open a file
53             $editor_app->AddView() ;
54            
55             $editor_app->show_all();
56             Gtk2->main();
57              
58             =head1 DESCRIPTION
59              
60             gnome fromt end to Text::Editor::Vip
61              
62             =head1 DOCUMENTATION
63              
64             This is a module I played with a few years ago. I upload it as an example of a gnome application using a CPAN module
65             as a back end. The editor itself is not functional and thus this release is maked as a developer release.
66              
67             I'd be happy to share maintenance with someone that has time for this kind of project.
68              
69             =head1 SUBROUTINES/METHODS
70              
71             =cut
72              
73             use App::Editor::GVip::View ;
74             use App::Editor::GVip::Menu ;
75             use Text::Editor::Vip::Buffer ;
76             use Text::Editor::Vip::Actions ;
77              
78             #---------------------------------------------------------------------------------------------
79              
80             sub new
81             {
82             my ($class, %arguments) = @_ ;
83              
84             my ($window_width, $window_height) = (400, 600) ;
85              
86             my $window = new Gtk2::Window() ;
87              
88             $window->signal_connect(destroy => sub {Gtk2->main_quit});
89             $window->set_default_size($window_width, $window_height);
90             $window->set_position('none');
91              
92             my $vbox = new Gtk2::VBox(FALSE, 0) ;
93             my ($menubar, $accelerator) = App::Editor::GVip::Menu::GetMenu($window) ;
94              
95             $vbox->pack_start($menubar, FALSE, FALSE, 0) ;
96             #~ $window->add_accelerator_group($accelerator) ;
97              
98             my $panel = new Gtk2::VPaned() ;
99              
100             my $notebook = new Gtk2::Notebook() ;
101             $notebook->set_tab_pos('top') ;
102              
103             # make notebook change the title when new one is selected
104             $notebook->signal_connect('switch-page' => sub{ $window->UpdateTitle(@_)}) ;
105              
106             $panel->add1($notebook) ;
107              
108             #~ my $terminal = Gtk2::DrawingArea->new() ;
109             #~ $panel->add2($terminal) ;
110             #~ $panel->set_position(1000) ;
111              
112             $vbox->pack_start($panel, TRUE, TRUE, 0) ;
113              
114             $window->add($vbox) ;
115              
116             $window->{BUFFERS} = [] ;
117             $window->{NOTEBOOK} = $notebook ;
118             $window->{SETUP_DATA} = \%arguments ;
119              
120             bless($window, ref($class) || $class) ;
121             }
122              
123             #---------------------------------------------------------------------------------------------
124              
125             sub UpdateTitle
126             {
127             my ($editor, $notebook, $time_maybe, $tab) = @_ ;
128              
129             #~ print DumpTree(\@_, 'update title', MAX_DEPTH => 1) ;
130              
131             for my $view (@{$editor->{BUFFERS}})
132             {
133             if($view->{TAB} == $tab)
134             {
135             $editor->set_title($view->{FILE_NAME} || 'Untitled') ;
136             last ;
137             }
138             }
139             }
140              
141             #---------------------------------------------------------------------------------------------
142              
143             use Gtk2::Gdk::Keysyms ;
144              
145             # we know default uses 32 .. 255 (as character) but we need it to use gtk symboles
146             my %key_to_symbole = () ;
147             for my $key (keys %Gtk2::Gdk::Keysyms)
148             {
149             $key_to_symbole{$Gtk2::Gdk::Keysyms{$key}} = $key ;
150             }
151            
152             my %ascii_keys= () ;
153             for my $key (32 .. 255)
154             {
155             if(exists $key_to_symbole{$key})
156             {
157             my $chr_key = chr($key) ;
158            
159             $ascii_keys{$chr_key} = $key_to_symbole{$key} ;
160             #~ print " $chr_key ($key) => $key_to_symbole{$key}\n" ;
161             }
162             }
163              
164             #---------------------------------------------------------------------------------------------
165              
166             sub AddView
167             {
168             my ($editor, $file_name) = @_ ;
169              
170             my $tab_name = 'Untitled' ;
171              
172             my ($volume, $directories, $file) ;
173             my ($basename, $path, $file_extension) ;
174              
175             if(defined $file_name)
176             {
177             ($volume, $directories, $file) = File::Spec->splitpath($file_name);
178             ($basename, $path, $file_extension) = File::Basename::fileparse($file, ('\..*')) ;
179            
180             $tab_name = $file ;
181             }
182              
183             my $new_buffer = GetNewBuffer($file_name) ;
184             $new_buffer->ExpandWith('PrintError', \&DisplayBufferErrorModal) ;
185              
186             # find out what to load for this type of file
187              
188             my $setup_path = $editor->{SETUP_DATA}{SETUP_PATH} ;
189              
190             my $config = do "$setup_path/default_settings.pl" ;
191              
192             $config->{setup_path} = $setup_path ;
193              
194             my @action_files = @{$config->{DEFAULT_ACTIONS}} ;
195             push @action_files, $config->{$file_extension} if(defined $file_extension && exists $config->{$file_extension}) ;
196              
197             # locate the files in the setup directory
198             @action_files = map {"$setup_path/$_"} @action_files ;
199              
200             my $view = new App::Editor::GVip::View($new_buffer) ;
201             my $actions = $view->GetActions() ;
202              
203             for my $action_file (@action_files)
204             {
205             eval { $actions->Load(\%ascii_keys, $view, $action_file) ;} ;
206             DisplayMessageModal(new Gtk2::Window(), "Couldn't load actions! Errors: $@") if($@) ;
207             }
208              
209             eval <<'EOE' ;
210             use lib $editor->{SETUP_DATA}{SETUP_PATH} ; ;
211             use Language::Perl::Perl ;
212             EOE
213              
214             croak $@ if $@ ;
215              
216             $view->{LEXER} = Lexer::Perl->new($setup_path) ;
217             #~ print DumpTree $view->{LEXER} ;
218              
219             my $label = new Gtk2::Label($tab_name) ;
220              
221             my $tab = $editor->{NOTEBOOK}->append_page($view->{WIDGET}, $label) ;
222             push @{$editor->{BUFFERS}},
223             {
224             BUFFER => $new_buffer,
225             FILE_NAME => $file_name,
226             TAB => $tab,
227             };
228              
229             $editor->show_all() ;
230              
231             return($tab) ;
232             }
233              
234             #---------------------------------------------------------------------------------------------
235              
236             sub ShowTab
237             {
238             my ($editor, $tab_number) = @_ ;
239              
240             $editor->{NOTEBOOK}->set_current_page($tab_number) ;
241             }
242              
243             #---------------------------------------------------------------------------------------------
244              
245             sub GetNewBuffer
246             {
247             my ($file_name) = @_ ;
248              
249             my $buffer = Text::Editor::Vip::Buffer->new();
250             $buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Plugins::Display') ;
251             $buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Plugins::File') ;
252              
253             if(defined $file_name)
254             {
255             $buffer->InsertFile($file_name) ;
256             }
257              
258             $buffer->SetModificationPosition(0, 0) ;
259              
260             return($buffer) ;
261             }
262              
263             #------------------------------------------------------------------------------------------------------
264              
265             sub DisplayMessageModal
266             {
267             my ($window, $message) = @_ ;
268              
269             my $dialog = Gtk2::MessageDialog->new
270             (
271             $window,
272             'destroy-with-parent' ,
273             'info' ,
274             'close' ,
275             $message ,
276             ) ;
277              
278             $dialog->signal_connect(response => sub { $dialog->destroy ; 1 }) ;
279             $dialog->run() ;
280             }
281              
282             #------------------------------------------------------------------------------------------------------
283              
284             sub DisplayBufferErrorModal
285             {
286             my ($buffer, $message) = @_ ;
287              
288             my $dialog = Gtk2::MessageDialog->new
289             (
290             new Gtk2::Window(),
291             'destroy-with-parent' ,
292             'error' ,
293             'close' ,
294             $message ,
295             ) ;
296              
297             $dialog->signal_connect(response => sub { $dialog->destroy ; 1 }) ;
298             $dialog->run() ;
299             }
300              
301             #-------------------------------------------------------------------------------
302              
303             sub A
304             {
305              
306             =head2 A( xxx )
307              
308             xxx description
309              
310             xxx some code
311              
312             I
313              
314             =over 2
315              
316             =item * $xxx -
317              
318             =back
319              
320             I - Nothing
321              
322             I
323              
324             See C.
325              
326             =cut
327              
328             my ($self) = @_ ;
329              
330             if(defined $self && __PACKAGE__ eq ref $self)
331             {
332             # object sub
333             my ($var, $var2) = @_ ;
334            
335             }
336             else
337             {
338             # class sub
339             unshift @_, $self ;
340             }
341              
342             return(0) ;
343             }
344              
345             #-------------------------------------------------------------------------------
346              
347             1 ;
348              
349             =head1 BUGS AND LIMITATIONS
350              
351             None so far.
352              
353             =head1 AUTHOR
354              
355             Nadim ibn hamouda el Khemir
356             CPAN ID: NH
357             mailto: nadim@cpan.org
358              
359             =head1 LICENSE AND COPYRIGHT
360              
361             This program is free software; you can redistribute
362             it and/or modify it under the same terms as Perl itself.
363              
364             =head1 SUPPORT
365              
366             You can find documentation for this module with the perldoc command.
367              
368             perldoc App::Editor::GVip
369              
370             You can also look for information at:
371              
372             =over 4
373              
374             =item * AnnoCPAN: Annotated CPAN documentation
375              
376             L
377              
378             =item * RT: CPAN's request tracker
379              
380             Please report any bugs or feature requests to L .
381              
382             We will be notified, and then you'll automatically be notified of progress on
383             your bug as we make changes.
384              
385             =item * Search CPAN
386              
387             L
388              
389             =back
390              
391             =head1 SEE ALSO
392              
393              
394             =cut