line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kephra::Dialog::Exit;
|
2
|
|
|
|
|
|
|
our $VERSION = '0.07';
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
999
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1240
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub save_on_exit {
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# checking settings if i should save or quit without question
|
11
|
0
|
|
|
0
|
0
|
|
my $save = Kephra::API::settings()->{file}{save}{b4_quit};
|
12
|
0
|
0
|
|
|
|
|
if ($save eq '0') { return}
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
elsif ($save eq '1') {&Kephra::File::save_all; return}
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# count unsaved dacuments?
|
16
|
0
|
|
|
|
|
|
my $unsaved_docs = 0;
|
17
|
0
|
|
|
|
|
|
for ( @{ Kephra::Document::Data::all_nr() } ) {
|
|
0
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
$unsaved_docs++ if Kephra::Document::Data::get_attribute('modified', $_)
|
19
|
|
|
|
|
|
|
}
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# if so...
|
22
|
0
|
0
|
|
|
|
|
if ($unsaved_docs) {
|
23
|
0
|
|
|
|
|
|
my $d18n = Kephra::Config::Localisation::strings()->{dialog};
|
24
|
0
|
|
|
|
|
|
my $dialog = $Kephra::app{dialog}{exit} = Wx::Dialog->new(
|
25
|
|
|
|
|
|
|
Kephra::App::Window::_ref(), -1,
|
26
|
|
|
|
|
|
|
$d18n->{file}{quit_unsaved}, [-1,-1], [-1,-1],
|
27
|
|
|
|
|
|
|
&Wx::wxNO_FULL_REPAINT_ON_RESIZE | &Wx::wxCAPTION | &Wx::wxSTAY_ON_TOP,
|
28
|
|
|
|
|
|
|
);
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# starting dialog layout
|
31
|
0
|
|
|
|
|
|
my $v_sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL);
|
32
|
0
|
|
|
|
|
|
my $h_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL);
|
33
|
0
|
|
|
|
|
|
my $button_sizer = Wx::GridSizer->new( 1, 4, 0, 25 );
|
34
|
0
|
|
|
|
|
|
my ( @temp_sizer, @check_boxes );
|
35
|
0
|
|
|
|
|
|
my ( $border, $b_border, $max_width ) = ( 10, 20, 0 );
|
36
|
0
|
|
|
|
|
|
my ( $x_size, $y_size );
|
37
|
0
|
|
|
|
|
|
my ( $file_name, $check_label );
|
38
|
0
|
|
|
|
|
|
my $align_lc = &Wx::wxLEFT | &Wx::wxALIGN_CENTER_VERTICAL;
|
39
|
0
|
|
|
|
|
|
my $l10n = Kephra::Config::Localisation::strings()->{dialog}{general};
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# generating checkbox list of unsaved files
|
42
|
0
|
|
|
|
|
|
for ( @{ Kephra::Document::Data::all_nr() } ) {
|
|
0
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ( Kephra::Document::Data::get_attribute('modified', $_) ) {
|
44
|
0
|
|
0
|
|
|
|
$file_name =
|
45
|
|
|
|
|
|
|
Kephra::Document::Data::get_file_path($_) ||
|
46
|
|
|
|
|
|
|
Kephra::Config::Localisation::strings()->{app}{general}{untitled};
|
47
|
0
|
|
|
|
|
|
$check_label = 1 + $_ . ' ' . $file_name;
|
48
|
0
|
|
|
|
|
|
$check_boxes[$_] = Wx::CheckBox->new($dialog, -1, $check_label);
|
49
|
0
|
|
|
|
|
|
$check_boxes[$_]->SetValue(1);
|
50
|
0
|
|
|
|
|
|
$temp_sizer[$_] = Wx::BoxSizer->new(&Wx::wxVERTICAL);
|
51
|
0
|
|
|
|
|
|
$temp_sizer[$_]->Add($check_boxes[$_], 0, $align_lc, $border );
|
52
|
0
|
|
|
|
|
|
$v_sizer->Add( $temp_sizer[$_], 0, &Wx::wxTOP, $border );
|
53
|
0
|
|
|
|
|
|
$temp_sizer[$_]->Fit($dialog);
|
54
|
0
|
|
|
|
|
|
( $x_size, $y_size ) = $dialog->GetSizeWH;
|
55
|
0
|
0
|
|
|
|
|
$max_width = $x_size if $x_size > $max_width;
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# seperator, label, buttons
|
60
|
0
|
|
|
|
|
|
my $base_line = Wx::StaticLine->new( $dialog, -1, [-1,-1],[2000,2], &Wx::wxLI_HORIZONTAL);
|
61
|
0
|
|
|
|
|
|
my $save_label = Wx::StaticText->new($dialog, -1, $l10n->{save} . ' : ');
|
62
|
0
|
|
|
|
|
|
$dialog->{save_all} = Wx::Button->new($dialog, -1, $l10n->{all} );
|
63
|
0
|
|
|
|
|
|
$dialog->{save_sel} = Wx::Button->new($dialog, -1, $l10n->{selected} );
|
64
|
0
|
|
|
|
|
|
$dialog->{save_none}= Wx::Button->new($dialog, -1, $l10n->{none} );
|
65
|
0
|
|
|
|
|
|
$dialog->{cancel} = Wx::Button->new($dialog, -1, $l10n->{cancel} );
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# events
|
68
|
|
|
|
|
|
|
Wx::Event::EVT_BUTTON( $dialog, $dialog->{save_all}, sub
|
69
|
0
|
|
|
0
|
|
|
{ &quit_dialog; &Kephra::File::save_all} );
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
|
|
Wx::Event::EVT_BUTTON( $dialog, $dialog->{save_sel}, sub
|
71
|
0
|
|
|
|
|
|
{&quit_dialog; save_selected(\@check_boxes)} );
|
|
0
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
|
|
Wx::Event::EVT_BUTTON( $dialog, $dialog->{save_none},sub {quit_dialog()} );
|
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Wx::Event::EVT_BUTTON( $dialog, $dialog->{cancel}, sub
|
74
|
0
|
|
|
0
|
|
|
{ &quit_dialog; $dialog->{cancel} = 1; } );
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
|
|
Wx::Event::EVT_CLOSE( $dialog, sub {quit_dialog()});
|
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# assembling the fix bottom of dialog layout
|
78
|
0
|
|
|
|
|
|
$h_sizer->Add( $save_label, 0, $align_lc, $border );
|
79
|
0
|
|
|
|
|
|
$h_sizer->Add( $dialog->{save_all}, 0, $align_lc, $border + $b_border );
|
80
|
0
|
|
|
|
|
|
$h_sizer->Add( $dialog->{save_sel}, 0, $align_lc, $b_border );
|
81
|
0
|
|
|
|
|
|
$h_sizer->Add( $dialog->{save_none}, 0, $align_lc, $b_border );
|
82
|
0
|
|
|
|
|
|
$h_sizer->Add( $dialog->{cancel}, 0, $align_lc, $b_border );
|
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$v_sizer->Add( $base_line, 0, &Wx::wxTOP | &Wx::wxCENTER, $border );
|
85
|
0
|
|
|
|
|
|
$v_sizer->Add( $h_sizer, 0, &Wx::wxTOP, $border );
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# figuring dialog size
|
88
|
0
|
|
|
|
|
|
$dialog->SetSizer($v_sizer);
|
89
|
0
|
|
|
|
|
|
$v_sizer->Fit($dialog);
|
90
|
0
|
|
|
|
|
|
( $x_size, $y_size ) = $dialog->GetSizeWH;
|
91
|
0
|
|
|
|
|
|
$h_sizer->Fit($dialog);
|
92
|
0
|
|
|
|
|
|
( $x_size, ) = $dialog->GetSizeWH;
|
93
|
0
|
0
|
|
|
|
|
$max_width = $x_size if ( $x_size > $max_width );
|
94
|
0
|
|
|
|
|
|
$dialog->SetSize( $max_width + $b_border, $y_size + $border );
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# go
|
97
|
0
|
|
|
|
|
|
$dialog->SetAutoLayout(1);
|
98
|
0
|
|
|
|
|
|
$dialog->CenterOnScreen;
|
99
|
0
|
|
|
|
|
|
$dialog->ShowModal;
|
100
|
0
|
0
|
|
|
|
|
return 'cancel' if $dialog->{cancel} == 1;
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# internal subs
|
105
|
|
|
|
|
|
|
################
|
106
|
|
|
|
|
|
|
sub save_selected {
|
107
|
0
|
|
|
0
|
0
|
|
my @check_boxes = @{ shift; };
|
|
0
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
for ( 0 .. $#check_boxes ) {
|
109
|
0
|
0
|
0
|
|
|
|
Kephra::File::_save_nr($_)
|
110
|
|
|
|
|
|
|
if ref $check_boxes[$_] ne '' and $check_boxes[$_]->GetValue;
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub quit_dialog {
|
115
|
0
|
|
|
0
|
0
|
|
my ( $win, $event ) = @_;
|
116
|
0
|
|
|
|
|
|
$Kephra::app{dialog}{exit}->Destroy;
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1;
|