| 1 | ################################################################################ | ||
| 2 | # This is CodeManager | ||
| 3 | # Copyright 2009-2013 by Waldemar Biernacki | ||
| 4 | # http://codemanager.sao.pl\n" . | ||
| 5 | # | ||
| 6 | # License statement: | ||
| 7 | # | ||
| 8 | # This program/library is free software; you can redistribute it | ||
| 9 | # and/or modify it under the same terms as Perl itself. | ||
| 10 | # | ||
| 11 | # Last modified (DMYhms): 14-01-2013 07:15:49. | ||
| 12 | ################################################################################ | ||
| 13 | |||
| 14 | package Prima::CodeManager::File; | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use warnings; | ||
| 18 | |||
| 19 | use File::Copy; | ||
| 20 | |||
| 21 | use Prima::CodeManager::Edit; | ||
| 22 | use Prima::CodeManager::Label; | ||
| 23 | |||
| 24 | my $findData; | ||
| 25 | |||
| 26 | #------------------------------------------------------------------------------- | ||
| 27 | |||
| 28 | eval "use Encode;"; | ||
| 29 | |||
| 30 | ################################################################################ | ||
| 31 | |||
| 32 | sub file_new | ||
| 33 | { | ||
| 34 | my ( $self ) = @_; | ||
| 35 | $self-> file_edit ( './.Untitled' ); | ||
| 36 | } | ||
| 37 | |||
| 38 | ################################################################################ | ||
| 39 | |||
| 40 | sub file_open | ||
| 41 | { | ||
| 42 | my ( $self ) = @_; | ||
| 43 | |||
| 44 | my @filtr; | ||
| 45 | push @filtr, [ "All" => "*" ]; | ||
| 46 | my @ext = split /\|/, $self->{global}->{extensions}; | ||
| 47 | for ( @ext ) { | ||
| 48 | push @filtr, [ "type $_" => "*.$_" ] if $_ !~ /all/i | ||
| 49 | } | ||
| 50 | my $nr = $Prima::CodeManager::developer{notes}-> pageIndex; | ||
| 51 | my $dire_name = '.'; | ||
| 52 | my $file_name = $Prima::CodeManager::list_of_files[ $nr ] || ''; | ||
| 53 | if ( $file_name =~ /^(.*)([\\\/]+)([^\\\/]*)$/ ) { | ||
| 54 | $dire_name = $1; | ||
| 55 | $file_name = $3; | ||
| 56 | } | ||
| 57 | my $open = Prima::OpenDialog-> new( | ||
| 58 | filter => [ @filtr ], | ||
| 59 | directory => $dire_name, | ||
| 60 | fileName => $file_name, | ||
| 61 | system => 0, | ||
| 62 | font => { | ||
| 63 | name => 'DejaVu Sans Mono', | ||
| 64 | size => 9, | ||
| 65 | style => fs::Normal, | ||
| 66 | }, | ||
| 67 | ); | ||
| 68 | if ( $open-> execute() ) { | ||
| 69 | my $fn = $open-> fileName(); | ||
| 70 | $self-> file_edit( $fn ) if -f $fn; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | ################################################################################ | ||
| 75 | |||
| 76 | sub file_edit | ||
| 77 | { | ||
| 78 | my ( $self, $file, $branch ) = @_; | ||
| 79 | |||
| 80 | my $ext = ''; $ext = lc($1) if $file =~ /\.(\w+)$/; | ||
| 81 | |||
| 82 | if ( $self->{global}->{EXTERNAL_EDITORS}{$ext} ) { | ||
| 83 | if ( $self->{global}->{EXTERNAL_EDITORS}{$ext} =~ /no edit!/ ) { | ||
| 84 | Prima::MsgBox::message_box ( | ||
| 85 | 'File edition', | ||
| 86 | "Sorry! This file is not presumed for edition: $file", mb::OK ); | ||
| 87 | return; | ||
| 88 | } | ||
| 89 | my $editor = $self->{global}->{EXTERNAL_EDITORS}{$ext}; | ||
| 90 | my $error = eval { system( $editor, $file ) }; | ||
| 91 | if ( $error ) { | ||
| 92 | Prima::MsgBox::message_box ( | ||
| 93 | 'Error calling external editor!', | ||
| 94 | "Sorry! I have a problem with the command:\n\n$editor $file\n\nError: $!", | ||
| 95 | |||
| 96 | mb::Cancel | ||
| 97 | ); | ||
| 98 | } | ||
| 99 | |||
| 100 | return; | ||
| 101 | } | ||
| 102 | |||
| 103 | $branch ||= 0; | ||
| 104 | unless ( $Prima::CodeManager::all_extensions{$ext} ) { | ||
| 105 | |||
| 106 | Prima::MsgBox::message_box ( | ||
| 107 | 'Unknown file type in the current project!', | ||
| 108 | "Sorry! I do not know how display the file - unknown type: $ext", mb::OK | ||
| 109 | ); | ||
| 110 | $ext = 'pl'; | ||
| 111 | } | ||
| 112 | my $short_file = $file; | ||
| 113 | if ( $Prima::CodeManager::info_of_files{$file}->{exists} ) { | ||
| 114 | for ( my $i = 0; $i < @Prima::CodeManager::list_of_files; $i++ ) { | ||
| 115 | if ( $Prima::CodeManager::list_of_files[$i] eq $file ) { | ||
| 116 | $Prima::CodeManager::developer{notes}-> pageIndex( $i ) ; | ||
| 117 | $Prima::CodeManager::developer{"notes_$i"}-> focus ; | ||
| 118 | return; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | my ( $type_dimen, $font_dimen ) = ( 'size', 10 ); | ||
| 124 | if ( $self->{global}->{GLOBAL}{editor_fontHeight} && $self->{global}->{GLOBAL}{editor_fontHeight} > 0 ) { | ||
| 125 | |||
| 126 | $type_dimen = 'height'; | ||
| 127 | $font_dimen = $self->{global}->{GLOBAL}{editor_fontHeight}; | ||
| 128 | |||
| 129 | } elsif ( $self->{global}->{GLOBAL}{editor_fontSize} && $self->{global}->{GLOBAL}{editor_fontSize}> 0 ) { | ||
| 130 | |||
| 131 | $type_dimen = 'size'; | ||
| 132 | $font_dimen = $self->{global}->{GLOBAL}{editor_fontSize}; | ||
| 133 | } | ||
| 134 | |||
| 135 | $self->{global}->{GLOBAL}{editor_fontName} ||= 'DejaVu Sans Mono'; | ||
| 136 | $self->{global}->{GLOBAL}{editor_backColor} ||= 0xffffff; | ||
| 137 | $self->{global}->{GLOBAL}{editor_lineSpace} ||= 0; | ||
| 138 | |||
| 139 | my $cap = ''; | ||
| 140 | if ( $file && -e $file) { | ||
| 141 | my $encoding = $self->{global}->{DIRECTORY}->{"encoding_$branch"} || $self->{global}->{GLOBAL}->{CodeManager_encoding}; | ||
| 142 | $Prima::CodeManager::file_encodings{$file} = $encoding; | ||
| 143 | my $reading_parameters = $encoding ? ":encoding($encoding)" : ''; | ||
| 144 | if ( CORE::open ( my $FH, "<$reading_parameters", $file )) { | ||
| 145 | if ( ! defined read( $FH, $cap, -s $file)) { | ||
| 146 | Prima::MsgBox::message("Cannot read file $file:$!"); | ||
| 147 | $file = undef; | ||
| 148 | } | ||
| 149 | CORE::close $FH; | ||
| 150 | } | ||
| 151 | $cap =~ s/\r\n/\n/g; | ||
| 152 | $cap =~ s/\r/\n/g; | ||
| 153 | } | ||
| 154 | my $type = 'nil'; | ||
| 155 | $type = lc($1) if $file =~ /\.(\w+)$/; | ||
| 156 | $type = 'pl' if $type eq 'pm' || !$Prima::CodeManager::all_extensions{$type}; | ||
| 157 | # my @ext = split /\|/, $self->{global}->{extensions}; | ||
| 158 | # for ( @ext ) { | ||
| 159 | eval( $self->read_file( "$Prima::CodeManager::CodeManager_directory/hilite/hilite_$type.pl")) if -f "$Prima::CodeManager::CodeManager_directory/hilite/hilite_$type.pl"; | ||
| 160 | $::hilite{"rexp_$type"} = [] unless $::hilite{"rexp_$type"}; | ||
| 161 | $::hilite{"case_$type"} = 0 unless $::hilite{"case_$type"}; | ||
| 162 | $::hilite{"styl_$type"} = 0 unless $::hilite{"styl_$type"}; | ||
| 163 | $::hilite{"blok_$type"} = [] unless $::hilite{"blok_$type"}; | ||
| 164 | # } | ||
| 165 | push @Prima::CodeManager::list_of_files, ( $short_file ); | ||
| 166 | # $Prima::CodeManager::info_of_files{$file}->{backColor} = | ||
| 167 | # $Prima::CodeManager::warpColors[ $Prima::CodeManager::file_number % scalar @Prima::CodeManager::warpColors ]; | ||
| 168 | |||
| 169 | $Prima::CodeManager::info_of_files{$file}->{backColor} = | ||
| 170 | Prima::CodeManager::Misc::angle_color(undef,int(rand(360)), 250,150 ); | ||
| 171 | |||
| 172 | # Prima::CodeManager::Misc::licz_kolor ( | ||
| 173 | # undef, | ||
| 174 | # 0xffffff, | ||
| 175 | # Prima::CodeManager::Misc::angle_color(undef,int(rand(360)), 255, 200 ), | ||
| 176 | # 0 | ||
| 177 | # ); | ||
| 178 | |||
| 179 | $Prima::CodeManager::file_number++; | ||
| 180 | my $pageCount = $Prima::CodeManager::developer{notes}->pageCount; | ||
| 181 | $pageCount = 0 unless $pageCount; | ||
| 182 | $Prima::CodeManager::developer{notes}->set_tabs( @Prima::CodeManager::list_of_files ); | ||
| 183 | |||
| 184 | Prima::CodeManager::Notebook::insert_page( $Prima::CodeManager::developer{notes}, $pageCount ); | ||
| 185 | my $kolor_paska = $self->licz_kolor( 0xffffff, $Prima::CodeManager::info_of_files{$file}->{backColor} , 0.75 ); | ||
| 186 | my $kolor_posre = $self->licz_kolor( $kolor_paska, 0x888888, 0.5 ); | ||
| 187 | my $szer = 5; | ||
| 188 | for ( my $k = 0; $k <= $szer; $k++ ) { | ||
| 189 | $Prima::CodeManager::developer{ "space_$pageCount-$k-1" } = $Prima::CodeManager::developer{notes}->insert_to_page ( | ||
| 190 | $pageCount, | ||
| 191 | Label => | ||
| 192 | text => '', | ||
| 193 | backColor => $self->licz_kolor( | ||
| 194 | $kolor_paska, | ||
| 195 | $Prima::CodeManager::info_of_files{$file}->{backColor}, | ||
| 196 | ($szer-$k)/$szer | ||
| 197 | ), | ||
| 198 | light3DColor => 0x000000, | ||
| 199 | dark3DColor => 0x000000, | ||
| 200 | borderWidth => 0, | ||
| 201 | autoWidth => 0, | ||
| 202 | place => { | ||
| 203 | x => 55 - $szer + $k, relx => 0.0, width => 1, relwidth => 0, | ||
| 204 | y => 0, rely => 0.5, height => 0, relheight => 1, | ||
| 205 | }, | ||
| 206 | ); | ||
| 207 | $Prima::CodeManager::developer{ "space_$pageCount-$k-2" } = $Prima::CodeManager::developer{notes}->insert_to_page( | ||
| 208 | $pageCount, | ||
| 209 | Label => | ||
| 210 | text => '', | ||
| 211 | backColor => $self->licz_kolor( | ||
| 212 | $Prima::CodeManager::info_of_files{$file}->{backColor}, | ||
| 213 | $self->{global}->{GLOBAL}{editor_backColor}, | ||
| 214 | ($szer-$k)/$szer, | ||
| 215 | ), | ||
| 216 | light3DColor=> 0x000000, | ||
| 217 | dark3DColor => 0x000000, | ||
| 218 | borderWidth => 0, | ||
| 219 | autoWidth => 0, | ||
| 220 | place => { | ||
| 221 | x => 67 - 2*$szer + 2*$k, relx => 0.0, width => 2, relwidth => 0, | ||
| 222 | y => 0, rely => 0.5, height => 0, relheight => 1, | ||
| 223 | }, | ||
| 224 | ); | ||
| 225 | } | ||
| 226 | |||
| 227 | $Prima::CodeManager::developer{ "numer_$pageCount" } = $Prima::CodeManager::developer{notes}->insert_to_page( | ||
| 228 | $pageCount, | ||
| 229 | 'CodeManager::Label' => | ||
| 230 | text => '', | ||
| 231 | backColor => $kolor_paska, | ||
| 232 | light3DColor => 0x000000, | ||
| 233 | dark3DColor => 0x000000, | ||
| 234 | borderWidth => 0, | ||
| 235 | alignment => ta::Right, | ||
| 236 | autoWidth => 0, | ||
| 237 | lineSpace => $self->{global}->{GLOBAL}{editor_lineSpace}, | ||
| 238 | place => { | ||
| 239 | x => 25, relx => 0.0, width => 50, relwidth => 0, | ||
| 240 | y => 0, rely => 0.5, height => 0, relheight => 1, | ||
| 241 | }, | ||
| 242 | font => { | ||
| 243 | name => $self->{global}->{GLOBAL}{editor_fontName}, | ||
| 244 | $type_dimen => $font_dimen, | ||
| 245 | style => fs::Normal, | ||
| 246 | }, | ||
| 247 | ); | ||
| 248 | |||
| 249 | $Prima::CodeManager::developer{ "notes_$pageCount" } = $Prima::CodeManager::developer{notes}->insert_to_page( | ||
| 250 | $pageCount, | ||
| 251 | 'CodeManager::Edit' => | ||
| 252 | name => "Edit_$pageCount", | ||
| 253 | title => $file, | ||
| 254 | textRef => \$cap, | ||
| 255 | hScroll => 1, | ||
| 256 | vScroll => 1, | ||
| 257 | tabIndent => 4, | ||
| 258 | syntaxHilite => 1, | ||
| 259 | hiliteREs => $::hilite{"rexp_$type"}, | ||
| 260 | hiliteCase => $::hilite{"case_$type"}, | ||
| 261 | hiliteStyl => $::hilite{"styl_$type"}, | ||
| 262 | hiliteBlok => $::hilite{"blok_$type"}, | ||
| 263 | exportHTML => 0, | ||
| 264 | backColor => $self->{global}->{GLOBAL}{editor_backColor}, | ||
| 265 | borderWidth => 0, | ||
| 266 | cursorWrap => 1, | ||
| 267 | scope => fds::Cursor, | ||
| 268 | lineSpace => $self->{global}->{GLOBAL}{editor_lineSpace}, | ||
| 269 | wheelRows => 5, | ||
| 270 | place => { | ||
| 271 | x => 33, relx => 0.5, width =>-66, relwidth => 1, | ||
| 272 | y => 0, rely => 0.5, height =>0, relheight => 1, | ||
| 273 | }, | ||
| 274 | font => { | ||
| 275 | name => $self->{global}->{GLOBAL}{editor_fontName}, | ||
| 276 | $type_dimen => $font_dimen, | ||
| 277 | # name => $fontName, | ||
| 278 | # size => $fontSize, | ||
| 279 | style => fs::Normal, | ||
| 280 | }, | ||
| 281 | ); | ||
| 282 | |||
| 283 | $Prima::CodeManager::info_of_files{$file}->{exists} = 1; | ||
| 284 | $Prima::CodeManager::developer{notes}-> tabIndex($pageCount); | ||
| 285 | $Prima::CodeManager::developer{"notes_$pageCount"}-> focus; | ||
| 286 | |||
| 287 | } | ||
| 288 | |||
| 289 | ######################################################################################## | ||
| 290 | |||
| 291 | sub file_close | ||
| 292 | { | ||
| 293 | my ( $self ) = ( shift ); | ||
| 294 | |||
| 295 | my $nr = $Prima::CodeManager::developer{notes}-> pageIndex; | ||
| 296 | if ( $nr >= 0 ) { | ||
| 297 | if ( $Prima::CodeManager::developer{ "notes_$nr" }-> modified) { | ||
| 298 | my $r = Prima::MsgBox::message_box ( | ||
| 299 | 'File not saved! ', | ||
| 300 | 'File '.$Prima::CodeManager::list_of_files[$nr].' has been modified. Save?', mb::YesNoCancel | mb::Warning | ||
| 301 | ); | ||
| 302 | $self-> clear_event, return if mb::Cancel == $r; | ||
| 303 | $self-> clear_event, return unless $self->file_save_batch( $nr ); | ||
| 304 | } | ||
| 305 | |||
| 306 | $Prima::CodeManager::developer{notes}-> tabIndex($nr); | ||
| 307 | for ( my $i = $nr; $i < $Prima::CodeManager::developer{notes}->pageCount - 1; $i++ ) { | ||
| 308 | for ( $Prima::CodeManager::developer{notes}-> widgets_from_page( $i ) ) { | ||
| 309 | $Prima::CodeManager::developer{notes}-> delete_widget ( $_ ); | ||
| 310 | } | ||
| 311 | my $hn = $i + 1; | ||
| 312 | for ( $Prima::CodeManager::developer{notes}-> widgets_from_page( $hn ) ) { | ||
| 313 | $Prima::CodeManager::developer{notes}-> move_widget ( $_, $i ); | ||
| 314 | $Prima::CodeManager::developer{notes}-> widget_set( $_, | ||
| 315 | visible => 1, | ||
| 316 | autoEnableChildren => 1, | ||
| 317 | enabled => 1, | ||
| 318 | geometry => gt::Default, | ||
| 319 | ); | ||
| 320 | my $k = 0; | ||
| 321 | while ( $Prima::CodeManager::developer{ "space_$i-$k-1" } ) { | ||
| 322 | $Prima::CodeManager::developer{ "space_$i-$k-1" } = $Prima::CodeManager::developer{ "space_$hn-$k-1" }; | ||
| 323 | $Prima::CodeManager::developer{ "space_$i-$k-2" } = $Prima::CodeManager::developer{ "space_$hn-$k-2" }; | ||
| 324 | $k++; | ||
| 325 | } | ||
| 326 | $Prima::CodeManager::developer{ "numer_$i" } = $Prima::CodeManager::developer{ "numer_$hn" }; | ||
| 327 | $Prima::CodeManager::developer{ "notes_$i" } = $Prima::CodeManager::developer{ "notes_$hn" }; | ||
| 328 | } | ||
| 329 | } | ||
| 330 | Prima::CodeManager::Notebook::delete_page( $Prima::CodeManager::developer{notes}, $nr, 1 ) ; | ||
| 331 | delete $Prima::CodeManager::info_of_files{ $Prima::CodeManager::list_of_files[$nr] }; | ||
| 332 | splice( @Prima::CodeManager::list_of_files, $nr, 1 ); | ||
| 333 | $Prima::CodeManager::developer{notes}-> set_tabs( @Prima::CodeManager::list_of_files ); | ||
| 334 | $Prima::CodeManager::developer{notes}-> repaint; | ||
| 335 | } | ||
| 336 | } | ||
| 337 | |||
| 338 | ######################################################################################## | ||
| 339 | |||
| 340 | sub file_save | ||
| 341 | { | ||
| 342 | my ( $self ) = @_; | ||
| 343 | |||
| 344 | my $nr = $Prima::CodeManager::developer{notes}-> pageIndex; | ||
| 345 | |||
| 346 | $self-> file_save_batch ( $nr ); | ||
| 347 | } | ||
| 348 | |||
| 349 | ######################################################################################## | ||
| 350 | |||
| 351 | sub file_save_as | ||
| 352 | { | ||
| 353 | my ( $self ) = ( shift ); | ||
| 354 | |||
| 355 | my $nr = $Prima::CodeManager::developer{notes}-> pageIndex; | ||
| 356 | my $dire_name = '.'; | ||
| 357 | my $file_name = $Prima::CodeManager::list_of_files[ $nr ] || ''; | ||
| 358 | if ( $file_name =~ /^(.*)([\\\/]+)([^\\\/]*)$/ ) { | ||
| 359 | $dire_name = $1; | ||
| 360 | $file_name = $3; | ||
| 361 | } | ||
| 362 | my $fn = Prima::save_file( | ||
| 363 | directory => $dire_name, | ||
| 364 | fileName => $file_name, | ||
| 365 | system => 0, | ||
| 366 | font => { | ||
| 367 | name => 'DejaVu Sans Mono', | ||
| 368 | size => 9, | ||
| 369 | style => fs::Normal, | ||
| 370 | }, | ||
| 371 | ); | ||
| 372 | my $ret = 0; | ||
| 373 | if ( defined $fn ) { | ||
| 374 | SAVE: | ||
| 375 | while(1) { | ||
| 376 | next SAVE unless CORE::open my $FH, '>', $fn; | ||
| 377 | my $white_trimming = $self->{global}->{GLOBAL}{white_trimming} || $Prima::CodeManager::_OS; | ||
| 378 | my $cap = $Prima::CodeManager::developer{ "notes_$nr" }->text(); | ||
| 379 | $cap =~ s/[ \r\t]+$//mgs; | ||
| 380 | $cap .= "\n" unless $cap =~ /\n$/s; | ||
| 381 | $cap =~ s/\n/\r\n/mgs if $white_trimming =~ /windows/; | ||
| 382 | |||
| 383 | my $modified= $self->czas('DD-MM-YYYY h:m:s'); | ||
| 384 | my $year_to = $self->czas('YYYY'); | ||
| 385 | my $today = $self->czas('DD-MM-YYYY'); | ||
| 386 | $cap =~ s/Waldemar Biernacki, (20\d{2})-20\d{2}/Waldemar Biernacki, $1-$year_to/g; | ||
| 387 | $cap =~ s/Last modified \(DMYhms\): [^\$\.]*\./Last modified \(DMYhms\): $modified\./; | ||
| 388 | $cap =~ s/This version date: \d{2}-\d{2}-\d{4}/This version date: $today/; | ||
| 389 | $cap = encode( $Prima::CodeManager::file_encodings{$fn} , $cap ) if $Prima::CodeManager::file_encodings{$fn}; | ||
| 390 | my $swr = syswrite( $FH, $cap,length($cap)); | ||
| 391 | CORE::close $FH; | ||
| 392 | |||
| 393 | unless ( defined $swr && $swr == length($cap)) { | ||
| 394 | undef $cap; | ||
| 395 | unlink $fn; | ||
| 396 | next SAVE; | ||
| 397 | } | ||
| 398 | undef $cap; | ||
| 399 | $Prima::CodeManager::developer{ "notes_$nr" }-> modified(0); | ||
| 400 | $Prima::CodeManager::list_of_files[ $nr ] = $fn; | ||
| 401 | $Prima::CodeManager::developer{notes}-> set_tabs( @Prima::CodeManager::list_of_files ); | ||
| 402 | $Prima::CodeManager::developer{notes}-> repaint; | ||
| 403 | $ret = 1; | ||
| 404 | last; | ||
| 405 | } continue { | ||
| 406 | last SAVE unless | ||
| 407 | mb::Retry == Prima::MsgBox::message_box( $fn, "Cannot save to $fn", mb::Error|mb::Retry|mb::Cancel ); | ||
| 408 | } | ||
| 409 | } | ||
| 410 | return $ret; | ||
| 411 | } | ||
| 412 | |||
| 413 | ######################################################################################## | ||
| 414 | |||
| 415 | sub file_save_batch | ||
| 416 | { | ||
| 417 | my ( $self, $nr ) = (shift,shift); | ||
| 418 | $nr = $Prima::CodeManager::developer{notes}-> pageIndex unless defined $nr; | ||
| 419 | my $fn = $Prima::CodeManager::list_of_files[ $nr ]; | ||
| 420 | |||
| 421 | $fn =~ s/^\*//; | ||
| 422 | return $self->file_save_as if $fn eq './.Untitled'; | ||
| 423 | |||
| 424 | my $white_trimming = $self->{global}->{GLOBAL}{white_trimming} || $Prima::CodeManager::_OS; | ||
| 425 | |||
| 426 | if ( CORE::open my $FH, '>', $fn ) { | ||
| 427 | my $cap = $Prima::CodeManager::developer{ "notes_$nr" }->text(); | ||
| 428 | $cap =~ s/[ \r\t]+$//mgs; | ||
| 429 | $cap .= "\n" unless $cap =~ /\n$/s; | ||
| 430 | $cap =~ s/\n/\r\n/mgs if $white_trimming =~ /windows/; | ||
| 431 | |||
| 432 | my $modified = $self->czas('DD-MM-YYYY h:m:s'); | ||
| 433 | my $year_to = $self->czas('YYYY'); | ||
| 434 | my $today = $self->czas('DD-MM-YYYY'); | ||
| 435 | $cap =~ s/Waldemar Biernacki, (20\d{2})-20\d{2}/Waldemar Biernacki, $1-$year_to/g; | ||
| 436 | $cap =~ s/Last modified \(DMYhms\): [^\$\.]*\./Last modified \(DMYhms\): $modified\./g; | ||
| 437 | $cap =~ s/This version date: \d{2}-\d{2}-\d{4}/This version date: $today/g; | ||
| 438 | $cap = encode( $Prima::CodeManager::file_encodings{$fn} , $cap ) if $Prima::CodeManager::file_encodings{$fn}; | ||
| 439 | my $swr = syswrite( $FH, $cap, length( $cap )); | ||
| 440 | CORE::close $FH; | ||
| 441 | |||
| 442 | unless (defined $swr && $swr == length( $cap )) { | ||
| 443 | undef $cap; | ||
| 444 | unlink $fn; | ||
| 445 | Prima::MsgBox::message_box( $fn, "Cannot save to $fn", mb::Error|mb::OK); | ||
| 446 | return 0; | ||
| 447 | } | ||
| 448 | undef $cap; | ||
| 449 | |||
| 450 | $Prima::CodeManager::developer{ "notes_$nr" }-> modified(0); | ||
| 451 | $Prima::CodeManager::list_of_files[ $nr ] = $fn; | ||
| 452 | $Prima::CodeManager::developer{notes}-> set_tabs( @Prima::CodeManager::list_of_files ); | ||
| 453 | |||
| 454 | return 1; | ||
| 455 | |||
| 456 | } else { | ||
| 457 | |||
| 458 | Prima::MsgBox::message_box( $fn, "Cannot save to $fn", mb::Error|mb::OK); | ||
| 459 | } | ||
| 460 | |||
| 461 | return 0; | ||
| 462 | } | ||
| 463 | |||
| 464 | ################################################################################ | ||
| 465 | |||
| 466 | sub hilite_open | ||
| 467 | { | ||
| 468 | my ( $self ) = @_; | ||
| 469 | |||
| 470 | my $nr = $Prima::CodeManager::developer{notes}-> pageIndex; | ||
| 471 | my $hfn = ''; | ||
| 472 | $hfn = "hilite_$1.pl" if ( $Prima::CodeManager::list_of_files[ $nr ] =~ /\.(\w+)$/ ); | ||
| 473 | my $fn = Prima::open_file( | ||
| 474 | directory => './hilite/', | ||
| 475 | fileName => $hfn, | ||
| 476 | system => 0, | ||
| 477 | ); | ||
| 478 | edit( $fn ) if $fn; | ||
| 479 | } | ||
| 480 | |||
| 481 | ######################################################################################## | ||
| 482 | |||
| 483 | sub show_size | ||
| 484 | { | ||
| 485 | my ( $self, $size, $glue ) = @_; | ||
| 486 | return unless $size == 1 || $size == 0 || $size == -1; | ||
| 487 | return unless $glue == 1 || $glue == 0 || $glue == -1; | ||
| 488 | return unless $size != 0 || $glue != 0; | ||
| 489 | |||
| 490 | my $i = $Prima::CodeManager::developer{notes}-> pageIndex; | ||
| 491 | |||
| 492 | $size = $Prima::CodeManager::developer{ "notes_$i" }-> font-> size + $size; | ||
| 493 | $size = 1 if $size < 1; | ||
| 494 | $glue = $Prima::CodeManager::developer{ "notes_$i" }-> {lineSpace} + $glue; | ||
| 495 | $glue = 1 - $size if $glue < 1 - $size; | ||
| 496 | |||
| 497 | $Prima::CodeManager::developer{ "notes_$i" }-> font-> size( $size ); | ||
| 498 | $Prima::CodeManager::developer{ "notes_$i" }-> {lineSpace} = $glue; | ||
| 499 | $Prima::CodeManager::developer{ "notes_$i" }-> repaint; | ||
| 500 | |||
| 501 | $Prima::CodeManager::developer{ "numer_$i" }-> font-> size( $size ); | ||
| 502 | $Prima::CodeManager::developer{ "numer_$i" }-> {lineSpace} = $glue; | ||
| 503 | $Prima::CodeManager::developer{ "numer_$i" }-> repaint; | ||
| 504 | } | ||
| 505 | |||
| 506 | ######################################################################################## | ||
| 507 | |||
| 508 | sub show_tab | ||
| 509 | { | ||
| 510 | my ( $self, $step ) = @_; | ||
| 511 | return unless $step == 1 || $step == -1; | ||
| 512 | my $next = $Prima::CodeManager::developer{notes}-> pageIndex + $step; | ||
| 513 | $next = 0 if $next >= $Prima::CodeManager::developer{notes}-> pageCount; | ||
| 514 | $next = $Prima::CodeManager::developer{notes}-> pageCount - 1 if $next < 0; | ||
| 515 | $Prima::CodeManager::developer{notes}-> tabIndex($next); | ||
| 516 | } | ||
| 517 | |||
| 518 | ######################################################################################## | ||
| 519 | |||
| 520 | sub jump | ||
| 521 | { | ||
| 522 | my ( $self ) = ( shift ); | ||
| 523 | # my $this = $Prima::CodeManager::developer{ "notes_".$Prima::CodeManager::developer{notes}->pageIndex }; | ||
| 524 | # undef $self-> {findData}; | ||
| 525 | $self-> find_dialog( 1 ); | ||
| 526 | $self-> do_find; | ||
| 527 | } | ||
| 528 | ######################################################################################## | ||
| 529 | sub find | ||
| 530 | { | ||
| 531 | my ( $self ) = ( shift ); | ||
| 532 | # my $this = $Prima::CodeManager::developer{ "notes_".$Prima::CodeManager::developer{notes}->pageIndex }; | ||
| 533 | # undef $self-> {findData}; | ||
| 534 | $self-> find_dialog( 1 ); | ||
| 535 | $self-> do_find; | ||
| 536 | } | ||
| 537 | #-------------------------------------------------------------------------------------- | ||
| 538 | sub find_dialog | ||
| 539 | { | ||
| 540 | my ( $self ) = ( shift ); | ||
| 541 | my $findStyle = $_[0]; | ||
| 542 | my $this = $Prima::CodeManager::developer{ "notes_".$Prima::CodeManager::developer{notes}->pageIndex }; | ||
| 543 | my %prf; | ||
| 544 | %{$findData} = ( | ||
| 545 | replaceText => '', | ||
| 546 | findText => $this-> get_selected_text, | ||
| 547 | replaceItems => [], | ||
| 548 | findItems => [], | ||
| 549 | options => 0, | ||
| 550 | scope => fds::Cursor, | ||
| 551 | ) unless defined $findData; | ||
| 552 | $findData->{findText} = $this-> get_selected_text; | ||
| 553 | my $fd = $findData; | ||
| 554 | my @props = qw(findText options scope); | ||
| 555 | push( @props, q(replaceText)) unless $findStyle; | ||
| 556 | if ( $fd) { for( @props) { $prf{$_} = $fd-> {$_}}} | ||
| 557 | my $findDialog = Prima::FindDialog-> create; | ||
| 558 | $findDialog-> set( %prf, findStyle => $findStyle); | ||
| 559 | $findDialog-> Find-> items($fd-> {findItems}); | ||
| 560 | $findDialog-> Replace-> items($fd-> {replaceItems}) unless $findStyle; | ||
| 561 | my $ret = 0; | ||
| 562 | my $rf = $findDialog-> execute; | ||
| 563 | if ( $rf != mb::Cancel) { | ||
| 564 | { for( @props) { $findData-> {$_} = $findDialog-> $_()}} | ||
| 565 | $findData-> {result} = $rf; | ||
| 566 | $findData-> {asFind} = $findStyle; | ||
| 567 | ############## | ||
| 568 | my @pozycje = @{$findDialog-> Find-> items}; | ||
| 569 | my @newitems; | ||
| 570 | for ( my $i = 0 ; $i < @pozycje; $i++ ) { | ||
| 571 | my $czy = 1; | ||
| 572 | for ( my $j = 0 ; $j < $i; $j++ ) { | ||
| 573 | $czy = 0 if lc($pozycje[$i]) eq lc($pozycje[$j]); | ||
| 574 | last unless $czy; | ||
| 575 | } | ||
| 576 | push @newitems, $pozycje[$i] if $czy; | ||
| 577 | } | ||
| 578 | ############## | ||
| 579 | @{$findData-> {findItems}} = @newitems; | ||
| 580 | # @{$findData-> {findItems}} = @{$findDialog-> Find-> items}; | ||
| 581 | @{$findData-> {replaceItems}} = @{$findDialog-> Replace-> items} | ||
| 582 | unless $findStyle; | ||
| 583 | $ret = 1; | ||
| 584 | } | ||
| 585 | return $ret; | ||
| 586 | } | ||
| 587 | #-------------------------------------------------------------------------------------- | ||
| 588 | sub do_find | ||
| 589 | { | ||
| 590 | my ( $self ) = ( shift ); | ||
| 591 | my $e = $Prima::CodeManager::developer{ "notes_".$Prima::CodeManager::developer{notes}-> pageIndex }; | ||
| 592 | # my $e = $this; | ||
| 593 | # my $p = $this-> {findData}; | ||
| 594 | my $p = $findData; | ||
| 595 | my @scope; | ||
| 596 | FIND:{ | ||
| 597 | if ( $$p{scope} != fds::Cursor) { | ||
| 598 | if ( $e-> has_selection) { | ||
| 599 | my @sel = $e-> selection; | ||
| 600 | @scope = ($$p{scope} == fds::Top) ? ($sel[0],$sel[1]) : ($sel[2], $sel[3]); | ||
| 601 | } else { | ||
| 602 | @scope = ($$p{scope} == fds::Top) ? (0,0) : (-1,-1); | ||
| 603 | } | ||
| 604 | } else { | ||
| 605 | @scope = $e-> cursor; | ||
| 606 | } | ||
| 607 | my @n = $e-> find( $$p{findText}, @scope, $$p{replaceText}, $$p{options}); | ||
| 608 | if ( !defined $n[0]) { | ||
| 609 | Prima::MsgBox::message( "No more matches found!" , mb::NoSound | mb::Information ); | ||
| 610 | return; | ||
| 611 | } | ||
| 612 | $e-> cursor(($$p{options} & fdo::BackwardSearch) ? $n[0] : $n[0] + $n[2], $n[1]); | ||
| 613 | $e-> selection( $n[0], $n[1], $n[0] + $n[2], $n[1]); | ||
| 614 | unless ( $$p{asFind}) { | ||
| 615 | if ( $$p{options} & fdo::ReplacePrompt) { | ||
| 616 | my $r = Prima::MsgBox::message_box( "Replace...","Replace text '$$p{findText}'?", mb::YesNoCancel|mb::Information|mb::NoSound); | ||
| 617 | # my $r = Prima::MsgBox::message_box( $e-> text, | ||
| 618 | # "Replace this text?", | ||
| 619 | # mb::YesNoCancel|mb::Information|mb::NoSound); | ||
| 620 | redo FIND if ($r == mb::No) && ($$p{result} == mb::ChangeAll); | ||
| 621 | last FIND if $r == mb::Cancel; | ||
| 622 | } | ||
| 623 | $e-> set_line( $n[1], $n[3]); | ||
| 624 | redo FIND if $$p{result} && $$p{result} == mb::ChangeAll; | ||
| 625 | } | ||
| 626 | } | ||
| 627 | } | ||
| 628 | #------------------------------------------------------------------------------- | ||
| 629 | sub find_next | ||
| 630 | { | ||
| 631 | my ( $self ) = ( shift ); | ||
| 632 | # my ( $this ) = ( $Prima::CodeManager::developer{ "notes_".$Prima::CodeManager::developer{notes}->pageIndex } ); | ||
| 633 | # return unless $this-> {findData}; | ||
| 634 | return unless $findData; | ||
| 635 | $self-> do_find; | ||
| 636 | } | ||
| 637 | #------------------------------------------------------------------------------- | ||
| 638 | sub replace | ||
| 639 | { | ||
| 640 | my ( $self ) = ( shift ); | ||
| 641 | # my ( $self ) = ( $d::eveloper{ "notes_".$Prima::CodeManager::developer{notes}->pageIndex } ); | ||
| 642 | return unless find_dialog(0); | ||
| 643 | $self-> do_find; | ||
| 644 | } | ||
| 645 | ################################################################################ | ||
| 646 | sub about | ||
| 647 | { | ||
| 648 | my ( $self ) = @_; | ||
| 649 | my $project_color = 0x0088ff; | ||
| 650 | my @dim = ( 360, 170 ); | ||
| 651 | # my $img = $self-> load_icon( "$::Prima::CodeManager::CodeManager_directory/img/CodeManager64.png" ); | ||
| 652 | my $tmp_popup = Prima::Dialog-> create( | ||
| 653 | icon => $self-> load_icon( "$Prima::CodeManager::CodeManager_directory/img/cm64.png" ), | ||
| 654 | title => "CodeManager - About", | ||
| 655 | text => "CodeManager - About", | ||
| 656 | size => [ @dim ], | ||
| 657 | origin => [ 0, 0 ], | ||
| 658 | borderIcons => bi::SystemMenu, | ||
| 659 | centered => 1, | ||
| 660 | # borderStyle => bs::None, | ||
| 661 | backColor => $self->licz_kolor( 0xffffff, $project_color, 0.5, 0 ), | ||
| 662 | onPaint => sub { | ||
| 663 | my ( $this, $canvas) = @_; | ||
| 664 | $canvas-> clear; | ||
| 665 | $canvas-> color( $self->licz_kolor( 0xffffff, $project_color, 0.2, 0 ) ); | ||
| 666 | $canvas-> bar( 0, 0, $this-> width, $this-> height); | ||
| 667 | my $margin = 2; | ||
| 668 | my $width = 1; | ||
| 669 | $canvas-> color( $self->licz_kolor( 0xffffff, $project_color, 0.8, 0 ) ); | ||
| 670 | $canvas-> fillpoly([ | ||
| 671 | $margin, $margin, | ||
| 672 | $margin, $this-> height - $margin - 1, | ||
| 673 | $this-> width - $margin - 1, $this-> height - $margin - 1, | ||
| 674 | $this-> width - $margin - 1, $margin | ||
| 675 | ]); | ||
| 676 | $canvas-> color( $self->licz_kolor( 0xffffff, $project_color, 0.5, 0 ) ); | ||
| 677 | $canvas-> fillpoly([ | ||
| 678 | $margin + $width, $margin + $width, | ||
| 679 | $margin + $width, $this-> height - $margin - 1 - $width, | ||
| 680 | $this-> width - $margin - 1 - $width, $this-> height - $margin - 1 - $width, | ||
| 681 | $this-> width - $margin - 1 - $width, $margin + $width | ||
| 682 | ]); | ||
| 683 | # $canvas-> put_image( $dim[0]/2-64, $dim[1] - 64 - 10, $img ); | ||
| 684 | }, | ||
| 685 | ); | ||
| 686 | my $height = 18; | ||
| 687 | $tmp_popup-> insert ( | ||
| 688 | Label => | ||
| 689 | origin => [ 10, $dim[1]-15 - $height ], | ||
| 690 | size => [ $dim[0]-20, $height ], | ||
| 691 | text => "This is CodeManager, ver. $Prima::CodeManager::VERSION", | ||
| 692 | flat => 1, | ||
| 693 | x_centered => 1, | ||
| 694 | alignment => ta::Center, | ||
| 695 | color => $self->licz_kolor( 0x000000, $project_color, 0.6, 0 ), | ||
| 696 | borderWidth => 1, | ||
| 697 | font => { | ||
| 698 | height => $height, | ||
| 699 | style => fs::Bold, | ||
| 700 | }, | ||
| 701 | ); | ||
| 702 | my $about = "Copyright 2009-2013 by Waldemar Biernacki\n" . | ||
| 703 | "http://codemanager.sao.pl\n" . | ||
| 704 | "\n" . | ||
| 705 | "\nLicense statement:\n" . | ||
| 706 | "This program/library is free software; you can redistribute it\n" . | ||
| 707 | "and/or modify it under the same terms as Perl itself."; | ||
| 708 | $tmp_popup->insert( Label => | ||
| 709 | origin => [ 10, 30 ], | ||
| 710 | size => [ $dim[0] - 20, $dim[1] - 75 ], | ||
| 711 | text => $about, | ||
| 712 | flat => 1, | ||
| 713 | x_centered => 1, | ||
| 714 | alignment => ta::Center, | ||
| 715 | color => $self->licz_kolor( 0x000000, $project_color, 0.6, 0 ), | ||
| 716 | borderWidth => 1, | ||
| 717 | font => { size=>8, style=>fs::Normal, }, | ||
| 718 | ); | ||
| 719 | $tmp_popup->insert( Button => | ||
| 720 | origin => [ int($dim[0]/2) - 40, 10 ], | ||
| 721 | size => [ 80, 20 ], | ||
| 722 | text => 'OK', | ||
| 723 | enabled => 1, | ||
| 724 | flat => 0, | ||
| 725 | color => 0x000000, | ||
| 726 | color => 0xffffff, | ||
| 727 | borderWidth => 1, | ||
| 728 | borderColor => 0xffffff, | ||
| 729 | backColor => $self->licz_kolor( 0xffffff, $project_color, 0.3, 0 ), | ||
| 730 | font => { size => 9, style => fs::Normal, }, | ||
| 731 | onClick => sub { $tmp_popup->close; }, | ||
| 732 | ); | ||
| 733 | $tmp_popup->execute; | ||
| 734 | return; | ||
| 735 | } | ||
| 736 | 1; | ||
| 737 | __END__ |