root/trunk/Padre/lib/Padre/Config.pm

Revision 12407, 32.1 KB (checked in by adamk, 3 days ago)
  • The startup splash is now disabled by default. Padre starts up very quickly these days, and delaying image loading should reduce the per-thread memory cost more (ADAMK)
Line 
1package Padre::Config;
2
3# Configuration subsystem for Padre
4
5# To help force the break from the first-generation HASH based configuration
6# over to the second-generation method based configuration, initially we
7# will use an ARRAY-based object, so that all existing code is forcefully
8# broken.
9
10use 5.008;
11use strict;
12use warnings;
13use Carp                   ();
14use YAML::Tiny             ();
15use Params::Util           ();
16use Padre::Constant        ();
17use Padre::Util            ('_T');
18use Padre::Current         ();
19use Padre::Config::Setting ();
20use Padre::Config::Human   ();
21use Padre::Config::Project ();
22use Padre::Config::Host    ();
23use Padre::Config::Upgrade ();
24use Padre::Logger;
25
26our $VERSION = '0.69';
27
28our ( %SETTING, %DEFAULT, %STARTUP, $REVISION, $SINGLETON );
29
30BEGIN {
31
32        # Master storage of the settings
33        %SETTING = ();
34
35        # A cache for the defaults
36        %DEFAULT = ();
37
38        # A cache for startup.yml settings
39        %STARTUP = ();
40
41        # The configuration revision.
42        # (Functionally similar to the database revision)
43        $REVISION = 1;
44
45        # Storage for the default config object
46        $SINGLETON = undef;
47}
48
49# Accessor generation
50use Class::XSAccessor::Array {
51        getters => {
52                host    => Padre::Constant::HOST,
53                human   => Padre::Constant::HUMAN,
54                project => Padre::Constant::PROJECT,
55        }
56};
57
58
59
60
61
62#####################################################################
63# Settings Specification
64
65# This section identifies the set of all named configuration entries,
66# and where the configuration system should resolve them to.
67
68sub settings {
69        sort keys %SETTING;
70}
71
72#
73# setting( %params );
74#
75# create a new setting, with %params used to feed the new object.
76#
77sub setting {
78
79        # Allow this sub to be called as a method or function
80        shift if ref( $_[0] ) eq __PACKAGE__;
81
82        # Validate the setting
83        my $object = Padre::Config::Setting->new(@_);
84        my $name   = $object->{name};
85        if ( $SETTING{$name} ) {
86                Carp::croak("The $name setting is already defined");
87        }
88
89        # Generate the accessor
90        eval $object->code;
91        Carp::croak("Failed to compile setting $object->{name}: $@") if $@;
92
93        # Save the setting
94        $SETTING{$name} = $object;
95        $DEFAULT{$name} = $object->{default};
96        $STARTUP{$name} = 1 if $object->{startup};
97
98        return 1;
99}
100
101
102
103
104
105#####################################################################
106# Constructor and Input/Output
107
108sub new {
109        my $class = shift;
110        my $host  = shift;
111        my $human = shift;
112        unless ( Params::Util::_INSTANCE( $host, 'Padre::Config::Host' ) ) {
113                Carp::croak("Did not provide a host config to Padre::Config->new");
114        }
115        unless ( Params::Util::_INSTANCE( $human, 'Padre::Config::Human' ) ) {
116                Carp::croak("Did not provide a user config to Padre::Config->new");
117        }
118
119        # Create the basic object with the two required elements
120        my $self = bless [ $host, $human, undef ], $class;
121
122        # Add the optional third element
123        if (@_) {
124                my $project = shift;
125                unless ( Params::Util::_INSTANCE( $project, 'Padre::Config::Project' ) ) {
126                        Carp::croak("Did not provide a project config to Padre::Config->new");
127                }
128                $self->[Padre::Constant::PROJECT] = $project;
129        }
130
131        return $self;
132}
133
134sub read {
135        my $class = shift;
136
137        unless ($SINGLETON) {
138                TRACE("Loading configuration for $class") if DEBUG;
139
140                # Load the host configuration
141                my $host = Padre::Config::Host->read;
142
143                # Load the user configuration
144                my $human = Padre::Config::Human->read
145                        || Padre::Config::Human->create;
146
147                # Hand off to the constructor
148                $SINGLETON = $class->new( $host, $human );
149
150                Padre::Config::Upgrade::check($SINGLETON);
151        }
152
153        return $SINGLETON;
154}
155
156sub write {
157        TRACE( $_[0] ) if DEBUG;
158        my $self = shift;
159
160        # Save the user configuration
161        $self->[Padre::Constant::HUMAN]->{version} = $REVISION;
162        $self->[Padre::Constant::HUMAN]->write;
163
164        # Save the host configuration
165        $self->[Padre::Constant::HOST]->{version} = $REVISION;
166        $self->[Padre::Constant::HOST]->write;
167
168        # Write the startup subset of the configuration.
169        # NOTE: Use a hyper-minimalist listified key/value file format
170        # so that we don't need to load YAML::Tiny before the thread fork.
171        # This should save around 400k of memory per background thread.
172        my %startup = map { $_ => $self->$_() } sort keys %STARTUP;
173        open( my $FILE, '>', Padre::Constant::CONFIG_STARTUP ) or return 1;
174        print $FILE map {"$_\n$startup{$_}\n"} sort keys %startup or return 1;
175        close $FILE or return 1;
176
177        return 1;
178}
179
180
181
182
183
184######################################################################
185# Main Methods
186
187# Fetches an explicitly named default
188sub default {
189        my $self = shift;
190        my $name = shift;
191
192        # Does the setting exist?
193        unless ( $SETTING{$name} ) {
194                Carp::croak("The configuration setting '$name' does not exist");
195        }
196
197        return $DEFAULT{$name};
198}
199
200sub set {
201        TRACE( $_[1] ) if DEBUG;
202        my $self  = shift;
203        my $name  = shift;
204        my $value = shift;
205
206        # Does the setting exist?
207        my $setting = $SETTING{$name};
208        unless ($setting) {
209                Carp::croak("The configuration setting '$name' does not exist");
210        }
211
212        # All types are Padre::Constant::ASCII-like
213        unless ( defined $value and not ref $value ) {
214                Carp::croak("Missing or non-scalar value for setting '$name'");
215        }
216
217        # We don't need to do additional checks on Padre::Constant::ASCII
218        my $type = $setting->type;
219        if ( $type == Padre::Constant::BOOLEAN ) {
220                $value = 0 if $value eq '';
221                if ( $value ne '1' and $value ne '0' ) {
222                        Carp::croak("Tried to change setting '$name' to non-boolean '$value'");
223                }
224        }
225        if ( $type == Padre::Constant::POSINT and not Params::Util::_POSINT($value) ) {
226                Carp::croak("Tried to change setting '$name' to non-posint '$value'");
227        }
228        if ( $type == Padre::Constant::INTEGER and not _INTEGER($value) ) {
229                Carp::croak("Tried to change setting '$name' to non-integer '$value'");
230        }
231        if ( $type == Padre::Constant::PATH ) {
232                if ( Padre::Constant::WIN32 and utf8::is_utf8($value) ) {
233                        require Win32;
234                        $value = Win32::GetLongPathName($value);
235
236                        #Wx::DirPickerCtrl upgrades data to utf8.
237                        #Perl on Windows cannot handle utf8 in file names, so this hack converts
238                        #path back
239                }
240                if ( not -e $value ) {
241                        Carp::croak("Tried to change setting '$name' to non-existant path '$value'");
242                }
243        }
244
245        # Set the value into the appropriate backend
246        my $store = $SETTING{$name}->store;
247        $self->[$store]->{$name} = $value;
248
249        return 1;
250}
251
252# Set a value in the configuration and apply the preference change
253# to the application.
254sub apply {
255        TRACE( $_[0] ) if DEBUG;
256        my $self    = shift;
257        my $name    = shift;
258        my $value   = shift;
259        my $current = Padre::Current::_CURRENT(@_);
260
261        # Set the config value
262        $self->set( $name => $value );
263
264        # Does this setting have an apply hook
265        my $code = $SETTING{$name}->apply;
266        if ($code) {
267                $code->( $current->main, $value );
268        }
269
270        return 1;
271}
272
273sub meta {
274        $SETTING{ $_[1] } or die("Missing or invalid setting name '$_[1]'");
275}
276
277
278
279
280
281######################################################################
282# Support Functions
283
284#
285# my $is_integer = _INTEGER( $scalar );
286#
287# return true if $scalar is an integer.
288#
289sub _INTEGER {
290        return defined $_[0] && !ref $_[0] && $_[0] =~ m/^(?:0|-?[1-9]\d*)$/;
291}
292
293
294
295
296
297######################################################################
298# Basic Settings
299
300# User identity (simplistic initial version)
301# Initially, this must be ascii only
302setting(
303        name    => 'identity_name',
304        type    => Padre::Constant::ASCII,
305        store   => Padre::Constant::HUMAN,
306        default => '',
307);
308setting(
309        name    => 'identity_email',
310        type    => Padre::Constant::ASCII,
311        store   => Padre::Constant::HUMAN,
312        default => '',
313);
314setting(
315        name    => 'identity_nickname',
316        type    => Padre::Constant::ASCII,
317        store   => Padre::Constant::HUMAN,
318        default => '',
319);
320
321# Support for Module::Starter
322setting(
323        name    => 'license',
324        type    => Padre::Constant::ASCII,
325        store   => Padre::Constant::HUMAN,
326        default => '',
327);
328setting(
329        name    => 'builder',
330        type    => Padre::Constant::ASCII,
331        store   => Padre::Constant::HUMAN,
332        default => '',
333);
334setting(
335        name    => 'module_start_directory',
336        type    => Padre::Constant::ASCII,
337        store   => Padre::Constant::HUMAN,
338        default => '',
339);
340
341# Indent settings
342# Allow projects to forcefully override personal settings
343setting(
344        name    => 'editor_indent_auto',
345        type    => Padre::Constant::BOOLEAN,
346        store   => Padre::Constant::HUMAN,
347        default => 1,
348        project => 1,
349);
350setting(
351        name    => 'editor_indent_tab',
352        type    => Padre::Constant::BOOLEAN,
353        store   => Padre::Constant::HUMAN,
354        default => 1,
355        project => 1,
356);
357setting(
358        name    => 'editor_indent_tab_width',
359        type    => Padre::Constant::POSINT,
360        store   => Padre::Constant::HUMAN,
361        default => 8,
362        project => 1,
363);
364setting(
365        name    => 'editor_indent_width',
366        type    => Padre::Constant::POSINT,
367        store   => Padre::Constant::HUMAN,
368        default => 8,
369        project => 1,
370);
371
372
373
374
375
376#####################################################################
377# Startup Behaviour Rules
378
379setting(
380        name    => 'startup_splash',
381        type    => Padre::Constant::BOOLEAN,
382        store   => Padre::Constant::HUMAN,
383        default => 0,
384        startup => 1,
385);
386
387# Startup mode, if no files given on the command line this can be
388#   new        - a new empty buffer
389#   nothing    - nothing to open
390#   last       - the files that were open last time
391setting(
392        name    => 'startup_files',
393        type    => Padre::Constant::ASCII,
394        store   => Padre::Constant::HUMAN,
395        default => 'new',
396        options => {
397                'last'    => _T('Previous open files'),
398                'new'     => _T('A new empty file'),
399                'nothing' => _T('No open files'),
400                'session' => _T('Open session'),
401        },
402);
403
404# How many times has the user run Padre?
405# Default is 1 and the value is incremented at shutdown rather than
406# startup so that we don't have to write files in the startup sequence.
407setting(
408        name    => 'startup_count',
409        type    => Padre::Constant::POSINT,
410        store   => Padre::Constant::HUMAN,
411        default => 1,
412);
413
414
415
416
417
418######################################################################
419# Main Window Tools and Layout
420
421# Window
422setting(
423        name    => 'main_title',
424        type    => Padre::Constant::ASCII,
425        store   => Padre::Constant::HUMAN,
426        default => 'Padre [%p]',
427);
428
429setting(
430        name    => 'main_singleinstance',
431        type    => Padre::Constant::BOOLEAN,
432        store   => Padre::Constant::HUMAN,
433        default => Padre::Constant::DEFAULT_SINGLEINSTANCE,
434        startup => 1,
435        apply   => sub {
436                my $main  = shift;
437                my $value = shift;
438                if ($value) {
439                        $main->single_instance_start;
440                } else {
441                        $main->single_instance_stop;
442                }
443                return 1;
444        },
445);
446
447setting(
448        name    => 'main_singleinstance_port',
449        type    => Padre::Constant::POSINT,
450        store   => Padre::Constant::HOST,
451        default => Padre::Constant::DEFAULT_SINGLEINSTANCE_PORT,
452        startup => 1,
453);
454
455setting(
456        name    => 'main_lockinterface',
457        type    => Padre::Constant::BOOLEAN,
458        store   => Padre::Constant::HUMAN,
459        default => 1,
460        apply   => sub {
461                my $main  = shift;
462                my $value = shift;
463
464                # Update the lock status
465                $main->aui->lock_panels($value);
466
467                # The toolbar can't dynamically switch between
468                # tearable and non-tearable so rebuild it.
469                # TO DO: Review this assumption
470
471                # (Ticket #668)
472
473                if ($Padre::Wx::Toolbar::DOCKABLE) {
474                        $main->rebuild_toolbar;
475                }
476
477                return 1;
478        }
479);
480setting(
481        name    => 'main_functions',
482        type    => Padre::Constant::BOOLEAN,
483        store   => Padre::Constant::HUMAN,
484        default => 0,
485);
486setting(
487        name    => 'main_functions_order',
488        type    => Padre::Constant::ASCII,
489        store   => Padre::Constant::HUMAN,
490        default => 'alphabetical',
491        options => {
492                'original'                  => _T('Code Order'),
493                'alphabetical'              => _T('Alphabetical Order'),
494                'alphabetical_private_last' => _T('Alphabetical Order (Private Last)'),
495        },
496);
497setting(
498        name    => 'main_outline',
499        type    => Padre::Constant::BOOLEAN,
500        store   => Padre::Constant::HUMAN,
501        default => 0,
502);
503setting(
504        name    => 'main_todo',
505        type    => Padre::Constant::BOOLEAN,
506        store   => Padre::Constant::HUMAN,
507        default => 0,
508);
509setting(
510        name    => 'main_directory',
511        type    => Padre::Constant::BOOLEAN,
512        store   => Padre::Constant::HUMAN,
513        default => 0,
514);
515setting(
516        name    => 'main_directory_order',
517        type    => Padre::Constant::ASCII,
518        store   => Padre::Constant::HUMAN,
519        default => 'first',
520        options => {
521                first => _T('Directories First'),
522                mixed => _T('Directories Mixed'),
523        },
524);
525setting(
526        name    => 'main_directory_panel',
527        type    => Padre::Constant::ASCII,
528        store   => Padre::Constant::HUMAN,
529        default => 'left',
530        options => {
531                'left'  => _T('Project Tools (Left)'),
532                'right' => _T('Document Tools (Right)'),
533        },
534        apply => sub {
535                my $main  = shift;
536                my $value = shift;
537
538                # Is it visible and on the wrong side?
539                return 1 unless $main->has_directory;
540                my $directory = $main->directory;
541                return 1 unless $directory->IsShown;
542                return 1 unless $directory->side ne $value;
543
544                # Hide and reshow the tool with the new setting
545                $directory->panel->hide($directory);
546                $main->directory_panel->show($directory);
547                $main->Layout;
548                $main->Update;
549
550                return 1;
551        }
552);
553setting(
554        name  => 'main_directory_root',
555        type  => Padre::Constant::ASCII,
556        store => Padre::Constant::HOST,
557        default => File::HomeDir->my_documents || '',
558);
559setting(
560        name    => 'main_output',
561        type    => Padre::Constant::BOOLEAN,
562        store   => Padre::Constant::HUMAN,
563        default => 0,
564);
565setting(
566        name    => 'main_command_line',
567        type    => Padre::Constant::BOOLEAN,
568        store   => Padre::Constant::HUMAN,
569        default => 0,
570);
571setting(
572        name    => 'main_output_ansi',
573        type    => Padre::Constant::BOOLEAN,
574        store   => Padre::Constant::HUMAN,
575        default => 1,
576);
577setting(
578        name    => 'main_syntaxcheck',
579        type    => Padre::Constant::BOOLEAN,
580        store   => Padre::Constant::HUMAN,
581        default => 0,
582);
583setting(
584        name    => 'main_errorlist',
585        type    => Padre::Constant::BOOLEAN,
586        store   => Padre::Constant::HUMAN,
587        default => 0,
588);
589setting(
590        name    => 'main_statusbar',
591        type    => Padre::Constant::BOOLEAN,
592        store   => Padre::Constant::HUMAN,
593        default => 1,
594);
595setting(
596        name  => 'main_toolbar',
597        type  => Padre::Constant::BOOLEAN,
598        store => Padre::Constant::HUMAN,
599
600        # Toolbars are not typically used for Mac apps.
601        # Hide it by default so Padre looks "more Mac'ish"
602        # NOTE: Or at least, so we were told. Opinions apparently vary.
603        default => Padre::Constant::MAC ? 0 : 1,
604);
605setting(
606        name  => 'main_toolbar_items',
607        type  => Padre::Constant::ASCII,
608        store => Padre::Constant::HUMAN,
609
610        # This lives here until a better place is found:
611        # This is a list of toolbar items, seperated by ;
612        # The following items are supported:
613        #   action
614        #     Insert the action
615        #   action(argument,argument)
616        #     Insert an action which requires one or more arguments
617        #   |
618        #     Insert a seperator
619        default => 'file.new;'
620                . 'file.open;'
621                . 'file.save;'
622                . 'file.save_as;'
623                . 'file.save_all;'
624                . 'file.close;' . '|;'
625                . 'file.open_example;' . '|;'
626                . 'edit.undo;'
627                . 'edit.redo;' . '|;'
628                . 'edit.cut;'
629                . 'edit.copy;'
630                . 'edit.paste;'
631                . 'edit.select_all;' . '|;'
632                . 'search.find;'
633                . 'search.replace;' . '|;'
634                . 'edit.comment_toggle;' . '|;'
635                . 'file.doc_stat;' . '|;'
636                . 'search.open_resource;'
637                . 'search.quick_menu_access;' . '|;'
638                . 'run.run_document;'
639                . 'run.stop;' . '|;'
640                . 'debug.step_in;'
641                . 'debug.step_over;'
642                . 'debug.step_out;'
643                . 'debug.run;'
644                . 'debug.set_breakpoint;'
645                . 'debug.display_value;'
646                . 'debug.quit;'
647);
648
649setting(
650        name    => 'swap_ctrl_tab_alt_right',
651        type    => Padre::Constant::BOOLEAN,
652        store   => Padre::Constant::HUMAN,
653        default => 0,
654);
655
656# Directory Tree Settings
657setting(
658        name  => 'default_projects_directory',
659        type  => Padre::Constant::PATH,
660        store => Padre::Constant::HOST,
661        default => File::HomeDir->my_documents || '',
662);
663
664# Editor Settings
665setting(
666        name    => 'editor_font',
667        type    => Padre::Constant::ASCII,
668        store   => Padre::Constant::HUMAN,
669        default => '',
670);
671setting(
672        name    => 'editor_linenumbers',
673        type    => Padre::Constant::BOOLEAN,
674        store   => Padre::Constant::HUMAN,
675        default => 1,
676);
677setting(
678        name    => 'editor_eol',
679        type    => Padre::Constant::BOOLEAN,
680        store   => Padre::Constant::HUMAN,
681        default => 0,
682);
683setting(
684        name    => 'editor_whitespace',
685        type    => Padre::Constant::BOOLEAN,
686        store   => Padre::Constant::HUMAN,
687        default => 0,
688);
689setting(
690        name    => 'editor_indentationguides',
691        type    => Padre::Constant::BOOLEAN,
692        store   => Padre::Constant::HUMAN,
693        default => 0,
694);
695setting(
696        name    => 'editor_calltips',
697        type    => Padre::Constant::BOOLEAN,
698        store   => Padre::Constant::HUMAN,
699        default => 0,
700);
701setting(
702        name    => 'editor_autoindent',
703        type    => Padre::Constant::ASCII,
704        store   => Padre::Constant::HUMAN,
705        default => 'deep',
706        options => {
707                'no'   => _T('No Autoindent'),
708                'same' => _T('Indent to Same Depth'),
709                'deep' => _T('Indent Deeply'),
710        },
711);
712setting(
713        name    => 'editor_folding',
714        type    => Padre::Constant::BOOLEAN,
715        store   => Padre::Constant::HUMAN,
716        default => 0,
717);
718setting(
719        name    => 'editor_fold_pod',
720        type    => Padre::Constant::BOOLEAN,
721        store   => Padre::Constant::HUMAN,
722        default => 0,
723);
724
725setting(
726        name    => 'editor_brace_expression_highlighting',
727        type    => Padre::Constant::BOOLEAN,
728        store   => Padre::Constant::HUMAN,
729        default => 0,
730);
731
732setting(
733        name    => 'save_autoclean',
734        type    => Padre::Constant::BOOLEAN,
735        store   => Padre::Constant::HUMAN,
736        default => 0,
737);
738setting(
739        name    => 'editor_currentline',
740        type    => Padre::Constant::BOOLEAN,
741        store   => Padre::Constant::HUMAN,
742        default => 1,
743);
744setting(
745        name    => 'editor_currentline_color',
746        type    => Padre::Constant::ASCII,
747        store   => Padre::Constant::HUMAN,
748        default => 'FFFF04',
749);
750setting(
751        name    => 'editor_beginner',
752        type    => Padre::Constant::BOOLEAN,
753        store   => Padre::Constant::HUMAN,
754        default => 1,
755);
756setting(
757        name    => 'editor_wordwrap',
758        type    => Padre::Constant::BOOLEAN,
759        store   => Padre::Constant::HUMAN,
760        default => 0,
761);
762setting(
763        name    => 'editor_file_size_limit',
764        type    => Padre::Constant::POSINT,
765        store   => Padre::Constant::HUMAN,
766        default => 500_000,
767);
768setting(
769        name    => 'editor_right_margin_enable',
770        type    => Padre::Constant::BOOLEAN,
771        store   => Padre::Constant::HUMAN,
772        default => 0,
773);
774setting(
775        name    => 'editor_right_margin_column',
776        type    => Padre::Constant::POSINT,
777        store   => Padre::Constant::HUMAN,
778        default => 80,
779);
780setting(
781        name    => 'editor_smart_highlight_enable',
782        type    => Padre::Constant::BOOLEAN,
783        store   => Padre::Constant::HUMAN,
784        default => 1,
785);
786setting(
787        name  => 'editor_cursor_blink',
788        type  => Padre::Constant::INTEGER,
789        store => Padre::Constant::HUMAN,
790        default => 500, # milliseconds - this is the actual default for the wxStyledTextCtrl - set to 0 to turn off
791);
792setting(
793        name    => 'find_case',
794        type    => Padre::Constant::BOOLEAN,
795        store   => Padre::Constant::HUMAN,
796        default => 1,
797);
798setting(
799        name    => 'find_regex',
800        type    => Padre::Constant::BOOLEAN,
801        store   => Padre::Constant::HUMAN,
802        default => 0,
803);
804setting(
805        name    => 'find_reverse',
806        type    => Padre::Constant::BOOLEAN,
807        store   => Padre::Constant::HUMAN,
808        default => 0,
809);
810setting(
811        name    => 'find_first',
812        type    => Padre::Constant::BOOLEAN,
813        store   => Padre::Constant::HUMAN,
814        default => 0,
815);
816setting(
817        name    => 'find_nohidden',
818        type    => Padre::Constant::BOOLEAN,
819        store   => Padre::Constant::HUMAN,
820        default => 1,
821);
822setting(
823        name    => 'find_nomatch',
824        type    => Padre::Constant::BOOLEAN,
825        store   => Padre::Constant::HUMAN,
826        default => 0,
827);
828setting(
829        name    => 'find_quick',
830        type    => Padre::Constant::BOOLEAN,
831        store   => Padre::Constant::HUMAN,
832        default => 0,
833);
834setting(
835        name    => 'default_line_ending',
836        type    => Padre::Constant::ASCII,
837        store   => Padre::Constant::HUMAN,
838        default => Padre::Constant::NEWLINE
839);
840setting(
841        name    => 'update_file_from_disk_interval',
842        type    => Padre::Constant::ASCII,
843        store   => Padre::Constant::HUMAN,
844        default => 2,
845);
846
847# Autocomplete settings (global and Perl-specific)
848setting(
849        name    => 'autocomplete_multiclosebracket',
850        type    => Padre::Constant::BOOLEAN,
851        store   => Padre::Constant::HUMAN,
852        default => 0,
853);
854setting(
855        name    => 'autocomplete_always',
856        type    => Padre::Constant::BOOLEAN,
857        store   => Padre::Constant::HUMAN,
858        default => 0,
859);
860setting(
861        name    => 'autocomplete_method',
862        type    => Padre::Constant::BOOLEAN,
863        store   => Padre::Constant::HUMAN,
864        default => 0,
865);
866setting(
867        name    => 'autocomplete_subroutine',
868        type    => Padre::Constant::BOOLEAN,
869        store   => Padre::Constant::HUMAN,
870        default => 0,
871);
872setting(
873        name    => 'perl_autocomplete_max_suggestions',
874        type    => Padre::Constant::ASCII,
875        store   => Padre::Constant::HUMAN,
876        default => 20,
877);
878setting(
879        name    => 'perl_autocomplete_min_chars',
880        type    => Padre::Constant::ASCII,
881        store   => Padre::Constant::HUMAN,
882        default => 1,
883);
884setting(
885        name    => 'perl_autocomplete_min_suggestion_len',
886        type    => Padre::Constant::ASCII,
887        store   => Padre::Constant::HUMAN,
888        default => 3,
889);
890setting(
891        name    => 'perl_ppi_lexer_limit',
892        type    => Padre::Constant::POSINT,
893        store   => Padre::Constant::HUMAN,
894        default => 4000,
895);
896
897# Behaviour Tuning
898# When running a script from the application some of the files might have
899# not been saved yet. There are several option what to do before running the
900# script:
901# none - don't save anything (the script will be run without current modifications)
902# unsaved - as above but including modifications present in the buffer
903# same - save the file in the current buffer
904# all_files - all the files (but not buffers that have no filenames)
905# all_buffers - all the buffers even if they don't have a name yet
906setting(
907        name    => 'run_save',
908        type    => Padre::Constant::ASCII,
909        store   => Padre::Constant::HUMAN,
910        default => 'same',
911);
912setting(
913        name  => 'run_perl_cmd',
914        type  => Padre::Constant::ASCII,
915        store => Padre::Constant::HOST,
916
917        # We don't get a default from Padre::Perl, because the saved value
918        # may be outdated sometimes in the future, reading it fresh on
919        # every run makes us more future-compatible
920        default => '',
921);
922
923setting(
924        name  => 'perl_tags_file',
925        type  => Padre::Constant::ASCII,
926        store => Padre::Constant::HOST,
927
928        # Don't save a default to allow future updates
929        default => '',
930);
931
932setting(
933        name    => 'xs_calltips_perlapi_version',
934        type    => Padre::Constant::ASCII,
935        store   => Padre::Constant::PROJECT,
936        default => 'newest',
937        project => 1,
938);
939
940setting(
941        name    => 'info_on_statusbar',
942        type    => Padre::Constant::BOOLEAN,
943        store   => Padre::Constant::HUMAN,
944        default => 0,
945);
946
947# Move of stacktrace to run menu: will be removed (run_stacktrace)
948setting(
949        name    => 'run_stacktrace',
950        type    => Padre::Constant::BOOLEAN,
951        store   => Padre::Constant::HUMAN,
952        default => 0,
953);
954setting(
955        name    => 'autocomplete_brackets',
956        type    => Padre::Constant::BOOLEAN,
957        store   => Padre::Constant::HUMAN,
958        default => 0,
959);
960
961setting(
962        name    => 'mid_button_paste',
963        type    => Padre::Constant::BOOLEAN,
964        store   => Padre::Constant::HUMAN,
965        default => 0,
966);
967setting(
968        name    => 'todo_regexp',
969        type    => Padre::Constant::ASCII,
970        store   => Padre::Constant::HUMAN,
971        default => "#\\s*(?:TO[- ]?DO|XXX|FIX[- ]?ME)(?:[ \\t]*[:-]?)(?:[ \\t]*)(.*?)\\s*\$",
972);
973setting(
974        name    => 'sessionmanager_sortorder',
975        type    => Padre::Constant::ASCII,
976        store   => Padre::Constant::HUMAN,
977        default => "0,0",
978);
979
980
981# By default use background threads unless profiling
982# TO DO - Make the default actually change
983
984# (Ticket # 669)
985setting(
986        name    => 'threads',
987        type    => Padre::Constant::BOOLEAN,
988        store   => Padre::Constant::HUMAN,
989        default => 1,
990        startup => 1,
991);
992setting(
993        name    => 'locale',
994        type    => Padre::Constant::ASCII,
995        store   => Padre::Constant::HUMAN,
996        default => '',
997);
998setting(
999        name    => 'locale_perldiag',
1000        type    => Padre::Constant::ASCII,
1001        store   => Padre::Constant::HUMAN,
1002        default => '',
1003);
1004
1005# Colour Data
1006# Since it's in local files, it has to be a host-specific setting.
1007setting(
1008        name    => 'editor_style',
1009        type    => Padre::Constant::ASCII,
1010        store   => Padre::Constant::HOST,
1011        default => 'default',
1012);
1013
1014# Window Geometry
1015setting(
1016        name    => 'main_maximized',
1017        type    => Padre::Constant::BOOLEAN,
1018        store   => Padre::Constant::HOST,
1019        default => 0,
1020);
1021setting(
1022        name    => 'main_top',
1023        type    => Padre::Constant::INTEGER,
1024        store   => Padre::Constant::HOST,
1025        default => -1,
1026);
1027setting(
1028        name    => 'main_left',
1029        type    => Padre::Constant::INTEGER,
1030        store   => Padre::Constant::HOST,
1031        default => -1,
1032);
1033setting(
1034        name    => 'main_width',
1035        type    => Padre::Constant::POSINT,
1036        store   => Padre::Constant::HOST,
1037        default => -1,
1038);
1039setting(
1040        name    => 'main_height',
1041        type    => Padre::Constant::POSINT,
1042        store   => Padre::Constant::HOST,
1043        default => -1,
1044);
1045
1046# Run Parameters
1047setting(
1048        name    => 'run_interpreter_args_default',
1049        type    => Padre::Constant::ASCII,
1050        store   => Padre::Constant::HOST,
1051        default => '',
1052);
1053setting(
1054        name    => 'run_script_args_default',
1055        type    => Padre::Constant::ASCII,
1056        store   => Padre::Constant::HOST,
1057        default => '',
1058);
1059setting(
1060        name    => 'run_use_external_window',
1061        type    => Padre::Constant::BOOLEAN,
1062        store   => Padre::Constant::HOST,
1063        default => 0,
1064);
1065setting(
1066        name    => 'external_diff_tool',
1067        type    => Padre::Constant::ASCII,
1068        store   => Padre::Constant::HOST,
1069        default => '',
1070);
1071
1072# Enable/Disable entire functions that some people dislike.
1073# Normally these should be enabled by default (or should be
1074# planned to eventually be enabled by default).
1075setting(
1076        name    => 'feature_config',
1077        type    => Padre::Constant::BOOLEAN,
1078        store   => Padre::Constant::HUMAN,
1079        default => 0,
1080);
1081setting(
1082        name    => 'feature_bookmark',
1083        type    => Padre::Constant::BOOLEAN,
1084        store   => Padre::Constant::HUMAN,
1085        default => 1,
1086);
1087setting(
1088        name    => 'feature_fontsize',
1089        type    => Padre::Constant::BOOLEAN,
1090        store   => Padre::Constant::HUMAN,
1091        default => 1,
1092);
1093setting(
1094        name    => 'feature_session',
1095        type    => Padre::Constant::BOOLEAN,
1096        store   => Padre::Constant::HUMAN,
1097        default => 1,
1098);
1099setting(
1100        name    => 'feature_cursormemory',
1101        type    => Padre::Constant::BOOLEAN,
1102        store   => Padre::Constant::HUMAN,
1103        default => 1,
1104);
1105
1106# Window menu list shorten common path
1107setting(
1108        name    => 'window_list_shorten_path',
1109        type    => Padre::Constant::ASCII,
1110        store   => Padre::Constant::HUMAN,
1111        default => 1,
1112);
1113
1114# Beginner error checks configuration
1115setting(
1116        name    => 'begerror_split',
1117        type    => Padre::Constant::BOOLEAN,
1118        store   => Padre::Constant::HOST,
1119        default => 1,
1120);
1121
1122setting(
1123        name    => 'begerror_warning',
1124        type    => Padre::Constant::BOOLEAN,
1125        store   => Padre::Constant::HOST,
1126        default => 1,
1127);
1128
1129setting(
1130        name    => 'begerror_map',
1131        type    => Padre::Constant::BOOLEAN,
1132        store   => Padre::Constant::HOST,
1133        default => 1,
1134);
1135
1136setting(
1137        name    => 'begerror_DB',
1138        type    => Padre::Constant::BOOLEAN,
1139        store   => Padre::Constant::HOST,
1140        default => 1,
1141);
1142
1143setting(
1144        name    => 'begerror_chomp',
1145        type    => Padre::Constant::BOOLEAN,
1146        store   => Padre::Constant::HOST,
1147        default => 1,
1148);
1149
1150setting(
1151        name    => 'begerror_map2',
1152        type    => Padre::Constant::BOOLEAN,
1153        store   => Padre::Constant::HOST,
1154        default => 1,
1155);
1156
1157setting(
1158        name    => 'begerror_perl6',
1159        type    => Padre::Constant::BOOLEAN,
1160        store   => Padre::Constant::HOST,
1161        default => 1,
1162);
1163
1164setting(
1165        name    => 'begerror_ifsetvar',
1166        type    => Padre::Constant::BOOLEAN,
1167        store   => Padre::Constant::HOST,
1168        default => 1,
1169);
1170
1171setting(
1172        name    => 'begerror_pipeopen',
1173        type    => Padre::Constant::BOOLEAN,
1174        store   => Padre::Constant::HOST,
1175        default => 1,
1176);
1177
1178setting(
1179        name    => 'begerror_pipe2open',
1180        type    => Padre::Constant::BOOLEAN,
1181        store   => Padre::Constant::HOST,
1182        default => 1,
1183);
1184
1185setting(
1186        name    => 'begerror_regexq',
1187        type    => Padre::Constant::BOOLEAN,
1188        store   => Padre::Constant::HOST,
1189        default => 1,
1190);
1191
1192setting(
1193        name    => 'begerror_elseif',
1194        type    => Padre::Constant::BOOLEAN,
1195        store   => Padre::Constant::HOST,
1196        default => 1,
1197);
1198
1199setting(
1200        name    => 'begerror_close',
1201        type    => Padre::Constant::BOOLEAN,
1202        store   => Padre::Constant::HOST,
1203        default => 1,
1204);
1205
1206# Padre::File options
1207
1208#   ::HTTP
1209setting(
1210        name    => 'file_http_timeout',
1211        type    => Padre::Constant::ASCII,
1212        store   => Padre::Constant::HUMAN,
1213        default => 30,
1214);
1215
1216#   ::FTP
1217setting(
1218        name    => 'file_ftp_timeout',
1219        type    => Padre::Constant::ASCII,
1220        store   => Padre::Constant::HUMAN,
1221        default => 30,
1222);
1223
1224setting(
1225        name    => 'file_ftp_passive',
1226        type    => Padre::Constant::BOOLEAN,
1227        store   => Padre::Constant::HUMAN,
1228        default => 1,
1229);
1230
1231# Non-preference settings
1232setting(
1233        name    => 'session_autosave',
1234        type    => Padre::Constant::BOOLEAN,
1235        store   => Padre::Constant::HUMAN,
1236        default => 0,
1237);
1238
1239# The "config_" namespace is for the locations of configuration content
1240# outside of the configuration API, and the paths to other non-Padre config
1241# files for various external tools (usually so that projects can define the
1242# the location of their project-specific policies).
1243
1244# The location of the server that will share config data between installs
1245setting(
1246        name    => 'config_sync_server',
1247        type    => Padre::Constant::ASCII,
1248        store   => Padre::Constant::HUMAN,
1249        default => 'http://escher.ath.cx:3000',
1250);
1251
1252setting(
1253        name    => 'config_sync_username',
1254        type    => Padre::Constant::ASCII,
1255        store   => Padre::Constant::HUMAN,
1256        default => '',
1257);
1258
1259setting(
1260        name    => 'config_sync_password',
1261        type    => Padre::Constant::ASCII,
1262        store   => Padre::Constant::HUMAN,
1263        default => '',
1264);
1265
1266# Location of the Perl::Tidy RC file, if a project wants to set a custom one.
1267# When set to false, allow Perl::Tidy to use its own default config location.
1268# Load this from the project backend in preference to the host one, so that
1269# projects can set their own project-specific config file.
1270setting(
1271        name    => 'config_perltidy',
1272        type    => Padre::Constant::PATH,
1273        store   => Padre::Constant::PROJECT,
1274        default => '',
1275);
1276
1277# Location of the Perl::Critic RC file, if a project wants to set a custom
1278# one. When set to false, allow Perl::Critic to use its own default config
1279# location. Load this from the project backend in preference to the host one,
1280# so that projects can set their own project-specific config file.
1281setting(
1282        name    => 'config_perlcritic',
1283        type    => Padre::Constant::PATH,
1284        store   => Padre::Constant::PROJECT,
1285        default => '',
1286);
1287
1288# Save if feedback has been send or not
1289setting(
1290        name    => 'feedback_done',
1291        type    => Padre::Constant::BOOLEAN,
1292        store   => Padre::Constant::HUMAN,
1293        default => 0,
1294);
1295
12961;
1297
1298__END__
1299
1300=pod
1301
1302=head1 NAME
1303
1304Padre::Config - Configuration subsystem for Padre
1305
1306=head1 SYNOPSIS
1307
1308    use Padre::Config;
1309    [...]
1310    if ( Padre::Config->main_statusbar ) { [...] }
1311
1312=head1 DESCRIPTION
1313
1314This module not only stores the complete Padre configuration, it also holds
1315the functions for loading and saving the configuration.
1316
1317The Padre configuration lives in two places:
1318
1319=over
1320
1321=item a user-editable text file usually called F<config.yml>
1322
1323=item an SQLite database which shouldn't be edited by the user
1324
1325=back
1326
1327=head2 Generic usage
1328
1329Every setting is accessed by a mutator named after it,
1330i.e. it can be used both as a getter and a setter depending on the number
1331of arguments passed to it.
1332
1333=head2 Different types of settings
1334
1335Padre needs to store different settings. Those preferences are stored in
1336different places depending on their impact. But C<Padre::Config> allows to
1337access them with a unified API (a mutator). Only their declaration differs
1338in the module.
1339
1340Here are the various types of settings that C<Padre::Config> can manage:
1341
1342=over 4
1343
1344=item * User settings
1345
1346Those settings are general settings that relates to user preferences. They range
1347from general user interface I<look & feel> (whether to show the line numbers, etc.)
1348to editor preferences (tab width, etc.) and other personal settings.
1349
1350Those settings are stored in a YAML file, and accessed with C<Padre::Config::Human>.
1351
1352=item * Host settings
1353
1354Those preferences are related to the host on which Padre is run. The principal
1355example of those settings are window appearance.
1356
1357Those settings are stored in a DB file, and accessed with C<Padre::Config::Host>.
1358
1359=item * Project settings
1360
1361Those preferences are related to the project of the file you are currently
1362editing. Examples of those settings are whether to use tabs or spaces, etc.
1363
1364Those settings are accessed with C<Padre::Config::Project>.
1365
1366=back
1367
1368=head1 ADDING CONFIGURATION OPTIONS
1369
1370Add a "setting()" - call to the correct section of this file.
1371
1372The setting() call initially creates the option and defines some
1373metadata like the type of the option, it's living place and the
1374default value which should be used until the user configures
1375a own value.
1376
1377=head1 COPYRIGHT & LICENSE
1378
1379Copyright 2008-2010 The Padre development team as listed in Padre.pm.
1380
1381This program is free software; you can redistribute it and/or modify it under the
1382same terms as Perl 5 itself.
1383
1384=cut
1385
1386# Copyright 2008-2010 The Padre development team as listed in Padre.pm.
1387# LICENSE
1388# This program is free software; you can redistribute it and/or
1389# modify it under the same terms as Perl 5 itself.
Note: See TracBrowser for help on using the browser.