Thread Kephra: Texteditor nur in Perl
(538 answers)
Opened by lichtkind at 2008-03-09 00:08
Vielleicht interessiert es Dich ja...
Ich habe mir das Erstellen von neuen Dateien mit Templates etwas erleichtert: Template.pm: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 package Kephra::Dialog::Template; our $VERSION = 0.01; use strict; use warnings; use Wx qw( wxVERTICAL wxHORIZONTAL wxLEFT wxRIGHT wxTOP wxALL wxBOTTOM wxGROW wxEXPAND wxALIGN_RIGHT wxSYSTEM_MENU wxCAPTION wxSTAY_ON_TOP wxNO_FULL_REPAINT_ON_RESIZE wxCLOSE_BOX wxMINIMIZE_BOX wxFRAME_NO_TASKBAR wxBITMAP_TYPE_XPM wxWHITE wxTR_NO_BUTTONS wxTR_HIDE_ROOT wxTR_SINGLE ); use Wx::Event qw( EVT_BUTTON EVT_LISTBOX EVT_LISTBOX_DCLICK EVT_CLOSE); my $TEMPLATE = ""; sub _ref { if (ref $_[0] eq 'Wx::Dialog'){ $Kephra::app{dialog}{config} = $_[0] } else { $Kephra::app{dialog}{config} } } sub template_dialog { my $frame = Kephra::App::Window::_ref(); my $g_l10n = $Kephra::localisation{dialog}{general}; $TEMPLATE = ""; # making window & main design my $d = Wx::Dialog->new( $frame, -1, ' Templates', [ 0,0 ], [ 470, 560 ], ); my ($panel); my $list = Wx::ListBox->new( $d, -1 ); my $counter = 0; for my $name ( _list() ){ $list->Append( $name ); $list->SetClientData( $counter++, $name ); } EVT_LISTBOX( $list, $list, \&onselected ); EVT_LISTBOX_DCLICK( $list, $list, sub{ &onselected; $d->Close } ); # button line $d->{apply_button} = Wx::Button->new ( $d, -1, $g_l10n->{apply} ); $d->{cancel_button} = Wx::Button->new( $d, -1, $g_l10n->{cancel}); EVT_BUTTON( $d, $d->{apply_button}, sub {shift->Close} ); EVT_BUTTON( $d, $d->{cancel_button},sub {shift->Close} ); my $button_sizer = Wx::BoxSizer->new(wxHORIZONTAL); $button_sizer->Add( $d->{apply_button}, 0, wxRIGHT, 14 ); $button_sizer->Add( $d->{cancel_button}, 0, wxRIGHT, 22 ); # assembling lines my $d_sizer = Wx::BoxSizer->new(wxVERTICAL); $d_sizer->Add( $list, 1, wxEXPAND|wxALL, 14); $d_sizer->Add( $button_sizer, 0, wxBOTTOM|wxALIGN_RIGHT, 12); # release $d->SetSizer($d_sizer); $d->SetAutoLayout(1); $d->ShowModal; Wx::Window::SetFocus( $d->{cancel_button} ); EVT_CLOSE( $d, \&quit_config_dialog ); $TEMPLATE; } sub onselected { my ($list,$event) = @_; my $new = ""; unless( $event->GetInt() == -1 ) { $new = $event->GetString; } $TEMPLATE = $new; } sub _list { my @list; my $cfg = $Kephra::config{file}{templates}; my $file = Kephra::Config::filepath($cfg->{directory}, $cfg->{file}); my $tmp = Kephra::Config::File::load( $file ); if (exists $tmp->{template}){ $tmp = Kephra::Config::Tree::_convert_node_2_AoH(\$tmp->{template}); for my $template ( @{$tmp} ) { push @list, $template->{name}; } } @list; } sub quit_config_dialog { my ( $win, $event ) = @_; $win->Destroy; } 1; Änderungen in Kephra::Dialog: Code (perl): (dl
)
1 2 3 4 sub get_template { require Kephra::Dialog::Template; &Kephra::Dialog::Template::template_dialog; } Änderung in Kephra::File: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 sub new_from_template { my $template_name = Kephra::Dialog::get_template(); warn $template_name; return unless $template_name; Kephra::File->new(); my $cfg = $Kephra::config{file}{templates}; my $file = Kephra::Config::filepath($cfg->{directory}, $cfg->{file}); my $tmp = Kephra::Config::File::load( $file ); if (exists $tmp->{template}){ $tmp = Kephra::Config::Tree::_convert_node_2_AoH(\$tmp->{template}); my $untitled = $Kephra::localisation{app}{general}{untitled}; for my $template ( @{$tmp} ) { next unless $template_name eq $template->{name}; my $filepath = Kephra::Document::get_file_path() || "<$untitled>"; my $filename = Kephra::Document::file_name() || "<$untitled>"; my $firstname = Kephra::Document::first_name() || "<$untitled>"; my $content = $template->{content}; $content =~ s/\[\$\$firstname\]/$firstname/g; $content =~ s/\[\$\$filename\]/$filename/g; $content =~ s/\[\$\$filepath\]/$filepath/g; Kephra::Edit::insert_text($content); last; } } } Code: (dl
)
1 C:\Kephra_4\Kephra\config\interface>C:\Programme\Gnu\bin\diff.exe -u commands.conf.bak commands.conf Code: (dl
)
1 C:\Kephra_4\Kephra\config\interface>C:\Programme\Gnu\bin\diff.exe -u mainmenu.yml.bak mainmenu.yml In den "localisation"-Dateien habe ich das auch noch eingetragen... Ist wahrscheinlich nicht optimal, aber langsam komme ich mit der Kephra-Struktur besser zurecht... OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/) -- Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html Perl-Entwicklung: http://perl-services.de/ |