File Coverage

lib/Kephra/Dialog/Notify.pm
Criterion Covered Total %
statement 6 78 7.6
branch n/a
condition 0 2 0.0
subroutine 2 14 14.2
pod 0 5 0.0
total 8 99 8.0


line stmt bran cond sub pod time code
1             package Kephra::Dialog::Notify;
2             our $VERSION = '0.06';
3            
4 1     1   1980 use strict;
  1         2  
  1         36  
5 1     1   6 use warnings;
  1         1  
  1         1329  
6            
7             our $dialog;
8            
9             sub file_changed {
10 0     0 0   my $file_nr = shift;#Kephra::Document::Data::current_nr();
11 0           my $file_path = Kephra::Document::Data::get_attribute('file_path', $file_nr);
12 0           my $file_name = Kephra::Document::Data::get_attribute('name', $file_nr);
13 0           my $d10n = Kephra::Config::Localisation::strings()->{dialog};
14 0           my $g10n = $d10n->{general};
15            
16             #$Kephra::app{dialog}{notify}{changed}
17 0           $dialog = create_raw_dialog(3);
18 0           $dialog->SetTitle($file_name . ' ' . $g10n->{changed});
19 0           $dialog->{msg}->SetLabel( $d10n->{file}{file_changed_msg} );
20 0           $dialog->{filename}->SetValue($file_path);
21 0           $dialog->{btn}{1}->SetLabel( $g10n->{reload});
22 0           $dialog->{btn}{2}->SetLabel( $g10n->{save_reload} );
23 0           $dialog->{btn}{3}->SetLabel( $g10n->{ignore} );
24             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{1}, sub {
25 0     0     quit_dialog();
26 0           Kephra::File::reload_current();
27 0           } );
28             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{2}, sub {
29 0     0     quit_dialog();
30 0           Kephra::File::save_copy_as();
31 0           Kephra::File::reload_current()
32 0           } );
33             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{3}, sub {
34 0     0     quit_dialog();
35 0           } );
36             #Kephra::Document::Data::get_attribute('did_notify', 'ignore', $file_nr);
37 0           ready_dialog($dialog);
38             }
39            
40             sub file_deleted {
41 0     0 0   my $file_nr = shift;#Kephra::Document::current_nr();
42 0           my $file_path = Kephra::Document::Data::get_attribute('file_path', $file_nr);
43 0           my $file_name = Kephra::Document::Data::get_attribute('name', $file_nr);
44 0           my $d10n = Kephra::Config::Localisation::strings()->{dialog};
45 0           my $g10n = $d10n->{general};
46            
47             # $Kephra::app{dialog}{notify}{deleted}
48 0           $dialog = create_raw_dialog(4);
49 0           $dialog->{msg}->SetLabel( $d10n->{file}{file_deleted_msg} );
50 0           $dialog->{btn}{1}->SetLabel( $g10n->{close});
51 0           $dialog->{btn}{2}->SetLabel( $d10n->{file}{save_as} );
52 0           $dialog->{btn}{3}->SetLabel( $g10n->{save} );
53 0           $dialog->{btn}{4}->SetLabel( $g10n->{ignore} );
54             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{1}, sub {
55 0     0     quit_dialog(); Kephra::File::close_current_unsaved()
  0            
56 0           } );
57             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{2}, sub {
58 0     0     quit_dialog(); Kephra::File::save_as()
  0            
59 0           } );
60             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{3}, sub {
61 0     0     quit_dialog(); Kephra::File::save_current()
  0            
62 0           } );
63 0           $dialog->SetTitle($file_name . ' ' . $g10n->{deleted});
64 0           $dialog->{filename}->SetValue($file_path);
65             Wx::Event::EVT_BUTTON($dialog, $dialog->{btn}{4}, sub {
66 0     0     quit_dialog();
67 0           Kephra::Document::Data::set_attribute('did_notify', 'ignore', $file_nr);
68 0           } );
69 0           ready_dialog($dialog);
70             }
71            
72             sub create_raw_dialog {
73 0   0 0 0   my $btn_count = shift || 3;
74 0           my $dialog = Wx::Dialog->new(
75             Kephra::App::Window::_ref(), -1, '', [-1,-1], [361, 145],
76             &Wx::wxNO_FULL_REPAINT_ON_RESIZE | &Wx::wxSTAY_ON_TOP |
77             &Wx::wxSYSTEM_MENU | &Wx::wxCAPTION | &Wx::wxCLOSE_BOX ,
78             );
79 0           Kephra::App::Window::load_icon
80             ($dialog, Kephra::Config::filepath
81             (Kephra::API::settings()->{app}{window}{icon}));
82             #$dialog->SetBackgroundColour(&Wx::wxWHITE);
83 0           Wx::Event::EVT_CLOSE( $dialog, \&quit_dialog );
84            
85             # starting dialog layout
86 0           my $h_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL);
87 0           $dialog->{btn}{1} = Wx::Button->new( $dialog, -1, '' );
88 0           $h_sizer->Add( $dialog->{btn}{1} ,0, &Wx::wxLEFT, 0);
89 0           for my $btn_nr (2 .. $btn_count) {
90 0           $dialog->{btn}{$btn_nr} = Wx::Button->new( $dialog, -1, '' );
91 0           $h_sizer->Add( $dialog->{btn}{$btn_nr} ,0, &Wx::wxLEFT, 10);
92             }
93            
94 0           $dialog->{msg} = Wx::StaticText->new($dialog, -1, '');
95 0           $dialog->{filename} = Wx::TextCtrl->new
96             ( $dialog,-1, '', [-1,-1], [-1,-1], &Wx::wxTE_READONLY | &Wx::wxTE_CENTRE );
97 0           my $v_sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL);
98 0           $v_sizer->Add( $dialog->{msg} ,1, &Wx::wxCENTER | &Wx::wxTOP , 10 );
99 0           $v_sizer->Add( $dialog->{filename},0, &Wx::wxCENTER | &Wx::wxBOTTOM | &Wx::wxGROW, 10 );
100 0           $v_sizer->Add( $h_sizer ,0, &Wx::wxALL | &Wx::wxALIGN_CENTER_HORIZONTAL, 10 );
101            
102 0           $dialog->SetSizer($v_sizer);
103 0           return $dialog;
104             }
105            
106             sub ready_dialog {
107 0     0 0   $dialog = shift;
108 0           $dialog->SetAutoLayout(1);
109 0           $dialog->CenterOnScreen;
110 0           $dialog->ShowModal; #$v_sizer->Fit($dialog);
111             }
112            
113             sub quit_dialog {
114 0     0 0   my ( $win, $event ) = @_;
115 0           $dialog->Destroy();
116             }
117            
118             1;