~ubuntu-branches/ubuntu/saucy/padre/saucy-proposed

« back to all changes in this revision

Viewing changes to lib/Padre/Document.pm

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont
  • Date: 2012-01-25 16:16:07 UTC
  • mfrom: (1.3.4)
  • Revision ID: package-import@ubuntu.com-20120125161607-ydc0rgxlfqk2ctrb
Tags: 0.94+dfsg1-1
* new upstream version
* watch: updated to match dfsg tag
* debian/not-real-manual.list: updated lib/Padre/Document/Perl.pm entry
* debian/copyright:
  * fixed DEP-5 syntax errors
  * updated copyright years.
  * reformatted with cme
* control: updated dependency list

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package Padre::Document;
2
2
 
3
 
=pod
4
 
 
5
3
=head1 NAME
6
4
 
7
5
Padre::Document - Padre Document API
124
122
use 5.008;
125
123
use strict;
126
124
use warnings;
127
 
use Carp ();
128
 
use File::Spec 3.21 (); # 3.21 needed for volume-safe abs2rel
129
 
use File::Temp       ();
130
 
use Params::Util     ();
131
 
use Wx::Scintilla    ();
132
 
use Padre::Constant  ();
133
 
use Padre::Current   ();
134
 
use Padre::Util      ();
135
 
use Padre::Wx        ();
136
 
use Padre::MimeTypes ();
137
 
use Padre::File      ();
 
125
use Carp                    ();
 
126
use File::Spec          3.2 (); # 3.21 needed for volume-safe abs2rel
 
127
use File::Temp              ();
 
128
use Params::Util            ();
 
129
use Wx::Scintilla::Constant ();
 
130
use Padre::Constant         ();
 
131
use Padre::Current          ();
 
132
use Padre::Util             ();
 
133
use Padre::Wx               ();
 
134
use Padre::MIME             ();
 
135
use Padre::File             ();
138
136
use Padre::Logger;
139
137
 
140
 
our $VERSION    = '0.92';
 
138
our $VERSION    = '0.94';
141
139
our $COMPATIBLE = '0.91';
142
140
 
143
141
 
155
153
        'text/x-bat'                => 'REM',
156
154
        'application/x-bibtex'      => '%',
157
155
        'application/x-bml'         => [ '<?_c', '_c?>' ],
158
 
        'text/x-c'                  => '//',
 
156
        'text/x-csrc'               => '//',
159
157
        'text/x-cobol'              => '      *',
160
158
        'text/x-config'             => '#',
161
159
        'text/x-csharp'             => '//',
168
166
        'text/html'                 => [ '<!--', '-->' ],
169
167
        'application/javascript'    => '//',
170
168
        'application/x-latex'       => '%',
171
 
        'text/x-java-source'        => '//',
 
169
        'text/x-java'               => '//',
172
170
        'application/x-lisp'        => ';',
173
171
        'text/x-lua'                => '--',
174
172
        'text/x-makefile'           => '#',
191
189
);
192
190
 
193
191
 
194
 
# JavaScript keywords
195
 
my @SCINTILLA_JS_KEYWORDS = qw{
196
 
        abstract boolean break byte case catch char class
197
 
        const continue debugger default delete do double else enum export extends
198
 
        final finally float for function goto if implements import in instanceof
199
 
        int interface long native new package private protected public
200
 
        return short static super switch synchronized this throw throws
201
 
        transient try typeof var void volatile while with
202
 
};
203
 
 
204
 
# PHP keywords
205
 
my @SCINTILLA_PHP_KEYWORDS = qw{
206
 
        and array as bool boolean break case cfunction class const
207
 
        continue declare default die directory do double echo else
208
 
        elseif empty enddeclare endfor endforeach endif endswitch
209
 
        endwhile eval exit extends false float for foreach function
210
 
        global goto if include include_once int integer isset list
211
 
        namespace new null object old_function or parent print real
212
 
        require require_once resource return static stdclass string
213
 
        switch true unset use var while xor abstract catch clone
214
 
        exception final implements interface php_user_filter private
215
 
        protected public this throw try __class__ __dir__ __file__
216
 
        __function__ __line__ __method__ __namespace__ __sleep __wakeup
217
 
};
218
 
 
219
 
# VB keyword list is obtained from src/scite/src/vb.properties
220
 
my @SCINTILLA_VB_KEYWORDS = qw{addressof alias and as attribute base begin binary
221
 
        boolean byref byte byval call case cdbl cint clng compare const csng cstr currency
222
 
        date decimal declare defbool defbyte defcur
223
 
        defdate defdbl defdec defint deflng defobj defsng defstr defvar dim do double each else
224
 
        elseif empty end enum eqv erase error event exit explicit false for friend function get
225
 
        global gosub goto if imp implements in input integer is len let lib like load lock long
226
 
        loop lset me mid midb mod new next not nothing null object on option optional or paramarray
227
 
        preserve print private property public raiseevent randomize redim rem resume return rset
228
 
        seek select set single static step stop string sub text then time to true type typeof
229
 
        unload until variant wend while with withevents xor
230
 
};
231
 
 
232
 
# Take mostly from src/scite/src/ properties files
233
 
my %SCINTILLA_KEY_WORDS = (
234
 
 
235
 
        # C/C++ keyword list is obtained from src/scite/src/cpp.properties
236
 
        'text/x-c' => [
237
 
                [   qw{
238
 
                                and and_eq asm auto bitand bitor bool break
239
 
                                case catch char class compl const const_cast continue
240
 
                                default delete do double dynamic_cast else enum explicit export
241
 
                                extern false float for friend goto if inline int long mutable
242
 
                                namespace new not not_eq operator or or_eq private protected
243
 
                                public register reinterpret_cast return short signed sizeof
244
 
                                static static_cast struct switch template this throw true try
245
 
                                typedef typeid typename union unsigned using virtual void
246
 
                                volatile wchar_t while xor xor_eq
247
 
                                }
248
 
                ]
249
 
        ],
250
 
 
251
 
        # PHP keyword list is obtained from src/scite/src/html.properties
252
 
        'application/x-php' => [ [@SCINTILLA_PHP_KEYWORDS] ],
253
 
 
254
 
        'text/x-sql' => [
255
 
                [   qw{
256
 
                                absolute action add admin after aggregate alias all allocate
257
 
                                alter and any are array as asc assertion at authorization
258
 
                                before begin binary bit body both breadth by call
259
 
                                cascade cascaded case cast catalog check class
260
 
                                close collate collation column commit completion connect
261
 
                                connection constraint constraints constructor continue
262
 
                                corresponding create cross cube current current_date
263
 
                                current_path current_role current_time current_timestamp
264
 
                                current_user cursor cycle data deallocate dec decimal
265
 
                                declare default deferrable deferred delete depth deref desc
266
 
                                describe descriptor destroy destructor deterministic dictionary
267
 
                                diagnostics disconnect distinct domain drop dynamic each
268
 
                                else end end-exec equals escape every except exception exec
269
 
                                execute exists exit external false fetch first for
270
 
                                foreign found from free full function general get global go
271
 
                                goto grant group grouping having host hour identity if ignore
272
 
                                immediate in indicator initialize initially inner inout input
273
 
                                insert intersect interval into is isolation iterate
274
 
                                join key language large last lateral leading left less level
275
 
                                like limit local locator loop map match
276
 
                                merge minus modifies modify module names national natural
277
 
                                new next no none not numeric object of off old
278
 
                                on only open operation option or order ordinality out outer
279
 
                                output package pad parameter parameters partial path postfix
280
 
                                precision prefix preorder prepare preserve primary prior
281
 
                                privileges procedure public read reads real recursive ref
282
 
                                references referencing relative replace restrict result return returns
283
 
                                revoke right role rollback rollup routine row rows savepoint
284
 
                                schema scroll scope search second section select sequence
285
 
                                session session_user set sets size some| space
286
 
                                specific specifictype sql sqlexception sqlstate sqlwarning
287
 
                                start state statement static structure system_user table
288
 
                                temporary terminate than then timezone_hour
289
 
                                timezone_minute to trailing transaction translation treat
290
 
                                trigger true under union unique unknown unnest update usage
291
 
                                user using value values variable varying view when
292
 
                                whenever where with without work write zone
293
 
                                }
294
 
                ],
295
 
 
296
 
                # keywords2 - being used for datatypes
297
 
                [
298
 
 
299
 
                        # oracle centric
300
 
                        qw( varchar varchar2 nvarchar nvarchar2 char nchar number
301
 
                                integer pls_integer binary_integer long date time
302
 
                                timestamp with local timezone interval year day month second minute
303
 
                                raw rowid urowid mlslabel clob nclob blob bfile xmltype rowtype
304
 
                                ),
305
 
                        qw(
306
 
                                boolean smallint null localtime localtimestamp  int integer
307
 
                                float double char character
308
 
                                ),
309
 
 
310
 
                ],
311
 
 
312
 
                # pldoc keywords - bare minimum
313
 
                [qw( headcom deprecated param return throws )],
314
 
 
315
 
                # SQL*Plus
316
 
                [   qw(
317
 
                                accept append archive log archivelog attribute
318
 
                                break btitle
319
 
                                change clear column default compute connect copy
320
 
                                define del describe disconnect document
321
 
                                edit execute exit
322
 
                                get
323
 
                                help host html
324
 
                                input
325
 
                                list logon
326
 
                                markup
327
 
                                newpage
328
 
                                password pause print product_user_profile prompt
329
 
                                recover remark repfooter repheader restrict run
330
 
                                save set show label shutdown silent spool start startup store
331
 
                                timing ttitle
332
 
                                undefine
333
 
                                variable
334
 
                                version
335
 
                                whenever oserror sqlerror
336
 
                                )
337
 
                ],
338
 
 
339
 
                # User Keywords #1 , reserve this for PLSQL functions, procedures, packages
340
 
                [   qw(
341
 
                                utl_coll utl_encode utl_file utl_http utl_inaddr utl_raw utl_ref
342
 
                                utl_smtp utl_tcp utl_url
343
 
                                anydata anytype anydataset
344
 
 
345
 
                                dbms_alert dbms_application_info dbms_apply_adm dbms_aq dbms_aqadm
346
 
                                dbms_aqelm dbms_capture_adm dbms_ddl dbms_debug dbms_defer
347
 
                                dbms_defer_query dbms_defer_sys dbms_describe
348
 
                                dbms_distributed_trust_admin dbms_fga dbms_flashback
349
 
                                dbms_hs_passthrough dbms_iot dbms_job dbms_ldap dbms_libcache
350
 
                                dbms_lob dbms_lock dbms_logmnr dbms_logmnr_cdc_publish
351
 
                                dbms_logmnr_cdc_subscribe dbms_logmnr_d dbms_logstdby dbms_metadata
352
 
                                dbms_mgwadm dbms_mgwmsg dbms_mview dbms_obfuscation_toolkit
353
 
                                dbms_odci dbms_offline_og dbms_offline_snapshot dbms_olap
354
 
                                dbms_oracle_trace_agent dbms_oracle_trace_user dbms_outln
355
 
                                dbms_outln_edit dbms_output dbms_pclxutil dbms_pipe dbms_profiler
356
 
                                dbms_propagation_adm dbms_random dbms_rectifier_diff dbms_redefinition
357
 
                                dbms_refresh dbms_repair dbms_repcat dbms_repcat_admin
358
 
                                dbms_repcat_instantiate dbms_repcat_rgt dbms_reputil
359
 
                                dbms_resource_manager dbms_resource_manager_privs dbms_resumable
360
 
                                dbms_rls dbms_rowid dbms_rule dbms_rule_adm dbms_session
361
 
                                dbms_shared_pool dbms_space dbms_space_admin dbms_sql dbms_stats
362
 
                                dbms_storage_map dbms_streams dbms_streams_adm dbms_trace
363
 
                                dbms_transaction dbms_transform dbms_tts dbms_types dbms_utility
364
 
                                dbms_wm dbms_xdb dbms_xdbt dbms_xdb_version dbms_xmldom dbms_xmlgen
365
 
                                dbms_xmlparser dbms_xmlquery dbms_xmlsave dbms_xplan dbms_xslprocessor
366
 
                                debug_extproc
367
 
                                )
368
 
                ],
369
 
 
370
 
                # User Keywords #2 , sql functions
371
 
                [   qw( sqlerrm
372
 
                                abs greatest sin
373
 
                                acos group_id sinh add_months hextoraw soundex ascii initcap sqlcode
374
 
                                asciistr instr sqlerrm asin lag sqrt atan last_day stddev atan2 lead
375
 
                                substr avg least sum bfilename length sys_context bin_to_num lnnvl
376
 
                                sysdate bitand ln systimestamp cardinality localtimestamp tan case
377
 
                                statement log tanh cast lower to_char ceil lpad to_clob chartorowid
378
 
                                ltrim to_date chr max to_dsinterval coalesce median to_lob compose min
379
 
                                to_multi_byte concat mod to_nclob months_between to_number convert nanvl
380
 
                                to_single_byte corr new_time to_timestamp cos next_day to_timestamp_tz
381
 
                                cosh nullif to_yminterval count numtodsinterval translate covar_pop
382
 
                                numtoyminterval trim covar_samp nvl trunc cume_dist nvl2 trunc
383
 
                                current_date power tz_offset current_timestamp rank uid
384
 
                                dbtimezone rawtohex upper decode remainder user decompose replace
385
 
                                userenv dense_rank round var_pop dump var_samp exp rpad variance extract
386
 
                                rtrim vsize floor sessiontimezone from_tz sign
387
 
                                )
388
 
                ],
389
 
 
390
 
                # User Keywords #3 , exception types
391
 
                [
392
 
 
393
 
                        # exception types
394
 
                        qw(
395
 
                                no_data_found too_many_rows invalid_cursor value_error
396
 
                                invalid_number zero_divide dup_val_on_index cursor_already_open
397
 
                                not_logged_on transaction_backed_out login_denied program_error
398
 
                                storage_error timeout_on_resource others
399
 
                                ) ],
400
 
 
401
 
                # User Keywords #4 , reserve this for plugins, eg known schema entities
402
 
                [qw()],
403
 
 
404
 
        ],
405
 
 
406
 
        # YAML keyword list is obtained from src/scite/src/yaml.properties
407
 
        'text/x-yaml' => [ [qw{true false yes no}] ],
408
 
 
409
 
        # The list is obtained from src/scite/src/cpp.properties
410
 
        # Some of these are reserved for future use.
411
 
        # https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
412
 
        'application/javascript' => [ [@SCINTILLA_JS_KEYWORDS] ],
413
 
 
414
 
        # CSS keyword list is obtained from src/scite/src/css.properties
415
 
        'text/css' => [
416
 
                [
417
 
 
418
 
                        # CSS1
419
 
                        qw{
420
 
                                color background-color background-image background-repeat background-attachment background-position background
421
 
                                font-family font-style font-variant font-weight font-size font
422
 
                                word-spacing letter-spacing text-decoration vertical-align text-transform text-align text-indent line-height
423
 
                                margin-top margin-right margin-bottom margin-left margin
424
 
                                padding-top padding-right padding-bottom padding-left padding
425
 
                                border-top-width border-right-width border-bottom-width border-left-width border-width
426
 
                                border-top border-right border-bottom border-left border
427
 
                                border-color border-style width height float clear
428
 
                                display white-space list-style-type list-style-image list-style-position list-style
429
 
                                position top bottom left right
430
 
                                }
431
 
                ],
432
 
 
433
 
                # Pseudoclasses
434
 
                [qw( link visited hover active focus first-child lang )],
435
 
 
436
 
                [
437
 
 
438
 
                        # CSS2
439
 
                        qw{
440
 
                                border-top-color border-right-color border-bottom-color border-left-color border-color
441
 
                                border-top-style border-right-style border-bottom-style border-left-style border-style
442
 
                                top right bottom left position z-index direction unicode-bidi
443
 
                                min-width max-width min-height max-height overflow clip visibility content quotes
444
 
                                counter-reset counter-increment marker-offset
445
 
                                size marks page-break-before page-break-after page-break-inside page orphans widows
446
 
                                font-stretch font-size-adjust unicode-range units-per-em src
447
 
                                panose-1 stemv stemh slope cap-height x-height ascent descent widths bbox definition-src
448
 
                                baseline centerline mathline topline text-shadow
449
 
                                caption-side table-layout border-collapse border-spacing empty-cells speak-header
450
 
                                cursor outline outline-width outline-style outline-color
451
 
                                volume speak pause-before pause-after pause cue-before cue-after cue
452
 
                                play-during azimuth elevation speech-rate voice-family pitch pitch-range stress richness
453
 
                                speak-punctuation speak-numeral
454
 
                                visibility z-index
455
 
                                }
456
 
 
457
 
                ],
458
 
                [
459
 
 
460
 
                        # CSS3
461
 
                        qw{
462
 
                                border-radius border-top-right-radius border-bottom-right-radius border-bottom-left-radius
463
 
                                border-top-left-radius box-shadow columns column-width column-count column-rule column-gap
464
 
                                column-rule-color column-rule-style column-rule-width resize opacity word-wrap
465
 
                                }
466
 
                ],
467
 
 
468
 
                # pseudo elements
469
 
                [qw( first-letter first-line before after selection)],
470
 
 
471
 
                # I presume extended in LexCSS means -moz -x -webkit and friends
472
 
                # extended-props
473
 
                [qw( )],
474
 
 
475
 
                # extended-pseudo-classes
476
 
                [qw( )],
477
 
 
478
 
                # extended-pseudo-elements
479
 
                [qw( )],
480
 
        ],
481
 
 
482
 
        # HTML keyword list is obtained from src/scite/src/css.properties
483
 
        'text/html' => [
484
 
                [
485
 
 
486
 
                        # HTML elements
487
 
                        qw{a abbr acronym address applet area b base basefont
488
 
                                bdo big blockquote body br button caption center
489
 
                                cite code col colgroup dd del dfn dir div dl dt em
490
 
                                fieldset font form frame frameset h1 h2 h3 h4 h5 h6
491
 
                                head hr html i iframe img input ins isindex kbd label
492
 
                                legend li link map menu meta noframes noscript
493
 
                                object ol optgroup option p param pre q s samp
494
 
                                script select small span strike strong style sub sup
495
 
                                table tbody td textarea tfoot th thead title tr tt u ul
496
 
                                var xml xmlns
497
 
                                },
498
 
 
499
 
                        # HTML attributes
500
 
                        qw{abbr accept-charset accept accesskey action align alink
501
 
                                alt archive axis background bgcolor border
502
 
                                cellpadding cellspacing char charoff charset checked cite
503
 
                                class classid clear codebase codetype color cols colspan
504
 
                                compact content coords
505
 
                                data datafld dataformatas datapagesize datasrc datetime
506
 
                                declare defer dir disabled enctype event
507
 
                                face for frame frameborder
508
 
                                headers height href hreflang hspace http-equiv
509
 
                                id ismap label lang language leftmargin link longdesc
510
 
                                marginwidth marginheight maxlength media method multiple
511
 
                                name nohref noresize noshade nowrap
512
 
                                object onblur onchange onclick ondblclick onfocus
513
 
                                onkeydown onkeypress onkeyup onload onmousedown
514
 
                                onmousemove onmouseover onmouseout onmouseup
515
 
                                onreset onselect onsubmit onunload
516
 
                                profile prompt readonly rel rev rows rowspan rules
517
 
                                scheme scope selected shape size span src standby start style
518
 
                                summary tabindex target text title topmargin type usemap
519
 
                                valign value valuetype version vlink vspace width
520
 
                                text password checkbox radio submit reset
521
 
                                file hidden image
522
 
                                ^data-
523
 
                                },
524
 
 
525
 
                        # HTML 5 elements
526
 
                        qw{
527
 
                                address article aside audio base canvas command details datalist embed
528
 
                                figure figcaption footer header hgroup keygen mark menu meter nav output
529
 
                                progress ruby rt rp section source time video wbr
530
 
                                },
531
 
 
532
 
                        # HTML 5 attributes
533
 
                        qw{
534
 
                                async autocomplete autofocus contenteditable contextmenu draggable
535
 
                                form formaction formenctype formmethod formnovalidate formtarget
536
 
                                list manifest max min novalidate pattern placeholder
537
 
                                required reversed role sandbox scoped seamless sizes spellcheck srcdoc step
538
 
                                },
539
 
                ],
540
 
 
541
 
                # Embedded Javascript
542
 
                [@SCINTILLA_JS_KEYWORDS],
543
 
 
544
 
                # Embedded Python
545
 
                [   qw(and as assert break class continue def del elif
546
 
                                else except exec finally for from global if import in is lambda None
547
 
                                not or pass print raise return try while with yield)
548
 
                ],
549
 
 
550
 
                # Embedded VBScript
551
 
                [@SCINTILLA_VB_KEYWORDS],
552
 
 
553
 
                # Embedded PHP
554
 
                [@SCINTILLA_PHP_KEYWORDS],
555
 
 
556
 
        ],
557
 
 
558
 
        # Ada keyword list is obtained from src/scite/src/ada.properties
559
 
        'text/x-adasrc' => [
560
 
                [
561
 
 
562
 
                        # Ada keywords
563
 
                        qw{abort abstract accept access aliased all array at begin body
564
 
                                case constant declare delay delta digits do else elsif end entry exception exit for
565
 
                                function generic goto if in is limited loop new null of others out package pragma
566
 
                                private procedure protected raise range record renames requeue return reverse
567
 
                                select separate subtype tagged task terminate then type until use when while with
568
 
                                },
569
 
 
570
 
                        # Ada Operators
571
 
                        qw{abs and mod not or rem xor},
572
 
                ]
573
 
        ],
574
 
 
575
 
        # COBOL keyword list is obtained from src/scite/src/cobol.properties
576
 
        'text/x-cobol' => [
577
 
                [   qw{configuration data declaratives division environment
578
 
                                environment-division file file-control function i-o i-o-control
579
 
                                identification input input-output linkage local-storage output procedure
580
 
                                program program-id receive-control section special-names working-storage},
581
 
                ],
582
 
                [   qw{accept add alter apply assign call chain close compute continue
583
 
                                control convert copy count delete display divide draw drop eject else
584
 
                                enable end-accept end-add end-call end-chain end-compute end-delete
585
 
                                end-display end-divide end-evaluate end-if end-invoke end-multiply
586
 
                                end-perform end-read end-receive end-return end-rewrite end-search
587
 
                                end-start end-string end-subtract end-unstring end-write erase evaluate
588
 
                                examine exec execute exit go goback generate if ignore initialize
589
 
                                initiate insert inspect invoke leave merge move multiply open otherwise
590
 
                                perform print read receive release reload replace report reread rerun
591
 
                                reserve reset return rewind rewrite rollback run search seek select send
592
 
                                set sort start stop store string subtract sum suppress terminate then
593
 
                                transform unlock unstring update use wait when wrap write},
594
 
                ],
595
 
                [   qw{access acquire actual address advancing after all allowing
596
 
                                alphabet alphabetic alphabetic-lower alphabetic-upper alphanumeric
597
 
                                alphanumeric-edited also alternate and any are area areas as ascending at
598
 
                                attribute author auto auto-hyphen-skip auto-skip automatic autoterminate
599
 
                                background-color background-colour backward basis beep before beginning
600
 
                                bell binary blank blink blinking block bold bottom box boxed by c01 c02
601
 
                                c03 c04 c05 c06 c07 c08 c09 c10 c11 c12 cancel cbl cd centered cf ch
602
 
                                chaining changed character characters chart class clock-units cobol code
603
 
                                code-set col collating color colour column com-reg comma command-line
604
 
                                commit commitment common communication comp comp-0 comp-1 comp-2 comp-3
605
 
                                comp-4 comp-5 comp-6 comp-x compression computational computational-1
606
 
                                computational-2 computational-3 computational-4 computational-5
607
 
                                computational-6 computational-x computational console contains content
608
 
                                control-area controls conversion converting core-index corr corresponding
609
 
                                crt crt-under csp currency current-date cursor cycle cyl-index
610
 
                                cyl-overflow date date-compiled date-written day day-of-week dbcs de
611
 
                                debug debug-contents debug-item debug-line debug-name debug-sub-1
612
 
                                debug-sub-2 debug-sub-3 debugging decimal-point default delimited
613
 
                                delimiter depending descending destination detail disable disk disp
614
 
                                display-1 display-st down duplicates dynamic echo egcs egi emi
615
 
                                empty-check encryption end end-of-page ending enter entry eol eop eos
616
 
                                equal equals error escape esi every exceeds exception excess-3 exclusive
617
 
                                exhibit extend extended-search external externally-described-key factory
618
 
                                false fd fh--fcd fh--keydef file-id file-limit file-limits file-prefix
619
 
                                filler final first fixed footing for foreground-color foreground-colour
620
 
                                footing format from full giving global greater grid group heading high
621
 
                                high-value high-values highlight id in index indexed indic indicate
622
 
                                indicator indicators inheriting initial installation into invalid invoked
623
 
                                is japanese just justified kanji kept key keyboard label last leading
624
 
                                left left-justify leftline length length-check less limit limits lin
625
 
                                linage linage-counter line line-counter lines lock lock-holding locking
626
 
                                low low-value low-values lower lowlight manual mass-update master-index
627
 
                                memory message method mode modified modules more-labels multiple name
628
 
                                named national national-edited native nchar negative next no no-echo
629
 
                                nominal not note nstd-reels null nulls number numeric numeric-edited
630
 
                                numeric-fill o-fill object object-computer object-storage occurs of off
631
 
                                omitted on oostackptr optional or order organization other others
632
 
                                overflow overline packed-decimal padding page page-counter packed-decimal
633
 
                                paragraph password pf ph pic picture plus pointer pop-up pos position
634
 
                                positioning positive previous print-control print-switch printer
635
 
                                printer-1 printing prior private procedure-pointer procedures proceed
636
 
                                process processing prompt protected public purge queue quote quotes
637
 
                                random range rd readers ready record record-overflow recording records
638
 
                                redefines reel reference references relative remainder remarks removal
639
 
                                renames reorg-criteria repeated replacing reporting reports required
640
 
                                resident return-code returning reverse reverse-video reversed rf rh right
641
 
                                right-justify rolling rounded s01 s02 s03 s04 s05 same screen scroll sd
642
 
                                secure security segment segment-limit selective self selfclass sentence
643
 
                                separate sequence sequential service setshadow shift-in shift-out sign
644
 
                                size skip1 skip2 skip3 sort-control sort-core-size sort-file-size
645
 
                                sort-merge sort-message sort-mode-size sort-option sort-return source
646
 
                                source-computer space spaces space-fill spaces standard standard-1
647
 
                                standard-2 starting status sub-queue-1 sub-queue-2 sub-queue-3 subfile
648
 
                                super symbolic sync synchronized sysin sysipt syslst sysout syspch
649
 
                                syspunch system-info tab tallying tape terminal terminal-info test text
650
 
                                than through thru time time-of-day time-out timeout times title to top
651
 
                                totaled totaling trace track-area track-limit tracks trailing
652
 
                                trailing-sign transaction true type typedef underline underlined unequal
653
 
                                unit until up updaters upon upper upsi-0 upsi-1 upsi-2 upsi-3 upsi-4
654
 
                                upsi-5 upsi-6 upsi-7 usage user using value values variable varying
655
 
                                when-compiled window with words write-only write-verify writerszero zero
656
 
                                zero-fill zeros zeroes},
657
 
                ],
658
 
        ],
659
 
 
660
 
        # Haskell keyword list is obtained from src/scite/src/haskell.properties
661
 
        'text/x-haskell' => [
662
 
                [
663
 
 
664
 
                        # Haskell 98
665
 
                        qw{case class data default deriving do else hiding if
666
 
                                import in infix infixl infixr instance let module
667
 
                                newtype of then type where forall foreign
668
 
                                }
669
 
                ],
670
 
                [
671
 
 
672
 
                        # Haskell Foreign Function Interface (FFI) (
673
 
                        qw{export label dynamic safe threadsafe unsafe stdcall ccall prim}
674
 
                ],
675
 
        ],
676
 
 
677
 
        # Pascal keyword list is obtained from src/scite/src/pascal.properties
678
 
        'text/x-pascal' => [
679
 
                [
680
 
 
681
 
                        # Pascal keywords
682
 
                        qw{absolute abstract and array as asm assembler automated begin case
683
 
                                cdecl class const constructor deprecated destructor dispid dispinterface div do downto
684
 
                                dynamic else end except export exports external far file final finalization finally for
685
 
                                forward function goto if implementation in inherited initialization inline interface is
686
 
                                label library message mod near nil not object of on or out overload override packed
687
 
                                pascal platform private procedure program property protected public published raise
688
 
                                record register reintroduce repeat resourcestring safecall sealed set shl shr static
689
 
                                stdcall strict string then threadvar to try type unit unsafe until uses var varargs
690
 
                                virtual while with xor
691
 
                                },
692
 
 
693
 
                        # Smart pascal highlighting
694
 
                        qw{add default implements index name nodefault read readonly
695
 
                                remove stored write writeonly},
696
 
 
697
 
                        # Pascal package
698
 
                        #TODO only package dpk should get this list
699
 
                        qw{package contains requires},
700
 
                ],
701
 
        ],
702
 
 
703
 
        # ActionScript keyword list is obtained from src/scite/src/cpp.properties
704
 
        'text/x-actionscript' => [
705
 
                [   qw{
706
 
                                add and break case catch class continue default delete do
707
 
                                dynamic else eq extends false finally for function ge get gt if implements import in
708
 
                                instanceof interface intrinsic le lt ne new not null or private public return
709
 
                                set static super switch this throw true try typeof undefined var void while with
710
 
                                }
711
 
                ],
712
 
                [   qw{
713
 
                                Array Arguments Accessibility Boolean Button Camera Color
714
 
                                ContextMenu ContextMenuItem Date Error Function Key LoadVars LocalConnection Math
715
 
                                Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number Object
716
 
                                PrintJob Selection SharedObject Sound Stage String StyleSheet System TextField
717
 
                                TextFormat TextSnapshot Video Void XML XMLNode XMLSocket
718
 
                                _accProps _focusrect _global _highquality _parent _quality _root _soundbuftime
719
 
                                arguments asfunction call capabilities chr clearInterval duplicateMovieClip
720
 
                                escape eval fscommand getProperty getTimer getURL getVersion gotoAndPlay gotoAndStop
721
 
                                ifFrameLoaded Infinity -Infinity int isFinite isNaN length loadMovie loadMovieNum
722
 
                                loadVariables loadVariablesNum maxscroll mbchr mblength mbord mbsubstring MMExecute
723
 
                                NaN newline nextFrame nextScene on onClipEvent onUpdate ord parseFloat parseInt play
724
 
                                prevFrame prevScene print printAsBitmap printAsBitmapNum printNum random removeMovieClip
725
 
                                scroll set setInterval setProperty startDrag stop stopAllSounds stopDrag substring
726
 
                                targetPath tellTarget toggleHighQuality trace unescape unloadMovie unLoadMovieNum updateAfterEvent
727
 
                                }
728
 
                ],
729
 
        ],
730
 
 
731
 
        # Inspired from Perl 6 vim syntax file
732
 
        # https://github.com/petdance/vim-perl/blob/master/syntax/perl6.vim
733
 
        'application/x-perl6' => [
734
 
                [
735
 
 
736
 
                        # Perl 6 routine declaration keywords
737
 
                        qw{macro sub submethod method multi proto only rule token regex category},
738
 
 
739
 
                        # Perl 6 module keywords
740
 
                        qw{module class role package enum grammar slang subset},
741
 
 
742
 
                        # Perl 6 variable keywords
743
 
                        qw{self},
744
 
 
745
 
                        # Perl 6 include keywords
746
 
                        qw{use require},
747
 
 
748
 
                        # Perl 6 conditional keywords
749
 
                        qw{if else elsif unless},
750
 
 
751
 
                        # Perl 6 variable storage keywords
752
 
                        qw{let my our state temp has constant},
753
 
 
754
 
                        # Perl 6 repeat keywords
755
 
                        qw{for loop repeat while until gather given},
756
 
 
757
 
                        # Perl flow control keywords
758
 
                        qw{take do when next last redo return contend maybe defer
759
 
                                default exit make continue break goto leave async lift},
760
 
 
761
 
                        # Perl 6 type constraints keywords
762
 
                        qw{is as but trusts of returns handles where augment supersede},
763
 
 
764
 
                        # Perl 6 closure traits keywords
765
 
                        qw{BEGIN CHECK INIT START FIRST ENTER LEAVE KEEP
766
 
                                UNDO NEXT LAST PRE POST END CATCH CONTROL TEMP},
767
 
 
768
 
                        # Perl 6 exception keywords
769
 
                        qw{die fail try warn},
770
 
 
771
 
                        # Perl 6 property keywords
772
 
                        qw{prec irs ofs ors export deep binary unary reparsed rw parsed cached
773
 
                                readonly defequiv will ref copy inline tighter looser equiv assoc
774
 
                                required},
775
 
 
776
 
                        # Perl 6 number keywords
777
 
                        qw{NaN Inf},
778
 
 
779
 
                        # Perl 6 pragma keywords
780
 
                        qw{oo fatal},
781
 
 
782
 
                        # Perl 6 type keywords
783
 
                        qw{Object Any Junction Whatever Capture Match
784
 
                                Signature Proxy Matcher Package Module Class
785
 
                                Grammar Scalar Array Hash KeyHash KeySet KeyBag
786
 
                                Pair List Seq Range Set Bag Mapping Void Undef
787
 
                                Failure Exception Code Block Routine Sub Macro
788
 
                                Method Submethod Regex Str Blob Char Byte
789
 
                                Codepoint Grapheme StrPos StrLen Version Num
790
 
                                Complex num complex Bit bit bool True False
791
 
                                Increasing Decreasing Ordered Callable AnyChar
792
 
                                Positional Associative Ordering KeyExtractor
793
 
                                Comparator OrderingPair IO KitchenSink Role
794
 
                                Int int int1 int2 int4 int8 int16 int32 int64
795
 
                                Rat rat rat1 rat2 rat4 rat8 rat16 rat32 rat64
796
 
                                Buf buf buf1 buf2 buf4 buf8 buf16 buf32 buf64
797
 
                                UInt uint uint1 uint2 uint4 uint8 uint16 uint32
798
 
                                uint64 Abstraction utf8 utf16 utf32},
799
 
 
800
 
                        # Perl 6 operator keywords
801
 
                        qw{div x xx mod also leg cmp before after eq ne le lt
802
 
                                gt ge eqv ff fff and andthen Z X or xor
803
 
                                orelse extra m mm rx s tr},
804
 
                ],
805
 
        ],
806
 
        
807
 
        # 8 different keyword lists for povray
808
 
        'text/x-povray' => [
809
 
                # structure keyword1 == SCE_POV_DIRECTIVE
810
 
                [qw( declare local undef default macro if else while end
811
 
                include version debug error warning switch case range break
812
 
                ifdef indef  fopen fclose read write render statistics )],
813
 
                
814
 
                # objects  SCE_POV_WORD2
815
 
                [
816
 
                qw(blob  box bicubic_patch object light_source 
817
 
                camera  cylinder cubic global_settings height_field
818
 
                isosurface julia_fractal sor sphere sphere_sweep superellipsoid
819
 
                torus triangle quadric quartic sky_sphere plane poly polygon ),
820
 
                
821
 
                qw(
822
 
                looks_like bounded_by contained_by clipped_by
823
 
                ),
824
 
                qw(
825
 
                union intersection difference
826
 
                )
827
 
                ],
828
 
                
829
 
                # patterns  SCE_POV_WORD3
830
 
                [qw( agate bozo checker cells bumps brick facets dents crackle
831
 
                hexagon gradient granite  spotted spiral1 ripples marble
832
 
                leopard spiral2 wrinkles)],
833
 
                        
834
 
                # transforms  SCE_POV_WORD4
835
 
                [qw( translate rotate scale transform matrix point_at look_at )],
836
 
                
837
 
                # modifiers - SCE_POV_WORD5
838
 
                [qw( 
839
 
                
840
 
                )],
841
 
                
842
 
                ## float functions - SCE_POV_WORD6
843
 
                [qw(
844
 
                abs acos acosh asc asin asinh atan atanh atan2 ceil cos cosh defined 
845
 
                degrees dimensions dimension_size div exp file_exists floor int inside 
846
 
                ln log max min mod pow radians rand seed select sin sinh sqrt strcmp strlen 
847
 
                tan tanh val vdot vlength ), 
848
 
                ## vector functions
849
 
                qw( min_extent max_extent trace vaxis_rotate vcross vrotate 
850
 
                vnormalize vturbulence ),
851
 
                ## string functions
852
 
                qw( chr concat str strlwr strupr substr vstr )
853
 
                ],
854
 
                
855
 
                ## reserved identifiers SCE_POV_WORD7
856
 
                [qw(
857
 
                x y z red green blue alpha filter rgb rgbf rgba rgbfa u v
858
 
                )],
859
 
        ],
860
 
 
861
 
);
862
 
$SCINTILLA_KEY_WORDS{'text/x-c++src'} = $SCINTILLA_KEY_WORDS{'text/x-c'};
863
 
$SCINTILLA_KEY_WORDS{'text/x-perlxs'} = $SCINTILLA_KEY_WORDS{'text/x-c'};
864
 
 
865
 
 
866
192
 
867
193
 
868
194
 
925
251
        },
926
252
};
927
253
 
928
 
=pod
929
 
 
930
 
=head2 C<new>
 
254
=head2 new
931
255
 
932
256
  my $doc = Padre::Document->new(
933
257
      filename => $file,
972
296
 
973
297
                        # Test script must be able to pass an alternate config object
974
298
                        # NOTE: Since when do we support per-document configuration objects?
975
 
                        my $config = $self->{config} || $self->current->config;
 
299
                        my $config = $self->{config} || $self->config;
976
300
                        if ( defined( $self->{file}->size ) and ( $self->{file}->size > $config->editor_file_size_limit ) ) {
977
301
                                my $ret = Wx::MessageBox(
978
302
                                        sprintf(
1030
354
        # to the the base class,
1031
355
        # This isn't exactly the most elegant way to do this, but will
1032
356
        # do for a first implementation.
1033
 
        my $mime_type = $self->mimetype or return;
1034
 
        my $class = Padre::MimeTypes->get_mime_class($mime_type) || __PACKAGE__;
1035
 
        TRACE("Reblessing to mimetype: '$class'") if DEBUG;
 
357
        my $class = $self->mime->document;
 
358
        TRACE("Reblessing to mimetype class: '$class'") if DEBUG;
1036
359
        if ($class) {
1037
360
                unless ( $class->VERSION ) {
1038
361
                        eval "require $class;";
1041
364
                bless $self, $class;
1042
365
        }
1043
366
 
1044
 
        my $module   = Padre::MimeTypes->get_current_highlighter_of_mime_type($mime_type);
1045
 
        my $filename = '';                                                                # Not undef
1046
 
        $filename = $self->{file}->filename
1047
 
                if defined( $self->{file} )
1048
 
                        and defined( $self->{file}->{filename} );
1049
 
        if ( not $module ) {
1050
 
                $self->current->main->error(
1051
 
                        sprintf(
1052
 
                                Wx::gettext("No module mime_type='%s' filename='%s'"),
1053
 
                                $mime_type, $filename
1054
 
                        )
1055
 
                );
1056
 
        }
1057
 
        $self->set_highlighter($module);
 
367
        require Padre::Wx::Scintilla;
 
368
        $self->set_highlighter(
 
369
                Padre::Wx::Scintilla->highlighter($self)
 
370
        );
1058
371
 
1059
372
        return;
1060
373
}
1063
376
        Padre::Current->new( document => $_[0] );
1064
377
}
1065
378
 
 
379
sub config {
 
380
        $_[0]->{config} or $_[0]->current->config
 
381
}
 
382
 
 
383
sub mime {
 
384
        Padre::MIME->find($_[0]->mimetype);
 
385
}
 
386
 
1066
387
# Abstract methods, each subclass should implement it
1067
388
# TO DO: Clearly this isn't ACTUALLY abstract (since they exist)
1068
389
 
1071
392
}
1072
393
 
1073
394
sub scintilla_key_words {
1074
 
        my $self = shift;
1075
 
        my $mime = $self->mimetype or return [];
1076
 
        $SCINTILLA_KEY_WORDS{$mime} or return [];
 
395
        require Padre::Wx::Scintilla;
 
396
        Padre::Wx::Scintilla->keywords( $_[0]->mimetype );
1077
397
}
1078
398
 
1079
399
sub get_calltip_keywords {
1123
443
 
1124
444
sub colourize {
1125
445
        my $self   = shift;
1126
 
        my $lexer  = $self->lexer;
1127
446
        my $editor = $self->editor;
 
447
        require Padre::Wx::Scintilla;
 
448
        my $lexer  = Padre::Wx::Scintilla->lexer( $self->mimetype );
1128
449
        $editor->SetLexer($lexer);
1129
450
        TRACE("colourize called") if DEBUG;
1130
451
 
1131
452
        $editor->remove_color;
1132
 
        if ( $lexer == Wx::Scintilla::SCLEX_CONTAINER ) {
 
453
        if ( $lexer == Wx::Scintilla::Constant::SCLEX_CONTAINER ) {
1133
454
                $self->colorize;
1134
455
        } else {
1135
456
                TRACE("Colourize is being called") if DEBUG;
1139
460
}
1140
461
 
1141
462
sub colorize {
1142
 
        my $self = shift;
1143
 
        TRACE("colorize called") if DEBUG;
1144
 
 
 
463
        my $self   = shift;
1145
464
        my $module = $self->highlighter;
1146
 
        TRACE("module: '$module'") if DEBUG;
1147
 
        if ( $module eq 'stc' ) {
1148
 
 
1149
 
                #TO DO sometime this happens when I open Padre with several file
 
465
        unless ( $module ) {
 
466
                # TO DO sometime this happens when I open Padre with several file
1150
467
                # I think this can be somehow related to the quick (or slow ?) switching of
1151
468
                # what is the current document while the code is still running.
1152
469
                # for now I hide the warnings as this would just frighten people and the
1161
478
        unless ( $module->can('colorize') ) {
1162
479
                eval "use $module";
1163
480
                if ($@) {
1164
 
                        Carp::cluck( "Could not load module '$module' for file '" . ( $self->{file}->filename || '' ) . "'\n" );
 
481
                        my $name = $self->{file} ? $self->{file}->filename : $self->get_title;
 
482
                        Carp::cluck( "Could not load module '$module' for file '$name'\n" );
1165
483
                        return;
1166
484
                }
1167
485
        }
1184
502
                return Padre::Constant::NEWLINE;
1185
503
        }
1186
504
 
1187
 
        $self->current->config->default_line_ending;
 
505
        $self->config->default_line_ending;
1188
506
}
1189
507
 
1190
 
=pod
1191
 
 
1192
 
=head2 C<error>
 
508
=head2 error
1193
509
 
1194
510
    $document->error( $msg );
1195
511
 
1301
617
        return $file->mtime;
1302
618
}
1303
619
 
1304
 
=pod
1305
 
 
1306
 
=head2 C<load_file>
1307
 
 
1308
 
 $doc->load_file;
 
620
=head2 load_file
 
621
 
 
622
    $doc->load_file;
1309
623
 
1310
624
Loads the current file.
1311
625
 
1352
666
 
1353
667
        # if guess encoding fails then use 'utf-8'
1354
668
        require Padre::Locale;
 
669
        require Encode;
1355
670
        $self->{encoding} = Padre::Locale::encoding_from_string($content);
1356
 
 
1357
 
        #warn $self->{encoding};
1358
 
        require Encode;
1359
671
        $content = Encode::decode( $self->{encoding}, $content );
1360
672
 
1361
673
        # Determine new line type using file content.
1369
681
        return 1;
1370
682
}
1371
683
 
1372
 
# New line type can be one of these values:
 
684
# New line type acan be one of these values:
1373
685
# WIN, MAC (for classic Mac) or UNIX (for Mac OS X and Linux/*BSD)
1374
686
# Special cases:
1375
687
# 'Mixed' for mixed end of lines,
1391
703
        return "\n";
1392
704
}
1393
705
 
1394
 
=pod
1395
 
 
1396
 
=head2 C<autocomplete_matching_char>
 
706
=head2 autocomplete_matching_char
1397
707
 
1398
708
The first argument needs to be a reference to the editor this method should
1399
709
work on.
1577
887
        return 1;
1578
888
}
1579
889
 
1580
 
=pod
1581
 
 
1582
 
=head2 C<write>
 
890
=head2 write
1583
891
 
1584
892
Writes the document to an arbitrary local file using the same semantics
1585
893
as when we do a full file save.
1609
917
        $file->write( $text, $encoding );
1610
918
}
1611
919
 
1612
 
=pod
1613
 
 
1614
 
=head2 C<reload>
 
920
=head2 reload
1615
921
 
1616
922
Reload the current file discarding changes in the editor.
1617
923
 
1661
967
#####################################################################
1662
968
# Basic Content Manipulation
1663
969
 
 
970
=head2 text_get
 
971
 
 
972
  my $string = $document->text_get;
 
973
 
 
974
The C<text_get> method returns the content of the document as a simple
 
975
plain scalar string.
 
976
 
 
977
=cut
 
978
 
1664
979
sub text_get {
1665
980
        $_[0]->editor->GetText;
1666
981
}
1667
982
 
 
983
=head2 text_length
 
984
 
 
985
  my $chars = $document->GetLength;
 
986
 
 
987
The C<text_length> method returns the size of the document in characters.
 
988
 
 
989
Note that this is the character length of the document and not the byte
 
990
size of the document. The byte size of the file when saved is likely to
 
991
differ from the character size.
 
992
 
 
993
=cut
 
994
 
1668
995
sub text_length {
1669
996
        $_[0]->editor->GetLength;
1670
997
}
1671
998
 
1672
 
sub text_set {
1673
 
        $_[0]->editor->SetText( $_[1] );
1674
 
}
 
999
=head2 text_like
 
1000
 
 
1001
  my $cool = $document->text_like( qr/(?:robot|ninja|pirate)/i );
 
1002
 
 
1003
The C<text_like> method takes a regular expression and tests the document
 
1004
to see if it matches.
 
1005
 
 
1006
Returns true if the document matches the regular express, or false if not.
 
1007
 
 
1008
=cut
1675
1009
 
1676
1010
sub text_like {
1677
1011
        my $self = shift;
1691
1025
        return $text;
1692
1026
}
1693
1027
 
 
1028
=head2 text_set
 
1029
 
 
1030
  $document->text_set("This is an\nentirely new document");
 
1031
 
 
1032
The C<text_set> method takes a content string and does a complete atomic
 
1033
replacement of the document with new and entirely different content.
 
1034
 
 
1035
It uses a simple and direct approach which is fast but is not aware of
 
1036
context such as the current cursor position and the undo buffer.
 
1037
 
 
1038
As a result, it is only appropriate for use when a document is being
 
1039
changed for new content that is completely and utterly different.
 
1040
 
 
1041
To change a document to a new version that is similar to the old one
 
1042
(such as when you are doing refactoring tasks) the alternative
 
1043
L</text_replace> or ideally L</text_delta> should be used instead.
 
1044
 
 
1045
=cut
 
1046
 
 
1047
sub text_set {
 
1048
        my $self   = shift;
 
1049
        my $editor = $self->editor or return;
 
1050
        $editor->SetText(shift);
 
1051
        $editor->refresh_notebook;
 
1052
        return 1;
 
1053
}
 
1054
 
 
1055
=head2 text_replace
 
1056
 
 
1057
  $document->text_replace("This is a\nmodified document");
 
1058
 
 
1059
The C<text_replace> method takes content as a string and incrementally
 
1060
modifies the current document to look like the new content.
 
1061
 
 
1062
The logic for this process is done with a L<Padre::Delta> object created
 
1063
using L<Algorithm::Diff> and is run in the foreground. Because this blocks
 
1064
the entire IDE it is considered relatively slow and expensive, and is
 
1065
particularly bad for large documents.
 
1066
 
 
1067
But because it is by the most simple way of applying changes to a document
 
1068
and does not require locks or background tasks, this method has a role to
 
1069
play in early implementations of new logic.
 
1070
 
 
1071
Once functionality using C<text_replace> has matured, you should consider
 
1072
moving it into a background task which emits a L<Padre::Delta> and then
 
1073
use C<text_delta> to apply the change to the editor in the foreground.
 
1074
 
 
1075
Returns true if changes were made to the current document, or false if the
 
1076
new document is identical to the existing one and no change was needed.
 
1077
 
 
1078
=cut
 
1079
 
1694
1080
sub text_replace {
1695
1081
        my $self = shift;
1696
1082
        my $to   = shift;
1697
1083
        my $from = $self->text_get;
 
1084
        return 0 if $to eq $from;
1698
1085
 
1699
1086
        # Generate a delta and apply it
1700
1087
        require Padre::Delta;
1701
 
 
1702
 
        #TODO Please implement the text_patch method or remove
1703
 
        #$self->text_patch(
1704
 
        #       Padre::Delta->from_scalars( \$from, \$to )
1705
 
        #);
 
1088
        my $delta = Padre::Delta->from_scalars( \$from => \$to );
 
1089
        return $self->text_delta($delta);
1706
1090
}
1707
1091
 
 
1092
=head2 text_delta
 
1093
 
 
1094
The C<text_delta> method takes a single L<Padre::Delta> object as a
 
1095
parameter and applies it to the current document.
 
1096
 
 
1097
Returns true if the document was changed, false if passed the null delta
 
1098
and no changes were needed, or C<undef> if not passed a L<Padre::Delta>.
 
1099
 
 
1100
=cut
 
1101
 
1708
1102
sub text_delta {
1709
 
        my $self = shift;
 
1103
        my $self  = shift;
1710
1104
        my $delta = Params::Util::_INSTANCE( shift, 'Padre::Delta' ) or return;
1711
 
        $delta->apply( $self->editor );
 
1105
        return 0 if $delta->null;
 
1106
 
 
1107
        my $editor = $self->editor;
 
1108
        $delta->to_editor($editor);
 
1109
        $editor->refresh_notebook;
 
1110
        return 1;
1712
1111
}
1713
1112
 
1714
1113
 
1718
1117
#####################################################################
1719
1118
# GUI Integration Methods
1720
1119
 
1721
 
# Determine the Scintilla lexer to use
1722
 
sub lexer {
1723
 
        my $self = shift;
1724
 
 
1725
 
        # this should never happen as now we set mime-type on everything
1726
 
        return Wx::Scintilla::SCLEX_AUTOMATIC unless $self->mimetype;
1727
 
 
1728
 
        my $highlighter = $self->highlighter;
1729
 
        if ( not $highlighter ) {
1730
 
                $self->current->main->error(
1731
 
                        sprintf(
1732
 
                                Wx::gettext("no highlighter for mime-type '%s' using stc"),
1733
 
                                $self->mimetype
1734
 
                        )
1735
 
                );
1736
 
                $highlighter = 'stc';
1737
 
        }
1738
 
        TRACE("The highlighter is '$highlighter'") if DEBUG;
1739
 
        return Wx::Scintilla::SCLEX_CONTAINER if $highlighter ne 'stc';
1740
 
        return Wx::Scintilla::SCLEX_AUTOMATIC unless defined Padre::MimeTypes->get_lexer( $self->mimetype );
1741
 
 
1742
 
        TRACE( 'STC Lexer will be based on mime type "' . $self->mimetype . '"' ) if DEBUG;
1743
 
        return Padre::MimeTypes->get_lexer( $self->mimetype );
1744
 
}
1745
 
 
1746
1120
# What should be shown in the notebook tab
1747
1121
sub get_title {
1748
1122
        my $self = shift;
1764
1138
# TO DO: experimental
1765
1139
sub get_indentation_style {
1766
1140
        my $self   = shift;
1767
 
        my $config = $self->current->config;
 
1141
        my $config = $self->config;
1768
1142
 
1769
1143
        # TO DO: (document >) project > config
1770
1144
 
1784
1158
        return $style;
1785
1159
}
1786
1160
 
1787
 
=head2 C<get_indentation_level_string>
 
1161
=head2 get_indentation_level_string
1788
1162
 
1789
1163
Calculates the string that should be used to indent a given
1790
1164
number of levels for this document.
1822
1196
        return $indent;
1823
1197
}
1824
1198
 
1825
 
=head2 C<event_on_char>
 
1199
=head2 event_on_char
1826
1200
 
1827
1201
NOT IMPLEMENTED IN THE BASE CLASS
1828
1202
 
1838
1212
 
1839
1213
Cf. C<Padre::Document::Perl> for an example.
1840
1214
 
1841
 
=head2 C<event_on_context_menu>
 
1215
=head2 event_on_context_menu
1842
1216
 
1843
1217
NOT IMPLEMENTED IN THE BASE CLASS
1844
1218
 
1854
1228
 
1855
1229
Returns nothing.
1856
1230
 
1857
 
=head2 C<event_on_left_up>
 
1231
=head2 event_on_left_up
1858
1232
 
1859
1233
NOT IMPLEMENTED IN THE BASE CLASS
1860
1234
 
1934
1308
# Maybe we need to remove this sub.
1935
1309
sub guess_mimetype {
1936
1310
        my $self = shift;
1937
 
        Padre::MimeTypes->guess_mimetype(
1938
 
                $self->{original_content},
1939
 
                $self->file,
 
1311
        Padre::MIME->detect(
 
1312
                text  => $self->{original_content},
 
1313
                file  => $self->file,
 
1314
                perl6 => $self->config->lang_perl6_auto_detection,
1940
1315
        );
1941
1316
}
1942
1317
 
1943
 
=head2 C<guess_indentation_style>
 
1318
=head2 guess_indentation_style
1944
1319
 
1945
1320
Automatically infer the indentation style of the document using
1946
1321
L<Text::FindIndent>.
1969
1344
        }
1970
1345
 
1971
1346
        my $style;
1972
 
        my $config = $self->current->config;
 
1347
        my $config = $self->config;
1973
1348
        if ( $indentation =~ /^t\d+/ ) { # we only do ONE tab
1974
1349
                $style = {
1975
1350
                        use_tabs    => 1,
2001
1376
        return $style;
2002
1377
}
2003
1378
 
2004
 
=head2 C<guess_filename>
 
1379
=head2 guess_filename
2005
1380
 
2006
1381
  my $name = $document->guess_filename
2007
1382
 
2031
1406
        return undef;
2032
1407
}
2033
1408
 
2034
 
=head2 C<guess_subpath>
 
1409
=head2 guess_subpath
2035
1410
 
2036
1411
  my $subpath = $document->guess_subpath;
2037
1412
 
2125
1500
#####################################################################
2126
1501
# Document Manipulation Methods
2127
1502
 
 
1503
# Apply an arbitrary transform
 
1504
sub transform {
 
1505
        my $self   = shift;
 
1506
        my %args   = @_;
 
1507
        my $driver = Params::Util::_DRIVER( delete $args{class}, 'Padre::Transform' ) or return;
 
1508
        my $editor = $self->editor;
 
1509
        my $input  = $editor->GetText;
 
1510
        my $delta  = $driver->new(%args)->scalar_delta(\$input);
 
1511
        $delta->to_editor($editor);
 
1512
        return 1;
 
1513
}
 
1514
 
2128
1515
# Delete all leading spaces.
2129
1516
# Passes through to the editor by default, and is only defined in the
2130
1517
# document class so that document classes can overload and do special stuff.
2216
1603
 
2217
1604
1;
2218
1605
 
2219
 
# Copyright 2008-2011 The Padre development team as listed in Padre.pm.
 
1606
# Copyright 2008-2012 The Padre development team as listed in Padre.pm.
2220
1607
# LICENSE
2221
1608
# This program is free software; you can redistribute it and/or
2222
1609
# modify it under the same terms as Perl 5 itself.