Commits

Herbert Breunung committed 748edfd

sanitized file open empty docs will be replaced, if you have a file name

Comments (0)

Files changed (4)

Empty file added.

lib/Kephra/App/Bar/Document.pm

 }
 
 sub add_edit_page {
-    my ($tb, $active, $label) = @_;
+    my ($tb, $set_active, $label) = @_;
+    $label = '<untitled>' unless $label;
+    $set_active = 1       unless defined $set_active;
+    my $ed;
+    my $pages = $tb->GetPageCount;
+    
+    my $active_pos = $tb->GetSelection;
+    my $active_ed = $tb->GetPage($active_pos);
 
-    $label = '<untitled>' unless $label;
-
-    #$pos = $tb->GetPageCount unless defined $pos;
-    #$active = 1              unless defined $active;
-    my $pos = $tb->GetPageCount;
-
-    my $ed = Kephra::App::Editor->new($tb);
-
-    $tb->InsertPage( $pos, $ed, $label, $active );
-    $ed->set_focus() if $active;
+    if ($active_pos > -1 and $active_ed->is_empty and $label !~ /untitled/){
+        $ed = $active_ed;
+        $tb->SetPageText( $active_pos, $label);
+    } else {
+        $ed = Kephra::App::Editor->new($tb);
+        $tb->InsertPage( $pages, $ed, $label, $set_active );
+        $ed->set_focus() if $set_active;
+    }
 
     return $ed;
 }

lib/Kephra/App/Editor.pm

     return $ed;
 }
 
+sub is_empty { not shift->GetTextLength }
+
 sub mount_events {
     my ($ed, @which) = @_;
     $ed->SetAcceleratorTable(

lib/Kephra/App/Panel/Editor.pm

 sub create_document {
     my $file = shift;
     my $doc = Kephra::Document->new(file_path => $file);
-    $doc->editor( $doc_bar{'leftup'}->add_edit_page(1, $doc->file_name) );
+    my $main_doc_bar = _active_docbar();
+    $doc->editor( $main_doc_bar->add_edit_page(1, $doc->file_name) );
     Kephra::DocumentStash::add( $doc );
     return $doc;
 }