Commits

Herbert Breunung committed 53668ed

title bar alway recent, sane refactored

Comments (0)

Files changed (7)

 );
 our @used_wx_modules = qw/Wx::AUI Wx::DND Wx::RichText/; # Wx::STC
 
-#our @needed_at_first = qw/App API/;
+our @needed_at_first = qw/App API/;
 #our @starttime_modules = qw/App API/;
+#our @runtime_modules = qw/Dialog::* Config::Default::*/;
 #our @command_modules;
 
 sub load_libs {

lib/Kephra/App/Bar/Document.pm

 	});
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
 		my ($nb, $event ) = @_;
-		set_active_doc
 		my $new_nr = $event->GetSelection;
-		my $doc = Kephra::DocumentStash::get_by_ed( $nb->GetPage($new_nr) );
-		my $title = defined $doc->file_name
-			? $doc->file_name.' ('.$doc->file_path.')'
-			: $nb->GetPageText($new_nr);
-		$title .= " - Kephra $Kephra::VERSION";
-		Kephra::API::widget('win')->set_title($title);
+		Kephra::DocumentStash::set_active_doc( $nb->GetPage($new_nr) );
+		Kephra::API::widget('win')->refresh_title();
 		$event->Skip; # $event->Veto;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub { });

lib/Kephra/App/Editor.pm

 use warnings;
 use Wx;
 #use Wx::DND;
-use Wx::STC;
-#use Wx::Scintilla;
+#use Wx::STC;
+use Wx::Scintilla;
 use Kephra::App::Util;
 
 package Kephra::App::Editor;
-our @ISA = 'Wx::StyledTextCtrl';
-#our @ISA = 'Wx::ScintillaTextCtrl';
-	
+#our @ISA = 'Wx::StyledTextCtrl';
+our @ISA = 'Wx::ScintillaTextCtrl';
+
 my $mk_color = Kephra::App::Util::get('make_color');
 
 sub new {

lib/Kephra/App/Panel/Editor.pm

 sub _active_docbar{ $doc_bar{'leftup'} }
 
 sub new {
-    my( $class, $parent) = @_;
-    $doc_bar{'leftup'} = Kephra::App::Bar::Document->new( $parent );
-    # Wx::SplitterWindow->new( $splitter{'left'}, -1 );
+	my( $class, $parent) = @_;
+	$doc_bar{'leftup'} = Kephra::App::Bar::Document->new( $parent );
+	# Wx::SplitterWindow->new( $splitter{'left'}, -1 );
 
-    return $doc_bar{'leftup'};
+	return $doc_bar{'leftup'};
 }
 
 sub create_document {
-    my $file_path = shift;
-    my $doc = Kephra::API::active_doc();
-    my $main_doc_bar = _active_docbar();
+	my $file_path = shift;
+	my $doc = Kephra::API::active_doc();
+	my $main_doc_bar = _active_docbar();
 
-    # doc is alread open
-    if ( $file_path and Kephra::DocumentStash::file_loaded($file_path) ){
-        $main_doc_bar->raise_panel( Kephra::DocumentStash::get_by_path($file_path)->{editor} );
-    # overwrite empty doc
-    } elsif ($doc and $doc->editor->is_empty and $file_path) {
-        $doc->load($file_path);
-        $main_doc_bar->SetPageText( $main_doc_bar->GetSelection , $doc->file_name );
-        $doc->editor->set_focus()
-    # make new editor
-    } else {
-        my $ed = Kephra::App::Editor->new( $main_doc_bar );
-        $doc = Kephra::Document->new();
-        $doc->editor( $ed );
-        $doc->assign_file($file_path);
-        Kephra::DocumentStash::add( $doc );
-        $main_doc_bar->add_page( $doc->file_name, -1, 1, $ed) ;
-    }
-    return $doc;
+	# doc is alread open
+	if ( $file_path and Kephra::DocumentStash::file_loaded($file_path) ){
+		$main_doc_bar->raise_panel( Kephra::DocumentStash::get_by_path($file_path)->{editor} );
+	# overwrite empty doc
+	} elsif ($doc and $doc->editor->is_empty and $file_path) {
+		$doc->assign_file($file_path);
+		$main_doc_bar->SetPageText( $main_doc_bar->GetSelection , $doc->file_name );
+		$doc->editor->set_focus();
+		Kephra::API::widget('win')->refresh_title();
+	# make new editor
+	} else {
+		my $ed = Kephra::App::Editor->new( $main_doc_bar );
+		$doc = Kephra::Document->new();
+		$doc->editor( $ed );
+		$doc->assign_file($file_path);
+		Kephra::DocumentStash::add( $doc );
+		$main_doc_bar->add_page( $doc->file_name, -1, 1, $ed) ;
+		Kephra::API::widget('win')->refresh_title();
+	}
+	return $doc;
+}
+
+sub active_title {
+	my $nb = _active_docbar();
+	$nb->GetPageText( $nb->GetSelection );
 }
 
 1;

lib/Kephra/App/Window.pm

 use Kephra::App::Panel::TreeLib;
 use Kephra::App::Panel::OrgPad;
 use Kephra::App::Panel::ScratchSheet;
+use Kephra::DocumentStash;
 
 package Kephra::App::Window;
 our @ISA = 'Wx::Frame';
 sub get_title { $_ref->GetTitle( )       }
 sub set_title { $_ref->SetTitle( $_[1] ) }
 sub refresh_title {
-    my $title = 
-    set_title();
+	my $self = shift;
+	my $doc = Kephra::DocumentStash::active_doc();
+	my $title = defined $doc->file_name
+		? $doc->file_name.' ('.$doc->file_path.')'
+		: Kephra::App::Panel::Editor::active_title();
+	$title .= " - $Kephra::NAME $Kephra::VERSION";
+	$self->set_title($title);
 }
 
 

lib/Kephra/Document.pm

     is  => 'rw',
     isa => sub {die "$_[0] is no editor" unless ref $_[0] eq 'Kephra::App::Editor'},
 );
-has file_path    => ( is  => 'ro', );
-has file_dir     => ( is  => 'ro', );
-has file_name    => ( is  => 'ro', );
+has file_path    => ( is  => 'rw', );
+has file_dir     => ( is  => 'rw', );
+has file_name    => ( is  => 'rw', );
 #has content      => ( is  => 'rw' );
 has notes        => ( is  => 'rw', );
 

lib/Kephra/DocumentStash.pm

 
 my %side_buffer;
 
+sub previous_doc  { $previous }
 sub active_doc    { $active }
 sub active_editor { $active->editor }
 sub set_active_doc{
-    my $doc = shift;
-    my $previous = $active;
-    my $new_doc = 
-        not ref $doc                     ? get_by_path($doc)       : 
-        $doc->isa('Kephra::App::Editor') ? $document{$doc}         :
-        $doc->isa('Kephra::Document')    ? $document{$doc->editor} : undef;
-    return unless defined $doc;
-    $previous = $active;
-    $active = $new_doc;
+	my $doc = shift;
+	warn "Kephra::DocumentStash::set_active_doc: need a parameter!" unless $doc;
+	my $new_doc = ref($doc) eq ''                  ? get_by_path($doc)       
+				: $doc->isa('Kephra::App::Editor') ? $document{$doc}         
+				: $doc->isa('Kephra::Document')    ? $document{$doc->editor} 
+				:                                    undef;
+	return unless defined $doc;
+	$previous = $active;
+	$active = $new_doc;
+}
+sub add_active {
+	my $doc = shift;
+	add($doc);
+	set_active_doc($doc);
 }
 sub add {
 	my $doc = shift;
 	warn "Kephra::DocumentStash::add: add to me only docs, not $doc!"
 		unless $doc->isa('Kephra::Document');
-	$document{$doc->editor} = $active = $doc;
+	$document{$doc->editor} = $doc;
 }
 sub del {
 	my $doc = shift;