1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed e2c90af

titel showss file name and path , except when opening into empty file

  • Participants
  • Parent commits 0a0c3e0
  • Branches default

Comments (0)

Files changed (5)

File lib/Kephra/App/Bar/Document.pm

View file
  • Ignore whitespace
 use warnings;
 use Wx;
 use Wx::DND;
+use Kephra::API;
 use Kephra::App::Editor;
 use Kephra::App::Util;
 
 our @ISA = 'Wx::AuiNotebook';
 
 my $put_on_panel = Kephra::App::Util::get('put_on_panel');
+my @tab_nr;
 
 sub new {
-    my( $class, $parent) = @_;
-    my $self = $class->SUPER::new( $parent, -1, [-1,-1], [-1,-1],
-        &Wx::wxAUI_NB_TOP | &Wx::wxAUI_NB_TAB_MOVE | &Wx::wxAUI_NB_WINDOWLIST_BUTTON |
-        &Wx::wxAUI_NB_SCROLL_BUTTONS | &Wx::wxAUI_NB_CLOSE_ON_ACTIVE_TAB
-    );
+	my( $class, $parent) = @_;
+	my $self = $class->SUPER::new( $parent, -1, [-1,-1], [-1,-1],
+		&Wx::wxAUI_NB_TOP | &Wx::wxAUI_NB_TAB_MOVE | &Wx::wxAUI_NB_WINDOWLIST_BUTTON |
+		&Wx::wxAUI_NB_SCROLL_BUTTONS | &Wx::wxAUI_NB_CLOSE_ON_ACTIVE_TAB
+	);
 
-    Wx::Event::EVT_AUINOTEBOOK_BEGIN_DRAG( $self, -1, sub {});
-    Wx::Event::EVT_AUINOTEBOOK_END_DRAG($self, -1, sub {});
-    Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
-        my ($nb, $event ) = @_;
-        #$nb->GetSelection
-        #$event->Skip; #$event->Veto;
-    });
-    Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub { });
+	my $dragged_tab_nr;
+	Wx::Event::EVT_AUINOTEBOOK_BEGIN_DRAG( $self, -1, sub {
+		my ($nb, $event ) = @_;
+	});
+	Wx::Event::EVT_AUINOTEBOOK_END_DRAG($self, -1, sub {
+		my ($nb, $event ) = @_;
+	});
+	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
+		my ($nb, $event ) = @_;
+		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);
+		$event->Skip; # $event->Veto;
+	});
+	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub { });
 
-    return $self;
+	return $self;
 }
 
-sub add_edit_page {
-    my ($self, $label, $set_active, $position) = @_;
-    $label = '<untitled>' unless $label;
-    $set_active = 1       unless defined $set_active;
+sub add_page {
+	my ($self, $label, $position, $set_active, $panel ) = @_;
+	$label = '<untitled>' unless $label;
+	$set_active = 1       unless defined $set_active;
 
-    my $pages = $self->GetPageCount;
-    
-    my $active_pos = $self->GetSelection;
-    my $active_ed = $self->GetPage($active_pos);
+	my $pages      = $self->GetPageCount;
+	my $active_pos = $self->GetSelection;
+	my $active_ed  = $self->GetPage($active_pos);
 
-    my $ed = Kephra::App::Editor->new($self);
-    $self->InsertPage( $pages, $ed, $label, $set_active );
-    $ed->set_focus() if $set_active;
+	my $ed = defined $panel
+		? $panel
+		: Kephra::App::Editor->new($self);
 
-    return $ed;
+	$self->InsertPage( $pages, $ed, $label, $set_active );
+	$ed->set_focus() if $set_active;
+
+	return $ed;
 }
 
 sub raise_panel {
-    my ($self, $ed) = @_;
-    $self->SetSelection( $self->GetPageIndex($ed) );
+	my ($self, $ed) = @_;
+	$self->SetSelection( $self->GetPageIndex($ed) );
 }
 
 1;

File lib/Kephra/App/Panel/Editor.pm

View file
  • Ignore whitespace
     my $doc = Kephra::API::active_doc();
     my $main_doc_bar = _active_docbar();
 
-    # doc is alreadopen
+    # 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->load($file_path);
-        $doc->editor( $main_doc_bar->add_edit_page( $doc->file_name, 1) );
         Kephra::DocumentStash::add( $doc );
+        $main_doc_bar->add_page( $doc->file_name, -1, 1, $ed) ;
     }
     return $doc;
 }

File lib/Kephra/App/Panel/FileBrowser.pm

View file
  • Ignore whitespace
     );
 
     my @lib = @{ get_modules_and_paths('lib') };
-    my $root_ID = $self->AddRoot( 'Root', -1, -1, Wx::TreeItemData->new( 'Data' ));
+    my $root_ID = $self->AddRoot( 'Root', -1, -1, Wx::TreeItemData->new( ));
     for (0 .. $#lib){
         my $data = Wx::TreeItemData->new; 
         $data->SetData( $lib[$_][1] );

File lib/Kephra/App/Window.pm

View file
  • Ignore whitespace
 sub close   { $_ref->Close() }
 sub destroy { $_ref->Destroy() }
 
+sub get_title { $_ref->GetTitle( )       }
+sub set_title { $_ref->SetTitle( $_[1] ) }
+
 1;

File lib/Kephra/DocumentStash.pm

View file
  • Ignore whitespace
 sub active_doc    { $active }
 sub active_editor { $active->editor }
 sub add {
-    my $ed = shift;
-    warn "Kephra::DocumentStash::add: add to me only docs, not $ed!"
-        unless $ed->isa('Kephra::Document');
-    $document{$ed->editor} = $active = $ed;
+	my $doc = shift;
+	warn "Kephra::DocumentStash::add: add to me only docs, not $doc!"
+		unless $doc->isa('Kephra::Document');
+	$document{$doc->editor} = $active = $doc;
 }
 sub del {
-    my $ed = shift;
-    warn "Kephra::DocumentStash::del: add to me only docs, not $ed!" 
-        unless $ed->isa('Kephra::Document');
-    warn "DocStash:del: $ed was not in the stash!" unless $document{$ed};
-    delete $document{$ed};
+	my $doc = shift;
+	warn "Kephra::DocumentStash::del: add to me only docs, not $doc!" 
+		unless $doc->isa('Kephra::Document');
+	warn "DocStash:del: $doc was not in the stash!" unless $document{$doc->editor};
+	delete $document{$doc->editor};
 }
 
 sub get_by_ed {
-    my $ed = shift;
-    warn "Kephra::DocumentStash::get_by_ed needs a Kephra::App::Editor, not $ed!"
-        unless $ed->isa('Kephra::App::Editor');
-    return $document{$ed};
+	my $ed = shift;
+	warn "Kephra::DocumentStash::get_by_ed needs a Kephra::App::Editor, not $ed!"
+		unless $ed->isa('Kephra::App::Editor');
+	return $document{$ed};
 }
 sub get_by_path {
-    my $file_path = shift;
-    warn "Kephra::DocumentStash::get_by_path needs a file path as input!"
-        unless $file_path and -e $file_path;
-    for my $ed (keys %document) {
-        return $document{$ed} if $document{$ed}->file_path eq $file_path;
-    }
+	my $file_path = shift;
+	warn "Kephra::DocumentStash::get_by_path needs a file path as input!"
+		unless $file_path and -e $file_path;
+	for my $ed (keys %document) {
+		return $document{$ed} if $document{$ed}->file_path eq $file_path;
+	}
 }
 sub get_by_nr {}
-sub get_all {
-}
+sub get_all {}
+sub dump_all_ed { print "$_ + \n" for keys %document }
 
 sub file_loaded {
-    my $file_path = shift;
-    warn "Kephra::DocumentStash::file_loaded needs a file path as input!"
-        unless $file_path and -e $file_path;
-    for my $ed (keys %document) {
-        return 1 if $document{$ed}->file_path and $document{$ed}->file_path eq $file_path;
-    }
+	my $file_path = shift;
+	warn "Kephra::DocumentStash::file_loaded needs a file path as input!"
+		unless $file_path and -e $file_path;
+	for my $ed (keys %document) {
+		return 1 if $document{$ed}->file_path and $document{$ed}->file_path eq $file_path;
+	}
 }
 1;