line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kephra::Config::Global;
|
2
|
|
|
|
|
|
|
our $VERSION = '0.29';
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1122
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2212
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# handling main config files under /config/global/
|
8
|
|
|
|
|
|
|
my %settings;
|
9
|
0
|
|
|
0
|
0
|
|
sub settings { \%settings }
|
10
|
|
|
|
|
|
|
sub _settings {
|
11
|
0
|
|
|
0
|
|
|
my $conf = shift;
|
12
|
0
|
0
|
|
|
|
|
%settings = %$conf if ref $conf eq 'HASH';
|
13
|
0
|
|
|
|
|
|
\%settings;
|
14
|
|
|
|
|
|
|
}
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub merge_hash_into_settings {
|
17
|
0
|
|
|
0
|
0
|
|
my $conf = shift;
|
18
|
0
|
0
|
|
|
|
|
return unless ref $conf eq 'HASH';
|
19
|
0
|
|
|
|
|
|
_settings( Kephra::Config::Tree::update( settings(), $conf ) );
|
20
|
|
|
|
|
|
|
}
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub merge_subfile_into_settings {
|
23
|
0
|
|
|
0
|
0
|
|
my $file = shift;
|
24
|
0
|
0
|
|
|
|
|
return unless $file;
|
25
|
0
|
|
|
|
|
|
$file = Kephra::Config::filepath( _sub_dir(), 'sub', $file );
|
26
|
0
|
0
|
|
|
|
|
return unless -r $file;
|
27
|
0
|
|
|
|
|
|
merge_hash_into_settings( Kephra::Config::File::load($file) );
|
28
|
|
|
|
|
|
|
}
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
|
|
sub _sub_dir {'global'}
|
32
|
|
|
|
|
|
|
my ($auto_file, $current_file);
|
33
|
0
|
0
|
|
0
|
0
|
|
sub current_file{ $current_file = defined $_[0] ? $_[0] : $current_file }
|
34
|
0
|
0
|
|
0
|
0
|
|
sub auto_file { $auto_file = defined $_[0] ? $_[0] : $auto_file }
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub autoload {
|
37
|
0
|
|
|
0
|
0
|
|
my $autosave = auto_file();
|
38
|
0
|
|
|
|
|
|
current_file( $autosave );
|
39
|
0
|
|
|
|
|
|
my $backup = $autosave . '~';
|
40
|
|
|
|
|
|
|
#$main::logger->debug("autoload");
|
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
for my $file ($autosave, $backup) {
|
43
|
0
|
0
|
|
|
|
|
if ( -e $file ) {
|
44
|
0
|
|
|
|
|
|
my $config_tree = Kephra::Config::File::load($file);
|
45
|
0
|
0
|
|
|
|
|
%settings = %$config_tree if ref $config_tree eq 'HASH';
|
46
|
0
|
0
|
0
|
|
|
|
if (exists $settings{about}{version}
|
47
|
|
|
|
|
|
|
and $settings{about}{version} ne $Kephra::VERSION){
|
48
|
0
|
|
|
|
|
|
rename $file, $file . '.old';
|
49
|
0
|
|
|
|
|
|
%settings = %{ Kephra::Config::Tree::update(
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Kephra::Config::Default::global_settings(),
|
51
|
|
|
|
|
|
|
\%settings,
|
52
|
|
|
|
|
|
|
) };
|
53
|
0
|
|
|
|
|
|
$settings{about}{version} = $Kephra::VERSION;
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
last if %settings;
|
57
|
0
|
|
|
|
|
|
rename $file, $file . '.failed';
|
58
|
|
|
|
|
|
|
}
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
%settings
|
62
|
0
|
0
|
|
|
|
|
? evaluate()
|
63
|
|
|
|
|
|
|
: load_defaults();
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
Kephra::File::History::init();
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# are settings loaded, hist init will produce one
|
68
|
0
|
|
|
|
|
|
keys %settings;
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub autosave {
|
72
|
|
|
|
|
|
|
#$main::logger->debug("save_autosaved");
|
73
|
0
|
|
|
0
|
0
|
|
my $file_name = auto_file();
|
74
|
0
|
|
|
|
|
|
rename $file_name, $file_name . '~';
|
75
|
0
|
|
|
|
|
|
Kephra::Config::File::store( $file_name, \%settings );
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub open_current_file {
|
80
|
0
|
|
|
0
|
0
|
|
save_current();
|
81
|
0
|
|
|
|
|
|
Kephra::Config::open_file_absolute( current_file() );
|
82
|
|
|
|
|
|
|
#Kephra::File::reload_current();
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
0
|
|
sub load_backup_file { reload( auto_file() . '~' ) }
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub load_defaults {
|
88
|
0
|
|
|
0
|
0
|
|
%settings = %{ Kephra::Config::Default::global_settings() };
|
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
evaluate();
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub load_from {
|
93
|
0
|
|
|
0
|
0
|
|
my $file_name = Kephra::Dialog::get_file_open(
|
94
|
|
|
|
|
|
|
Kephra::Config::Localisation::strings()->{dialog}{config_file}{load},
|
95
|
|
|
|
|
|
|
Kephra::Config::dirpath( _sub_dir() ),
|
96
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{config}
|
97
|
|
|
|
|
|
|
);
|
98
|
0
|
0
|
|
|
|
|
reload($file_name) if -e $file_name;
|
99
|
0
|
|
|
|
|
|
current_file($file_name);
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub update {
|
103
|
0
|
|
|
0
|
0
|
|
Kephra::App::Window::save_positions();
|
104
|
0
|
|
|
|
|
|
Kephra::Document::Data::update_attributes();
|
105
|
0
|
|
|
|
|
|
Kephra::Edit::Search::save_search_data();
|
106
|
0
|
|
|
|
|
|
Kephra::App::EditPanel::Fold::store();
|
107
|
0
|
|
|
|
|
|
Kephra::App::Panel::Notepad::save();
|
108
|
0
|
|
|
|
|
|
Kephra::App::Panel::Output::save();
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub evaluate {
|
112
|
0
|
|
|
0
|
0
|
|
my $t0 = new Benchmark;
|
113
|
0
|
|
|
|
|
|
Kephra::EventTable::del_all();
|
114
|
0
|
|
|
|
|
|
Kephra::EventTable::stop_timer();
|
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $t1 = new Benchmark;
|
117
|
0
|
0
|
|
|
|
|
print " iface cnfg:", Benchmark::timestr( Benchmark::timediff( $t1, $t0 ) ), "\n"
|
118
|
|
|
|
|
|
|
if $Kephra::BENCHMARK;
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# set interna to default
|
121
|
0
|
|
|
|
|
|
$Kephra::app{GUI}{masterID} = 20;
|
122
|
0
|
|
|
|
|
|
$Kephra::temp{dialog}{control} = 0;
|
123
|
0
|
|
|
|
|
|
Kephra::Document::SyntaxMode::_ID('none');
|
124
|
0
|
|
|
|
|
|
Kephra::Edit::Search::_refresh_search_flags();
|
125
|
|
|
|
|
|
|
# delete unnecessary ecaping of vars
|
126
|
0
|
|
|
|
|
|
Kephra::API::settings()->{app}{window}{title}=~ s/\\\$/\$/g;
|
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $t2 = new Benchmark;
|
129
|
0
|
0
|
|
|
|
|
print " prep. data:", Benchmark::timestr( Benchmark::timediff( $t2, $t1 ) ), "\n"
|
130
|
|
|
|
|
|
|
if $Kephra::BENCHMARK;
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# loading interface data (localisation, menus and bar defs)
|
133
|
0
|
|
|
|
|
|
Kephra::Config::Interface::load();
|
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $t3 = new Benchmark;
|
136
|
0
|
0
|
|
|
|
|
print " create gui:", Benchmark::timestr( Benchmark::timediff( $t3, $t2 ) ), "\n"
|
137
|
|
|
|
|
|
|
if $Kephra::BENCHMARK;
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# main window components
|
140
|
0
|
|
|
|
|
|
Kephra::App::Window::apply_settings();
|
141
|
0
|
|
|
|
|
|
Kephra::App::ContextMenu::create_all();
|
142
|
0
|
|
|
|
|
|
Kephra::App::MenuBar::create();
|
143
|
0
|
|
|
|
|
|
Kephra::App::MainToolBar::show();
|
144
|
0
|
|
|
|
|
|
Kephra::App::SearchBar::create();
|
145
|
0
|
|
|
|
|
|
Kephra::App::TabBar::apply_settings();
|
146
|
0
|
|
|
|
|
|
Kephra::App::StatusBar::create();
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
Kephra::App::Panel::Notepad::create();
|
149
|
0
|
|
|
|
|
|
Kephra::App::Panel::Output::create();
|
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
Kephra::App::assemble_layout();
|
152
|
0
|
|
|
|
|
|
Kephra::Config::Interface::del_temp_data();
|
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $t4 = new Benchmark;
|
155
|
0
|
0
|
|
|
|
|
print " apply sets:", Benchmark::timestr( Benchmark::timediff( $t4, $t3 ) ), "\n"
|
156
|
|
|
|
|
|
|
if $Kephra::BENCHMARK;
|
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
Kephra::App::ContextMenu::connect_all();
|
159
|
0
|
|
|
|
|
|
Kephra::App::EditPanel::apply_settings_here();
|
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
Kephra::Config::build_fileendings2syntaxstyle_map();
|
162
|
0
|
|
|
|
|
|
Kephra::Config::build_fileendings_filterstring();
|
163
|
0
|
|
|
|
|
|
Kephra::EventTable::start_timer();
|
164
|
|
|
|
|
|
|
#todo:
|
165
|
|
|
|
|
|
|
#Kephra::EventTable::thaw_all();
|
166
|
|
|
|
|
|
|
#Kephra::App::clean_acc_table();
|
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return 1;
|
169
|
|
|
|
|
|
|
}
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub reload {
|
173
|
0
|
|
0
|
0
|
0
|
|
my $configfile = shift || current_file();
|
174
|
0
|
0
|
|
|
|
|
if ( -e $configfile ) {
|
175
|
0
|
|
|
|
|
|
Kephra::Document::Data::update_attributes();
|
176
|
0
|
|
|
|
|
|
my %test_hash = %{ Kephra::Config::File::load($configfile) };
|
|
0
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
|
if (%test_hash) {
|
178
|
0
|
|
|
|
|
|
%settings = %test_hash;
|
179
|
0
|
|
|
|
|
|
reload_tree();
|
180
|
|
|
|
|
|
|
} else {
|
181
|
0
|
|
|
|
|
|
save();
|
182
|
0
|
|
|
|
|
|
Kephra::File::reload_current();
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
} else {
|
185
|
0
|
|
|
|
|
|
my $err_msg = Kephra::Config::Localisation::strings()->{dialog}{error};
|
186
|
0
|
|
|
|
|
|
Kephra::Dialog::warning_box
|
187
|
|
|
|
|
|
|
($err_msg->{file_find} . "\n $configfile", $err_msg->{config_read} );
|
188
|
|
|
|
|
|
|
}
|
189
|
|
|
|
|
|
|
}
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub reload_tree {
|
192
|
0
|
|
|
0
|
0
|
|
update();
|
193
|
0
|
|
|
|
|
|
evaluate();
|
194
|
0
|
|
|
|
|
|
Kephra::App::TabBar::refresh_all_label();
|
195
|
0
|
|
|
|
|
|
Kephra::Document::Data::evaluate_attributes();
|
196
|
|
|
|
|
|
|
}
|
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
0
|
0
|
|
sub reload_current { reload( current_file() ) }
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub eval_config_file {
|
201
|
0
|
|
|
0
|
0
|
|
my $file_path = Kephra::Config::standartize_path_slashes( shift );
|
202
|
0
|
|
|
|
|
|
my $config_path = Kephra::Config::dirpath();
|
203
|
0
|
|
|
|
|
|
my $l_path = length $config_path;
|
204
|
0
|
0
|
|
|
|
|
if ($config_path eq substr( $file_path, 0, $l_path)){
|
205
|
0
|
|
|
|
|
|
$file_path = substr $file_path, $l_path+1;
|
206
|
|
|
|
|
|
|
}
|
207
|
0
|
|
|
|
|
|
my $conf = settings()->{app};
|
208
|
0
|
|
|
|
|
|
my $match = \&Kephra::Config::path_matches;
|
209
|
|
|
|
|
|
|
|
210
|
0
|
0
|
|
|
|
|
if ( &$match( $file_path, auto_file(),
|
211
|
|
|
|
|
|
|
$conf->{localisation_file}, $conf->{commandlist}{file} )) {
|
212
|
0
|
|
|
|
|
|
return reload();
|
213
|
|
|
|
|
|
|
}
|
214
|
0
|
0
|
|
|
|
|
if ( &$match( $file_path, $conf->{menubar}{file} ) ) {
|
215
|
0
|
|
|
|
|
|
return Kephra::App::MenuBar::create()
|
216
|
|
|
|
|
|
|
}
|
217
|
0
|
0
|
|
|
|
|
if ( &$match( $file_path, $conf->{toolbar}{main}{file} ) ) {
|
218
|
0
|
|
|
|
|
|
return Kephra::App::MainToolBar::create();
|
219
|
|
|
|
|
|
|
}
|
220
|
0
|
0
|
|
|
|
|
if ( &$match( $file_path, $conf->{toolbar}{search}{file} ) ) {
|
221
|
0
|
|
|
|
|
|
Kephra::App::SearchBar::create();
|
222
|
0
|
|
|
|
|
|
Kephra::App::SearchBar::position();
|
223
|
0
|
|
|
|
|
|
return;
|
224
|
|
|
|
|
|
|
}
|
225
|
|
|
|
|
|
|
# reload template menu wenn template file changed
|
226
|
0
|
0
|
|
|
|
|
if ( &$match($file_path, Kephra::Config::path_from_node($settings{file}{templates})) ){
|
227
|
0
|
|
|
|
|
|
return Kephra::Menu::set_absolete('insert_templates');
|
228
|
|
|
|
|
|
|
}
|
229
|
0
|
0
|
|
|
|
|
reload() if Kephra::Document::Data::get_attribute('config_file');
|
230
|
|
|
|
|
|
|
}
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
#
|
233
|
|
|
|
|
|
|
sub save {
|
234
|
0
|
|
0
|
0
|
0
|
|
my $file_name = shift || current_file();
|
235
|
0
|
|
|
|
|
|
update();
|
236
|
0
|
|
|
|
|
|
Kephra::Config::File::store( $file_name, \%settings );
|
237
|
|
|
|
|
|
|
}
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub save_as {
|
240
|
0
|
|
|
0
|
0
|
|
my $file_name = Kephra::Dialog::get_file_save(
|
241
|
|
|
|
|
|
|
Kephra::Config::Localisation::strings()->{dialog}{config_file}{save},
|
242
|
|
|
|
|
|
|
Kephra::Config::dirpath( _sub_dir() ),
|
243
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{config}
|
244
|
|
|
|
|
|
|
);
|
245
|
0
|
0
|
|
|
|
|
save($file_name) if ( length($file_name) > 0 );
|
246
|
|
|
|
|
|
|
}
|
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
0
|
0
|
|
sub save_current { save( current_file() ) }
|
249
|
|
|
|
|
|
|
#
|
250
|
|
|
|
|
|
|
sub merge_with {
|
251
|
0
|
|
|
0
|
0
|
|
my $filename = Kephra::Dialog::get_file_open(
|
252
|
|
|
|
|
|
|
Kephra::Config::Localisation::strings()->{dialog}{config_file}{load},
|
253
|
|
|
|
|
|
|
Kephra::Config::dirpath( _sub_dir(), 'sub'),
|
254
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{config}
|
255
|
|
|
|
|
|
|
);
|
256
|
0
|
|
|
|
|
|
load_subconfig($filename);
|
257
|
|
|
|
|
|
|
}
|
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
#
|
260
|
|
|
|
|
|
|
sub load_subconfig {
|
261
|
0
|
|
|
0
|
0
|
|
my $file = shift;
|
262
|
0
|
0
|
|
|
|
|
if ( -e $file ) {
|
263
|
0
|
|
|
|
|
|
merge_hash_into_settings( Kephra::Config::File::load($file) );
|
264
|
0
|
|
|
|
|
|
reload_tree();
|
265
|
|
|
|
|
|
|
}
|
266
|
|
|
|
|
|
|
}
|
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub open_templates_file {
|
269
|
0
|
|
|
0
|
0
|
|
my $config = $settings{file}{templates};
|
270
|
0
|
|
|
|
|
|
Kephra::Config::open_file( $config->{directory}, $config->{file} );
|
271
|
|
|
|
|
|
|
}
|
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1;
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
__END__
|