~ubuntu-branches/ubuntu/precise/padre/precise

« back to all changes in this revision

Viewing changes to lib/Padre/Document.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2010-12-11 20:56:34 UTC
  • mfrom: (1.3.1 upstream) (13.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20101211205634-sitpxguuf9cct47q
Tags: 0.76.ds1-1
* New upstream release

* bump liborlite (build-)dependency to 1.46
* bump libparse-errorstring-perl-perl (build-)dependency to 0.14
* bump libwx-perl-processstream-perl (build-)dependency to 0.29
* update the list of incomplete manuals

* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
patch Padre. What if they need it for some internal project?
72
72
 
73
73
A plug-in is able to add new supported MIME types. Padre should
74
 
either check for collisions if a plug-in already wants to provide
 
74
either check for collisions if a plug-in wants to provide
75
75
an already supported MIME type or should allow multiple support
76
76
modules with a way to select the current one. (Again I think we
77
77
probably don't need this. People can just come and add the
127
127
use Carp             ();
128
128
use File::Spec       ();
129
129
use File::Temp       ();
 
130
use Padre::Cache     ();
130
131
use Padre::Constant  ();
131
132
use Padre::Current   ();
132
133
use Padre::Util      ();
136
137
use Padre::File      ();
137
138
use Padre::Logger;
138
139
 
139
 
our $VERSION = '0.63';
 
140
our $VERSION = '0.76';
 
141
 
 
142
 
 
143
 
 
144
 
 
145
 
 
146
#####################################################################
 
147
# Task Integration
 
148
 
 
149
sub task_functions {
 
150
        return '';
 
151
}
 
152
 
 
153
sub task_outline {
 
154
        return '';
 
155
}
 
156
 
 
157
sub task_syntax {
 
158
        return '';
 
159
}
140
160
 
141
161
 
142
162
 
224
244
                # syntax to correct (for example) .//file.pl to ./file.pl)
225
245
                $self->{filename} = $self->{file}->{filename};
226
246
 
227
 
                # TODO: Fix Ticket #845 here. We need to make sure only the filename and not the folder name is here.
228
 
                # This causes F5 to fail as the get_command in Document::Perl doesn' handle this corretly
229
 
 
230
247
                if ( $self->{file}->exists ) {
231
248
 
232
249
                        # Test script must be able to pass an alternate config object:
233
250
                        my $config = $self->{config} || Padre->ide->config;
234
251
                        if ( defined( $self->{file}->size ) and ( $self->{file}->size > $config->editor_file_size_limit ) ) {
235
 
                                $self->error(
 
252
                                my $ret = Wx::MessageBox(
236
253
                                        sprintf(
237
254
                                                Wx::gettext(
238
 
                                                        "Cannot open %s as it is over the arbitrary file size limit of Padre which is currently %s"
 
255
                                                        "The file %s you are trying to open is over the arbitrary file size limit of Padre which is currently %s. Opening this file may reduce performance. Do you still want to open the file?"
239
256
                                                ),
240
257
                                                $self->{file}->{filename},
241
258
                                                $config->editor_file_size_limit
242
 
                                        )
 
259
                                        ),
 
260
                                        Wx::gettext("Warning"),
 
261
                                        Wx::wxYES_NO | Wx::wxCENTRE,
 
262
                                        Padre->ide->wx->main,
243
263
                                );
244
 
                                return;
 
264
                                if ( $ret != Wx::wxYES ) {
 
265
                                        return;
 
266
                                }
245
267
                        }
246
268
                }
247
269
                $self->load_file;
286
308
        if ($class) {
287
309
                unless ( $class->VERSION ) {
288
310
                        eval "require $class;";
289
 
                        die("Failed to load $class: $@") if $@;
 
311
                        die "Failed to load $class: $@" if $@;
290
312
                }
291
313
                bless $self, $class;
292
314
        }
296
318
        $filename = $self->{file}->filename
297
319
                if defined( $self->{file} )
298
320
                        and defined( $self->{file}->{filename} );
299
 
        warn("No module  mime_type='$mime_type' filename='$filename'\n") unless $module;
300
 
 
301
 
        #warn("Module '$module' mime_type='$mime_type' filename='$filename'\n") if $module;
 
321
        if ( not $module ) {
 
322
                $self->current->main->error(
 
323
                        sprintf(
 
324
                                Wx::gettext("No module mime_type='%s' filename='%s'"),
 
325
                                $mime_type, $filename
 
326
                        )
 
327
                );
 
328
        }
302
329
        $self->set_highlighter($module);
303
330
 
304
331
        return;
312
339
 
313
340
 
314
341
 
 
342
######################################################################
 
343
# Padre::Cache Integration
 
344
 
 
345
sub DESTROY {
 
346
        if ( defined $_[0]->{filename} ) {
 
347
                Padre::Cache->release( $_[0]->{filename} );
 
348
        }
 
349
}
 
350
 
 
351
 
 
352
 
 
353
 
 
354
 
315
355
#####################################################################
316
356
# Padre::Document GUI Integration
317
357
 
320
360
        my $lexer  = $self->lexer;
321
361
        my $editor = $self->editor;
322
362
        $editor->SetLexer($lexer);
 
363
        TRACE("coloUrize called") if DEBUG;
323
364
 
324
365
        $self->remove_color;
325
366
        if ( $lexer == Wx::wxSTC_LEX_CONTAINER ) {
326
367
                $self->colorize;
327
368
        } else {
 
369
                TRACE("Colourize is being called") if DEBUG;
328
370
                $editor->Colourise( 0, $editor->GetLength );
329
371
        }
330
372
}
515
557
        my $file = $self->file;
516
558
 
517
559
        if (DEBUG) {
518
 
                my $name = $file->{file}->{filename} || '';
 
560
                my $name = $file->{filename} || '';
519
561
                TRACE("Loading file '$name'");
520
562
        }
521
563
 
 
564
        # Show the file-changed-dialog again after the file was (re)loaded:
 
565
        delete $self->{_already_popup_file_changed};
 
566
 
522
567
        # check if file exists
523
568
        if ( !$file->exists ) {
524
569
 
547
592
        #warn $self->{encoding};
548
593
        $content = Encode::decode( $self->{encoding}, $content );
549
594
 
 
595
        # Determine new line type using file content.
 
596
        $self->{newline_type} = Padre::Util::newline_type($content);
 
597
 
 
598
        # Cache the original value of various things so we can do
 
599
        # smart things at save time later.
550
600
        $self->{original_content} = $content;
551
 
 
552
 
        # Determine new line type using file content.
553
 
        $self->{newline_type} = Padre::Util::newline_type($content);
 
601
        $self->{original_newline} = $self->{newline_type};
554
602
 
555
603
        return 1;
556
604
}
693
741
sub save_file {
694
742
        my $self = shift;
695
743
 
 
744
        # Show the file-changed-dialog again after the file was saved:
 
745
        delete $self->{_already_popup_file_changed};
 
746
 
696
747
        # If padre is run on files that have no project
697
748
        # I.E Padre foo.pl &
698
749
        # The assumption of $self->project as defined will cause a fail
849
900
        $_[0]->editor->GetText;
850
901
}
851
902
 
 
903
sub text_length {
 
904
        $_[0]->editor->GetLength;
 
905
}
 
906
 
852
907
sub text_set {
853
908
        $_[0]->editor->SetText( $_[1] );
854
909
}
919
974
 
920
975
        my $highlighter = $self->highlighter;
921
976
        if ( not $highlighter ) {
922
 
                warn "no highlighter\n";
 
977
                $self->current->main->error(
 
978
                        sprintf(
 
979
                                Wx::gettext("no highlighter for mime-type '%s' using stc"),
 
980
                                $self->mimetype
 
981
                        )
 
982
                );
923
983
                $highlighter = 'stc';
924
984
        }
 
985
        TRACE("The highlighter is '$highlighter'") if DEBUG;
925
986
        return Wx::wxSTC_LEX_CONTAINER if $highlighter ne 'stc';
926
987
        return Wx::wxSTC_LEX_AUTOMATIC unless defined Padre::MimeTypes->get_lexer( $self->mimetype );
927
988
 
1191
1252
        );
1192
1253
 
1193
1254
        my $style;
 
1255
        my $config = Padre->ide->config;
1194
1256
        if ( $indentation =~ /^t\d+/ ) { # we only do ONE tab
1195
1257
                $style = {
1196
1258
                        use_tabs    => 1,
1197
 
                        tabwidth    => 8,
 
1259
                        tabwidth    => $config->editor_indent_tab_width || 8,
1198
1260
                        indentwidth => 8,
1199
1261
                };
1200
1262
        } elsif ( $indentation =~ /^s(\d+)/ ) {
1201
1263
                $style = {
1202
1264
                        use_tabs    => 0,
1203
 
                        tabwidth    => 8,
 
1265
                        tabwidth    => $config->editor_indent_tab_width || 8,
1204
1266
                        indentwidth => $1,
1205
1267
                };
1206
1268
        } elsif ( $indentation =~ /^m(\d+)/ ) {
1207
1269
                $style = {
1208
1270
                        use_tabs    => 1,
1209
 
                        tabwidth    => 8,
 
1271
                        tabwidth    => $config->editor_indent_tab_width || 8,
1210
1272
                        indentwidth => $1,
1211
1273
                };
1212
1274
        } else {
1213
1275
 
1214
1276
                # fallback
1215
 
                my $config = Padre->ide->config;
1216
1277
                $style = {
1217
1278
                        use_tabs    => $config->editor_indent_tab,
1218
1279
                        tabwidth    => $config->editor_indent_tab_width,
1450
1511
# order for padre not to crash if user wants to un/comment lines with
1451
1512
# a document type that did not define those methods.
1452
1513
#
1453
 
# TO DO Remove this base method, and compensate by disabling the menu entries
1454
 
# if the document class does not define this method.
 
1514
# TO DO Remove this base method
1455
1515
sub comment_lines_str { }
1456
1516
 
1457
1517
 
1483
1543
        my $post = $editor->GetTextRange( $first, $last );
1484
1544
 
1485
1545
        my $regex = eval {qr{\b(\Q$prefix\E\w+)\b}};
1486
 
        return ("Cannot build regex for '$prefix'") if $@;
 
1546
        return ("Cannot build regular expression for '$prefix'.") if $@;
1487
1547
 
1488
1548
        my %seen;
1489
1549
        my @words;