| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kephra::File::Session; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
993
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
32
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3320
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# intern API |
|
8
|
0
|
|
|
0
|
|
|
sub _config { Kephra::API::settings()->{file}{session} } |
|
9
|
0
|
|
|
0
|
|
|
sub _dialog_l18n { Kephra::Config::Localisation::strings()->{dialog} } |
|
10
|
0
|
|
|
0
|
|
|
sub _saved_properties {[ qw( |
|
11
|
|
|
|
|
|
|
syntaxmode EOL codepage readonly tab_size tab_use |
|
12
|
|
|
|
|
|
|
cursor_pos edit_pos marked_lines folded_lines |
|
13
|
|
|
|
|
|
|
file_path config_file |
|
14
|
|
|
|
|
|
|
)]} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _forget_gone_files { |
|
17
|
0
|
|
|
0
|
|
|
my @true_files = (); |
|
18
|
0
|
|
|
|
|
|
my $node = shift; |
|
19
|
0
|
0
|
0
|
|
|
|
$node = $$node if ref $node eq 'REF' and ref $$node eq 'ARRAY'; |
|
20
|
0
|
0
|
|
|
|
|
if ( ref $node eq 'ARRAY' ) { |
|
21
|
0
|
|
|
|
|
|
my @files = @{$node}; |
|
|
0
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
for ( 0 .. $#files ) { |
|
23
|
0
|
0
|
0
|
|
|
|
if ( defined $files[$_]{file_path} and -e $files[$_]{file_path} ) { |
|
24
|
0
|
|
|
|
|
|
my %file_properties = %{ $files[$_] }; |
|
|
0
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
push( @true_files, \%file_properties ); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
0
|
|
|
|
|
|
return \@true_files; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _remember_directory { |
|
33
|
0
|
|
|
0
|
|
|
my ( $filename, $dir, @dirs ) = shift; |
|
34
|
0
|
0
|
|
|
|
|
if ( length($filename) > 0 ) { |
|
35
|
0
|
0
|
|
|
|
|
@dirs = split( /\\/, $filename ) if $filename =~ /\\/ ; |
|
36
|
0
|
0
|
|
|
|
|
@dirs = split( /\//, $filename ) if $filename =~ /\// ; |
|
37
|
0
|
|
|
|
|
|
$dir .= "$dirs[$_]/" for 0 .. $#dirs - 1; |
|
38
|
0
|
0
|
|
|
|
|
_config()->{dialog_dir} = $dir if $dir; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
sub _add { |
|
42
|
0
|
|
|
0
|
|
|
my $session_data = shift; # session data |
|
43
|
0
|
0
|
0
|
|
|
|
return unless %$session_data |
|
|
|
|
0
|
|
|
|
|
|
44
|
|
|
|
|
|
|
and $session_data->{document} |
|
45
|
|
|
|
|
|
|
and $session_data->{document}[0]; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my @load_files = @{Kephra::Config::Tree::_convert_node_2_AoH |
|
|
0
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
( \$session_data->{document} )}; |
|
49
|
0
|
|
|
|
|
|
@load_files = @{ _forget_gone_files( \@load_files ) }; |
|
|
0
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $start_nr = Kephra::Document::Data::current_nr(); |
|
51
|
0
|
|
|
|
|
|
my $prev_doc_nr = Kephra::Document::Data::previous_nr(); |
|
52
|
0
|
|
|
|
|
|
my $loaded = Kephra::Document::Data::get_value('loaded'); |
|
53
|
0
|
|
|
|
|
|
Kephra::Document::Data::update_attributes($start_nr); |
|
54
|
0
|
0
|
0
|
|
|
|
$start_nr = $session_data->{current_nr} |
|
|
|
|
0
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if $session_data->{current_nr} |
|
56
|
|
|
|
|
|
|
and not $loaded and Kephra::App::EditPanel::_ref()->GetText eq ''; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# open remembered files with all properties |
|
59
|
0
|
|
|
|
|
|
Kephra::Document::restore( $_ ) for @load_files; |
|
60
|
0
|
|
|
|
|
|
my $buffer = Kephra::Document::Data::get_value('buffer'); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# selecting starting doc nr |
|
63
|
0
|
0
|
0
|
|
|
|
$start_nr = 0 if (not defined $start_nr) or ($start_nr < 0 ); |
|
64
|
0
|
0
|
|
|
|
|
$start_nr = $buffer - 1 if $start_nr >= $buffer; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# activate the starting document & some afterwork |
|
67
|
0
|
|
|
|
|
|
Kephra::Document::Change::to_number($start_nr); |
|
68
|
0
|
|
|
|
|
|
Kephra::Document::Data::set_previous_nr($prev_doc_nr); |
|
69
|
0
|
|
|
|
|
|
Kephra::App::Window::refresh_title(); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
# |
|
72
|
|
|
|
|
|
|
# extern API |
|
73
|
|
|
|
|
|
|
# |
|
74
|
|
|
|
|
|
|
sub restore { |
|
75
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
|
76
|
0
|
0
|
|
|
|
|
return unless -e $file; |
|
77
|
0
|
|
|
|
|
|
Kephra::File::close_all(); |
|
78
|
0
|
|
|
|
|
|
add($file); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub restore_from { # |
|
82
|
0
|
|
|
0
|
0
|
|
my $file = Kephra::Dialog::get_file_open( |
|
83
|
|
|
|
|
|
|
_dialog_l18n()->{file}{open_session}, |
|
84
|
|
|
|
|
|
|
Kephra::Config::filepath( _config->{directory} |
|
85
|
|
|
|
|
|
|
), $Kephra::temp{file}{filterstring}{config} |
|
86
|
|
|
|
|
|
|
); |
|
87
|
0
|
|
|
|
|
|
restore($file); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub add { |
|
91
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
|
92
|
0
|
|
|
|
|
|
my $restore = shift; |
|
93
|
0
|
0
|
|
|
|
|
if (-r $file) { |
|
94
|
0
|
|
|
|
|
|
my $session_def = Kephra::Config::File::load($file); |
|
95
|
0
|
0
|
|
|
|
|
if (ref $session_def eq 'HASH'){ |
|
96
|
0
|
|
|
|
|
|
_add($session_def); |
|
97
|
|
|
|
|
|
|
} else { |
|
98
|
0
|
|
|
|
|
|
Kephra::Dialog::warning_box($file, _dialog_l18n()->{error}{config_parse}); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} else { |
|
101
|
0
|
|
|
|
|
|
Kephra::Dialog::warning_box($file, _dialog_l18n()->{error}{file_read}); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub add_from { |
|
106
|
0
|
|
|
0
|
0
|
|
my $file = Kephra::Dialog::get_file_open( |
|
107
|
|
|
|
|
|
|
_dialog_l18n()->{file}{add_session}, |
|
108
|
|
|
|
|
|
|
Kephra::Config::filepath( _config->{directory} ), |
|
109
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{config} |
|
110
|
|
|
|
|
|
|
); |
|
111
|
0
|
|
|
|
|
|
add($file); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub save { |
|
115
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
|
116
|
0
|
0
|
|
|
|
|
return unless $file; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
Kephra::Config::Global::update(); |
|
119
|
0
|
|
|
|
|
|
my $doc2vis = \&Kephra::App::TabBar::_doc2vis_pos; |
|
120
|
0
|
|
|
|
|
|
my $config = _config(); |
|
121
|
0
|
0
|
|
|
|
|
my %temp_config = %{ Kephra::Config::File::load($file) } if -r $file; |
|
|
0
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$temp_config{current_nr} = $doc2vis->(Kephra::Document::Data::current_nr()); |
|
123
|
0
|
|
|
|
|
|
$temp_config{document} = []; |
|
124
|
0
|
|
|
|
|
|
my @doc_list = @{ Kephra::Document::Data::_attributes() }; |
|
|
0
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
for my $nr (0 .. $#doc_list) { |
|
126
|
0
|
|
|
|
|
|
my $vis_pos = $doc2vis->($nr); |
|
127
|
0
|
|
|
|
|
|
$temp_config{document}[$vis_pos]{$_} = $doc_list[$nr]{$_} |
|
128
|
0
|
|
|
|
|
|
for @{ _saved_properties() }; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
0
|
|
|
|
|
|
@{ $temp_config{document} } = @{ _forget_gone_files( \$temp_config{document} ) }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
Kephra::Config::File::store( $file, \%temp_config ); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub save_as { |
|
135
|
0
|
|
|
0
|
0
|
|
my $file_name = Kephra::Dialog::get_file_save( |
|
136
|
|
|
|
|
|
|
_dialog_l18n()->{file}{save_session}, |
|
137
|
|
|
|
|
|
|
Kephra::Config::filepath( _config->{directory} ), |
|
138
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{config} |
|
139
|
|
|
|
|
|
|
); |
|
140
|
0
|
0
|
|
|
|
|
if ( length($file_name) > 0 ) { |
|
141
|
0
|
|
|
|
|
|
save( $file_name, "files" ); |
|
142
|
0
|
|
|
|
|
|
_remember_directory($file_name); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
# default session handling |
|
146
|
|
|
|
|
|
|
sub do_autosave { # answers if autosave is turned on by config settings |
|
147
|
0
|
|
|
0
|
0
|
|
my $config = _config()->{auto}{save}; |
|
148
|
0
|
0
|
0
|
|
|
|
return 1 if defined $config and $config and not $config eq 'not'; |
|
|
|
|
0
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return 0; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
sub autoload { # restore session that was opened while last app shut down |
|
152
|
0
|
0
|
|
0
|
0
|
|
if ( do_autosave() ) { |
|
153
|
0
|
|
|
|
|
|
my $config = _config(); |
|
154
|
0
|
|
|
|
|
|
my $session_file = Kephra::Config::filepath |
|
155
|
|
|
|
|
|
|
( $config->{directory}, $config->{auto}{file} ); |
|
156
|
0
|
|
|
|
|
|
restore($session_file); |
|
157
|
0
|
|
|
|
|
|
} else { Kephra::Document::reset() } |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
sub autosave { |
|
160
|
0
|
|
|
0
|
0
|
|
my $config = _config(); |
|
161
|
0
|
|
|
|
|
|
my $file = Kephra::Config::filepath($config->{directory}, $config->{auto}{file}); |
|
162
|
0
|
0
|
|
|
|
|
save( $file ) if do_autosave(); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
# backup session handling |
|
165
|
|
|
|
|
|
|
sub load_backup { |
|
166
|
0
|
|
|
0
|
0
|
|
my $config = _config(); |
|
167
|
0
|
|
|
|
|
|
restore( Kephra::Config::filepath( $config->{directory}, $config->{backup} ) ); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub save_backup { |
|
171
|
0
|
|
|
0
|
0
|
|
my $config = _config(); |
|
172
|
0
|
|
|
|
|
|
save( Kephra::Config::filepath( $config->{directory}, $config->{backup} ) ); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
# other session formats |
|
175
|
|
|
|
|
|
|
sub import_scite { |
|
176
|
0
|
|
|
0
|
0
|
|
my $err_msg = _dialog_l18n()->{error}; |
|
177
|
0
|
|
|
|
|
|
my $file = Kephra::Dialog::get_file_open ( |
|
178
|
|
|
|
|
|
|
_dialog_l18n()->{file}{open_session}, |
|
179
|
|
|
|
|
|
|
$Kephra::temp{path}{config}, |
|
180
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{scite} |
|
181
|
|
|
|
|
|
|
); |
|
182
|
0
|
0
|
|
|
|
|
if ( -r $file ) { |
|
183
|
0
|
0
|
|
|
|
|
if ( open my $FH, '<', $file ) { |
|
184
|
0
|
|
|
|
|
|
my @load_files; |
|
185
|
0
|
|
|
|
|
|
my ( $start_file_nr, $file_nr ); |
|
186
|
0
|
|
|
|
|
|
while (<$FH>) { |
|
187
|
0
|
|
|
|
|
|
m/ (.+)/; |
|
188
|
0
|
0
|
|
|
|
|
if ( -e $3 ) { |
|
189
|
0
|
0
|
|
|
|
|
$start_file_nr = $file_nr if $1; |
|
190
|
0
|
|
|
|
|
|
$load_files[$file_nr]{cursor_pos} = $2; |
|
191
|
0
|
|
|
|
|
|
$load_files[$file_nr++]{file_path} = $3; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
} |
|
194
|
0
|
0
|
|
|
|
|
if (@load_files) { |
|
195
|
0
|
|
|
|
|
|
&Kephra::File::close_all; |
|
196
|
0
|
|
|
|
|
|
for (@load_files) { |
|
197
|
0
|
|
|
|
|
|
Kephra::Document::add( ${$_}{file_path} ); |
|
|
0
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
Kephra::Edit::_goto_pos( ${$_}{cursor_pos} ); |
|
|
0
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
} |
|
200
|
0
|
|
|
|
|
|
Kephra::Document::Change::to_number($start_file_nr); |
|
201
|
0
|
|
|
|
|
|
$Kephra::document{previous_nr} = $start_file_nr; |
|
202
|
|
|
|
|
|
|
} else { |
|
203
|
0
|
|
|
|
|
|
Kephra::Dialog::warning_box($file, $err_msg->{config_parse}); |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
} else { |
|
206
|
0
|
|
|
|
|
|
Kephra::Dialog::warning_box |
|
207
|
|
|
|
|
|
|
($err_msg->{file_read}." $file", $err_msg->{file}); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub export_scite { |
|
213
|
0
|
|
|
0
|
0
|
|
my $win = Kephra::App::Window::_ref(); |
|
214
|
0
|
|
|
|
|
|
my $file = Kephra::Dialog::get_file_save( |
|
215
|
|
|
|
|
|
|
_dialog_l18n()->{file}{save_session}, |
|
216
|
|
|
|
|
|
|
$Kephra::temp{path}{config}, |
|
217
|
|
|
|
|
|
|
$Kephra::temp{file}{filterstring}{scite} |
|
218
|
|
|
|
|
|
|
); |
|
219
|
0
|
0
|
|
|
|
|
if ( length($file) > 0 ) { |
|
220
|
0
|
0
|
|
|
|
|
if ( open my $FH, '>', $file ) { |
|
221
|
0
|
|
|
|
|
|
my $current = Kephra::Document::Data::current_nr(); |
|
222
|
0
|
|
|
|
|
|
my $output; |
|
223
|
0
|
|
|
|
|
|
for ( @{ Kephra::Document::Data::all_nr() } ) { |
|
|
0
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
my %file_attr = %{ Kephra::Document::Data::_hash($_) }; |
|
|
0
|
|
|
|
|
|
|
|
225
|
0
|
0
|
|
|
|
|
if ( -e $file_attr{file_path} ) { |
|
226
|
0
|
|
|
|
|
|
$output .= "
|
|
227
|
0
|
0
|
|
|
|
|
$output .= "-" if $_ == $current; |
|
228
|
0
|
|
|
|
|
|
$output .= "$file_attr{cursor_pos}> $file_attr{file_path}\n"; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
} |
|
231
|
0
|
|
|
|
|
|
print $FH $output; |
|
232
|
|
|
|
|
|
|
} else { |
|
233
|
0
|
|
|
|
|
|
my $err_msg = _dialog_l18n()->{error}; |
|
234
|
0
|
|
|
|
|
|
Kephra::Dialog::warning_box |
|
235
|
|
|
|
|
|
|
($err_msg->{file_write}." $file", $err_msg->{file} ); |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
1; |