Commits

Herbert Breunung committed ce820f1

docstash is now the doc boss

  • Participants
  • Parent commits 6c95f3a
  • Branches sp2

Comments (0)

Files changed (4)

File lib/ded/Kephra/App/DocBar.pm

 	my ($self, $label, $page) = @_;
 	$page = $self->GetSelection unless defined $page;
 	return warning("need a Kephra::App::Panel or valid position number") 
-		unless (looks_like_number($page) and $self->valid_page_pos($page))
-		or is_editor($page) or is_panel($page);
+		unless is_panel($page) or (looks_like_number($page) and $self->valid_page_pos($page));
 	my $found = $self->GetPageIndex($page);
 	my $position = $found eq &Wx::wxNOT_FOUND ? $page : $found;
 	$self->SetPageText( $position, $label );
 sub remove_page {
 	my ($self, $page) = @_;
 	my $internal_position = $self->GetPageIndex( $page );
-	if ($internal_position == -1 and is_editor($page) ){
-		for my $index (0 .. $self->GetPageCount){
-			$internal_position = $index
-				if is_editor($self->GetPage($index))
-				and $self->GetPage($index)->GetDocPointer() == $page->GetDocPointer();
-		}
-	}
 	return warning("could not remove requested page $page") if $internal_position == -1;
 
 	$self->RemovePage( $internal_position );

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

 	});
 	Wx::Event::EVT_STC_SAVEPOINTREACHED($self, -1, sub {
 		Kephra::API::app_window()->refresh_title();
-		#Kephra::App::Part::Editor::refresh_doc_label()
+		Kephra::DocumentStash::refresh_doc_label($self);
 	});
 	Wx::Event::EVT_STC_SAVEPOINTLEFT($self, -1, sub {
 		Kephra::API::app_window()->refresh_title();
-		#Kephra::App::Part::Editor::refresh_doc_label() 
+		Kephra::DocumentStash::refresh_doc_label($self);
 	});
 	Wx::Event::EVT_SET_FOCUS( $self, sub {
 		my ($ed, $event ) = @_;

File lib/ded/Kephra/App/Part/Main.pm

 }
 
 
-sub add_doc {
-	my ($self, $doc) = @_;
-	$self->{'doc_bar'}[0]->add_page( $doc->{'editor'}, $doc->{'title'}, -1, 1);
-	if ($self->doc_bar_count() > 1){
-		my $ed1 = Kephra::App::Editor->new($self->{'doc_bar'}[1]);
-		$ed1->SetDocPointer( $doc->{'editor'}->GetDocPointer() );
-		$self->{'doc_bar'}[1]->add_page( $ed1, $doc->{'title'}, -1, 1);
-	}
-}
-sub remove_doc {
-	my ($self, $doc) = @_;
-	$self->{'doc_bar'}[0]->remove_page( $doc->{'editor'});
-	$self->{'doc_bar'}[1]->remove_page( $doc->{'editor'});
-
-}
-
-
 sub switch_focus {
 	my ($self) = @_;
 	$self->{'active'} = $self->{'active'} == 0 ? 1 : 0;
 	#$self->active_doc_bar()->raise_page();
 }
 
-sub update_page_title {
-	my ($self, $doc) = @_;
-	
-}
 
 1;

File lib/ded/Kephra/DocumentStash.pm

 	return $doc;
 }
 
+
 sub find_doc_by   {
 	my ($criterion, $selector) = @_;
 	return $document{$criterion}{$selector};
 	delete $document{'file_path'}{$oldfile} if defined $oldfile;
 	$document{'file_path'}{$file_path} = $doc;
 }
+sub get_anon_title { 'untitled ' . $lowest_free_anon_NR++ }
 
 
 #
 	return $doc;
 }
 
+sub add_doc_bar    {
+	my $doc_bar = shift;
+	for my $doc (all_docs()){
+		$doc->{'panel'}{$doc_bar} = Kephra::App::Panel->new($doc_bar);
+		$doc->{'editor'}{$doc_bar} = Kephra::App::Editor->new($doc->{'panel'}{$doc_bar});
+		$doc->{'panel'}{$doc_bar}->append_expanded($doc->{'editor'}{$doc_bar});
+		$doc->{'editor'}{$doc_bar}->SetDocPointer( $doc->{'active_editor'}->GetDocPointer() );
+		$document{'panel'}{ $doc->{'panel'}{$doc_bar} } = $doc;
+		$document{'editor'}{ $doc->{'editor'}{$doc_bar} } = $doc;
+		$doc_bar->add_page( $doc->{'panel'}{$doc_bar}, $doc->{'title'}, -1, 0);
+	}
+}
+sub remove_doc_bar {
+	my $doc_bar = shift;
+	for my $doc (all_docs()){
+		$doc_bar->remove_page( $doc->{'panel'}{$doc_bar} );
+		$document{'editor'}{ $doc->{'editor'}{$doc_bar} }->Destroy();
+		$document{'panel'}{ $doc->{'panel'}{$doc_bar} }->Destroy();
+		delete $document{'panel'}{ $doc->{'panel'}{$doc_bar} };
+		delete $document{'editor'}{ $doc->{'editor'}{$doc_bar} };
+		delete $doc->{'panel'}{$doc_bar};
+		delete $doc->{'editor'}{$doc_bar};
+	}
+}
+
+
 sub delete_doc {
 	my $doc = shift;
 	return unless is_document($doc);
-	delete $document{$_}{$doc->{$_}} for qw(editor file_path);
+	delete $document{$_}{$doc->{$_}} for qw(file_path);
+	delete $document{'panel'}{$_} for values %{$doc->{'editor'}};
 	delete $document{'panel'}{$_} for values %{$doc->{'panel'}};
 	doc_panel()->remove_doc( $doc );
-	$doc->DESTROY;
 }
 
-sub get_anon_title { 'untitled ' . $lowest_free_anon_NR++ }
 
+sub refresh_doc_label {
+	my $ed = shift;
+	my $doc = find_doc_by('editor', $ed);
+	return unless defined $doc;
+	my $title = $doc->{'title'};
+	$title .= ' *' unless $doc->saved();
+	for my $doc_bar (doc_panel()->all_doc_bar()){
+		$doc_bar->set_page_title($title, $doc->{'panel'}{$doc_bar});
+	}
+}
 
-sub add_doc_bar    {
-	my $doc_bar = shift;
-
-}
-sub remove_doc_bar {
-	my $doc_bar = shift;
-	#$document{'bar'}{$doc};
-}
 
 sub do_with_all_doc {}
 sub do_with_all_ed  {}
 
 1;
-
-
-__END__
-my %document = ('ID'=>{});             # keys of subhashes: ID editor panel file
-active_panel  
-previous      
-sub rename_file {
-	my $doc = find( shift );
-	Kephra::Log::warning('need a ' . DOC_CLASS . " thats in stash, not $doc!", 1)
-		unless is_doc($doc);
-	my $file = $doc->prev_file_path;
-	delete $document{'file'}{$file} if $file and $document{'file'}{$file};
-	if ($doc->file_path){
-		$document{'file'}{$doc->file_path} = $doc;
-		unless ($doc->prev_file_path) {
-			delete $document{'anon'}{$doc->anon_NR};
-			$doc->anon_NR(0);
-		}
-	} else {
-		if ($doc->prev_file_path) {
-			$doc->anon_NR( $lowest_free_anon_NR++ );
-			$document{'anon'}{$doc->anon_NR} = $doc;
-		}
-	}
-}