Commits

Herbert Breunung committed e5217c2

refactore some smartness into File.pm more should follow

Comments (0)

Files changed (2)

lib/Kephra/App/Panel/Editor.pm

 	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) {
+	if ($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->focus();
-		Kephra::API::widget('win')->refresh_title();
 	# make new editor
 	} else {
 		my $ed = Kephra::App::Editor->new( $main_doc_bar );
 		$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();
 	}
+	Kephra::API::widget('win')->refresh_title();
 	return $doc;
 }
 
+sub raise_file {
+	my $file = shift;
+	_active_docbar()->raise_panel( 
+		Kephra::DocumentStash::get_by_path($file)->{editor}
+	);
+}
+
 sub active_title {
 	my $nb = _active_docbar();
 	$nb->GetPageText( $nb->GetSelection );

lib/Kephra/File.pm

 use File::Spec;
 use Kephra::API;
 use Kephra::App::Panel::Editor;
+use Kephra::DocumentStash;
 
 package Kephra::File;
 
 	my $file = _normalize_name( shift );
 	return unless $file and -e $file;
 
+	# doc is alread open
+	return Kephra::App::Panel::Editor::raise_file( $file)
+		if Kephra::DocumentStash::file_loaded($file);
+
 	my $doc = Kephra::App::Panel::Editor::create_document($file);
 	return unless ref $doc eq 'Kephra::Document';
 	open my $FH, '<', $file;