Commits

Herbert Breunung committed 29977f3

switch active toolbar by click

Comments (0)

Files changed (6)

lib/Kephra/API/Docs.pm

 	my $doc = find( shift );
 	Kephra::Log::warning('need a ' . DOC_CLASS . " thats in stash, not $doc!", 1)
 		unless is_doc($doc);
-	for (keys %{$document{'file'}} ){
-		delete $document{'file'}{$_} if $document{'file'}{$_} eq $doc;
-	}
+	my $file = $doc->old_file_path;
+	delete $document{'file'}{$file} if $file and $document{'file'}{$file};
 	if ($doc->file_path){
 		$document{'file'}{$doc->file_path} = $doc;
 		unless ($doc->old_file_path) {
 			delete $document{'anon'}{$doc->anon_NR};
 			$doc->anon_NR(0);
 		}
+	} else {
+		if ($doc->old_file_path) {
+			$doc->anon_NR( $lowest_free_anon_NR++ );
+			$document{'anon'}{$doc->anon_NR} = $doc;
+		}
 	}
 }
 

lib/Kephra/App/Bar/Document.pm

 		Kephra::File::close_active();
 	});
 	# keep focus on editor even when klicking on tab bar
-	#Wx::Event::EVT_LEFT_UP($self, sub { Kephra::API::active_editor()->focus; print "--"; });
+	#Wx::Event::EVT_LEFT_DOWN( $self, sub { Kephra::API::active_editor()->focus; print "--down"; });
 	#$self->Connect( -1, -1, &Wx::wxEVT_SET_FOCUS, sub {  print "--"; } )
+	#Wx::Event::EVT_SET_FOCUS( $self, sub { my ($bar, $event ) = @_; $event->Skip; say "--bar"; });
 }
 
 sub unmount_events {
 	# if just selecting the currrent, only tab drives focus nuts
 	$self->SetSelection( $position ) unless $position == $self->GetSelection;
 	my $page = $self->GetPage($position);
-	my $doc = Kehra::API::Docs::find($page);
+	my $doc = Kephra::API::Docs::find($page);
 	Kephra::API::focus ( defined $doc ? $doc->editor->{$self} : $page );
 }
 

lib/Kephra/App/Editor.pm

 		($self, -1, sub { Kephra::App::Part::Editor::refresh_doc_label() });
 	Wx::Event::EVT_STC_SAVEPOINTLEFT
 		($self, -1, sub { Kephra::App::Part::Editor::refresh_doc_label() });
+	Wx::Event::EVT_SET_FOCUS( $self, sub {
+		my ($ed, $event ) = @_; $event->Skip;
+		Kephra::App::Part::Editor::select_docbar( $ed->GetParent->GetParent );
+	});
+
 	#Wx::Event::EVT_DROP_FILES       ($ep, sub{});
 	#Wx::Event::EVT_STC_START_DRAG   ($ep, -1, sub {
 	#Wx::Event::EVT_STC_DRAG_OVER    ($ep, -1, sub { $droppos = $_[1]->GetPosition });

lib/Kephra/App/Part/Editor.pm

 package Kephra::App::Part::Editor;
 our @ISA = 'Kephra::App::Panel';
 my ($active_bar, @passive_bar, $panel);
+use Scalar::Util qw(blessed);
 
 Kephra::API::Command::register({
  'docbar-prev' =>{sub=>'select_docbar_prev', label=>'Prev Docbar',  keys=>'alt+pageup'},
 	$active_bar = pop @passive_bar;
 	$active_bar->raise_page( $active_bar->GetSelection );
 }
+sub select_docbar {
+	my $bar = shift;
+	return Kephra::Log::warning("need a Kephra::App::Bar::Document instance") 
+		unless ref $bar eq 'Kephra::App::Bar::Document';
+	return if $active_bar eq $bar;
+	my $i;
+	for (0 ..  $#passive_bar){ $i = $_ if $bar eq $passive_bar[$_] }
+	return Kephra::Log::warning("$bar is unknown") unless defined $i;
+	@passive_bar = ( splice(@passive_bar, $i+1), $active_bar, splice(@passive_bar, 0, $i) );
+	$active_bar = $bar;
+	$active_bar->raise_page( $active_bar->GetSelection );
+}
+
 
 sub switch_bar{
 	

lib/Kephra/Document.pm

 	coerce  =>  sub { Kephra::File::normalize_path($_[0]) },
 	trigger =>  sub {
 		my $self = shift;
-		return if $self->old_file_path and $self->old_file_path eq $self->file_path;
-		my @path_parts = File::Spec->splitpath( $self->file_path );
-		$self->_set_file_dir( $path_parts[1] );
-		$self->_set_file_name( $path_parts[2] );
+		return if $self->old_file_path and $self->file_path
+				and $self->old_file_path eq $self->file_path;
 		Kephra::API::Docs::rename_file($self) if $self->ID;
 
 		if ($self->file_path) {
+			my @path_parts = File::Spec->splitpath( $self->file_path );
+			$self->_set_file_dir( $path_parts[1] );
+			$self->_set_file_name( $path_parts[2] );
+
 			my $title = $path_parts[2];
 			$title = substr( $title, 0, $max_title_width - 2 ) . '..'
 				if length($title) > $max_title_width and $max_title_width > 7;
 			$self->_set_title($title);
+		} else {
+			$self->_set_title('<untitled '.$self->anon_NR.'>');
 		}
-
 		$self->_set_old_file_path( $self->file_path );
 	});
 has file_dir     => ( is => 'rwp', );
 	$self->_set_ID( Kephra::API::Docs::add($self) );
 	$self->_set_title('<untitled '.$self->anon_NR.'>') unless $self->file_path;
 }
-sub DEMOLISH { Kephra::API::Docs::remove($_[0]); #say "demolish $_[0]"; 
+sub DEMOLISH { Kephra::API::Docs::remove($_[0]); say "demolish $_[0]"; 
 }
 
 sub raise { Kephra::API::focus( shift->panel ) }

lib/Kephra/File.pm

 			$ed->ClearAll();
 			$ed->SetSavePoint;
 			$ed->EmptyUndoBuffer;
-			$active_bar->set_page_title('');
+			$doc->file_path('');
+			#$active_bar->set_page_title($doc->title;);
 		}
-		Kephra::API::main_window()->refresh_title();
 	}
+	Kephra::API::main_window()->refresh_title();
+	Kephra::API::focus($active_bar->GetSelection);
+
 }
 sub close_active { Kephra::File::close( Kephra::API::document() )}
 sub close_all    { Kephra::File::close( Kephra::API::all_documents() ) }