~ubuntu-branches/ubuntu/wily/padre/wily

« back to all changes in this revision

Viewing changes to lib/Padre/Config.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2009-08-12 14:44:55 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090812144455-yvk90oa92khfcnls
Tags: 0.42-1
* New Upstream Version
  + add explicit dependency on libtest-simple-perl (>= 0.88)
  + rules: use dh --with quilt (and bump quilt build-dependency to 0.46-7)
  + rules: no need to re-generate .mo files from .po. Upstream does it now
  + copyright: describe share/icons/padre/16x16/logo.png
    - describe share/icons/padre/16x16/toggle-comments.png
    - Padre license is the same as Perl (i.e. not Perl 5)
    - update list of copright holders
    - also list translators
  + drop libtest-most-perl from build-dependencies
  + add liblocale-msgfmt-perl to build-dependencies
  + add libcapture-tiny-perl to (build-)dependencies
  + add libfile-remove-perl (>= 1.42) to (build-)dependencies
  + drop libmodule-inspector-perl from (build-)dependencies
  + add libppix-editortools-perl to (build-)dependencies
  + add libparse-exuberantctags-perl to (build-)dependencies
  + patches:
    - drop lower-wx-requirement-to-2.8.7.patch and replace it with
      SKIP_WXWIDGETS_VERSION_CHECK=1 when configuring
      adjust README.debian accordingly
    - refresh disable-tcp-server.patch
    - drop don't-require-new-file-path.patch (applied upstream)
    - rework fix-pod2-errors.patch (new release, new errors :))
* add fix-perl-interpreter-path.patch fixing the path to the perl interpreter
  in three examples (thanks lintian)
* add more lintian overrides about script-not-executable for scripts that are
  treated as examples/templates
* add fix-whatis.patch fixing the whatis entry of Padre::Wx
* add menu and .desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
use Carp                   ();
16
16
use Params::Util           ();
17
17
use Padre::Constant        ();
 
18
use Padre::Util            ('_T');
 
19
use Padre::Current         ('_CURRENT');
18
20
use Padre::Config::Setting ();
19
21
use Padre::Config::Human   ();
20
22
use Padre::Config::Project ();
21
23
use Padre::Config::Host    ();
22
24
 
23
 
our $VERSION = '0.36';
 
25
our $VERSION = '0.42';
24
26
 
25
27
# Master storage of the settings
26
28
our %SETTING = ();
42
44
        project => Padre::Constant::PROJECT,
43
45
};
44
46
 
 
47
 
 
48
 
 
49
 
 
50
 
45
51
#####################################################################
46
52
# Settings Specification
47
53
 
48
54
# This section identifies the set of all named configuration entries,
49
55
# and where the configuration system should resolve them to.
50
56
 
51
 
my %settings = (
52
 
        human => [
53
 
 
54
 
                # for each setting, add an array ref:
55
 
                # [ $setting_name, $setting_type, $setting_default ]
56
 
 
57
 
                # -- user identity (simplistic initial version)
58
 
                [ 'identity_name',  Padre::Constant::ASCII, '' ],    # Initially, this must be ascii only
59
 
                [ 'identity_email', Padre::Constant::ASCII, '' ],
60
 
 
61
 
                # -- for module::starter
62
 
                [ 'license',                Padre::Constant::ASCII, '' ],
63
 
                [ 'builder',                Padre::Constant::ASCII, '' ],
64
 
                [ 'module_start_directory', Padre::Constant::ASCII, '' ],
65
 
 
66
 
                # -- indent settings
67
 
                # allow projects to forcefully override personal settings
68
 
                [ 'editor_indent_auto',      Padre::Constant::BOOLEAN, 1 ],
69
 
                [ 'editor_indent_tab',       Padre::Constant::BOOLEAN, 1 ],
70
 
                [ 'editor_indent_tab_width', Padre::Constant::POSINT,  8 ],
71
 
                [ 'editor_indent_width',     Padre::Constant::POSINT,  8 ],
72
 
 
73
 
                # -- pages and panels
74
 
                # startup mode, if no files given on the command line this can be
75
 
                #   new        - a new empty buffer
76
 
                #   nothing    - nothing to open
77
 
                #   last       - the files that were open last time
78
 
                [ 'main_startup',         Padre::Constant::ASCII,   'new' ],
79
 
                [ 'main_singleinstance',  Padre::Constant::BOOLEAN, 0 ],
80
 
                [ 'main_lockinterface',   Padre::Constant::BOOLEAN, 1 ],
81
 
                [ 'main_functions',       Padre::Constant::BOOLEAN, 0 ],
82
 
                [ 'main_functions_order', Padre::Constant::ASCII,   'alphabetical' ],
83
 
                [ 'main_outline',         Padre::Constant::BOOLEAN, 0 ],
84
 
                [ 'main_directory',       Padre::Constant::BOOLEAN, 0 ],
85
 
                [ 'main_output',          Padre::Constant::BOOLEAN, 0 ],
86
 
                [ 'main_output_ansi',     Padre::Constant::BOOLEAN, 1 ],
87
 
                [ 'main_syntaxcheck',     Padre::Constant::BOOLEAN, 0 ],
88
 
                [ 'main_errorlist',       Padre::Constant::BOOLEAN, 0 ],
89
 
                [ 'main_statusbar',       Padre::Constant::BOOLEAN, 1 ],
90
 
 
91
 
                # -- editor settings
92
 
                [ 'editor_font',              Padre::Constant::ASCII,   '' ],
93
 
                [ 'editor_linenumbers',       Padre::Constant::BOOLEAN, 1 ],
94
 
                [ 'editor_eol',               Padre::Constant::BOOLEAN, 0 ],
95
 
                [ 'editor_whitespace',        Padre::Constant::BOOLEAN, 0 ],
96
 
                [ 'editor_indentationguides', Padre::Constant::BOOLEAN, 0 ],
97
 
                [ 'editor_calltips',          Padre::Constant::BOOLEAN, 0 ],
98
 
                [ 'editor_autoindent',        Padre::Constant::ASCII,   'deep' ],
99
 
                [ 'editor_folding',           Padre::Constant::BOOLEAN, 0 ],
100
 
                [ 'editor_fold_pod',          Padre::Constant::BOOLEAN, 0 ],
101
 
                [ 'editor_currentline',       Padre::Constant::BOOLEAN, 1 ],
102
 
                [ 'editor_currentline_color', Padre::Constant::ASCII,   'FFFF04' ],
103
 
                [ 'editor_beginner',          Padre::Constant::BOOLEAN, 1 ],
104
 
                [ 'editor_wordwrap',          Padre::Constant::BOOLEAN, 0 ],
105
 
                [ 'editor_file_size_limit',   Padre::Constant::POSINT,  500_000 ],
106
 
                [ 'find_case',                Padre::Constant::BOOLEAN, 1 ],
107
 
                [ 'find_regex',               Padre::Constant::BOOLEAN, 0 ],
108
 
                [ 'find_reverse',             Padre::Constant::BOOLEAN, 0 ],
109
 
                [ 'find_first',               Padre::Constant::BOOLEAN, 0 ],
110
 
                [ 'find_nohidden',            Padre::Constant::BOOLEAN, 1 ],
111
 
                [ 'find_quick',               Padre::Constant::BOOLEAN, 0 ],
112
 
                [ 'ppi_highlight',            Padre::Constant::BOOLEAN, 0 ],
113
 
                [ 'ppi_highlight_limit',      Padre::Constant::POSINT,  2000 ],
114
 
 
115
 
                # -- behaviour tuning
116
 
                # When running a script from the application some of the files might have
117
 
                # not been saved yet. There are several option what to do before running the
118
 
                # script:
119
 
                # none - don't save anything (the script will be run without current modifications)
120
 
                # unsaved - as above but including modifications present in the buffer
121
 
                # same - save the file in the current buffer
122
 
                # all_files - all the files (but not buffers that have no filenames)
123
 
                # all_buffers - all the buffers even if they don't have a name yet
124
 
                [ 'run_save', Padre::Constant::ASCII, 'same' ],
125
 
 
126
 
                # move of stacktrace to run menu: will be removed (run_stacktrace)
127
 
                [ 'run_stacktrace',        Padre::Constant::BOOLEAN, 0 ],
128
 
                [ 'autocomplete_brackets', Padre::Constant::BOOLEAN, 0 ],
129
 
 
130
 
                # by default use background threads unless profiling
131
 
                # TODO - Make the default actually change
132
 
                [ 'threads',         Padre::Constant::BOOLEAN, 1 ],
133
 
                [ 'locale',          Padre::Constant::ASCII,   '' ],
134
 
                [ 'locale_perldiag', Padre::Constant::ASCII,   '' ],
135
 
                [ 'experimental',    Padre::Constant::BOOLEAN, 0 ],
136
 
        ],
137
 
        host => [
138
 
 
139
 
                # for each setting, add an array ref:
140
 
                # [ $setting_name, $setting_type, $setting_default ]
141
 
 
142
 
                # -- color data
143
 
                # since it's in local files, it has to be a host-specific setting
144
 
                [ 'editor_style', Padre::Constant::ASCII, 'default' ],
145
 
 
146
 
                # -- window geometry
147
 
                [ 'main_maximized', Padre::Constant::BOOLEAN, 0 ],
148
 
                [ 'main_top',       Padre::Constant::INTEGER, 40 ],
149
 
                [ 'main_left',      Padre::Constant::INTEGER, 20 ],
150
 
                [ 'main_width',     Padre::Constant::POSINT,  600 ],
151
 
                [ 'main_height',    Padre::Constant::POSINT,  400 ],
152
 
 
153
 
                [ 'logging',       Padre::Constant::BOOLEAN, 0 ],
154
 
                [ 'logging_trace', Padre::Constant::BOOLEAN, 0 ],
155
 
 
156
 
                # -- default run parameters
157
 
                [ 'run_interpreter_args_default', Padre::Constant::ASCII, '' ],
158
 
                [ 'run_script_args_default',      Padre::Constant::ASCII, '' ],
159
 
                [ 'external_diff_tool',           Padre::Constant::ASCII, '' ],
160
 
        ],
161
 
);
162
 
 
163
 
my %store = (
164
 
        human => Padre::Constant::HUMAN,
165
 
        host  => Padre::Constant::HOST,
166
 
);
167
 
foreach my $type ( keys %settings ) {
168
 
        my $settings = $settings{$type};
169
 
        my $store    = $store{$type};
170
 
        foreach my $setting (@$settings) {
171
 
                my ( $name, $type, $default ) = @$setting;
172
 
                _setting(
173
 
                        name    => $name,
174
 
                        type    => $type,
175
 
                        store   => $store,
176
 
                        default => $default,
177
 
                );
178
 
        }
179
 
}
 
57
#
 
58
# setting( %params );
 
59
#
 
60
# create a new setting, with %params used to feed the new object.
 
61
#
 
62
sub setting {
 
63
 
 
64
        # Validate the setting
 
65
        my $object = Padre::Config::Setting->new(@_);
 
66
        if ( $SETTING{ $object->{name} } ) {
 
67
                Carp::croak("The $object->{name} setting is already defined");
 
68
        }
 
69
 
 
70
        # Generate the accessor
 
71
        my $code = <<"END_PERL";
 
72
package Padre::Config;
 
73
 
 
74
sub $object->{name} {
 
75
        my \$self = shift;
 
76
        if ( exists \$self->[$object->{store}]->{'$object->{name}'} ) {
 
77
                return \$self->[$object->{store}]->{'$object->{name}'};
 
78
        }
 
79
        return \$DEFAULT{'$object->{name}'};
 
80
}
 
81
END_PERL
 
82
 
 
83
        # Compile the accessor
 
84
        eval $code; ## no critic
 
85
        if ($@) {
 
86
                Carp::croak("Failed to compile setting $object->{name}");
 
87
        }
 
88
 
 
89
        # Save the setting
 
90
        $SETTING{ $object->{name} } = $object;
 
91
        $DEFAULT{ $object->{name} } = $object->{default};
 
92
 
 
93
        return 1;
 
94
}
 
95
 
 
96
# User identity (simplistic initial version)
 
97
# Initially, this must be ascii only
 
98
setting(
 
99
        name    => 'identity_name',
 
100
        type    => Padre::Constant::ASCII,
 
101
        store   => Padre::Constant::HUMAN,
 
102
        default => '',
 
103
);
 
104
setting(
 
105
        name    => 'identity_email',
 
106
        type    => Padre::Constant::ASCII,
 
107
        store   => Padre::Constant::HUMAN,
 
108
        default => '',
 
109
);
 
110
setting(
 
111
        name    => 'identity_nickname',
 
112
        type    => Padre::Constant::ASCII,
 
113
        store   => Padre::Constant::HUMAN,
 
114
        default => '',
 
115
);
 
116
 
 
117
# Support for Module::Starter
 
118
setting(
 
119
        name    => 'license',
 
120
        type    => Padre::Constant::ASCII,
 
121
        store   => Padre::Constant::HUMAN,
 
122
        default => '',
 
123
);
 
124
setting(
 
125
        name    => 'builder',
 
126
        type    => Padre::Constant::ASCII,
 
127
        store   => Padre::Constant::HUMAN,
 
128
        default => '',
 
129
);
 
130
setting(
 
131
        name    => 'module_start_directory',
 
132
        type    => Padre::Constant::ASCII,
 
133
        store   => Padre::Constant::HUMAN,
 
134
        default => '',
 
135
);
 
136
 
 
137
# Indent settings
 
138
# Allow projects to forcefully override personal settings
 
139
setting(
 
140
        name    => 'editor_indent_auto',
 
141
        type    => Padre::Constant::BOOLEAN,
 
142
        store   => Padre::Constant::HUMAN,
 
143
        default => 1,
 
144
        project => 1,
 
145
);
 
146
setting(
 
147
        name    => 'editor_indent_tab',
 
148
        type    => Padre::Constant::BOOLEAN,
 
149
        store   => Padre::Constant::HUMAN,
 
150
        default => 1,
 
151
        project => 1,
 
152
);
 
153
setting(
 
154
        name    => 'editor_indent_tab_width',
 
155
        type    => Padre::Constant::POSINT,
 
156
        store   => Padre::Constant::HUMAN,
 
157
        default => 8,
 
158
        project => 1,
 
159
);
 
160
setting(
 
161
        name    => 'editor_indent_width',
 
162
        type    => Padre::Constant::POSINT,
 
163
        store   => Padre::Constant::HUMAN,
 
164
        default => 8,
 
165
        project => 1,
 
166
);
 
167
 
 
168
# Startup mode, if no files given on the command line this can be
 
169
#   new        - a new empty buffer
 
170
#   nothing    - nothing to open
 
171
#   last       - the files that were open last time
 
172
setting(
 
173
        name    => 'main_startup',
 
174
        type    => Padre::Constant::ASCII,
 
175
        store   => Padre::Constant::HUMAN,
 
176
        default => 'new',
 
177
        options => [
 
178
                'last'    => _T('Previous open files'),
 
179
                'new'     => _T('A new empty file'),
 
180
                'nothing' => _T('No open files'),
 
181
        ],
 
182
);
 
183
 
 
184
# Pages and panels
 
185
setting(
 
186
        name    => 'main_singleinstance',
 
187
        type    => Padre::Constant::BOOLEAN,
 
188
        store   => Padre::Constant::HUMAN,
 
189
        default => 0,
 
190
        apply   => sub {
 
191
                my $main  = shift;
 
192
                my $value = shift;
 
193
                if ($value) {
 
194
                        $main->single_instance_start;
 
195
                } else {
 
196
                        $main->single_instance_stop;
 
197
                }
 
198
                return 1;
 
199
        },
 
200
);
 
201
setting(
 
202
        name    => 'main_lockinterface',
 
203
        type    => Padre::Constant::BOOLEAN,
 
204
        store   => Padre::Constant::HUMAN,
 
205
        default => 1,
 
206
        apply   => sub {
 
207
                my $main  = shift;
 
208
                my $value = shift;
 
209
 
 
210
                # Update the lock status
 
211
                $main->aui->lock_panels($value);
 
212
 
 
213
                # The toolbar can't dynamically switch between
 
214
                # tearable and non-tearable so rebuild it.
 
215
                # TODO: Review this assumption
 
216
                if ($Padre::Wx::Toolbar::DOCKABLE) {
 
217
                        $main->rebuild_toolbar;
 
218
                }
 
219
 
 
220
                return 1;
 
221
        }
 
222
);
 
223
setting(
 
224
        name    => 'main_functions',
 
225
        type    => Padre::Constant::BOOLEAN,
 
226
        store   => Padre::Constant::HUMAN,
 
227
        default => 0,
 
228
);
 
229
setting(
 
230
        name    => 'main_functions_order',
 
231
        type    => Padre::Constant::ASCII,
 
232
        store   => Padre::Constant::HUMAN,
 
233
        default => 'alphabetical',
 
234
        options => [
 
235
                'original'                  => _T('Code Order'),
 
236
                'alphabetical'              => _T('Alphabetical Order'),
 
237
                'alphabetical_private_last' => _T('Alphabetical Order (Private Last)'),
 
238
        ],
 
239
);
 
240
setting(
 
241
        name    => 'main_outline',
 
242
        type    => Padre::Constant::BOOLEAN,
 
243
        store   => Padre::Constant::HUMAN,
 
244
        default => 0,
 
245
);
 
246
setting(
 
247
        name    => 'main_directory',
 
248
        type    => Padre::Constant::BOOLEAN,
 
249
        store   => Padre::Constant::HUMAN,
 
250
        default => 0,
 
251
);
 
252
setting(
 
253
        name    => 'main_directory_panel',
 
254
        type    => Padre::Constant::ASCII,
 
255
        store   => Padre::Constant::HUMAN,
 
256
        default => 'left',
 
257
        options => [
 
258
                'left'  => _T('Project Tools (Left)'),
 
259
                'right' => _T('Document Tools (Right)'),
 
260
        ],
 
261
        apply => sub {
 
262
                my $main  = shift;
 
263
                my $value = shift;
 
264
 
 
265
                # Is it visible and on the wrong side?
 
266
                return 1 unless $main->has_directory;
 
267
                my $directory = $main->directory;
 
268
                return 1 unless $directory->IsShown;
 
269
                return 1 unless $directory->side ne $value;
 
270
 
 
271
                # Hide and reshow the tool with the new setting
 
272
                $directory->panel->hide($directory);
 
273
                $main->directory_panel->show($directory);
 
274
                $main->Layout;
 
275
                $main->Update;
 
276
 
 
277
                return 1;
 
278
        }
 
279
);
 
280
setting(
 
281
        name    => 'main_output',
 
282
        type    => Padre::Constant::BOOLEAN,
 
283
        store   => Padre::Constant::HUMAN,
 
284
        default => 0,
 
285
);
 
286
setting(
 
287
        name    => 'main_output_ansi',
 
288
        type    => Padre::Constant::BOOLEAN,
 
289
        store   => Padre::Constant::HUMAN,
 
290
        default => 1,
 
291
);
 
292
setting(
 
293
        name    => 'main_syntaxcheck',
 
294
        type    => Padre::Constant::BOOLEAN,
 
295
        store   => Padre::Constant::HUMAN,
 
296
        default => 0,
 
297
);
 
298
setting(
 
299
        name    => 'main_errorlist',
 
300
        type    => Padre::Constant::BOOLEAN,
 
301
        store   => Padre::Constant::HUMAN,
 
302
        default => 0,
 
303
);
 
304
setting(
 
305
        name    => 'main_statusbar',
 
306
        type    => Padre::Constant::BOOLEAN,
 
307
        store   => Padre::Constant::HUMAN,
 
308
        default => 1,
 
309
);
 
310
setting(
 
311
        name    => 'main_toolbar',
 
312
        type    => Padre::Constant::BOOLEAN,
 
313
        store   => Padre::Constant::HUMAN,
 
314
        default => 1,
 
315
);
 
316
 
 
317
# Directory Tree Settings
 
318
setting(
 
319
        name    => 'default_projects_directory',
 
320
        type    => Padre::Constant::ASCII,
 
321
        store   => Padre::Constant::HUMAN,
 
322
        default => File::HomeDir->my_documents,
 
323
);
 
324
 
 
325
# Editor Settings
 
326
setting(
 
327
        name    => 'editor_font',
 
328
        type    => Padre::Constant::ASCII,
 
329
        store   => Padre::Constant::HUMAN,
 
330
        default => '',
 
331
);
 
332
setting(
 
333
        name    => 'editor_linenumbers',
 
334
        type    => Padre::Constant::BOOLEAN,
 
335
        store   => Padre::Constant::HUMAN,
 
336
        default => 1,
 
337
);
 
338
setting(
 
339
        name    => 'editor_eol',
 
340
        type    => Padre::Constant::BOOLEAN,
 
341
        store   => Padre::Constant::HUMAN,
 
342
        default => 0,
 
343
);
 
344
setting(
 
345
        name    => 'editor_whitespace',
 
346
        type    => Padre::Constant::BOOLEAN,
 
347
        store   => Padre::Constant::HUMAN,
 
348
        default => 0,
 
349
);
 
350
setting(
 
351
        name    => 'editor_indentationguides',
 
352
        type    => Padre::Constant::BOOLEAN,
 
353
        store   => Padre::Constant::HUMAN,
 
354
        default => 0,
 
355
);
 
356
setting(
 
357
        name    => 'editor_calltips',
 
358
        type    => Padre::Constant::BOOLEAN,
 
359
        store   => Padre::Constant::HUMAN,
 
360
        default => 0,
 
361
);
 
362
setting(
 
363
        name    => 'editor_autoindent',
 
364
        type    => Padre::Constant::ASCII,
 
365
        store   => Padre::Constant::HUMAN,
 
366
        default => 'deep',
 
367
        options => [
 
368
                'no'   => 'No Autoindent',
 
369
                'same' => 'Indent to Same Depth',
 
370
                'deep' => 'Indent Deeply',
 
371
        ],
 
372
);
 
373
setting(
 
374
        name    => 'editor_folding',
 
375
        type    => Padre::Constant::BOOLEAN,
 
376
        store   => Padre::Constant::HUMAN,
 
377
        default => 0,
 
378
);
 
379
setting(
 
380
        name    => 'editor_fold_pod',
 
381
        type    => Padre::Constant::BOOLEAN,
 
382
        store   => Padre::Constant::HUMAN,
 
383
        default => 0,
 
384
);
 
385
setting(
 
386
        name    => 'editor_currentline',
 
387
        type    => Padre::Constant::BOOLEAN,
 
388
        store   => Padre::Constant::HUMAN,
 
389
        default => 1,
 
390
);
 
391
setting(
 
392
        name    => 'editor_currentline_color',
 
393
        type    => Padre::Constant::ASCII,
 
394
        store   => Padre::Constant::HUMAN,
 
395
        default => 'FFFF04',
 
396
);
 
397
setting(
 
398
        name    => 'editor_beginner',
 
399
        type    => Padre::Constant::BOOLEAN,
 
400
        store   => Padre::Constant::HUMAN,
 
401
        default => 1,
 
402
);
 
403
setting(
 
404
        name    => 'editor_wordwrap',
 
405
        type    => Padre::Constant::BOOLEAN,
 
406
        store   => Padre::Constant::HUMAN,
 
407
        default => 0,
 
408
);
 
409
setting(
 
410
        name    => 'editor_file_size_limit',
 
411
        type    => Padre::Constant::POSINT,
 
412
        store   => Padre::Constant::HUMAN,
 
413
        default => 500_000,
 
414
);
 
415
setting(
 
416
        name    => 'editor_right_margin_enable',
 
417
        type    => Padre::Constant::BOOLEAN,
 
418
        store   => Padre::Constant::HUMAN,
 
419
        default => 0,
 
420
);
 
421
setting(
 
422
        name    => 'editor_right_margin_column',
 
423
        type    => Padre::Constant::POSINT,
 
424
        store   => Padre::Constant::HUMAN,
 
425
        default => 80,
 
426
);
 
427
setting(
 
428
        name    => 'find_case',
 
429
        type    => Padre::Constant::BOOLEAN,
 
430
        store   => Padre::Constant::HUMAN,
 
431
        default => 1,
 
432
);
 
433
setting(
 
434
        name    => 'find_regex',
 
435
        type    => Padre::Constant::BOOLEAN,
 
436
        store   => Padre::Constant::HUMAN,
 
437
        default => 0,
 
438
);
 
439
setting(
 
440
        name    => 'find_reverse',
 
441
        type    => Padre::Constant::BOOLEAN,
 
442
        store   => Padre::Constant::HUMAN,
 
443
        default => 0,
 
444
);
 
445
setting(
 
446
        name    => 'find_first',
 
447
        type    => Padre::Constant::BOOLEAN,
 
448
        store   => Padre::Constant::HUMAN,
 
449
        default => 0,
 
450
);
 
451
setting(
 
452
        name    => 'find_nohidden',
 
453
        type    => Padre::Constant::BOOLEAN,
 
454
        store   => Padre::Constant::HUMAN,
 
455
        default => 1,
 
456
);
 
457
setting(
 
458
        name    => 'find_quick',
 
459
        type    => Padre::Constant::BOOLEAN,
 
460
        store   => Padre::Constant::HUMAN,
 
461
        default => 0,
 
462
);
 
463
setting(
 
464
        name    => 'update_file_from_disk_interval',
 
465
        type    => Padre::Constant::ASCII,
 
466
        store   => Padre::Constant::HUMAN,
 
467
        default => 2,
 
468
);
 
469
 
 
470
# Behaviour Tuning
 
471
# When running a script from the application some of the files might have
 
472
# not been saved yet. There are several option what to do before running the
 
473
# script:
 
474
# none - don't save anything (the script will be run without current modifications)
 
475
# unsaved - as above but including modifications present in the buffer
 
476
# same - save the file in the current buffer
 
477
# all_files - all the files (but not buffers that have no filenames)
 
478
# all_buffers - all the buffers even if they don't have a name yet
 
479
setting(
 
480
        name    => 'run_save',
 
481
        type    => Padre::Constant::ASCII,
 
482
        store   => Padre::Constant::HUMAN,
 
483
        default => 'same',
 
484
);
 
485
 
 
486
# Move of stacktrace to run menu: will be removed (run_stacktrace)
 
487
setting(
 
488
        name    => 'run_stacktrace',
 
489
        type    => Padre::Constant::BOOLEAN,
 
490
        store   => Padre::Constant::HUMAN,
 
491
        default => 0,
 
492
);
 
493
setting(
 
494
        name    => 'autocomplete_brackets',
 
495
        type    => Padre::Constant::BOOLEAN,
 
496
        store   => Padre::Constant::HUMAN,
 
497
        default => 0,
 
498
);
 
499
 
 
500
# By default use background threads unless profiling
 
501
# TODO - Make the default actually change
 
502
setting(
 
503
        name    => 'threads',
 
504
        type    => Padre::Constant::BOOLEAN,
 
505
        store   => Padre::Constant::HUMAN,
 
506
        default => 1,
 
507
);
 
508
setting(
 
509
        name    => 'locale',
 
510
        type    => Padre::Constant::ASCII,
 
511
        store   => Padre::Constant::HUMAN,
 
512
        default => '',
 
513
);
 
514
setting(
 
515
        name    => 'locale_perldiag',
 
516
        type    => Padre::Constant::ASCII,
 
517
        store   => Padre::Constant::HUMAN,
 
518
        default => '',
 
519
);
 
520
 
 
521
# Colour Data
 
522
# Since it's in local files, it has to be a host-specific setting.
 
523
setting(
 
524
        name    => 'editor_style',
 
525
        type    => Padre::Constant::ASCII,
 
526
        store   => Padre::Constant::HOST,
 
527
        default => 'default',
 
528
);
 
529
 
 
530
# Window Geometry
 
531
setting(
 
532
        name    => 'main_maximized',
 
533
        type    => Padre::Constant::BOOLEAN,
 
534
        store   => Padre::Constant::HOST,
 
535
        default => 0,
 
536
);
 
537
setting(
 
538
        name    => 'main_top',
 
539
        type    => Padre::Constant::INTEGER,
 
540
        store   => Padre::Constant::HOST,
 
541
        default => 40,
 
542
);
 
543
setting(
 
544
        name    => 'main_left',
 
545
        type    => Padre::Constant::INTEGER,
 
546
        store   => Padre::Constant::HOST,
 
547
        default => 20,
 
548
);
 
549
setting(
 
550
        name    => 'main_width',
 
551
        type    => Padre::Constant::POSINT,
 
552
        store   => Padre::Constant::HOST,
 
553
        default => 600,
 
554
);
 
555
setting(
 
556
        name    => 'main_height',
 
557
        type    => Padre::Constant::POSINT,
 
558
        store   => Padre::Constant::HOST,
 
559
        default => 400,
 
560
);
 
561
 
 
562
# Logging
 
563
setting(
 
564
        name    => 'logging',
 
565
        type    => Padre::Constant::BOOLEAN,
 
566
        store   => Padre::Constant::HOST,
 
567
        default => 0,
 
568
);
 
569
setting(
 
570
        name    => 'logging_trace',
 
571
        type    => Padre::Constant::BOOLEAN,
 
572
        store   => Padre::Constant::HOST,
 
573
        default => 0,
 
574
);
 
575
 
 
576
# Run Parameters
 
577
setting(
 
578
        name    => 'run_interpreter_args_default',
 
579
        type    => Padre::Constant::ASCII,
 
580
        store   => Padre::Constant::HOST,
 
581
        default => '',
 
582
);
 
583
setting(
 
584
        name    => 'run_script_args_default',
 
585
        type    => Padre::Constant::ASCII,
 
586
        store   => Padre::Constant::HOST,
 
587
        default => '',
 
588
);
 
589
setting(
 
590
        name    => 'run_use_external_window',
 
591
        type    => Padre::Constant::BOOLEAN,
 
592
        store   => Padre::Constant::HOST,
 
593
        default => 0,
 
594
);
 
595
setting(
 
596
        name    => 'external_diff_tool',
 
597
        type    => Padre::Constant::ASCII,
 
598
        store   => Padre::Constant::HOST,
 
599
        default => '',
 
600
);
 
601
 
 
602
 
 
603
 
 
604
 
180
605
 
181
606
#####################################################################
182
607
# Constructor and Accessors
207
632
        return $self;
208
633
}
209
634
 
 
635
sub read {
 
636
        my $class = shift;
 
637
 
 
638
        unless ($SINGLETON) {
 
639
 
 
640
                # Load the host configuration
 
641
                my $host = Padre::Config::Host->read;
 
642
 
 
643
                # Load the user configuration
 
644
                my $human = Padre::Config::Human->read
 
645
                        || Padre::Config::Human->create;
 
646
 
 
647
                # Hand off to the constructor
 
648
                $SINGLETON = $class->new( $host, $human );
 
649
 
 
650
                # TODO - Check the version
 
651
        }
 
652
 
 
653
        return $SINGLETON;
 
654
}
 
655
 
 
656
sub write {
 
657
        my $self = shift;
 
658
 
 
659
        # Save the user configuration
 
660
        $self->[Padre::Constant::HUMAN]->{version} = $REVISION;
 
661
        $self->[Padre::Constant::HUMAN]->write;
 
662
 
 
663
        # Save the host configuration
 
664
        $self->[Padre::Constant::HOST]->{version} = $REVISION;
 
665
        $self->[Padre::Constant::HOST]->write;
 
666
 
 
667
        return 1;
 
668
}
 
669
 
 
670
# Fetches an explicitly named default
 
671
sub default {
 
672
        my $self = shift;
 
673
        my $name = shift;
 
674
 
 
675
        # Does the setting exist?
 
676
        unless ( $SETTING{$name} ) {
 
677
                Carp::croak("The configuration setting '$name' does not exist");
 
678
        }
 
679
 
 
680
        return $DEFAULT{$name};
 
681
}
 
682
 
 
683
 
 
684
 
 
685
 
 
686
 
 
687
######################################################################
 
688
# Main Methods
 
689
 
210
690
sub set {
211
691
        my $self  = shift;
212
692
        my $name  = shift;
213
693
        my $value = shift;
214
694
 
215
695
        # Does the setting exist?
216
 
        my $setting = $SETTING{$name}
217
 
                or Carp::croak("The configuration setting '$name' does not exist");
 
696
        my $setting = $SETTING{$name};
 
697
        unless ($setting) {
 
698
                Carp::croak("The configuration setting '$name' does not exist");
 
699
        }
218
700
 
219
701
        # All types are Padre::Constant::ASCII-like
220
702
        unless ( defined $value and not ref $value ) {
222
704
        }
223
705
 
224
706
        # We don't need to do additional checks on Padre::Constant::ASCII
225
 
        # types at this point.
226
707
        my $type = $setting->type;
227
 
        if ( $type == Padre::Constant::BOOLEAN and $value ne '1' and $value ne '0' ) {
228
 
                Carp::croak("Tried to change setting '$name' to non-boolean '$value'");
 
708
        if ( $type == Padre::Constant::BOOLEAN ) {
 
709
                $value = 0 if $value eq '';
 
710
                if ( $value ne '1' and $value ne '0' ) {
 
711
                        Carp::croak("Tried to change setting '$name' to non-boolean '$value'");
 
712
                }
229
713
        }
230
714
        if ( $type == Padre::Constant::POSINT and not Params::Util::_POSINT($value) ) {
231
715
                Carp::croak("Tried to change setting '$name' to non-posint '$value'");
244
728
        return 1;
245
729
}
246
730
 
247
 
# Fetches an explicitly named default
248
 
sub default {
249
 
        my $self = shift;
250
 
        my $name = shift;
251
 
 
252
 
        # Does the setting exist?
253
 
        unless ( $SETTING{$name} ) {
254
 
                Carp::croak("The configuration setting '$name' does not exist");
255
 
        }
256
 
 
257
 
        return $DEFAULT{$name};
258
 
}
259
 
 
260
 
sub read {
261
 
        my $class = shift;
262
 
 
263
 
        unless ($SINGLETON) {
264
 
 
265
 
                # Load the host configuration
266
 
                my $host = Padre::Config::Host->read;
267
 
 
268
 
                # Load the user configuration
269
 
                my $human = Padre::Config::Human->read
270
 
                        || Padre::Config::Human->create;
271
 
 
272
 
                # Hand off to the constructor
273
 
                $SINGLETON = $class->new( $host, $human );
274
 
 
275
 
                # TODO - Check the version
276
 
        }
277
 
 
278
 
        return $SINGLETON;
279
 
}
280
 
 
281
 
sub write {
282
 
        my $self = shift;
283
 
 
284
 
        # Save the user configuration
285
 
        $self->[Padre::Constant::HUMAN]->{version} = $REVISION;
286
 
        $self->[Padre::Constant::HUMAN]->write;
287
 
 
288
 
        # Save the host configuration
289
 
        $self->[Padre::Constant::HOST]->{version} = $REVISION;
290
 
        $self->[Padre::Constant::HOST]->write;
291
 
 
292
 
        return 1;
293
 
}
294
 
 
295
 
# -- private subs
296
 
 
297
 
#
298
 
# _setting( %params );
299
 
#
300
 
# create a new setting, with %params used to feed the new object.
301
 
#
302
 
sub _setting {
303
 
 
304
 
        # Validate the setting
305
 
        my $object = Padre::Config::Setting->new(@_);
306
 
        if ( $SETTING{ $object->{name} } ) {
307
 
                Carp::croak("The $object->{name} setting is already defined");
308
 
        }
309
 
 
310
 
        # Generate the accessor
311
 
        my $code = <<"END_PERL";
312
 
package Padre::Config;
313
 
 
314
 
sub $object->{name} {
315
 
        my \$self = shift;
316
 
        if ( exists \$self->[$object->{store}]->{'$object->{name}'} ) {
317
 
                return \$self->[$object->{store}]->{'$object->{name}'};
318
 
        }
319
 
        return \$DEFAULT{'$object->{name}'};
320
 
}
321
 
END_PERL
322
 
 
323
 
        # Compile the accessor
324
 
        eval $code;    ## no critic
325
 
        if ($@) {
326
 
                Carp::croak("Failed to compile setting $object->{name}");
327
 
        }
328
 
 
329
 
        # Save the setting
330
 
        $SETTING{ $object->{name} } = $object;
331
 
        $DEFAULT{ $object->{name} } = $object->{default};
332
 
 
333
 
        return 1;
334
 
}
 
731
# Set a value in the configuration and apply the preference change
 
732
# to the application.
 
733
sub apply {
 
734
        my $self    = shift;
 
735
        my $name    = shift;
 
736
        my $value   = shift;
 
737
        my $current = _CURRENT(@_);
 
738
 
 
739
        # Set the config value
 
740
        $self->set( $name => $value );
 
741
 
 
742
        # Does this setting have an apply hook
 
743
        my $code = $SETTING{$name}->apply;
 
744
        if ($code) {
 
745
                $code->( $current->main, $value );
 
746
        }
 
747
 
 
748
        return 1;
 
749
}
 
750
 
 
751
 
 
752
 
 
753
 
 
754
 
 
755
######################################################################
 
756
# Support Functions
335
757
 
336
758
#
337
759
# my $is_integer = _INTEGER( $scalar );
354
776
 
355
777
=head1 SYNOPSIS
356
778
 
357
 
        use Padre::Config;
358
 
        [...]
359
 
        if ( Padre::Config->main_statusbar ) { [...] }
 
779
    use Padre::Config;
 
780
    [...]
 
781
    if ( Padre::Config->main_statusbar ) { [...] }
360
782
 
361
783
=head1 DESCRIPTION
362
784